GeezerVison is showing github.com — per_context: add warning to Atomics.wake · nodejs/node@0a1e8e0
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/bootstrap/cache.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,6 +25,7 @@ module.exports = { | 25 | 25 | // the code cache is also used when compiling these | 26 | 26 | // two files. | 27 | 27 | 'internal/bootstrap/loaders', | 28 | | - 'internal/bootstrap/node' | | 28 | + 'internal/bootstrap/node', | | 29 | + 'internal/per_context', | 29 | 30 | ] | 30 | 31 | }; |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/per_context.js +41-5Lines changed: 41 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | delete global.Intl.v8BreakIterator; | 8 | 8 |
| 9 | 9 | // 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 | + }, | 15 | 51 | }); | 16 | 52 | }(this)); |
Collapse file Copy file name to clipboard +12-3Lines changed: 12 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 'use strict'; | 2 | 2 |
| 3 | | -require('../common'); | | 3 | +const { expectWarning, noWarnCode } = require('../common'); | 4 | 4 |
| 5 | 5 | const assert = require('assert'); | 6 | 6 | const { runInNewContext } = require('vm'); | 7 | 7 |
| 8 | | -assert.strictEqual(Atomics.wake, Atomics.notify); | | 8 | +assert.strictEqual(typeof Atomics.wake, 'function'); | | 9 | +assert.strictEqual(typeof Atomics.notify, 'function'); | 9 | 10 |
| 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); |
|