Implement Error causes (#103)
This commit is contained in:
parent
d8ea7df950
commit
7aabea9db0
3 changed files with 20 additions and 2 deletions
|
@ -82,6 +82,7 @@ DEF(length, "length")
|
||||||
DEF(fileName, "fileName")
|
DEF(fileName, "fileName")
|
||||||
DEF(lineNumber, "lineNumber")
|
DEF(lineNumber, "lineNumber")
|
||||||
DEF(message, "message")
|
DEF(message, "message")
|
||||||
|
DEF(cause, "cause")
|
||||||
DEF(errors, "errors")
|
DEF(errors, "errors")
|
||||||
DEF(stack, "stack")
|
DEF(stack, "stack")
|
||||||
DEF(name, "name")
|
DEF(name, "name")
|
||||||
|
|
19
quickjs.c
19
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,
|
static JSValue js_error_constructor(JSContext *ctx, JSValueConst new_target,
|
||||||
int argc, JSValueConst *argv, int magic)
|
int argc, JSValueConst *argv, int magic)
|
||||||
{
|
{
|
||||||
JSValue obj, msg, proto;
|
JSValue obj, msg, proto, cause;
|
||||||
JSValueConst message;
|
JSValueConst message;
|
||||||
|
int opts;
|
||||||
|
BOOL present;
|
||||||
|
|
||||||
if (JS_IsUndefined(new_target))
|
if (JS_IsUndefined(new_target))
|
||||||
new_target = JS_GetActiveFunction(ctx);
|
new_target = JS_GetActiveFunction(ctx);
|
||||||
|
@ -35311,8 +35313,10 @@ static JSValue js_error_constructor(JSContext *ctx, JSValueConst new_target,
|
||||||
return obj;
|
return obj;
|
||||||
if (magic == JS_AGGREGATE_ERROR) {
|
if (magic == JS_AGGREGATE_ERROR) {
|
||||||
message = argv[1];
|
message = argv[1];
|
||||||
|
opts = 2;
|
||||||
} else {
|
} else {
|
||||||
message = argv[0];
|
message = argv[0];
|
||||||
|
opts = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!JS_IsUndefined(message)) {
|
if (!JS_IsUndefined(message)) {
|
||||||
|
@ -35323,6 +35327,19 @@ static JSValue js_error_constructor(JSContext *ctx, JSValueConst new_target,
|
||||||
JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
|
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) {
|
if (magic == JS_AGGREGATE_ERROR) {
|
||||||
JSValue error_list = iterator_to_array(ctx, argv[0]);
|
JSValue error_list = iterator_to_array(ctx, argv[0]);
|
||||||
if (JS_IsException(error_list))
|
if (JS_IsException(error_list))
|
||||||
|
|
|
@ -102,7 +102,7 @@ default-parameters
|
||||||
destructuring-assignment
|
destructuring-assignment
|
||||||
destructuring-binding
|
destructuring-binding
|
||||||
dynamic-import
|
dynamic-import
|
||||||
error-cause=skip
|
error-cause
|
||||||
exponentiation
|
exponentiation
|
||||||
export-star-as-namespace-from-module
|
export-star-as-namespace-from-module
|
||||||
FinalizationGroup=skip
|
FinalizationGroup=skip
|
||||||
|
|
Loading…
Reference in a new issue