Skip to content

Commit 7aabea9

Browse files
authored
Implement Error causes (#103)
1 parent d8ea7df commit 7aabea9

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

quickjs-atom.h

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ DEF(length, "length")
8282
DEF(fileName, "fileName")
8383
DEF(lineNumber, "lineNumber")
8484
DEF(message, "message")
85+
DEF(cause, "cause")
8586
DEF(errors, "errors")
8687
DEF(stack, "stack")
8788
DEF(name, "name")

quickjs.c

+18-1
Original file line numberDiff line numberDiff line change
@@ -35282,8 +35282,10 @@ static JSValue iterator_to_array(JSContext *ctx, JSValueConst items)
3528235282
static JSValue js_error_constructor(JSContext *ctx, JSValueConst new_target,
3528335283
int argc, JSValueConst *argv, int magic)
3528435284
{
35285-
JSValue obj, msg, proto;
35285+
JSValue obj, msg, proto, cause;
3528635286
JSValueConst message;
35287+
int opts;
35288+
BOOL present;
3528735289

3528835290
if (JS_IsUndefined(new_target))
3528935291
new_target = JS_GetActiveFunction(ctx);
@@ -35311,8 +35313,10 @@ static JSValue js_error_constructor(JSContext *ctx, JSValueConst new_target,
3531135313
return obj;
3531235314
if (magic == JS_AGGREGATE_ERROR) {
3531335315
message = argv[1];
35316+
opts = 2;
3531435317
} else {
3531535318
message = argv[0];
35319+
opts = 1;
3531635320
}
3531735321

3531835322
if (!JS_IsUndefined(message)) {
@@ -35323,6 +35327,19 @@ static JSValue js_error_constructor(JSContext *ctx, JSValueConst new_target,
3532335327
JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
3532435328
}
3532535329

35330+
if (argc > opts && JS_VALUE_GET_TAG(argv[opts]) == JS_TAG_OBJECT) {
35331+
present = JS_HasProperty(ctx, argv[opts], JS_ATOM_cause);
35332+
if (unlikely(present < 0))
35333+
goto exception;
35334+
if (present) {
35335+
cause = JS_GetProperty(ctx, argv[opts], JS_ATOM_cause);
35336+
if (unlikely(JS_IsException(cause)))
35337+
goto exception;
35338+
JS_DefinePropertyValue(ctx, obj, JS_ATOM_cause, cause,
35339+
JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
35340+
}
35341+
}
35342+
3532635343
if (magic == JS_AGGREGATE_ERROR) {
3532735344
JSValue error_list = iterator_to_array(ctx, argv[0]);
3532835345
if (JS_IsException(error_list))

test262.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ default-parameters
102102
destructuring-assignment
103103
destructuring-binding
104104
dynamic-import
105-
error-cause=skip
105+
error-cause
106106
exponentiation
107107
export-star-as-namespace-from-module
108108
FinalizationGroup=skip

0 commit comments

Comments
 (0)