atomis: add notify alias

PR-URL: https://github.com/nodejs/node/pull/21413
Refs: https://github.com/nodejs/node/issues/21219
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Gus Caplan authored and Michaël Zasso committed 2018-06-22 14:54:26 +02:00
1 parent 5d7218965d
commit a526b4e2c7
3 files changed
+34 -2

No files matched your search

+1
View File
@@ -243,6 +243,7 @@ module.exports = {
'node-core/no-unescaped-regexp-dot': 'error',
},
globals: {
Atomics: false,
BigInt: false,
BigInt64Array: false,
BigUint64Array: false,
+23 -2
View File
@@ -4031,16 +4031,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");
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;
}
+10
View File
@@ -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'));