Conversation
|
I don't think it's a good idea to make this public. What problem do you need to solve? |
|
We do some additional checks with the JS code - e.g. highlight an attempt to access filesystem functions or calling processes from contexts where users are not supposed to do so (e.g. do not call compiler during the "configure" stage). |
|
Would it help if you could create an Error object which collected the backtrace right there? The C equivalent to |
|
Do you mean JS_MakeError? Old API didn't have that... |
KInd of, yeah.
How come? Won't the engine get it right since it's running the source? Would the numbers be wrong if you computed the stack trace right there and then? I suppose the 1st frame would just be |
|
This PR does not expose the JS_BACKTRACE_FLAG constants. Should we? I'm unsure. It's odd though that you need to pass in the |
|
没必要暴露build_backtrace这个函数。 There is no need to expose // new Error("").stack
JSValue message = JS_NewString(ctx, "");
JSValue argv[] = {message};
JSValue error = JS_CallConstructor(ctx, error_t, 1, argv);
JS_FreeValue(ctx, message);
JS_FreeValue(ctx, error_t);
JSValue stack = JS_GetPropertyStr(ctx, error, "stack");
JS_FreeValue(ctx, error);
const char* cstr = JS_ToCString(ctx, stack);
std::string ret;
if (cstr) {
ret = cstr;
JS_FreeCString(ctx, cstr);
}
JS_FreeValue(ctx, stack);
return ret; |
|
So, I took another look and I noticed that we pass additional Any ideas how to achieve this without using |
|
That's only done for parse errors, not runtime errors. I think that speaks for not exposing build_backtrace directly but only through a public API wrapper that takes fewer arguments. I do wonder now if |
|
So, I exposed the
|
|
If that works, can you try this? #809 Then just creating a new Error with JS_NewError should be equivalent. |
|
Yup, this also works, thanks. |
|
Excellent! Shall we close this then? |
|
Sure |
|
FWIW, I verified that |
When using QuickJS as a JS engine it is desired sometimes to get a backtrace from outside JS and present it to user