Skip to content

Commit f99a3ea

Browse files
committed
[atomics] add notify alias
1 parent 8944a4f commit f99a3ea

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ module.exports = {
243243
'node-core/no-unescaped-regexp-dot': 'error',
244244
},
245245
globals: {
246+
Atomics: false,
246247
BigInt: false,
247248
BigInt64Array: false,
248249
BigUint64Array: false,

src/node.cc

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3478,16 +3478,37 @@ Local<Context> NewContext(Isolate* isolate,
34783478
auto context = Context::New(isolate, nullptr, object_template);
34793479
if (context.IsEmpty()) return context;
34803480
HandleScope handle_scope(isolate);
3481-
auto intl_key = FIXED_ONE_BYTE_STRING(isolate, "Intl");
3482-
auto break_iter_key = FIXED_ONE_BYTE_STRING(isolate, "v8BreakIterator");
34833481
context->SetEmbedderData(
34843482
ContextEmbedderIndex::kAllowWasmCodeGeneration, True(isolate));
3483+
3484+
auto intl_key = FIXED_ONE_BYTE_STRING(isolate, "Intl");
3485+
auto break_iter_key = FIXED_ONE_BYTE_STRING(isolate, "v8BreakIterator");
34853486
Local<Value> intl_v;
34863487
if (context->Global()->Get(context, intl_key).ToLocal(&intl_v) &&
34873488
intl_v->IsObject()) {
34883489
Local<Object> intl = intl_v.As<Object>();
34893490
intl->Delete(context, break_iter_key).FromJust();
34903491
}
3492+
3493+
// https://github.com/nodejs/node/issues/21219
3494+
// TODO(devsnek): remove when v8 supports Atomics.notify
3495+
auto atomics_key = FIXED_ONE_BYTE_STRING(isolate, "Atomics");
3496+
Local<Value> atomics_v;
3497+
if (context->Global()->Get(context, atomics_key).ToLocal(&atomics_v) &&
3498+
atomics_v->IsObject()) {
3499+
Local<Object> atomics = atomics_v.As<Object>();
3500+
auto wake_key = FIXED_ONE_BYTE_STRING(isolate, "wake");
3501+
3502+
Local<Value> wake = atomics->Get(context, wake_key).ToLocalChecked();
3503+
auto notify_key = FIXED_ONE_BYTE_STRING(isolate, "notify");
3504+
3505+
v8::PropertyDescriptor desc(wake, true);
3506+
desc.set_enumerable(false);
3507+
desc.set_configurable(true);
3508+
3509+
atomics->DefineProperty(context, notify_key, desc).ToChecked();
3510+
}
3511+
34913512
return context;
34923513
}
34933514

test/parallel/test-atomics-notify.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
const assert = require('assert');
6+
const { runInNewContext } = require('vm');
7+
8+
assert.strictEqual(Atomics.wake, Atomics.notify);
9+
10+
assert(runInNewContext('Atomics.wake === Atomics.notify'));

0 commit comments

Comments
 (0)