-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
src,lib: fix assert when Error.prepareStackTrace
not overridden
#49212
base: main
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -65,6 +65,7 @@ const { openSync, closeSync, readSync } = require('fs'); | |
const { inspect } = require('internal/util/inspect'); | ||
const { isPromise, isRegExp } = require('internal/util/types'); | ||
const { EOL } = require('internal/constants'); | ||
const { getEmbedderOptions } = require('internal/options'); | ||
const { BuiltinModule } = require('internal/bootstrap/realm'); | ||
const { isError, deprecate } = require('internal/util'); | ||
|
||
|
@@ -293,8 +294,16 @@ function getErrMessage(message, fn) { | |
ErrorCaptureStackTrace(err, fn); | ||
if (errorStackTraceLimitIsWritable) Error.stackTraceLimit = tmpLimit; | ||
|
||
overrideStackTrace.set(err, (_, stack) => stack); | ||
const call = err.stack[0]; | ||
let call; | ||
if (getEmbedderOptions().hasPrepareStackTraceCallback) { | ||
overrideStackTrace.set(err, (_, stack) => stack); | ||
call = err.stack[0]; | ||
} else { | ||
const tmpPrepare = Error.prepareStackTrace; | ||
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. hmm actually I think both blocks are assuming 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 should work: https://github.com/v8/v8/blob/main/src/execution/messages.cc#L325-L335 What we polyfill in nodejs is that 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. Ah didn't realize that V8 has not removed it yet..in that case I wonder if instead of using the |
||
Error.prepareStackTrace = (_, stack) => stack; | ||
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 would throw if |
||
call = err.stack[0]; | ||
Error.prepareStackTrace = tmpPrepare; | ||
} | ||
|
||
const filename = call.getFileName(); | ||
const line = call.getLineNumber() - 1; | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -1233,6 +1233,13 @@ void GetEmbedderOptions(const FunctionCallbackInfo<Value>& args) { | |||
Local<Context> context = env->context(); | ||||
Local<Object> ret = Object::New(isolate); | ||||
|
||||
if (ret->Set(context, | ||||
FIXED_ONE_BYTE_STRING( | ||||
env->isolate(), "hasPrepareStackTraceCallback"), | ||||
Boolean::New(isolate, | ||||
!env->prepare_stack_trace_callback().IsEmpty())) | ||||
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 overridden when the realm is bootstrapped though, unless node/lib/internal/bootstrap/realm.js Line 449 in fe219e0
I wonder if this flag should've been moved into 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. @joyeecheung ah, we do call |
||||
.IsNothing()) return; | ||||
|
||||
if (ret->Set(context, | ||||
FIXED_ONE_BYTE_STRING(env->isolate(), "shouldNotRegisterESMLoader"), | ||||
Boolean::New(isolate, env->should_not_register_esm_loader())) | ||||
|
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.
instead of removing this, you can add
// eslint-disable-next-line no-restricted-syntax