@@ -55047,6 +55047,32 @@ static js_mutex_t js_atomics_mutex;
5504755047static struct list_head js_atomics_waiter_list =
5504855048 LIST_HEAD_INIT(js_atomics_waiter_list);
5504955049
55050+ // no-op: Atomics.pause() is not allowed to block or yield to another
55051+ // thread, only to hint the CPU that it should back off for a bit;
55052+ // the amount of work we do here is a good enough substitute
55053+ static JSValue js_atomics_pause(JSContext *ctx, JSValue this_obj,
55054+ int argc, JSValue *argv)
55055+ {
55056+ double d;
55057+
55058+ if (argc > 0) {
55059+ switch (JS_VALUE_GET_TAG(argv[0])) {
55060+ case JS_TAG_FLOAT64: // accepted if and only if fraction == 0.0
55061+ d = JS_VALUE_GET_FLOAT64(argv[0]);
55062+ if (isfinite(d))
55063+ if (0 == modf(d, &d))
55064+ break;
55065+ // fallthru
55066+ default:
55067+ return JS_ThrowTypeError(ctx, "not an integral number");
55068+ case JS_TAG_UNDEFINED:
55069+ case JS_TAG_INT:
55070+ break;
55071+ }
55072+ }
55073+ return JS_UNDEFINED;
55074+ }
55075+
5505055076static JSValue js_atomics_wait(JSContext *ctx,
5505155077 JSValue this_obj,
5505255078 int argc, JSValue *argv)
@@ -55176,6 +55202,7 @@ static const JSCFunctionListEntry js_atomics_funcs[] = {
5517655202 JS_CFUNC_MAGIC_DEF("load", 2, js_atomics_op, ATOMICS_OP_LOAD ),
5517755203 JS_CFUNC_DEF("store", 3, js_atomics_store ),
5517855204 JS_CFUNC_DEF("isLockFree", 1, js_atomics_isLockFree ),
55205+ JS_CFUNC_DEF("pause", 0, js_atomics_pause ),
5517955206 JS_CFUNC_DEF("wait", 4, js_atomics_wait ),
5518055207 JS_CFUNC_DEF("notify", 3, js_atomics_notify ),
5518155208 JS_PROP_STRING_DEF("[Symbol.toStringTag]", "Atomics", JS_PROP_CONFIGURABLE ),
0 commit comments