Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.3k
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
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(); | ||
Member 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 |
|---|---|---|
| @@ -91,7 +91,8 @@ let cwdCounter; | ||
| const environmentData = new SafeMap(); | ||
| if (isMainThread){ | ||
| // SharedArrayBuffers can be disabled with --no-harmony-sharedarraybuffer. | ||
| if (isMainThread && typeof SharedArrayBuffer !== 'undefined'){ | ||
codebytere marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| cwdCounter = new Uint32Array(new SharedArrayBuffer(4)); | ||
| const originalChdir = process.chdir; | ||
| process.chdir = function(path){ | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,17 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Flags: --no-harmony-sharedarraybuffer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'use strict'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constcommon=require('../common'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constassert=require('assert'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const{ isMainThread, Worker }=require('worker_threads'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Regression test for https://github.com/nodejs/node/issues/39717. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constw=newWorker(__filename); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| w.on('exit',common.mustCall((status)=>{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.strictEqual(status,2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| })); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(!isMainThread)process.exit(2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines +7 to +17 Member 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
Member 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.
mainis going to be executed more than once. As such, it's probably best to move the check to the top of the file.