Chromium Code Reviews| Index: test/cctest/test-api.cc |
| diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
| index 19492a53278f5fdb714633a941775f7a94945ab5..1fe250096c9c1326299a0608c6db437f32f568f7 100644 |
| --- a/test/cctest/test-api.cc |
| +++ b/test/cctest/test-api.cc |
| @@ -202,8 +202,6 @@ THREADED_TEST(ReceiverSignature) { |
| } |
| - |
| - |
| THREADED_TEST(ArgumentSignature) { |
| v8::HandleScope scope; |
| LocalContext env; |
| @@ -13911,3 +13909,101 @@ THREADED_TEST(CreationContext) { |
| context2.Dispose(); |
| context3.Dispose(); |
| } |
| + |
| + |
| +Handle<Value> HasOwnPropertyIndexedPropertyGetter(uint32_t index, |
| + const AccessorInfo& info) { |
| + if (index == 42) return v8_str("yes"); |
| + return Handle<v8::Integer>(); |
| +} |
| + |
| + |
| +Handle<Value> HasOwnPropertyNamedPropertyGetter(Local<String> property, |
| + const AccessorInfo& info) { |
| + if (property->Equals(v8_str("foo"))) return v8_str("yes"); |
| + return Handle<Value>(); |
| +} |
| + |
| + |
| +Handle<v8::Integer> HasOwnPropertyIndexedPropertyQuery( |
| + uint32_t index, const AccessorInfo& info) { |
| + if (index == 42) return v8_num(1).As<v8::Integer>(); |
| + return Handle<v8::Integer>(); |
| +} |
| + |
| + |
| +Handle<v8::Integer> HasOwnPropertyNamedPropertyQuery( |
| + Local<String> property, const AccessorInfo& info) { |
| + if (property->Equals(v8_str("foo"))) return v8_num(1).As<v8::Integer>(); |
| + return Handle<v8::Integer>(); |
| +} |
| + |
| + |
| +Handle<Value> HasOwnPropertyAccessorGetter(Local<String> property, |
| + const AccessorInfo& info) { |
| + return v8_str("yes"); |
| +} |
| + |
| + |
| +TEST(HasOwnProperty) { |
| + v8::HandleScope scope; |
| + LocalContext env; |
| + { // Check normal properties and defined getters. |
| + Handle<Value> value = CompileRun( |
| + "function Foo() {" |
| + " this.foo = 11;" |
| + " this.__defineGetter__('baz', function() { return 1; });" |
| + "};" |
| + "function Bar() { " |
| + " this.bar = 13;" |
| + " this.__defineGetter__('bla', function() { return 2; });" |
| + "};" |
| + "Bar.prototype = new Foo();" |
| + "new Bar();"); |
| + CHECK(value->IsObject()); |
| + Handle<Object> object = value->ToObject(); |
| + CHECK(object->Has(v8_str("foo"))); |
| + CHECK(!object->HasOwnProperty(v8_str("foo"))); |
| + CHECK(object->HasOwnProperty(v8_str("bar"))); |
| + CHECK(object->Has(v8_str("baz"))); |
| + CHECK(!object->HasOwnProperty(v8_str("baz"))); |
| + CHECK(object->HasOwnProperty(v8_str("bla"))); |
| + } |
| + { // Check named getter interceptors. |
| + Handle<ObjectTemplate> templ = ObjectTemplate::New(); |
| + templ->SetNamedPropertyHandler(HasOwnPropertyNamedPropertyGetter); |
| + Handle<Object> instance = templ->NewInstance(); |
| + CHECK(!instance->HasOwnProperty(v8_str("42"))); |
| + CHECK(instance->HasOwnProperty(v8_str("foo"))); |
| + CHECK(!instance->HasOwnProperty(v8_str("bar"))); |
| + } |
| + { // Check indexed getter interceptors. |
| + Handle<ObjectTemplate> templ = ObjectTemplate::New(); |
| + templ->SetIndexedPropertyHandler(HasOwnPropertyIndexedPropertyGetter); |
| + Handle<Object> instance = templ->NewInstance(); |
| + CHECK(instance->HasOwnProperty(v8_str("42"))); |
| + CHECK(!instance->HasOwnProperty(v8_str("43"))); |
| + CHECK(!instance->HasOwnProperty(v8_str("foo"))); |
| + } |
| + { // Check named query interceptors. |
| + Handle<ObjectTemplate> templ = ObjectTemplate::New(); |
| + templ->SetNamedPropertyHandler(0, 0, HasOwnPropertyNamedPropertyQuery); |
|
Mads Ager (chromium)
2011/04/28 08:38:27
Maybe add a case with interceptor getters and inte
|
| + Handle<Object> instance = templ->NewInstance(); |
| + CHECK(instance->HasOwnProperty(v8_str("foo"))); |
| + CHECK(!instance->HasOwnProperty(v8_str("bar"))); |
| + } |
| + { // Check indexed query interceptors. |
| + Handle<ObjectTemplate> templ = ObjectTemplate::New(); |
| + templ->SetIndexedPropertyHandler(0, 0, HasOwnPropertyIndexedPropertyQuery); |
| + Handle<Object> instance = templ->NewInstance(); |
| + CHECK(instance->HasOwnProperty(v8_str("42"))); |
| + CHECK(!instance->HasOwnProperty(v8_str("41"))); |
| + } |
| + { // Check callbacks. |
| + Handle<ObjectTemplate> templ = ObjectTemplate::New(); |
| + templ->SetAccessor(v8_str("foo"), HasOwnPropertyAccessorGetter); |
| + Handle<Object> instance = templ->NewInstance(); |
| + CHECK(instance->HasOwnProperty(v8_str("foo"))); |
| + CHECK(!instance->HasOwnProperty(v8_str("bar"))); |
| + } |
| +} |