Index: test/cctest/test-api.cc |
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
index 9ddc9db71df6475affa0beae4f2d4ab9a7cb6da4..01c2ea8404ae5bac4c5b0d6a4b2440d3fbe2895f 100644 |
--- a/test/cctest/test-api.cc |
+++ b/test/cctest/test-api.cc |
@@ -63,6 +63,7 @@ using ::v8::FunctionTemplate; |
using ::v8::Handle; |
using ::v8::HandleScope; |
using ::v8::Local; |
+using ::v8::Name; |
using ::v8::Message; |
using ::v8::MessageCallback; |
using ::v8::Object; |
@@ -71,6 +72,7 @@ using ::v8::Persistent; |
using ::v8::Script; |
using ::v8::StackTrace; |
using ::v8::String; |
+using ::v8::Symbol; |
using ::v8::TryCatch; |
using ::v8::Undefined; |
using ::v8::UniqueId; |
@@ -1878,6 +1880,24 @@ void SimpleAccessorSetter(Local<String> name, Local<Value> value, |
self->Set(String::Concat(v8_str("accessor_"), name), value); |
} |
+void SymbolAccessorGetter(Local<Name> name, |
+ const v8::PropertyCallbackInfo<v8::Value>& info) { |
+ CHECK(name->IsSymbol()); |
+ Local<Symbol> sym = Local<Symbol>::Cast(name); |
+ if (sym->Name()->IsUndefined()) |
+ return; |
+ SimpleAccessorGetter(Local<String>::Cast(sym->Name()), info); |
+} |
+ |
+void SymbolAccessorSetter(Local<Name> name, Local<Value> value, |
+ const v8::PropertyCallbackInfo<void>& info) { |
+ CHECK(name->IsSymbol()); |
+ Local<Symbol> sym = Local<Symbol>::Cast(name); |
+ if (sym->Name()->IsUndefined()) |
+ return; |
+ SimpleAccessorSetter(Local<String>::Cast(sym->Name()), value, info); |
+} |
+ |
void EmptyInterceptorGetter(Local<String> name, |
const v8::PropertyCallbackInfo<v8::Value>& info) { |
} |
@@ -1936,6 +1956,14 @@ void AddInterceptor(Handle<FunctionTemplate> templ, |
} |
+void AddAccessor(Handle<FunctionTemplate> templ, |
+ Handle<Name> name, |
+ v8::AccessorNameGetterCallback getter, |
+ v8::AccessorNameSetterCallback setter) { |
+ templ->PrototypeTemplate()->SetAccessor(name, getter, setter); |
+} |
+ |
+ |
THREADED_TEST(EmptyInterceptorDoesNotShadowAccessors) { |
v8::HandleScope scope(CcTest::isolate()); |
Handle<FunctionTemplate> parent = FunctionTemplate::New(CcTest::isolate()); |
@@ -2747,6 +2775,8 @@ THREADED_TEST(SymbolProperties) { |
v8::Local<v8::Symbol> sym1 = v8::Symbol::New(isolate); |
v8::Local<v8::Symbol> sym2 = |
v8::Symbol::New(isolate, v8_str("my-symbol")); |
+ v8::Local<v8::Symbol> sym3 = |
+ v8::Symbol::New(isolate, v8_str("sym3")); |
CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
@@ -2802,27 +2832,44 @@ THREADED_TEST(SymbolProperties) { |
CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
+ CHECK(obj->SetAccessor(sym3, SymbolAccessorGetter, SymbolAccessorSetter)); |
+ CHECK(obj->Get(sym3)->IsUndefined()); |
+ CHECK(obj->Set(sym3, v8::Integer::New(isolate, 42))); |
+ CHECK(obj->Get(sym3)->Equals(v8::Integer::New(isolate, 42))); |
+ CHECK(obj->Get(v8::String::NewFromUtf8(isolate, "accessor_sym3"))->Equals( |
+ v8::Integer::New(isolate, 42))); |
+ |
// Add another property and delete it afterwards to force the object in |
// slow case. |
CHECK(obj->Set(sym2, v8::Integer::New(isolate, 2008))); |
CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); |
CHECK_EQ(2008, obj->Get(sym2)->Int32Value()); |
CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); |
- CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); |
+ CHECK_EQ(2, obj->GetOwnPropertyNames()->Length()); |
CHECK(obj->Has(sym1)); |
CHECK(obj->Has(sym2)); |
+ CHECK(obj->Has(sym3)); |
+ CHECK(obj->Has(v8::String::NewFromUtf8(isolate, "accessor_sym3"))); |
CHECK(obj->Delete(sym2)); |
CHECK(obj->Has(sym1)); |
CHECK(!obj->Has(sym2)); |
+ CHECK(obj->Has(sym3)); |
+ CHECK(obj->Has(v8::String::NewFromUtf8(isolate, "accessor_sym3"))); |
CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); |
- CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); |
+ CHECK(obj->Get(sym3)->Equals(v8::Integer::New(isolate, 42))); |
+ CHECK(obj->Get(v8::String::NewFromUtf8(isolate, "accessor_sym3"))->Equals( |
+ v8::Integer::New(isolate, 42))); |
+ CHECK_EQ(2, obj->GetOwnPropertyNames()->Length()); |
// Symbol properties are inherited. |
v8::Local<v8::Object> child = v8::Object::New(isolate); |
child->SetPrototype(obj); |
CHECK(child->Has(sym1)); |
CHECK_EQ(2002, child->Get(sym1)->Int32Value()); |
+ CHECK(obj->Get(sym3)->Equals(v8::Integer::New(isolate, 42))); |
+ CHECK(obj->Get(v8::String::NewFromUtf8(isolate, "accessor_sym3"))->Equals( |
+ v8::Integer::New(isolate, 42))); |
CHECK_EQ(0, child->GetOwnPropertyNames()->Length()); |
} |