Skip to content

Commit eab8251

Browse files
authored
Fix Error.stackTraceLimit = Infinity (#861)
1 parent b091b66 commit eab8251

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

quickjs.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -38051,10 +38051,16 @@ static JSValue js_error_set_stackTraceLimit(JSContext *ctx, JSValue this_val, JS
3805138051
{
3805238052
if (JS_IsUndefined(this_val) || JS_IsNull(this_val))
3805338053
return JS_ThrowTypeErrorNotAnObject(ctx);
38054-
int limit;
38055-
if (JS_ToInt32(ctx, &limit, value) < 0)
38054+
double limit = 0;
38055+
if (JS_ToFloat64(ctx, &limit, value) < 0)
3805638056
return JS_EXCEPTION;
38057-
ctx->error_stack_trace_limit = limit;
38057+
if (isfinite(limit)) {
38058+
ctx->error_stack_trace_limit = limit;
38059+
} else if (isnan(limit) || limit == -INFINITY) {
38060+
ctx->error_stack_trace_limit = 0;
38061+
} else {
38062+
ctx->error_stack_trace_limit = INT32_MAX;
38063+
}
3805838064
return JS_UNDEFINED;
3805938065
}
3806038066

tests/bug858.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {assert} from "./assert.js";
2+
3+
Error.stackTraceLimit = Infinity;
4+
assert(new Error("error").stack.includes("bug858.js")); // stack should not be empty
5+
6+
Error.stackTraceLimit = -Infinity;
7+
assert(!new Error("error").stack.includes("bug858.js")); // stack should be empty
8+
9+
Error.stackTraceLimit = NaN;
10+
assert(!new Error("error").stack.includes("bug858.js")); // stack should be empty

0 commit comments

Comments
 (0)