summaryrefslogtreecommitdiff
path: root/quickjs.c
diff options
context:
space:
mode:
authorFabrice Bellard <fabrice@bellard.org>2025-04-10 15:37:19 +0200
committerFabrice Bellard <fabrice@bellard.org>2025-04-10 15:37:19 +0200
commitd546fbfdb7d0f236c30a6c2a1a5641341e9d6aa7 (patch)
tree5aaa25207c90c025e76c44579b69d8cd42b06bfc /quickjs.c
parentc505ac0f39d1b185a35c518b37db928b7b9bc2a9 (diff)
downloadquickjs-d546fbfdb7d0f236c30a6c2a1a5641341e9d6aa7.tar.gz
quickjs-d546fbfdb7d0f236c30a6c2a1a5641341e9d6aa7.zip
changed js_throw_type_error ES5 workaround to be more compatible with test262
Diffstat (limited to 'quickjs.c')
-rw-r--r--quickjs.c20
1 files changed, 6 insertions, 14 deletions
diff --git a/quickjs.c b/quickjs.c
index 90d8fe3..24bb8db 100644
--- a/quickjs.c
+++ b/quickjs.c
@@ -14721,21 +14721,15 @@ static __exception int js_operator_delete(JSContext *ctx, JSValue *sp)
return 0;
}
-static JSValue js_throw_type_error(JSContext *ctx, JSValueConst this_val,
- int argc, JSValueConst *argv)
-{
- return JS_ThrowTypeError(ctx, "invalid property access");
-}
-
/* XXX: not 100% compatible, but mozilla seems to use a similar
implementation to ensure that caller in non strict mode does not
throw (ES5 compatibility) */
-static JSValue js_function_proto_caller(JSContext *ctx, JSValueConst this_val,
- int argc, JSValueConst *argv)
+static JSValue js_throw_type_error(JSContext *ctx, JSValueConst this_val,
+ int argc, JSValueConst *argv)
{
JSFunctionBytecode *b = JS_GetFunctionBytecode(this_val);
- if (!b || (b->js_mode & JS_MODE_STRICT) || !b->has_prototype) {
- return js_throw_type_error(ctx, this_val, 0, NULL);
+ if (!b || (b->js_mode & JS_MODE_STRICT) || !b->has_prototype || argc >= 1) {
+ return JS_ThrowTypeError(ctx, "invalid property access");
}
return JS_UNDEFINED;
}
@@ -50719,16 +50713,14 @@ void JS_AddIntrinsicBaseObjects(JSContext *ctx)
ctx->throw_type_error = JS_NewCFunction(ctx, js_throw_type_error, NULL, 0);
/* add caller and arguments properties to throw a TypeError */
- obj1 = JS_NewCFunction(ctx, js_function_proto_caller, NULL, 0);
JS_DefineProperty(ctx, ctx->function_proto, JS_ATOM_caller, JS_UNDEFINED,
- obj1, ctx->throw_type_error,
+ ctx->throw_type_error, ctx->throw_type_error,
JS_PROP_HAS_GET | JS_PROP_HAS_SET |
JS_PROP_HAS_CONFIGURABLE | JS_PROP_CONFIGURABLE);
JS_DefineProperty(ctx, ctx->function_proto, JS_ATOM_arguments, JS_UNDEFINED,
- obj1, ctx->throw_type_error,
+ ctx->throw_type_error, ctx->throw_type_error,
JS_PROP_HAS_GET | JS_PROP_HAS_SET |
JS_PROP_HAS_CONFIGURABLE | JS_PROP_CONFIGURABLE);
- JS_FreeValue(ctx, obj1);
JS_FreeValue(ctx, js_object_seal(ctx, JS_UNDEFINED, 1, (JSValueConst *)&ctx->throw_type_error, 1));
ctx->global_obj = JS_NewObject(ctx);