added Error cause

This commit is contained in:
Fabrice Bellard
2024-01-02 16:08:08 +01:00
parent 2ee6be705f
commit 5c120cd471
4 changed files with 23 additions and 8 deletions

View File

@@ -38204,7 +38204,8 @@ static JSValue js_error_constructor(JSContext *ctx, JSValueConst new_target,
int argc, JSValueConst *argv, int magic)
{
JSValue obj, msg, proto;
JSValueConst message;
JSValueConst message, options;
int arg_index;
if (JS_IsUndefined(new_target))
new_target = JS_GetActiveFunction(ctx);
@@ -38230,12 +38231,9 @@ static JSValue js_error_constructor(JSContext *ctx, JSValueConst new_target,
JS_FreeValue(ctx, proto);
if (JS_IsException(obj))
return obj;
if (magic == JS_AGGREGATE_ERROR) {
message = argv[1];
} else {
message = argv[0];
}
arg_index = (magic == JS_AGGREGATE_ERROR);
message = argv[arg_index++];
if (!JS_IsUndefined(message)) {
msg = JS_ToString(ctx, message);
if (unlikely(JS_IsException(msg)))
@@ -38244,6 +38242,22 @@ static JSValue js_error_constructor(JSContext *ctx, JSValueConst new_target,
JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
}
if (arg_index < argc) {
options = argv[arg_index];
if (JS_IsObject(options)) {
int present = JS_HasProperty(ctx, options, JS_ATOM_cause);
if (present < 0)
goto exception;
if (present) {
JSValue cause = JS_GetProperty(ctx, options, JS_ATOM_cause);
if (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))