Skip to content
Permalink
Browse files

per_context: add warning to Atomics.wake

PR-URL: #21518
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information...
devsnek authored and targos committed Jun 25, 2018
1 parent eb8d60b commit 0a1e8e01727ff6b55878427d032f2b1d6f5c8cd1
Showing with 55 additions and 9 deletions.
  1. +2 −1 lib/internal/bootstrap/cache.js
  2. +41 −5 lib/internal/per_context.js
  3. +12 −3 test/parallel/test-atomics-notify.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',
]
};
@@ -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));
@@ -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);

0 comments on commit 0a1e8e0

Please sign in to comment.
You can’t perform that action at this time.