Revision: 6689
Author: [email protected]
Date: Tue Feb  8 11:42:14 2011
Log: Propagate exceptions thrown when setting elements.

Plus use more robust path when formatting messages---work
directly with fixed arrays.

BUG=v8:1107
TEST=test/mjsunit/getter-in-prototype.js,test/mjsunit/regress/regress-1107.js

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

Added:
 /branches/bleeding_edge/test/mjsunit/regress/regress-1107.js
Modified:
 /branches/bleeding_edge/src/handles.cc
 /branches/bleeding_edge/src/messages.cc
 /branches/bleeding_edge/src/objects.cc
 /branches/bleeding_edge/src/objects.h
 /branches/bleeding_edge/test/mjsunit/getter-in-prototype.js

=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/mjsunit/regress/regress-1107.js Tue Feb 8 11:42:14 2011
@@ -0,0 +1,32 @@
+// Copyright 2011 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+//       notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+//       copyright notice, this list of conditions and the following
+//       disclaimer in the documentation and/or other materials provided
+//       with the distribution.
+//     * Neither the name of Google Inc. nor the names of its
+//       contributors may be used to endorse or promote products derived
+//       from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Test that even if we cannot set element 0 on all the objects, we still
+// can format exception messages to some extent.
+
+Object.prototype.__defineGetter__(0, function(){});
+assertThrows("x");
=======================================
--- /branches/bleeding_edge/src/handles.cc      Thu Feb  3 11:29:10 2011
+++ /branches/bleeding_edge/src/handles.cc      Tue Feb  8 11:42:14 2011
@@ -808,6 +808,7 @@
                               ClearExceptionFlag flag) {
   // Compile the source information to a code object.
   ASSERT(info->IsOptimizing() || !info->shared_info()->is_compiled());
+  ASSERT(!Top::has_pending_exception());
   bool result = Compiler::CompileLazy(info);
   ASSERT(result != Top::has_pending_exception());
   if (!result && flag == CLEAR_EXCEPTION) Top::clear_pending_exception();
=======================================
--- /branches/bleeding_edge/src/messages.cc     Wed Feb  2 05:31:52 2011
+++ /branches/bleeding_edge/src/messages.cc     Tue Feb  8 11:42:14 2011
@@ -69,10 +69,13 @@
     Handle<String> stack_trace,
     Handle<JSArray> stack_frames) {
   Handle<String> type_handle = Factory::LookupAsciiSymbol(type);
-  Handle<JSArray> arguments_handle = Factory::NewJSArray(args.length());
+  Handle<FixedArray> arguments_elements =
+      Factory::NewFixedArray(args.length());
   for (int i = 0; i < args.length(); i++) {
-    SetElement(arguments_handle, i, args[i]);
-  }
+    arguments_elements->set(i, *args[i]);
+  }
+  Handle<JSArray> arguments_handle =
+      Factory::NewJSArrayWithElements(arguments_elements);

   int start = 0;
   int end = 0;
@@ -87,7 +90,7 @@
       ? Factory::undefined_value()
       : Handle<Object>::cast(stack_trace);

-  Handle<Object> stack_frames_handle =  stack_frames.is_null()
+  Handle<Object> stack_frames_handle = stack_frames.is_null()
       ? Factory::undefined_value()
       : Handle<Object>::cast(stack_frames);

=======================================
--- /branches/bleeding_edge/src/objects.cc      Tue Feb  8 04:41:16 2011
+++ /branches/bleeding_edge/src/objects.cc      Tue Feb  8 11:42:14 2011
@@ -1707,8 +1707,9 @@
 }


-bool JSObject::SetElementWithCallbackSetterInPrototypes(uint32_t index,
-                                                        Object* value) {
+MaybeObject* JSObject::SetElementWithCallbackSetterInPrototypes(uint32_t index, + Object* value, + bool* found) {
   for (Object* pt = GetPrototype();
        pt != Heap::null_value();
        pt = pt->GetPrototype()) {
@@ -1718,15 +1719,16 @@
NumberDictionary* dictionary = JSObject::cast(pt)->element_dictionary();
     int entry = dictionary->FindEntry(index);
     if (entry != NumberDictionary::kNotFound) {
-      Object* element = dictionary->ValueAt(entry);
       PropertyDetails details = dictionary->DetailsAt(entry);
       if (details.type() == CALLBACKS) {
-        SetElementWithCallback(element, index, value, JSObject::cast(pt));
-        return true;
+        *found = true;
+        return SetElementWithCallback(
+            dictionary->ValueAt(entry), index, value, JSObject::cast(pt));
       }
     }
   }
-  return false;
+  *found = false;
+  return Heap::the_hole_value();
 }


@@ -6969,9 +6971,11 @@
   uint32_t elms_length = static_cast<uint32_t>(elms->length());

   if (check_prototype &&
-      (index >= elms_length || elms->get(index)->IsTheHole()) &&
-      SetElementWithCallbackSetterInPrototypes(index, value)) {
-    return value;
+      (index >= elms_length || elms->get(index)->IsTheHole())) {
+    bool found;
+    MaybeObject* result =
+        SetElementWithCallbackSetterInPrototypes(index, value, &found);
+    if (found) return result;
   }


@@ -7103,9 +7107,11 @@
         }
       } else {
// Index not already used. Look for an accessor in the prototype chain.
-        if (check_prototype &&
-            SetElementWithCallbackSetterInPrototypes(index, value)) {
-          return value;
+        if (check_prototype) {
+          bool found;
+          MaybeObject* result =
+ SetElementWithCallbackSetterInPrototypes(index, value, &found);
+          if (found) return result;
         }
         // When we set the is_extensible flag to false we always force
         // the element into dictionary mode (and force them to stay there).
=======================================
--- /branches/bleeding_edge/src/objects.h       Fri Feb  4 10:15:49 2011
+++ /branches/bleeding_edge/src/objects.h       Tue Feb  8 11:42:14 2011
@@ -1579,7 +1579,8 @@
   void LookupRealNamedProperty(String* name, LookupResult* result);
void LookupRealNamedPropertyInPrototypes(String* name, LookupResult* result); void LookupCallbackSetterInPrototypes(String* name, LookupResult* result); - bool SetElementWithCallbackSetterInPrototypes(uint32_t index, Object* value);
+  MUST_USE_RESULT MaybeObject* SetElementWithCallbackSetterInPrototypes(
+      uint32_t index, Object* value, bool* found);
   void LookupCallback(String* name, LookupResult* result);

// Returns the number of properties on this object filtering out properties
=======================================
--- /branches/bleeding_edge/test/mjsunit/getter-in-prototype.js Tue Dec 7 03:01:02 2010 +++ /branches/bleeding_edge/test/mjsunit/getter-in-prototype.js Tue Feb 8 11:42:14 2011
@@ -31,9 +31,11 @@
 var o = {};
 var p = {};
 p.__defineGetter__('x', function(){});
+p.__defineGetter__(0, function(){});
 o.__proto__ = p;

 assertThrows("o.x = 42");
+assertThrows("o[0] = 42");

 function f() {
   with(o) {
@@ -48,3 +50,9 @@
   x = 42;
 }
 assertThrows("g()");
+
+__proto__ = p;
+function g2() {
+  this[0] = 42;
+}
+assertThrows("g2()");

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

Reply via email to