Index: test/cctest/test-api.cc |
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
index 251177cb4d9ce8366413f1108f5acf937ba93f2f..cf583382cefe3d0a104545d372cc5db161aee89c 100644 |
--- a/test/cctest/test-api.cc |
+++ b/test/cctest/test-api.cc |
@@ -25892,6 +25892,78 @@ TEST(AccessCheckedToStringTag) { |
CHECK_EQ(0, strcmp(*result_denied, "[object Object]")); |
} |
+TEST(TemplateIteratorPrototypeIntrinsics) { |
+ v8::Isolate* isolate = CcTest::isolate(); |
+ v8::HandleScope scope(isolate); |
+ LocalContext env; |
+ |
+ // Object templates. |
+ { |
+ Local<ObjectTemplate> object_template = v8::ObjectTemplate::New(isolate); |
+ object_template->SetIntrinsicDataProperty(v8_str("iter_proto"), |
+ v8::kIteratorPrototype); |
+ Local<Object> object = |
+ object_template->NewInstance(env.local()).ToLocalChecked(); |
+ CHECK(env->Global()->Set(env.local(), v8_str("obj"), object).FromJust()); |
+ ExpectTrue("obj.iter_proto === [][Symbol.iterator]().__proto__.__proto__"); |
+ } |
+ // Setting %IteratorProto% on the function object's prototype template. |
+ { |
+ Local<FunctionTemplate> func_template = v8::FunctionTemplate::New(isolate); |
+ func_template->PrototypeTemplate()->SetIntrinsicDataProperty( |
+ v8_str("iter_proto"), v8::kIteratorPrototype); |
+ Local<Function> func1 = |
+ func_template->GetFunction(env.local()).ToLocalChecked(); |
+ CHECK(env->Global()->Set(env.local(), v8_str("func1"), func1).FromJust()); |
+ Local<Function> func2 = |
+ func_template->GetFunction(env.local()).ToLocalChecked(); |
+ CHECK(env->Global()->Set(env.local(), v8_str("func2"), func2).FromJust()); |
+ ExpectTrue( |
+ "func1.prototype.iter_proto === " |
+ "[][Symbol.iterator]().__proto__.__proto__"); |
+ ExpectTrue( |
+ "func2.prototype.iter_proto === " |
+ "[][Symbol.iterator]().__proto__.__proto__"); |
+ ExpectTrue("func1.prototype.iter_proto === func2.prototype.iter_proto"); |
+ |
+ Local<Object> instance1 = func1->NewInstance(env.local()).ToLocalChecked(); |
+ CHECK(env->Global() |
+ ->Set(env.local(), v8_str("instance1"), instance1) |
+ .FromJust()); |
+ ExpectFalse("instance1.hasOwnProperty('iter_proto')"); |
+ ExpectTrue("'iter_proto' in instance1.__proto__"); |
+ ExpectTrue( |
+ "instance1.iter_proto === [][Symbol.iterator]().__proto__.__proto__"); |
+ } |
+ // Put %IteratorProto% in a function object's inheritance chain. |
+ { |
+ Local<FunctionTemplate> parent_template = |
+ v8::FunctionTemplate::New(isolate); |
+ parent_template->RemovePrototype(); // Remove so there is no name clash. |
caitp
2017/03/29 12:36:44
This will force the instantiated Function to be no
|
+ parent_template->SetIntrinsicDataProperty(v8_str("prototype"), |
+ v8::kIteratorPrototype); |
+ Local<FunctionTemplate> func_template = v8::FunctionTemplate::New(isolate); |
+ func_template->Inherit(parent_template); |
+ |
+ Local<Function> func = |
+ func_template->GetFunction(env.local()).ToLocalChecked(); |
+ CHECK(env->Global()->Set(env.local(), v8_str("func"), func).FromJust()); |
+ ExpectTrue( |
+ "func.prototype.__proto__ === " |
+ "[][Symbol.iterator]().__proto__.__proto__"); |
+ |
+ Local<Object> func_instance = |
+ func->NewInstance(env.local()).ToLocalChecked(); |
+ CHECK(env->Global() |
+ ->Set(env.local(), v8_str("instance"), func_instance) |
+ .FromJust()); |
+ ExpectTrue( |
+ "instance.__proto__.__proto__ === " |
+ "[][Symbol.iterator]().__proto__.__proto__"); |
+ ExpectTrue("instance.__proto__.__proto__.__proto__ === Object.prototype"); |
+ } |
+} |
+ |
TEST(ObjectTemplateArrayProtoIntrinsics) { |
v8::Isolate* isolate = CcTest::isolate(); |
v8::HandleScope scope(isolate); |