Skip to content

Commit 559029b

Browse files
committed
Fix Iterator.prototype
Make sure all descriptors are attached to the one and only iterator prototype.
1 parent 554907e commit 559029b

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

quickjs.c

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,7 +2417,6 @@ static void JS_MarkContext(JSRuntime *rt, JSContext *ctx,
24172417
JS_MarkValue(rt, ctx->class_proto[i], mark_func);
24182418
}
24192419
JS_MarkValue(rt, ctx->iterator_ctor, mark_func);
2420-
JS_MarkValue(rt, ctx->iterator_proto, mark_func);
24212420
JS_MarkValue(rt, ctx->async_iterator_proto, mark_func);
24222421
JS_MarkValue(rt, ctx->promise_ctor, mark_func);
24232422
JS_MarkValue(rt, ctx->array_ctor, mark_func);
@@ -2486,7 +2485,6 @@ void JS_FreeContext(JSContext *ctx)
24862485
}
24872486
js_free_rt(rt, ctx->class_proto);
24882487
JS_FreeValue(ctx, ctx->iterator_ctor);
2489-
JS_FreeValue(ctx, ctx->iterator_proto);
24902488
JS_FreeValue(ctx, ctx->async_iterator_proto);
24912489
JS_FreeValue(ctx, ctx->promise_ctor);
24922490
JS_FreeValue(ctx, ctx->array_ctor);
@@ -40110,7 +40108,7 @@ static JSValue js_iterator_from(JSContext *ctx, JSValue this_val,
4011040108
JS_FreeValue(ctx, temp);
4011140109
if (JS_IsException(method))
4011240110
return JS_EXCEPTION;
40113-
iter = JS_NewObjectProtoClass(ctx, ctx->iterator_proto, JS_CLASS_ITERATOR);
40111+
iter = JS_NewObjectProtoClass(ctx, ctx->class_proto[JS_CLASS_ITERATOR], JS_CLASS_ITERATOR);
4011440112
if (JS_IsException(iter)) {
4011540113
JS_FreeValue(ctx, method);
4011640114
return JS_EXCEPTION;
@@ -40562,17 +40560,13 @@ static JSValue js_iterator_proto_get_toStringTag(JSContext *ctx, JSValue this_va
4056240560

4056340561
static JSValue js_iterator_proto_set_toStringTag(JSContext *ctx, JSValue this_val, JSValue val)
4056440562
{
40565-
JSObject *p;
4056640563
int res;
4056740564

4056840565
if (JS_VALUE_GET_TAG(this_val) != JS_TAG_OBJECT)
4056940566
return JS_ThrowTypeError(ctx,
4057040567
"set Iterator.prototype[Symbol.toStringTag] called on non-object");
40571-
p = JS_VALUE_GET_OBJ(this_val);
40572-
if (p->class_id == JS_CLASS_ITERATOR) {
40573-
// This is home.
40568+
if (js_same_value(ctx, this_val, ctx->class_proto[JS_CLASS_ITERATOR]))
4057440569
return JS_ThrowTypeError(ctx, "Cannot assign to read only property");
40575-
}
4057640570
res = JS_GetOwnProperty(ctx, NULL, this_val, JS_ATOM_Symbol_toStringTag);
4057740571
if (res < 0)
4057840572
return JS_EXCEPTION;
@@ -44962,7 +44956,7 @@ void JS_AddIntrinsicRegExp(JSContext *ctx)
4496244956
JS_SetPropertyFunctionList(ctx, obj, js_regexp_funcs, countof(js_regexp_funcs));
4496344957

4496444958
ctx->class_proto[JS_CLASS_REGEXP_STRING_ITERATOR] =
44965-
JS_NewObjectProto(ctx, ctx->iterator_proto);
44959+
JS_NewObjectProto(ctx, ctx->class_proto[JS_CLASS_ITERATOR]);
4496644960
JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_REGEXP_STRING_ITERATOR],
4496744961
js_regexp_string_iterator_proto_funcs,
4496844962
countof(js_regexp_string_iterator_proto_funcs));
@@ -48415,7 +48409,7 @@ void JS_AddIntrinsicMapSet(JSContext *ctx)
4841548409

4841648410
for(i = 0; i < 2; i++) {
4841748411
ctx->class_proto[JS_CLASS_MAP_ITERATOR + i] =
48418-
JS_NewObjectProto(ctx, ctx->iterator_proto);
48412+
JS_NewObjectProto(ctx, ctx->class_proto[JS_CLASS_ITERATOR]);
4841948413
JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_MAP_ITERATOR + i],
4842048414
js_map_proto_funcs_ptr[i + 4],
4842148415
js_map_proto_funcs_count[i + 4]);
@@ -51544,11 +51538,8 @@ void JS_AddIntrinsicBaseObjects(JSContext *ctx)
5154451538
JS_SetPropertyFunctionList(ctx, obj,
5154551539
js_iterator_funcs,
5154651540
countof(js_iterator_funcs));
51547-
ctx->iterator_proto =
51548-
JS_NewObjectProtoClass(ctx, ctx->class_proto[JS_CLASS_ITERATOR],
51549-
JS_CLASS_ITERATOR);
5155051541

51551-
ctx->class_proto[JS_CLASS_ITERATOR_HELPER] = JS_NewObjectProto(ctx, ctx->iterator_proto);
51542+
ctx->class_proto[JS_CLASS_ITERATOR_HELPER] = JS_NewObjectProto(ctx, ctx->class_proto[JS_CLASS_ITERATOR]);
5155251543
JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_ITERATOR_HELPER],
5155351544
js_iterator_helper_proto_funcs,
5155451545
countof(js_iterator_helper_proto_funcs));
@@ -51597,7 +51588,7 @@ void JS_AddIntrinsicBaseObjects(JSContext *ctx)
5159751588
ctx->array_proto_values =
5159851589
JS_GetProperty(ctx, ctx->class_proto[JS_CLASS_ARRAY], JS_ATOM_values);
5159951590

