From 84f3769ab1a0d3013b391f87b77f3106f991dbfc Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Tue, 19 Jun 2018 16:21:31 -0500 Subject: 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 Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: James M Snell --- .eslintrc.js | 1 + src/node.cc | 25 +++++++++++++++++++++++-- test/parallel/test-atomics-notify.js | 10 ++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 test/parallel/test-atomics-notify.js diff --git a/.eslintrc.js b/.eslintrc.js index dc83c0e8c1..a779517907 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -243,6 +243,7 @@ module.exports = { 'node-core/no-unescaped-regexp-dot': 'error', }, globals: { + Atomics: false, BigInt: false, BigInt64Array: false, BigUint64Array: false, diff --git a/src/node.cc b/src/node.cc index 292307e9da..6cf5f2ad84 100644 --- a/src/node.cc +++ b/src/node.cc @@ -3478,16 +3478,37 @@ Local 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 intl_v; if (context->Global()->Get(context, intl_key).ToLocal(&intl_v) && intl_v->IsObject()) { Local intl = intl_v.As(); 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 atomics_v; + if (context->Global()->Get(context, atomics_key).ToLocal(&atomics_v) && + atomics_v->IsObject()) { + Local atomics = atomics_v.As(); + auto wake_key = FIXED_ONE_BYTE_STRING(isolate, "wake"); + + Local 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; } diff --git a/test/parallel/test-atomics-notify.js b/test/parallel/test-atomics-notify.js new file mode 100644 index 0000000000..dcca7a9fd1 --- /dev/null +++ b/test/parallel/test-atomics-notify.js @@ -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')); -- cgit v1.2.3