Revision: 20080
Author:   [email protected]
Date:     Wed Mar 19 14:09:50 2014 UTC
Log:      Handlification of JSArray::SetElementsLength().

[email protected], [email protected]

Review URL: https://codereview.chromium.org/203333004
http://code.google.com/p/v8/source/detail?r=20080

Modified:
 /branches/bleeding_edge/src/accessors.cc
 /branches/bleeding_edge/src/elements.cc
 /branches/bleeding_edge/src/elements.h
 /branches/bleeding_edge/src/ic.cc
 /branches/bleeding_edge/src/objects.cc
 /branches/bleeding_edge/src/objects.h
 /branches/bleeding_edge/test/cctest/test-heap.cc

=======================================
--- /branches/bleeding_edge/src/accessors.cc    Thu Mar 13 00:20:06 2014 UTC
+++ /branches/bleeding_edge/src/accessors.cc    Wed Mar 19 14:09:50 2014 UTC
@@ -213,7 +213,9 @@
   if (has_exception) return Failure::Exception();

   if (uint32_v->Number() == number_v->Number()) {
-    return array_handle->SetElementsLength(*uint32_v);
+ Handle<Object> result = JSArray::SetElementsLength(array_handle, uint32_v);
+    RETURN_IF_EMPTY_HANDLE(isolate, result);
+    return *result;
   }
   return isolate->Throw(
       *isolate->factory()->NewRangeError("invalid_array_length",
=======================================
--- /branches/bleeding_edge/src/elements.cc     Tue Mar 18 11:38:27 2014 UTC
+++ /branches/bleeding_edge/src/elements.cc     Wed Mar 19 14:09:50 2014 UTC
@@ -736,6 +736,15 @@
         FixedArrayBase* backing_store) {
     return NULL;
   }
+
+  // TODO(ishell): Temporary wrapper until handlified.
+  MUST_USE_RESULT virtual Handle<Object> SetLength(
+      Handle<JSArray> array,
+      Handle<Object> length) {
+    CALL_HEAP_FUNCTION(array->GetIsolate(),
+                       SetLength(*array, *length),
+                       Object);
+  }

   MUST_USE_RESULT virtual MaybeObject* SetLength(JSArray* array,
                                                  Object* length) {
=======================================
--- /branches/bleeding_edge/src/elements.h      Tue Mar 18 11:38:27 2014 UTC
+++ /branches/bleeding_edge/src/elements.h      Wed Mar 19 14:09:50 2014 UTC
@@ -109,6 +109,9 @@
// changing array sizes as defined in EcmaScript 5.1 15.4.5.2, i.e. array that
   // have non-deletable elements can only be shrunk to the size of highest
   // element that is non-deletable.
+  MUST_USE_RESULT virtual Handle<Object> SetLength(
+      Handle<JSArray> holder,
+      Handle<Object> new_length) = 0;
   MUST_USE_RESULT virtual MaybeObject* SetLength(JSArray* holder,
                                                  Object* new_length) = 0;

=======================================
--- /branches/bleeding_edge/src/ic.cc   Tue Mar 18 14:15:09 2014 UTC
+++ /branches/bleeding_edge/src/ic.cc   Wed Mar 19 14:09:50 2014 UTC
@@ -1813,11 +1813,11 @@


 RUNTIME_FUNCTION(MaybeObject*, StoreIC_ArrayLength) {
-  SealHandleScope shs(isolate);
+  HandleScope scope(isolate);

   ASSERT(args.length() == 2);
-  JSArray* receiver = JSArray::cast(args[0]);
-  Object* len = args[1];
+  Handle<JSArray> receiver = args.at<JSArray>(0);
+  Handle<Object> len = args.at<Object>(1);

   // The generated code should filter out non-Smis before we get here.
   ASSERT(len->IsSmi());
@@ -1829,11 +1829,9 @@
   ASSERT(debug_lookup.IsPropertyCallbacks() && !debug_lookup.IsReadOnly());
 #endif

-  Object* result;
-  MaybeObject* maybe_result = receiver->SetElementsLength(len);
-  if (!maybe_result->To(&result)) return maybe_result;
-
-  return len;
+  RETURN_IF_EMPTY_HANDLE(isolate,
+                         JSArray::SetElementsLength(receiver, len));
+  return *len;
 }


=======================================
--- /branches/bleeding_edge/src/objects.cc      Wed Mar 19 10:48:54 2014 UTC
+++ /branches/bleeding_edge/src/objects.cc      Wed Mar 19 14:09:50 2014 UTC
@@ -11401,77 +11401,64 @@
 }


-// TODO(ishell): Temporary wrapper until handlified.
-// static
 Handle<Object> JSArray::SetElementsLength(Handle<JSArray> array,
-                                          Handle<Object> length) {
-  CALL_HEAP_FUNCTION(array->GetIsolate(),
-                     array->SetElementsLength(*length),
-                     Object);
-}
-
-
-MaybeObject* JSArray::SetElementsLength(Object* len) {
+ Handle<Object> new_length_handle) {
   // We should never end in here with a pixel or external array.
-  ASSERT(AllowsSetElementsLength());
-  if (!map()->is_observed())
-    return GetElementsAccessor()->SetLength(this, len);
+  ASSERT(array->AllowsSetElementsLength());
+  if (!array->map()->is_observed()) {
+ return array->GetElementsAccessor()->SetLength(array, new_length_handle);
+  }

-  Isolate* isolate = GetIsolate();
-  HandleScope scope(isolate);
-  Handle<JSArray> self(this);
+  Isolate* isolate = array->GetIsolate();
   List<uint32_t> indices;
   List<Handle<Object> > old_values;
-  Handle<Object> old_length_handle(self->length(), isolate);
-  Handle<Object> new_length_handle(len, isolate);
+  Handle<Object> old_length_handle(array->length(), isolate);
   uint32_t old_length = 0;
   CHECK(old_length_handle->ToArrayIndex(&old_length));
   uint32_t new_length = 0;
-  if (!new_length_handle->ToArrayIndex(&new_length))
-    return Failure::InternalError();
+  CHECK(new_length_handle->ToArrayIndex(&new_length));

   static const PropertyAttributes kNoAttrFilter = NONE;
-  int num_elements = self->NumberOfLocalElements(kNoAttrFilter);
+  int num_elements = array->NumberOfLocalElements(kNoAttrFilter);
   if (num_elements > 0) {
     if (old_length == static_cast<uint32_t>(num_elements)) {
       // Simple case for arrays without holes.
       for (uint32_t i = old_length - 1; i + 1 > new_length; --i) {
-        if (!GetOldValue(isolate, self, i, &old_values, &indices)) break;
+        if (!GetOldValue(isolate, array, i, &old_values, &indices)) break;
       }
     } else {
       // For sparse arrays, only iterate over existing elements.
// TODO(rafaelw): For fast, sparse arrays, we can avoid iterating over
       // the to-be-removed indices twice.
Handle<FixedArray> keys = isolate->factory()->NewFixedArray(num_elements);
-      self->GetLocalElementKeys(*keys, kNoAttrFilter);
+      array->GetLocalElementKeys(*keys, kNoAttrFilter);
       while (num_elements-- > 0) {
         uint32_t index = NumberToUint32(keys->get(num_elements));
         if (index < new_length) break;
- if (!GetOldValue(isolate, self, index, &old_values, &indices)) break; + if (!GetOldValue(isolate, array, index, &old_values, &indices)) break;
       }
     }
   }

-  MaybeObject* result =
-      self->GetElementsAccessor()->SetLength(*self, *new_length_handle);
-  Handle<Object> hresult;
-  if (!result->ToHandle(&hresult, isolate)) return result;
+  Handle<Object> hresult =
+      array->GetElementsAccessor()->SetLength(array, new_length_handle);
+  RETURN_IF_EMPTY_HANDLE_VALUE(isolate, hresult, hresult);

-  CHECK(self->length()->ToArrayIndex(&new_length));
-  if (old_length == new_length) return *hresult;
+  CHECK(array->length()->ToArrayIndex(&new_length));
+  if (old_length == new_length) return hresult;

-  BeginPerformSplice(self);
+  BeginPerformSplice(array);

   for (int i = 0; i < indices.length(); ++i) {
     JSObject::EnqueueChangeRecord(
-        self, "delete", isolate->factory()->Uint32ToString(indices[i]),
+        array, "delete", isolate->factory()->Uint32ToString(indices[i]),
         old_values[i]);
   }
   JSObject::EnqueueChangeRecord(
-      self, "update", isolate->factory()->length_string(),
+      array, "update", isolate->factory()->length_string(),
       old_length_handle);

-  EndPerformSplice(self);
+  EndPerformSplice(array);

   uint32_t index = Min(old_length, new_length);
uint32_t add_count = new_length > old_length ? new_length - old_length : 0;
@@ -11488,9 +11475,9 @@
                 NONE, SLOPPY);
   }

