Revision: 6636
Author: [email protected]
Date: Fri Feb  4 04:14:56 2011
Log: Make sure that we don't actually overwrite a property that has failed access checsk with Object.defineProperty.

Review URL: http://codereview.chromium.org/6246103
http://code.google.com/p/v8/source/detail?r=6636

Modified:
 /branches/bleeding_edge/src/runtime.cc
 /branches/bleeding_edge/src/v8natives.js

=======================================
--- /branches/bleeding_edge/src/runtime.cc      Thu Feb  3 11:29:10 2011
+++ /branches/bleeding_edge/src/runtime.cc      Fri Feb  4 04:14:56 2011
@@ -841,7 +841,7 @@
   }

   if (!CheckAccess(*obj, *name, &result, v8::ACCESS_HAS)) {
-    return Heap::undefined_value();
+    return Heap::false_value();
   }

   elms->set(ENUMERABLE_INDEX, Heap::ToBoolean(!result.IsDontEnum()));
=======================================
--- /branches/bleeding_edge/src/v8natives.js    Thu Feb  3 11:29:10 2011
+++ /branches/bleeding_edge/src/v8natives.js    Fri Feb  4 04:14:56 2011
@@ -491,28 +491,29 @@
 }


-
-// ES5 section 8.12.1.
-function GetOwnProperty(obj, p) {
-  var desc = new PropertyDescriptor();
-
-  // GetOwnProperty returns an array indexed by the constants
-  // defined in macros.py.
-  // If p is not a property on obj undefined is returned.
-  var props = %GetOwnProperty(ToObject(obj), ToString(p));
-
-  if (IS_UNDEFINED(props)) return void 0;
-
-  // This is an accessor
-  if (props[IS_ACCESSOR_INDEX]) {
-    desc.setGet(props[GETTER_INDEX]);
-    desc.setSet(props[SETTER_INDEX]);
+// Converts an array returned from Runtime_GetOwnProperty to an actual
+// property descriptor. For a description of the array layout please
+// see the runtime.cc file.
+function ConvertDescriptorArrayToDescriptor(desc_array) {
+  if (desc_array == false) {
+    throw 'Internal error: invalid desc_array';
+  }
+
+  if (IS_UNDEFINED(desc_array)) {
+    return void 0;
+  }
+
+  var desc = new PropertyDescriptor();
+  // This is an accessor.
+  if (desc_array[IS_ACCESSOR_INDEX]) {
+    desc.setGet(desc_array[GETTER_INDEX]);
+    desc.setSet(desc_array[SETTER_INDEX]);
   } else {
-    desc.setValue(props[VALUE_INDEX]);
-    desc.setWritable(props[WRITABLE_INDEX]);
-  }
-  desc.setEnumerable(props[ENUMERABLE_INDEX]);
-  desc.setConfigurable(props[CONFIGURABLE_INDEX]);
+    desc.setValue(desc_array[VALUE_INDEX]);
+    desc.setWritable(desc_array[WRITABLE_INDEX]);
+  }
+  desc.setEnumerable(desc_array[ENUMERABLE_INDEX]);
+  desc.setConfigurable(desc_array[CONFIGURABLE_INDEX]);

   return desc;
 }
@@ -533,11 +534,29 @@
   var desc = GetProperty(obj, p);
   return IS_UNDEFINED(desc) ? false : true;
 }
+
+
+// ES5 section 8.12.1.
+function GetOwnProperty(obj, p) {
+  // GetOwnProperty returns an array indexed by the constants
+  // defined in macros.py.
+  // If p is not a property on obj undefined is returned.
+  var props = %GetOwnProperty(ToObject(obj), ToString(p));
+
+  // A false value here means that access checks failed.
+  if (props == false) return void 0;
+
+  return ConvertDescriptorArrayToDescriptor(props);
+}


 // ES5 8.12.9.
 function DefineOwnProperty(obj, p, desc, should_throw) {
-  var current = GetOwnProperty(obj, p);
+  var current_or_access = %GetOwnProperty(ToObject(obj), ToString(p));
+  // A false value here means that access checks failed.
+  if (current_or_access == false) return void 0;
+
+  var current = ConvertDescriptorArrayToDescriptor(current_or_access);
   var extensible = %IsExtensible(ToObject(obj));

   // Error handling according to spec.

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

Reply via email to