util: fix isInsideNodeModules() check#30014
Conversation
Co-authored-by: Andy Locascio <[email protected]>
bacdc47 to
7976e06
Compare
|
I made this change so that I think it would serve better for electron to figure out a way to use node's prepareStackTrace. I think you can manually call |
|
I’d also be good with reverting 70c2444 as an option in general. |
|
@addaleax happy to help out with whatever the end-solution is here - the repl changes are fine for us so for our purposes we're happy with as thinly-scoped a PR as possible i think! |
|
I'm not so sure that it's okay to consider a node environment valid if the embedder overrides our hooks into V8. @codebytere do you know why electron is overriding our hook in the first place? |
|
@devsnek but it's not a hook into v8 as much as a mutable JS prototype, right? Since the current Node.js code relies on a v8 cross-context pollution (linked in my PR body), you all would hit this same issue when you upgraded to our current version of v8 (v7.9.74) that we're currently using in Electron 🤔 |
|
Our current hook runs for everything within an isolate, it isn't context specific. From there, it does context-specific dispatch (the line with |
|
@devsnek right - the issue here is that the test relies on Node's version of It seems like a fair assumption that we'd want to have behavior parity between the two versions, which is no longer the case with the change that was made to cause this issue. |
|
@codebytere node's version is identical except that it also falls back to the old v8 behaviour, which is needed for a lot of packages in the npm ecosystem. I assume electron wants to support those too? Additionally, I'm not sure what setup electron has where its both running node tests but doesn't have a proper node environment, so I can't really provide any good advice to that point. |
|
The |
|
@codebytere well yes, but if you're running node tests outside of a node environment with that callback, having failures seems expected to me. |
|
@devsnek i'm not married to this solution - i'd just like to see if we can find a solution that allows both to work. I'm super happy to switch up my approach in this PR, my goal is just to have |
|
I still don't understand why electron has disabled node's prepareStackTrace callback. |
|
@devsnek we don't explicitly disable it; this is at its root because we don't call Node.js' exposed As a result, |
|
I’ve been wondering for a while whether we should maybe expose the V8 callbacks that we set through our public API … maybe this would be a good start? That would also potentially allow embedders to provide per-Context behaviour when that applies, which would be good imo. If not, I think we should expose the two-argument variant of |
|
Also to elaborate a bit - we need to use this same isolate to set up |
|
@devsnek given my explanation above, what are your thoughts on a path forward here? |
|
if electron doesn't set up the isolate correctly, for whatever reason, things will fail to work correctly. On the node side, maybe we can expose SetUpIsolateForNode? |
|
Closing this given that we went the allow-custom-callbacks route in the end. |
This PR reverts away from use of
overrideStackTraceinisInsideNodeModules()introduced in #29777.At the moment, Electron uses the v8 version of
Error.prepareStackTraceas defined inv7.9.74(where https://crbug.com/v8/7848 has been fixed) and not the one polyfilled here: #23926. As a result, we were experiencing failures inparallel/test-buffer-constructor-outside-node-modules.jsbecause the polyfilledprepareStackTracewas not being run and thus the following code inside that function would never be executed:so
isInsideNodeModules()would always return false.This change still allows for
isInsideNodeModules()to be tested correctly while retaining correct functionality for Electron. SinceisInsideNodeModules()is only ever invoked when determining whether to print a deprecation warning fornew Buffer(), this change should have no effects on end users.cc @devsnek @loc
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesCo-authored-by: Andy Locascio [email protected]