Implement Error causes (#103)

This commit is contained in:
Divy Srivastava 2023-11-21 05:59:26 -08:00 committed by GitHub
parent d8ea7df950
commit 7aabea9db0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View file

@ -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")

View file

@ -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))

View file

@ -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