Skip to content

Commit 0a1e8e0

Browse files
devsnektargos
authored andcommitted
per_context: add warning to Atomics.wake
PR-URL: #21518 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent eb8d60b commit 0a1e8e0

File tree

3 files changed

+55
-9
lines changed

3 files changed

+55
-9
lines changed

lib/internal/bootstrap/cache.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module.exports = {
2525
// the code cache is also used when compiling these
2626
// two files.
2727
'internal/bootstrap/loaders',
28-
'internal/bootstrap/node'
28+
'internal/bootstrap/node',
29+
'internal/per_context',
2930
]
3031
};

lib/internal/per_context.js

+41-5
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,46 @@
77
delete global.Intl.v8BreakIterator;
88

99
// https://github.com/nodejs/node/issues/21219
10-
Object.defineProperty(global.Atomics, 'notify', {
11-
value: global.Atomics.wake,
12-
writable: true,
13-
enumerable: false,
14-
configurable: true,
10+
// Adds Atomics.notify and warns on first usage of Atomics.wake
11+
12+
const AtomicsWake = global.Atomics.wake;
13+
const ReflectApply = global.Reflect.apply;
14+
15+
// wrap for function.name
16+
function notify(...args) {
17+
return ReflectApply(AtomicsWake, this, args);
18+
}
19+
20+
const warning = 'Atomics.wake will be removed in a future version, ' +
21+
'use Atomics.notify instead.';
22+
23+
let wakeWarned = false;
24+
function wake(...args) {
25+
if (!wakeWarned) {
26+
wakeWarned = true;
27+
28+
if (global.process !== undefined) {
29+
global.process.emitWarning(warning, 'Atomics');
30+
} else {
31+
global.console.error(`Atomics: ${warning}`);
32+
}
33+
}
34+
35+
return ReflectApply(AtomicsWake, this, args);
36+
}
37+
38+
global.Object.defineProperties(global.Atomics, {
39+
notify: {
40+
value: notify,
41+
writable: true,
42+
enumerable: false,
43+
configurable: true,
44+
},
45+
wake: {
46+
value: wake,
47+
writable: true,
48+
enumerable: false,
49+
configurable: true,
50+
},
1551
});
1652
}(this));

test/parallel/test-atomics-notify.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
'use strict';
22

3-
require('../common');
3+
const { expectWarning, noWarnCode } = require('../common');
44

55
const assert = require('assert');
66
const { runInNewContext } = require('vm');
77

8-
assert.strictEqual(Atomics.wake, Atomics.notify);
8+
assert.strictEqual(typeof Atomics.wake, 'function');
9+
assert.strictEqual(typeof Atomics.notify, 'function');
910

10-
assert(runInNewContext('Atomics.wake === Atomics.notify'));
11+
assert.strictEqual(runInNewContext('typeof Atomics.wake'), 'function');
12+
assert.strictEqual(runInNewContext('typeof Atomics.notify'), 'function');
13+
14+
expectWarning(
15+
'Atomics',
16+
'Atomics.wake will be removed in a future version, ' +
17+
'use Atomics.notify instead.', noWarnCode);
18+
19+
Atomics.wake(new Int32Array(new SharedArrayBuffer(4)), 0, 0);

0 commit comments

Comments
 (0)