51600-
ctx->class_proto[JS_CLASS_ARRAY_ITERATOR] = JS_NewObjectProto(ctx, ctx->iterator_proto);
51591+
ctx->class_proto[JS_CLASS_ARRAY_ITERATOR] = JS_NewObjectProto(ctx, ctx->class_proto[JS_CLASS_ITERATOR]);
5160151592
JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_ARRAY_ITERATOR],
5160251593
js_array_iterator_proto_funcs,
5160351594
countof(js_array_iterator_proto_funcs));
@@ -51639,7 +51630,7 @@ void JS_AddIntrinsicBaseObjects(JSContext *ctx)
5163951630
JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_STRING], js_string_proto_funcs,
5164051631
countof(js_string_proto_funcs));
5164151632

51642-
ctx->class_proto[JS_CLASS_STRING_ITERATOR] = JS_NewObjectProto(ctx, ctx->iterator_proto);
51633+
ctx->class_proto[JS_CLASS_STRING_ITERATOR] = JS_NewObjectProto(ctx, ctx->class_proto[JS_CLASS_ITERATOR]);
5164351634
JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_STRING_ITERATOR],
5164451635
js_string_iterator_proto_funcs,
5164551636
countof(js_string_iterator_proto_funcs));
@@ -51671,7 +51662,7 @@ void JS_AddIntrinsicBaseObjects(JSContext *ctx)
5167151662
}
5167251663

5167351664
/* ES6 Generator */
51674-
ctx->class_proto[JS_CLASS_GENERATOR] = JS_NewObjectProto(ctx, ctx->iterator_proto);
51665+
ctx->class_proto[JS_CLASS_GENERATOR] = JS_NewObjectProto(ctx, ctx->class_proto[JS_CLASS_ITERATOR]);
5167551666
JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_GENERATOR],
5167651667
js_generator_proto_funcs,
5167751668
countof(js_generator_proto_funcs));

test262_errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ test262/test/built-ins/Date/prototype/setUTCSeconds/date-value-read-before-tonum
4444
test262/test/built-ins/Date/prototype/setUTCSeconds/date-value-read-before-tonumber-when-date-is-invalid.js:26: strict mode: Test262Error: time updated in valueOf Expected SameValue(«NaN», «0») to be true
4545
test262/test/built-ins/Iterator/from/get-return-method-when-call-return.js:24: TypeError: not a function
4646
test262/test/built-ins/Iterator/from/get-return-method-when-call-return.js:24: strict mode: TypeError: not a function
47+
test262/test/built-ins/Iterator/from/result-proto.js:10: unexpected error: Test262Error: Expected SameValue(«[object Object]», «[object Iterator]») to be true
48+
test262/test/built-ins/Iterator/from/result-proto.js:10: strict mode: unexpected error: Test262Error: Expected SameValue(«[object Object]», «[object Iterator]») to be true
4749
test262/test/built-ins/Iterator/from/return-method-calls-base-return-method.js:29: TypeError: not a function
4850
test262/test/built-ins/Iterator/from/return-method-calls-base-return-method.js:29: strict mode: TypeError: not a function
4951
test262/test/built-ins/Iterator/from/return-method-returns-iterator-result.js:18: TypeError: not a function
5052
test262/test/built-ins/Iterator/from/return-method-returns-iterator-result.js:18: strict mode: TypeError: not a function
5153
test262/test/built-ins/Iterator/from/return-method-throws-for-invalid-this.js:16: TypeError: not a function
5254
test262/test/built-ins/Iterator/from/return-method-throws-for-invalid-this.js:16: strict mode: TypeError: not a function
53-
test262/test/built-ins/Iterator/prototype/Symbol.iterator/prop-desc.js:15: Test262Error: obj should have an own property Symbol(Symbol.iterator)
54-
test262/test/built-ins/Iterator/prototype/Symbol.iterator/prop-desc.js:15: strict mode: Test262Error: obj should have an own property Symbol(Symbol.iterator)
5555
test262/test/built-ins/Iterator/prototype/constructor/prop-desc.js:10: Test262Error: Expected SameValue(«"undefined"», «"function"») to be true
5656
test262/test/built-ins/Iterator/prototype/constructor/prop-desc.js:10: strict mode: Test262Error: Expected SameValue(«"undefined"», «"function"») to be true
5757
test262/test/built-ins/Iterator/prototype/constructor/weird-setter.js:23: TypeError: cannot read property 'call' of undefined

0 commit comments

Comments
 (0)