-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
repl,worker: fix crash when SharedArrayBuffer disabled #39718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ const { | |
ArrayPrototypeSplice, | ||
ObjectDefineProperty, | ||
PromisePrototypeCatch, | ||
globalThis: { Atomics }, | ||
globalThis: { Atomics, SharedArrayBuffer }, | ||
} = primordials; | ||
|
||
const { | ||
|
@@ -142,6 +142,9 @@ port.on('message', (message) => { | |
const originalCwd = process.cwd; | ||
|
||
process.cwd = function() { | ||
// SharedArrayBuffers can be disabled with --no-harmony-sharedarraybuffer. | ||
if (typeof SharedArrayBuffer === 'undefined') return originalCwd(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine but we could prevent replacing |
||
|
||
const currentCounter = Atomics.load(cwdCounter, 0); | ||
if (currentCounter === lastCounter) | ||
return cachedCwd; | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,17 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Flags: --no-harmony-sharedarraybuffer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
'use strict'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
const common = require('../common'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
const assert = require('assert'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { isMainThread, Worker } = require('worker_threads'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Regression test for https://github.com/nodejs/node/issues/39717. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
const w = new Worker(__filename); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
w.on('exit', common.mustCall((status) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert.strictEqual(status, 2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!isMainThread) process.exit(2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+7
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @codebytere Are you ok if we commit this suggestion, run tests, check with @BridgeAR if they can then approve the PR,, and hopefully land? Or is there something about this suggestion that would make you reluctant to do that? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
main
is going to be executed more than once. As such, it's probably best to move the check to the top of the file.