Skip to content
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

Error.prepareStackTrace is exposed to user code #9062

Closed
ghost opened this issue Jan 9, 2021 · 6 comments
Closed

Error.prepareStackTrace is exposed to user code #9062

ghost opened this issue Jan 9, 2021 · 6 comments

Comments

@ghost
Copy link

ghost commented Jan 9, 2021

Title should describe this well enough.

Input:

console.log("prepareStackTrace" in Error);

Expected output:

false

Actual output:

true

I don't think any browsers do this.

Exposed here:

deno/runtime/js/99_main.js

Lines 158 to 167 in f3ead9c

// only for compiled standalone binaries.
let prepareStackTrace;
if (runtimeOptions.applySourceMaps) {
prepareStackTrace = core.createPrepareStackTrace(
errorStack.opApplySourceMap,
);
} else {
prepareStackTrace = core.createPrepareStackTrace();
}
Error.prepareStackTrace = prepareStackTrace;

@nayeemrmn
Copy link
Collaborator

nayeemrmn commented Jan 9, 2021

This is intentional, Error.prepareStackTrace() is a V8 concept supported in Chrome, but it doesn't have a default value. It does for us because we use it for internal purposes. There's a TODO to expose it properly for users in the way Chrome does:

// TODO(nayeemrmn): Support `Error.prepareStackTrace()`. We currently use this
// internally in a way that makes it unavailable for users.

@ghost
Copy link
Author

ghost commented Jan 9, 2021

This is intentional, Error.prepareStackTrace() is a V8 concept...

Exactly, it's a nonstandard V8 "feature."
Imho, to use it at all breaks web compatibility to a certain degree.

@nayeemrmn
Copy link
Collaborator

This is discussed in #5254 about Error.captureStackTrace. The gist of it is that Deno is tightly coupled to V8, and if V8 exposes something like this with documentation that suggests it's for user code (not host environments) to take advantage of, we would just pass it on. It's not clear how feasible it is to hide it, and we're only making the web compatibility trade-offs which any V8-based web browser is.

@ghost
Copy link
Author

ghost commented Jan 9, 2021

Oh, there was a PR explicitly exposing it, didn't find that.

In that case, is there a plan to allow users to take advantage of it?
Where is it used internally?

Could I try setting up a hacky workaround in the meanwhile?

@nayeemrmn
Copy link
Collaborator

(Its friend Error.captureStackTrace was explicitly exposed, Error.prepareStackTrace is the one that's used internally for now.) In the future I think we can replace our internal use of Error.prepareStackTrace = ourCallback with Isolate::set_prepare_stack_trace_callback(our_callback) in Rust. This is mentioned as point 2 in #7644.

@ghost
Copy link
Author

ghost commented Jan 9, 2021

Closing, as this is known and intentional.

@ghost ghost closed this as completed Jan 9, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant