diff --git a/lib/internal/bootstrap/cache.js b/lib/internal/bootstrap/cache.js index a3d22ba020979e..17c14e816ff668 100644 --- a/lib/internal/bootstrap/cache.js +++ b/lib/internal/bootstrap/cache.js @@ -25,6 +25,7 @@ module.exports = { // the code cache is also used when compiling these // two files. 'internal/bootstrap/loaders', - 'internal/bootstrap/node' + 'internal/bootstrap/node', + 'internal/per_context', ] }; diff --git a/lib/internal/per_context.js b/lib/internal/per_context.js index 77a44d52b937e1..bdbad5344ff430 100644 --- a/lib/internal/per_context.js +++ b/lib/internal/per_context.js @@ -7,10 +7,46 @@ delete global.Intl.v8BreakIterator; // https://github.com/nodejs/node/issues/21219 - Object.defineProperty(global.Atomics, 'notify', { - value: global.Atomics.wake, - writable: true, - enumerable: false, - configurable: true, + // Adds Atomics.notify and warns on first usage of Atomics.wake + + const AtomicsWake = global.Atomics.wake; + const ReflectApply = global.Reflect.apply; + + // wrap for function.name + function notify(...args) { + return ReflectApply(AtomicsWake, this, args); + } + + const warning = 'Atomics.wake will be removed in a future version, ' + + 'use Atomics.notify instead.'; + + let wakeWarned = false; + function wake(...args) { + if (!wakeWarned) { + wakeWarned = true; + + if (global.process !== undefined) { + global.process.emitWarning(warning, 'Atomics'); + } else { + global.console.error(`Atomics: ${warning}`); + } + } + + return ReflectApply(AtomicsWake, this, args); + } + + global.Object.defineProperties(global.Atomics, { + notify: { + value: notify, + writable: true, + enumerable: false, + configurable: true, + }, + wake: { + value: wake, + writable: true, + enumerable: false, + configurable: true, + }, }); }(this)); diff --git a/test/parallel/test-atomics-notify.js b/test/parallel/test-atomics-notify.js index dcca7a9fd16d2f..fc59d5aa331084 100644 --- a/test/parallel/test-atomics-notify.js +++ b/test/parallel/test-atomics-notify.js @@ -1,10 +1,19 @@ 'use strict'; -require('../common'); +const { expectWarning, noWarnCode } = require('../common'); const assert = require('assert'); const { runInNewContext } = require('vm'); -assert.strictEqual(Atomics.wake, Atomics.notify); +assert.strictEqual(typeof Atomics.wake, 'function'); +assert.strictEqual(typeof Atomics.notify, 'function'); -assert(runInNewContext('Atomics.wake === Atomics.notify')); +assert.strictEqual(runInNewContext('typeof Atomics.wake'), 'function'); +assert.strictEqual(runInNewContext('typeof Atomics.notify'), 'function'); + +expectWarning( + 'Atomics', + 'Atomics.wake will be removed in a future version, ' + + 'use Atomics.notify instead.', noWarnCode); + +Atomics.wake(new Int32Array(new SharedArrayBuffer(4)), 0, 0);