Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: add Atomics.notify alias #21413

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ module.exports = {
'node-core/no-unescaped-regexp-dot': 'error',
},
globals: {
Atomics: false,
BigInt: false,
BigInt64Array: false,
BigUint64Array: false,
Expand Down
25 changes: 23 additions & 2 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3478,16 +3478,37 @@ Local<Context> NewContext(Isolate* isolate,
auto context = Context::New(isolate, nullptr, object_template);
if (context.IsEmpty()) return context;
HandleScope handle_scope(isolate);
auto intl_key = FIXED_ONE_BYTE_STRING(isolate, "Intl");
auto break_iter_key = FIXED_ONE_BYTE_STRING(isolate, "v8BreakIterator");
context->SetEmbedderData(
ContextEmbedderIndex::kAllowWasmCodeGeneration, True(isolate));

auto intl_key = FIXED_ONE_BYTE_STRING(isolate, "Intl");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason these lines got moved?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a side-effect of the changes i was making before i finished up. should i change it back? they kinda make the order better anyway.

auto break_iter_key = FIXED_ONE_BYTE_STRING(isolate, "v8BreakIterator");
Local<Value> intl_v;
if (context->Global()->Get(context, intl_key).ToLocal(&intl_v) &&
intl_v->IsObject()) {
Local<Object> intl = intl_v.As<Object>();
intl->Delete(context, break_iter_key).FromJust();
}

// https://github.com/nodejs/node/issues/21219
// TODO(devsnek): remove when v8 supports Atomics.notify
auto atomics_key = FIXED_ONE_BYTE_STRING(isolate, "Atomics");
Local<Value> atomics_v;
if (context->Global()->Get(context, atomics_key).ToLocal(&atomics_v) &&
atomics_v->IsObject()) {
Local<Object> atomics = atomics_v.As<Object>();
auto wake_key = FIXED_ONE_BYTE_STRING(isolate, "wake");

Local<Value> wake = atomics->Get(context, wake_key).ToLocalChecked();
auto notify_key = FIXED_ONE_BYTE_STRING(isolate, "notify");

v8::PropertyDescriptor desc(wake, true);
desc.set_enumerable(false);
desc.set_configurable(true);

atomics->DefineProperty(context, notify_key, desc).ToChecked();
}

return context;
}

Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-atomics-notify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

require('../common');

const assert = require('assert');
const { runInNewContext } = require('vm');

assert.strictEqual(Atomics.wake, Atomics.notify);

assert(runInNewContext('Atomics.wake === Atomics.notify'));