Skip to content

Commit 54c7d18

Browse files
committed
Address review + unify build_backtrace call
1 parent 74a5d4b commit 54c7d18

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

quickjs.c

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57794,7 +57794,7 @@ static const JSDOMExceptionNameDef js_dom_exception_names_table[] = {
5779457794
{ "InvalidModificationError", "INVALID_MODIFICATION_ERR" },
5779557795
{ "NamespaceError", "NAMESPACE_ERR" },
5779657796
{ "InvalidAccessError", "INVALID_ACCESS_ERR" },
57797-
{ NULL, NULL },
57797+
{ NULL, "VALIDATION_ERR" },
5779857798
{ "TypeMismatchError", "TYPE_MISMATCH_ERR" },
5779957799
{ "SecurityError", "SECURITY_ERR" },
5780057800
{ "NetworkError", "NETWORK_ERR" },
@@ -57828,7 +57828,7 @@ static void js_domexception_mark(JSRuntime *rt, JSValueConst val,
5782857828

5782957829
static JSValue js_domexception_constructor0(JSContext *ctx, JSValueConst new_target,
5783057830
int argc, JSValueConst *argv,
57831-
bool add_backtrace)
57831+
int backtrace_flags)
5783257832
{
5783357833
JSDOMExceptionData *s;
5783457834
JSValue obj, message, name;
@@ -57839,13 +57839,13 @@ static JSValue js_domexception_constructor0(JSContext *ctx, JSValueConst new_tar
5783957839
if (!JS_IsUndefined(argv[0]))
5784057840
message = JS_ToString(ctx, argv[0]);
5784157841
else
57842-
message = JS_NewString(ctx, "");
57842+
message = JS_AtomToString(ctx, JS_ATOM_empty_string);
5784357843
if (JS_IsException(message))
5784457844
goto fail1;
5784557845
if (!JS_IsUndefined(argv[1]))
5784657846
name = JS_ToString(ctx, argv[1]);
5784757847
else
57848-
name = JS_NewString(ctx, "Error");
57848+
name = JS_AtomToString(ctx, JS_ATOM_Error);
5784957849
if (JS_IsException(name))
5785057850
goto fail2;
5785157851
s = js_malloc(ctx, sizeof(*s));
@@ -57855,9 +57855,7 @@ static JSValue js_domexception_constructor0(JSContext *ctx, JSValueConst new_tar
5785557855
s->message = message;
5785657856
s->code = -1;
5785757857
JS_SetOpaqueInternal(obj, s);
57858-
if (add_backtrace)
57859-
build_backtrace(ctx, obj, JS_UNDEFINED, NULL, 0, 0,
57860-
JS_BACKTRACE_FLAG_SKIP_FIRST_LEVEL);
57858+
build_backtrace(ctx, obj, JS_UNDEFINED, NULL, 0, 0, backtrace_flags);
5786157859
return obj;
5786257860
fail3:
5786357861
JS_FreeValue(ctx, name);
@@ -57873,27 +57871,21 @@ static JSValue js_domexception_constructor(JSContext *ctx, JSValueConst new_targ
5787357871
{
5787457872
if (JS_IsUndefined(new_target))
5787557873
return JS_ThrowTypeError(ctx, "constructor requires 'new'");
57876-
return js_domexception_constructor0(ctx, new_target, argc, argv, true);
57877-
}
57878-
57879-
static JSValue js_domexception_get_name(JSContext *ctx, JSValueConst this_val)
57880-
{
57881-
JSDOMExceptionData *s;
57882-
57883-
s = JS_GetOpaque2(ctx, this_val, JS_CLASS_DOM_EXCEPTION);
57884-
if (!s)
57885-
return JS_EXCEPTION;
57886-
return js_dup(s->name);
57874+
return js_domexception_constructor0(ctx, new_target, argc, argv,
57875+
JS_BACKTRACE_FLAG_SKIP_FIRST_LEVEL);
5788757876
}
5788857877

57889-
static JSValue js_domexception_get_message(JSContext *ctx, JSValueConst this_val)
57878+
static JSValue js_domexception_getfield(JSContext *ctx, JSValueConst this_val,
57879+
int magic)
5789057880
{
5789157881
JSDOMExceptionData *s;
57882+
JSValue *valp;
5789257883

5789357884
s = JS_GetOpaque2(ctx, this_val, JS_CLASS_DOM_EXCEPTION);
5789457885
if (!s)
5789557886
return JS_EXCEPTION;
57896-
return js_dup(s->message);
57887+
valp = (void *)((char *)s + magic);
57888+
return js_dup(*valp);
5789757889
}
5789857890

5789957891
static JSValue js_domexception_get_code(JSContext *ctx, JSValueConst this_val)
@@ -57924,8 +57916,10 @@ static JSValue js_domexception_get_code(JSContext *ctx, JSValueConst this_val)
5792457916
}
5792557917

5792657918
static const JSCFunctionListEntry js_domexception_proto_funcs[] = {
57927-
JS_CGETSET_DEF("name", js_domexception_get_name, NULL ),
57928-
JS_CGETSET_DEF("message", js_domexception_get_message, NULL ),
57919+
JS_CGETSET_MAGIC_DEF("name", js_domexception_getfield, NULL,
57920+
offsetof(JSDOMExceptionData, name) ),
57921+
JS_CGETSET_MAGIC_DEF("message", js_domexception_getfield, NULL,
57922+
offsetof(JSDOMExceptionData, message) ),
5792957923
JS_CGETSET_DEF("code", js_domexception_get_code, NULL ),
5793057924
JS_PROP_STRING_DEF("[Symbol.toStringTag]", "DOMException", JS_PROP_CONFIGURABLE ),
5793157925
};
@@ -57941,6 +57935,7 @@ JSValue JS_PRINTF_FORMAT_ATTR(3, 4) JS_ThrowDOMException(JSContext *ctx, const c
5794157935
va_list ap;
5794257936
char buf[256];
5794357937

57938+
assert(JS_IsRegisteredClass(ctx->rt, JS_CLASS_DOM_EXCEPTION));
5794457939
va_start(ap, fmt);
5794557940
vsnprintf(buf, sizeof(buf), fmt, ap);
5794657941
va_end(ap);
@@ -57954,12 +57949,11 @@ JSValue JS_PRINTF_FORMAT_ATTR(3, 4) JS_ThrowDOMException(JSContext *ctx, const c
5795457949
}
5795557950
argv[0] = js_message;
5795657951
argv[1] = js_name;
57957-
obj = js_domexception_constructor0(ctx, JS_UNDEFINED, 2, argv, false);
57952+
obj = js_domexception_constructor0(ctx, JS_UNDEFINED, 2, argv, 0);
5795857953
JS_FreeValue(ctx, js_message);
5795957954
JS_FreeValue(ctx, js_name);
5796057955
if (JS_IsException(obj))
5796157956
return JS_EXCEPTION;
57962-
build_backtrace(ctx, obj, JS_UNDEFINED, NULL, 0, 0, 0);
5796357957
return JS_Throw(ctx, obj);
5796457958
}
5796557959

@@ -57982,8 +57976,6 @@ void JS_AddIntrinsicDOMException(JSContext *ctx)
5798257976
JS_CFUNC_constructor_or_func, 0);
5798357977
JS_SetConstructor(ctx, ctor, proto);
5798457978
for (i = 0; i < countof(js_dom_exception_names_table); i++) {
57985-
if (!js_dom_exception_names_table[i].code_name)
57986-
continue;
5798757979
name = JS_NewAtom(ctx, js_dom_exception_names_table[i].code_name);
5798857980
JS_DefinePropertyValue(ctx, proto, name, js_int32(i + 1),
5798957981
JS_PROP_ENUMERABLE);

0 commit comments

Comments
 (0)