Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(752)

Unified Diff: test/cctest/test-api.cc

Issue 11644021: Fix treatment of hidden prototypes in SetProperty. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix warning Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 60405a6340e02097d5e8508604f0f4f629a820f1..a30fbdac957773635702ffe3366c8ffb79d50091 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -8233,6 +8233,66 @@ THREADED_TEST(HiddenPrototype) {
}
+THREADED_TEST(HiddenPrototypeSet) {
+ v8::HandleScope handle_scope;
+ LocalContext context;
+
+ Local<v8::FunctionTemplate> ot = v8::FunctionTemplate::New();
+ Local<v8::FunctionTemplate> ht = v8::FunctionTemplate::New();
+ ht->SetHiddenPrototype(true);
+ Local<v8::FunctionTemplate> pt = v8::FunctionTemplate::New();
+ ht->InstanceTemplate()->Set(v8_str("x"), v8_num(0));
+
+ Local<v8::Object> o = ot->GetFunction()->NewInstance();
+ Local<v8::Object> h = ht->GetFunction()->NewInstance();
+ Local<v8::Object> p = pt->GetFunction()->NewInstance();
+ o->Set(v8_str("__proto__"), h);
+ h->Set(v8_str("__proto__"), p);
+
+ // Setting a property that exists on the hidden prototype goes there.
+ o->Set(v8_str("x"), v8_num(7));
+ CHECK_EQ(7, o->Get(v8_str("x"))->Int32Value());
+ CHECK_EQ(7, h->Get(v8_str("x"))->Int32Value());
+ CHECK(p->Get(v8_str("x"))->IsUndefined());
+
+ // Setting a new property should not be forwarded to the hidden prototype.
+ o->Set(v8_str("y"), v8_num(6));
+ CHECK_EQ(6, o->Get(v8_str("y"))->Int32Value());
+ CHECK(h->Get(v8_str("y"))->IsUndefined());
+ CHECK(p->Get(v8_str("y"))->IsUndefined());
+
+ // Setting a property that only exists on a prototype of the hidden prototype
+ // is treated normally again.
+ p->Set(v8_str("z"), v8_num(8));
+ CHECK_EQ(8, o->Get(v8_str("z"))->Int32Value());
+ CHECK_EQ(8, h->Get(v8_str("z"))->Int32Value());
+ CHECK_EQ(8, p->Get(v8_str("z"))->Int32Value());
+ o->Set(v8_str("z"), v8_num(9));
+ CHECK_EQ(9, o->Get(v8_str("z"))->Int32Value());
+ CHECK_EQ(8, h->Get(v8_str("z"))->Int32Value());
+ CHECK_EQ(8, p->Get(v8_str("z"))->Int32Value());
+}
+
+
+// Regression test for issue 2457.
+THREADED_TEST(HiddenPrototypeIdentityHash) {
+ v8::HandleScope handle_scope;
+ LocalContext context;
+
+ Handle<FunctionTemplate> t = FunctionTemplate::New();
+ t->SetHiddenPrototype(true);
+ t->InstanceTemplate()->Set(v8_str("foo"), v8_num(75));
+ Handle<Object> p = t->GetFunction()->NewInstance();
+ Handle<Object> o = Object::New();
+ o->SetPrototype(p);
+
+ int hash = o->GetIdentityHash();
+ USE(hash);
+ o->Set(v8_str("foo"), v8_num(42));
+ ASSERT_EQ(hash, o->GetIdentityHash());
+}
+
+
THREADED_TEST(SetPrototype) {
v8::HandleScope handle_scope;
LocalContext context;
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698