Index: test/cctest/test-api.cc |
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
index 0d98b1a48dea8b276fccabab3d49ad8d5bc46992..8d050c6dbb99b8dc87c28209a292051fd7a51deb 100644 |
--- a/test/cctest/test-api.cc |
+++ b/test/cctest/test-api.cc |
@@ -2738,6 +2738,106 @@ THREADED_TEST(SymbolTemplateProperties) { |
} |
+THREADED_TEST(PrivatePropertiesOnProxies) { |
+ i::FLAG_harmony_proxies = true; |
+ LocalContext env; |
+ v8::Isolate* isolate = env->GetIsolate(); |
+ v8::HandleScope scope(isolate); |
+ |
+ v8::Local<v8::Object> target = CompileRun("({})").As<v8::Object>(); |
+ v8::Local<v8::Object> handler = CompileRun("({})").As<v8::Object>(); |
+ |
+ v8::Local<v8::Proxy> proxy = |
+ v8::Proxy::New(env.local(), target, handler).ToLocalChecked(); |
+ |
+ v8::Local<v8::Private> priv1 = v8::Private::New(isolate); |
+ v8::Local<v8::Private> priv2 = |
+ v8::Private::New(isolate, v8_str("my-private")); |
+ |
+ CcTest::heap()->CollectAllGarbage(); |
+ |
+ CHECK(priv2->Name() |
+ ->Equals(env.local(), |
+ v8::String::NewFromUtf8(isolate, "my-private", |
+ v8::NewStringType::kNormal) |
+ .ToLocalChecked()) |
+ .FromJust()); |
+ |
+ // Make sure delete of a non-existent private symbol property works. |
+ proxy->DeletePrivate(env.local(), priv1).FromJust(); |
+ CHECK(!proxy->HasPrivate(env.local(), priv1).FromJust()); |
+ |
+ CHECK(proxy->SetPrivate(env.local(), priv1, v8::Integer::New(isolate, 1503)) |
+ .FromJust()); |
+ CHECK(proxy->HasPrivate(env.local(), priv1).FromJust()); |
+ CHECK_EQ(1503, proxy->GetPrivate(env.local(), priv1) |
+ .ToLocalChecked() |
+ ->Int32Value(env.local()) |
+ .FromJust()); |
+ CHECK(proxy->SetPrivate(env.local(), priv1, v8::Integer::New(isolate, 2002)) |
+ .FromJust()); |
+ CHECK(proxy->HasPrivate(env.local(), priv1).FromJust()); |
+ CHECK_EQ(2002, proxy->GetPrivate(env.local(), priv1) |
+ .ToLocalChecked() |
+ ->Int32Value(env.local()) |
+ .FromJust()); |
+ |
+ CHECK_EQ(0u, |
+ proxy->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length()); |
+ unsigned num_props = |
+ proxy->GetPropertyNames(env.local()).ToLocalChecked()->Length(); |
+ CHECK(proxy->Set(env.local(), v8::String::NewFromUtf8( |
+ isolate, "bla", v8::NewStringType::kNormal) |
+ .ToLocalChecked(), |
+ v8::Integer::New(isolate, 20)) |
+ .FromJust()); |
+ CHECK_EQ(1u, |
+ proxy->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length()); |
+ CHECK_EQ(num_props + 1, |
+ proxy->GetPropertyNames(env.local()).ToLocalChecked()->Length()); |
+ |
+ CcTest::heap()->CollectAllGarbage(); |
+ |
+ // Add another property and delete it afterwards to force the object in |
+ // slow case. |
+ CHECK(proxy->SetPrivate(env.local(), priv2, v8::Integer::New(isolate, 2008)) |
+ .FromJust()); |
+ CHECK_EQ(2002, proxy->GetPrivate(env.local(), priv1) |
+ .ToLocalChecked() |
+ ->Int32Value(env.local()) |
+ .FromJust()); |
+ CHECK_EQ(2008, proxy->GetPrivate(env.local(), priv2) |
+ .ToLocalChecked() |
+ ->Int32Value(env.local()) |
+ .FromJust()); |
+ CHECK_EQ(2002, proxy->GetPrivate(env.local(), priv1) |
+ .ToLocalChecked() |
+ ->Int32Value(env.local()) |
+ .FromJust()); |
+ CHECK_EQ(1u, |
+ proxy->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length()); |
+ |
+ CHECK(proxy->HasPrivate(env.local(), priv1).FromJust()); |
+ CHECK(proxy->HasPrivate(env.local(), priv2).FromJust()); |
+ CHECK(proxy->DeletePrivate(env.local(), priv2).FromJust()); |
+ CHECK(proxy->HasPrivate(env.local(), priv1).FromJust()); |
+ CHECK(!proxy->HasPrivate(env.local(), priv2).FromJust()); |
+ CHECK_EQ(2002, proxy->GetPrivate(env.local(), priv1) |
+ .ToLocalChecked() |
+ ->Int32Value(env.local()) |
+ .FromJust()); |
+ CHECK_EQ(1u, |
+ proxy->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length()); |
+ |
+ // Private properties are not inherited (for the time being). |
+ v8::Local<v8::Object> child = v8::Object::New(isolate); |
+ CHECK(child->SetPrototype(env.local(), proxy).FromJust()); |
+ CHECK(!child->HasPrivate(env.local(), priv1).FromJust()); |
+ CHECK_EQ(0u, |
+ child->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length()); |
+} |
+ |
+ |
THREADED_TEST(PrivateProperties) { |
LocalContext env; |
v8::Isolate* isolate = env->GetIsolate(); |