Make intercepted properties retrievable only by getter to be not enumerable.
authorantonm@chromium.org <antonm@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 28 May 2010 11:54:58 +0000 (11:54 +0000)
committerantonm@chromium.org <antonm@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 28 May 2010 11:54:58 +0000 (11:54 +0000)
Currently if there is no query callback, V8 finds out intercepted properties'
attributes using getter: if getter returns not empty handle V8 treats
such a property as property with NONE attribues which means this property
is enumerable.

However, if there is no enumerator, this property cannot be enumerated.
Thus I think we should treat such properties as not enumerable.

Drawback of this approach is now one has to implement both query and enumerator
callbacks to implement enumerable intercepted properties.

BUG=725

Review URL: http://codereview.chromium.org/2270005

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4751 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/objects.cc
test/cctest/test-api.cc

index e5e1a4e..e2c5bc9 100644 (file)
@@ -2037,7 +2037,7 @@ PropertyAttributes JSObject::GetPropertyAttributeWithInterceptor(
       VMState state(EXTERNAL);
       result = getter(v8::Utils::ToLocal(name_handle), info);
     }
-    if (!result.IsEmpty()) return NONE;
+    if (!result.IsEmpty()) return DONT_ENUM;
   }
   return holder_handle->GetPropertyAttributePostInterceptor(*receiver_handle,
                                                             *name_handle,
index 6254eaa..a33eb94 100644 (file)
@@ -7228,6 +7228,18 @@ THREADED_TEST(NullIndexedInterceptor) {
 }
 
 
+THREADED_TEST(NamedPropertyHandlerGetterAttributes) {
+  v8::HandleScope scope;
+  v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
+  templ->InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter);
+  LocalContext env;
+  env->Global()->Set(v8_str("obj"),
+                     templ->GetFunction()->NewInstance());
+  ExpectTrue("obj.x === 42");
+  ExpectTrue("!obj.propertyIsEnumerable('x')");
+}
+
+
 static v8::Handle<Value> ParentGetter(Local<String> name,
                                       const AccessorInfo& info) {
   ApiTestFuzzer::Fuzz();