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:
parent
d13cdd9c48
commit
dcb371ff1f
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user