-  EnqueueSpliceRecord(self, index, deleted, add_count);
+  EnqueueSpliceRecord(array, index, deleted, add_count);

-  return *hresult;
+  return hresult;
 }


=======================================
--- /branches/bleeding_edge/src/objects.h       Wed Mar 19 10:32:12 2014 UTC
+++ /branches/bleeding_edge/src/objects.h       Wed Mar 19 14:09:50 2014 UTC
@@ -10028,7 +10028,6 @@
   // Can cause GC.
   static Handle<Object> SetElementsLength(Handle<JSArray> array,
                                           Handle<Object> length);
-  MUST_USE_RESULT MaybeObject* SetElementsLength(Object* length);

   // Set the content of the array to the content of storage.
   MUST_USE_RESULT inline MaybeObject* SetContent(FixedArrayBase* storage);
=======================================
--- /branches/bleeding_edge/test/cctest/test-heap.cc Wed Mar 19 13:39:09 2014 UTC +++ /branches/bleeding_edge/test/cctest/test-heap.cc Wed Mar 19 14:09:50 2014 UTC
@@ -759,7 +759,7 @@
   JSArray::Initialize(array, 0);

   // Set array length to 0.
-  array->SetElementsLength(Smi::FromInt(0))->ToObjectChecked();
+  *JSArray::SetElementsLength(array, handle(Smi::FromInt(0), isolate));
   CHECK_EQ(Smi::FromInt(0), array->length());
   // Must be in fast mode.
   CHECK(array->HasFastSmiOrObjectElements());
@@ -772,7 +772,7 @@
   // Set array length with larger than smi value.
   Handle<Object> length =
factory->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1);
-  array->SetElementsLength(*length)->ToObjectChecked();
+  *JSArray::SetElementsLength(array, length);

   uint32_t int_length = 0;
   CHECK(length->ToArrayIndex(&int_length));

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to