diff --git a/quickjs-atom.h b/quickjs-atom.h index 72db41f..cf92e68 100644 --- a/quickjs-atom.h +++ b/quickjs-atom.h @@ -82,6 +82,7 @@ DEF(length, "length") DEF(fileName, "fileName") DEF(lineNumber, "lineNumber") DEF(message, "message") +DEF(cause, "cause") DEF(errors, "errors") DEF(stack, "stack") DEF(name, "name") diff --git a/quickjs.c b/quickjs.c index 3a0cb6f..42a03ef 100644 --- a/quickjs.c +++ b/quickjs.c @@ -35282,8 +35282,10 @@ static JSValue iterator_to_array(JSContext *ctx, JSValueConst items) static JSValue js_error_constructor(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv, int magic) { - JSValue obj, msg, proto; + JSValue obj, msg, proto, cause; JSValueConst message; + int opts; + BOOL present; if (JS_IsUndefined(new_target)) new_target = JS_GetActiveFunction(ctx); @@ -35311,8 +35313,10 @@ static JSValue js_error_constructor(JSContext *ctx, JSValueConst new_target, return obj; if (magic == JS_AGGREGATE_ERROR) { message = argv[1]; + opts = 2; } else { message = argv[0]; + opts = 1; } if (!JS_IsUndefined(message)) { @@ -35323,6 +35327,19 @@ static JSValue js_error_constructor(JSContext *ctx, JSValueConst new_target, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE); } + if (argc > opts && JS_VALUE_GET_TAG(argv[opts]) == JS_TAG_OBJECT) { + present = JS_HasProperty(ctx, argv[opts], JS_ATOM_cause); + if (unlikely(present < 0)) + goto exception; + if (present) { + cause = JS_GetProperty(ctx, argv[opts], JS_ATOM_cause); + if (unlikely(JS_IsException(cause))) + goto exception; + JS_DefinePropertyValue(ctx, obj, JS_ATOM_cause, cause, + JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE); + } + } + if (magic == JS_AGGREGATE_ERROR) { JSValue error_list = iterator_to_array(ctx, argv[0]); if (JS_IsException(error_list)) diff --git a/test262.conf b/test262.conf index 1ad0980..e726385 100644 --- a/test262.conf +++ b/test262.conf @@ -102,7 +102,7 @@ default-parameters destructuring-assignment destructuring-binding dynamic-import -error-cause=skip +error-cause exponentiation export-star-as-namespace-from-module FinalizationGroup=skip