Reviewers: Kevin Millikin,

Description:
Fix and test use of property descriptor objects.

[email protected]
BUG=
TEST=


Please review this at http://codereview.chromium.org/7828080/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/bootstrapper.cc
  M src/contexts.h
  M src/objects.cc
  M test/mjsunit/harmony/proxies.js


Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index a5cb55525274f6b2c7e68443bc830cce096d6c00..6888ab71b60888d8a32f8ddc0404d896abbd2d59 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -1321,6 +1321,9 @@ void Genesis::InstallNativeFunctions() {
                  configure_instance_fun);
INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun);
   INSTALL_NATIVE(JSObject, "functionCache", function_cache);
+ INSTALL_NATIVE(JSFunction, "ToPropertyDescriptor", to_property_descriptor);
+  INSTALL_NATIVE(JSFunction, "ToCompletePropertyDescriptor",
+                 to_complete_property_descriptor);
 }

 void Genesis::InstallExperimentalNativeFunctions() {
Index: src/contexts.h
diff --git a/src/contexts.h b/src/contexts.h
index 53b40f127d8efac2f45ebfdca2dd55d116cf945b..156fdad44d41df86f4057a6c971185346c36e148 100644
--- a/src/contexts.h
+++ b/src/contexts.h
@@ -110,6 +110,9 @@ enum ContextLookupFlags {
   V(MAP_CACHE_INDEX, Object, map_cache) \
   V(CONTEXT_DATA_INDEX, Object, data) \
V(ALLOW_CODE_GEN_FROM_STRINGS_INDEX, Object, allow_code_gen_from_strings) \
+  V(TO_PROPERTY_DESCRIPTOR_INDEX, JSFunction, to_property_descriptor) \
+  V(TO_COMPLETE_PROPERTY_DESCRIPTOR_INDEX, JSFunction, \
+    to_complete_property_descriptor) \
   V(DERIVED_HAS_TRAP_INDEX, JSFunction, derived_has_trap) \
   V(DERIVED_GET_TRAP_INDEX, JSFunction, derived_get_trap) \
   V(DERIVED_SET_TRAP_INDEX, JSFunction, derived_set_trap)
@@ -228,6 +231,8 @@ class Context: public FixedArray {
     OUT_OF_MEMORY_INDEX,
     CONTEXT_DATA_INDEX,
     ALLOW_CODE_GEN_FROM_STRINGS_INDEX,
+    TO_PROPERTY_DESCRIPTOR_INDEX,
+    TO_COMPLETE_PROPERTY_DESCRIPTOR_INDEX,
     DERIVED_HAS_TRAP_INDEX,
     DERIVED_GET_TRAP_INDEX,
     DERIVED_SET_TRAP_INDEX,
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index ebcef01aff544a1a6606a87860528e071e97d44e..82eb4aee3cde26783bc9503641b4fc8109c007cf 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -2302,8 +2302,29 @@ MUST_USE_RESULT PropertyAttributes JSProxy::GetPropertyAttributeWithHandler(

   if (result->IsUndefined()) return ABSENT;

-  // TODO(rossberg): convert result to PropertyAttributes
-  return NONE;
+  bool has_pending_exception;
+  Object** argv[] = { result.location() };
+  Handle<Object> desc =
+      Execution::Call(isolate->to_complete_property_descriptor(), result,
+                      ARRAY_SIZE(argv), argv, &has_pending_exception);
+  if (has_pending_exception) return NONE;
+
+  // Convert result to PropertyAttributes.
+ Handle<String> enum_name = isolate->factory()->LookupAsciiSymbol("enumerable");
+  Handle<Object> enumerable(v8::internal::GetProperty(desc, enum_name));
+  if (isolate->has_pending_exception()) return NONE;
+ Handle<String> conf_name = isolate->factory()->LookupAsciiSymbol("configurable");
+  Handle<Object> configurable(v8::internal::GetProperty(desc, conf_name));
+  if (isolate->has_pending_exception()) return NONE;
+ Handle<String> writ_name = isolate->factory()->LookupAsciiSymbol("writable");
+  Handle<Object> writable(v8::internal::GetProperty(desc, writ_name));
+  if (isolate->has_pending_exception()) return NONE;
+
+  int attributes = NONE;
+  if (enumerable->ToBoolean()->IsFalse()) attributes |= DONT_ENUM;
+  if (configurable->ToBoolean()->IsFalse()) attributes |= DONT_DELETE;
+  if (writable->ToBoolean()->IsFalse()) attributes |= READ_ONLY;
+  return static_cast<PropertyAttributes>(attributes);
 }


Index: test/mjsunit/harmony/proxies.js
diff --git a/test/mjsunit/harmony/proxies.js b/test/mjsunit/harmony/proxies.js index 1a33f5fb05722bc7e7bb96869ea7132ee811ab0d..aca0cc34bee59e395922124f81a8ba81873fbfb6 100644
--- a/test/mjsunit/harmony/proxies.js
+++ b/test/mjsunit/harmony/proxies.js
@@ -1068,8 +1068,6 @@ TestInThrow(Proxy.create({
 }))


-/* TODO(rossberg): does not work yet, JSProxy::GetPropertyAttributeWithHandler
- * is not fully implemented.*/
 function TestInForDerived(handler) {
   TestWithProxies(TestInForDerived2, handler)
 }
@@ -1079,7 +1077,7 @@ function TestInForDerived2(handler, create) {
   var o = Object.create(p)
   assertTrue("a" in o)
   assertEquals("a", key)
-// TODO(rossberg): integer indexes not correctly imlemeted yet
+// TODO(rossberg): integer indexes not correctly implemeted yet
 //  assertTrue(99 in o)
 //  assertEquals("99", key)
   assertFalse("z" in o)
@@ -1164,6 +1162,62 @@ TestInForDerived(Proxy.create({



+// Property descriptor conversion.
+
+var descget
+
+function TestDescriptorGetOrder(handler) {
+  var p = Proxy.create(handler)
+  var o = Object.create(p, {b: {value: 0}})
+  TestDescriptorGetOrder2(function(n) { p[n] }, "vV")
+  TestDescriptorGetOrder2(function(n) { n in p }, "")
+  TestDescriptorGetOrder2(function(n) { o[n] }, "vV")
+  TestDescriptorGetOrder2(function(n) { n in o }, "eEcCvVwWgs")
+}
+
+function TestDescriptorGetOrder2(f, access) {
+  descget = ""
+  f("a")
+  assertEquals(access, descget)
+// TODO(rossberg): integer indexes not correctly implemented yet.
+//  descget = ""
+//  f(99)
+//  assertEquals(access, descget)
+  descget = ""
+  f("z")
+  assertEquals("", descget)
+}
+
+TestDescriptorGetOrder({
+  getPropertyDescriptor: function(k) {
+    if (k >= "z") return void 0
+    // Return a proxy as property descriptor, so that we can log accesses.
+    return Proxy.create({
+      get: function(r, attr) {
+        descget += attr[0].toUpperCase()
+        return true
+      },
+      has: function(attr) {
+        descget += attr[0]
+        switch (attr) {
+          case "writable":
+          case "enumerable":
+          case "configurable":
+          case "value":
+            return true
+          case "get":
+          case "set":
+            return false
+          default:
+            assertUnreachable()
+        }
+      }
+    })
+  }
+})
+
+
+
 // Own Properties (Object.prototype.hasOwnProperty).

 var key


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to