per_context: add warning to Atomics.wake

PR-URL: https://github.com/nodejs/node/pull/21518
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
Gus Caplan authored and Michaël Zasso committed 2018-06-28 20:41:12 +02:00
1 parent eb8d60b447
commit 0a1e8e0172
3 files changed
+55 -9

No files matched your search

+2 -1
View File
@@ -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',
]
};
+41 -5
View File
@@ -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));
+12 -3
View File
@@ -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);