Skip to content

Commit

Permalink
per_context: add warning to Atomics.wake
Browse files Browse the repository at this point in the history
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 28, 2018
1 parent eb8d60b commit 0a1e8e0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lib/internal/bootstrap/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]
};
46 changes: 41 additions & 5 deletions lib/internal/per_context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
15 changes: 12 additions & 3 deletions test/parallel/test-atomics-notify.js
Original file line number Diff line number Diff line change
@@ -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.