Skip to content

Commit 6b07a4e

Browse files
authored
Make Function.prototype.arguments conform to spec (#1057)
Also ensure Function.prototype.arguments and Function.prototype.caller are the same function.
1 parent f731e4a commit 6b07a4e

File tree

2 files changed

+3
-34
lines changed

2 files changed

+3
-34
lines changed

quickjs.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15086,19 +15086,10 @@ static __exception int js_operator_delete(JSContext *ctx, JSValue *sp)
1508615086

1508715087
static JSValue js_throw_type_error(JSContext *ctx, JSValueConst this_val,
1508815088
int argc, JSValueConst *argv)
15089-
{
15090-
return JS_ThrowTypeError(ctx, "invalid property access");
15091-
}
15092-
15093-
/* XXX: not 100% compatible, but mozilla seems to use a similar
15094-
implementation to ensure that caller in non strict mode does not
15095-
throw (ES5 compatibility) */
15096-
static JSValue js_function_proto_caller(JSContext *ctx, JSValueConst this_val,
15097-
int argc, JSValueConst *argv)
1509815089
{
1509915090
JSFunctionBytecode *b = JS_GetFunctionBytecode(this_val);
1510015091
if (!b || b->is_strict_mode || !b->has_prototype) {
15101-
return js_throw_type_error(ctx, this_val, 0, NULL);
15092+
return JS_ThrowTypeError(ctx, "invalid property access");
1510215093
}
1510315094
return JS_UNDEFINED;
1510415095
}
@@ -53264,16 +53255,14 @@ void JS_AddIntrinsicBaseObjects(JSContext *ctx)
5326453255
ctx->throw_type_error = JS_NewCFunction(ctx, js_throw_type_error, NULL, 0);
5326553256

5326653257
/* add caller and arguments properties to throw a TypeError */
53267-
obj1 = JS_NewCFunction(ctx, js_function_proto_caller, NULL, 0);
5326853258
JS_DefineProperty(ctx, ctx->function_proto, JS_ATOM_caller, JS_UNDEFINED,
53269-
obj1, ctx->throw_type_error,
53259+
ctx->throw_type_error, ctx->throw_type_error,
5327053260
JS_PROP_HAS_GET | JS_PROP_HAS_SET |
5327153261
JS_PROP_HAS_CONFIGURABLE | JS_PROP_CONFIGURABLE);
5327253262
JS_DefineProperty(ctx, ctx->function_proto, JS_ATOM_arguments, JS_UNDEFINED,
53273-
obj1, ctx->throw_type_error,
53263+
ctx->throw_type_error, ctx->throw_type_error,
5327453264
JS_PROP_HAS_GET | JS_PROP_HAS_SET |
5327553265
JS_PROP_HAS_CONFIGURABLE | JS_PROP_CONFIGURABLE);
53276-
JS_FreeValue(ctx, obj1);
5327753266
JS_FreeValue(ctx, js_object_seal(ctx, JS_UNDEFINED, 1, vc(&ctx->throw_type_error), 1));
5327853267

5327953268
/* Object */

test262_errors.txt

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,6 @@ test262/test/built-ins/AsyncFromSyncIteratorPrototype/throw/throw-undefined-retu
2424
test262/test/built-ins/AsyncFromSyncIteratorPrototype/throw/throw-undefined-return-not-object.js:72: strict mode: TypeError: $DONE() not called
2525
test262/test/built-ins/AsyncFromSyncIteratorPrototype/throw/throw-undefined-return-object.js:66: TypeError: $DONE() not called
2626
test262/test/built-ins/AsyncFromSyncIteratorPrototype/throw/throw-undefined-return-object.js:66: strict mode: TypeError: $DONE() not called
27-
test262/test/built-ins/Function/prototype/arguments/prop-desc.js:31: Test262Error: Function.prototype.arguments property getter/setter are the same function Expected SameValue(«function () {
28-
[native code]
29-
}», «function () {
30-
[native code]
31-
}») to be true
32-
test262/test/built-ins/Function/prototype/arguments/prop-desc.js:31: strict mode: Test262Error: Function.prototype.arguments property getter/setter are the same function Expected SameValue(«function () {
33-
[native code]
34-
}», «function () {
35-
[native code]
36-
}») to be true
37-
test262/test/built-ins/Function/prototype/caller/prop-desc.js:29: Test262Error: Caller property getter/setter are the same function Expected SameValue(«function () {
38-
[native code]
39-
}», «function () {
40-
[native code]
41-
}») to be true
42-
test262/test/built-ins/Function/prototype/caller/prop-desc.js:29: strict mode: Test262Error: Caller property getter/setter are the same function Expected SameValue(«function () {
43-
[native code]
44-
}», «function () {
45-
[native code]
46-
}») to be true
4727
test262/test/built-ins/Iterator/prototype/constructor/prop-desc.js:10: Test262Error: Expected SameValue(«"undefined"», «"function"») to be true
4828
test262/test/built-ins/Iterator/prototype/constructor/prop-desc.js:10: strict mode: Test262Error: Expected SameValue(«"undefined"», «"function"») to be true
4929
test262/test/built-ins/Iterator/prototype/constructor/weird-setter.js:23: TypeError: cannot read property 'call' of undefined

0 commit comments

Comments
 (0)