@@ -14817,6 +14817,18 @@ static void dump_single_byte_code(JSContext *ctx, const uint8_t *pc,
14817
14817
static void print_func_name(JSFunctionBytecode *b);
14818
14818
#endif
14819
14819
14820
+ static bool needs_backtrace(JSValue exc)
14821
+ {
14822
+ JSObject *p;
14823
+
14824
+ if (JS_VALUE_GET_TAG(exc) != JS_TAG_OBJECT)
14825
+ return false;
14826
+ p = JS_VALUE_GET_OBJ(exc);
14827
+ if (p->class_id != JS_CLASS_ERROR)
14828
+ return false;
14829
+ return !find_own_property1(p, JS_ATOM_stack);
14830
+ }
14831
+
14820
14832
/* argv[] is modified if (flags & JS_CALL_FLAG_COPY_ARGV) = 0. */
14821
14833
static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
14822
14834
JSValue this_obj, JSValue new_target,
@@ -17290,8 +17302,12 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
17290
17302
}
17291
17303
}
17292
17304
exception:
17293
- sf->cur_pc = pc;
17294
- build_backtrace(ctx, rt->current_exception, JS_UNDEFINED, NULL, 0, 0, 0);
17305
+ if (needs_backtrace(rt->current_exception)
17306
+ || JS_IsUndefined(ctx->error_back_trace)) {
17307
+ sf->cur_pc = pc;
17308
+ build_backtrace(ctx, rt->current_exception, JS_UNDEFINED,
17309
+ NULL, 0, 0, 0);
17310
+ }
17295
17311
if (!JS_IsUncatchableError(ctx, rt->current_exception)) {
17296
17312
while (sp > stack_buf) {
17297
17313
JSValue val = *--sp;
@@ -33325,9 +33341,15 @@ static JSValue JS_EvalInternal(JSContext *ctx, JSValue this_obj,
33325
33341
const char *input, size_t input_len,
33326
33342
const char *filename, int line, int flags, int scope_idx)
33327
33343
{
33344
+ JSRuntime *rt = ctx->rt;
33345
+
33328
33346
if (unlikely(!ctx->eval_internal)) {
33329
33347
return JS_ThrowTypeError(ctx, "eval is not supported");
33330
33348
}
33349
+ if (!rt->current_stack_frame) {
33350
+ JS_FreeValueRT(rt, ctx->error_back_trace);
33351
+ ctx->error_back_trace = JS_UNDEFINED;
33352
+ }
33331
33353
return ctx->eval_internal(ctx, this_obj, input, input_len, filename, line,
33332
33354
flags, scope_idx);
33333
33355
}
0 commit comments