Revision: 20024
Author:   [email protected]
Date:     Tue Mar 18 11:38:27 2014 UTC
Log:      Handlification of ArrayConstructorCommon().

[email protected]

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

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

=======================================
--- /branches/bleeding_edge/src/elements.cc     Mon Mar 17 15:01:45 2014 UTC
+++ /branches/bleeding_edge/src/elements.cc     Tue Mar 18 11:38:27 2014 UTC
@@ -1910,78 +1910,64 @@
 }


-// TODO(ishell): Temporary wrapper until handlified.
 Handle<Object> ArrayConstructInitializeElements(Handle<JSArray> array,
                                                 Arguments* args) {
-  CALL_HEAP_FUNCTION(array->GetIsolate(),
-                     ArrayConstructInitializeElements(*array, args),
-                     Object);
-}
-
-
-MUST_USE_RESULT MaybeObject* ArrayConstructInitializeElements(
-    JSArray* array, Arguments* args) {
-  Heap* heap = array->GetIsolate()->heap();
-
   // Optimize the case where there is one argument and the argument is a
   // small smi.
   if (args->length() == 1) {
-    Object* obj = (*args)[0];
+    Handle<Object> obj = args->at<Object>(0);
     if (obj->IsSmi()) {
-      int len = Smi::cast(obj)->value();
+      int len = Handle<Smi>::cast(obj)->value();
       if (len > 0 && len < JSObject::kInitialMaxFastElementArray) {
         ElementsKind elements_kind = array->GetElementsKind();
-        MaybeObject* maybe_array = array->Initialize(len, len);
-        if (maybe_array->IsFailure()) return maybe_array;
+        JSArray::Initialize(array, len, len);

         if (!IsFastHoleyElementsKind(elements_kind)) {
           elements_kind = GetHoleyElementsKind(elements_kind);
-          maybe_array = array->TransitionElementsKind(elements_kind);
-          if (maybe_array->IsFailure()) return maybe_array;
+          JSObject::TransitionElementsKind(array, elements_kind);
         }
-
         return array;
       } else if (len == 0) {
-        return array->Initialize(JSArray::kPreallocatedArrayElements);
+        JSArray::Initialize(array, JSArray::kPreallocatedArrayElements);
+        return array;
       }
     }

     // Take the argument as the length.
-    MaybeObject* maybe_obj = array->Initialize(0);
-    if (!maybe_obj->To(&obj)) return maybe_obj;
+    JSArray::Initialize(array, 0);

-    return array->SetElementsLength((*args)[0]);
+    return JSArray::SetElementsLength(array, obj);
   }

   // Optimize the case where there are no parameters passed.
   if (args->length() == 0) {
-    return array->Initialize(JSArray::kPreallocatedArrayElements);
+    JSArray::Initialize(array, JSArray::kPreallocatedArrayElements);
+    return array;
   }
+
+  Factory* factory = array->GetIsolate()->factory();

   // Set length and elements on the array.
   int number_of_elements = args->length();
-  MaybeObject* maybe_object =
-      array->EnsureCanContainElements(args, 0, number_of_elements,
-                                      ALLOW_CONVERTED_DOUBLE_ELEMENTS);
-  if (maybe_object->IsFailure()) return maybe_object;
+  JSObject::EnsureCanContainElements(
+      array, args, 0, number_of_elements, ALLOW_CONVERTED_DOUBLE_ELEMENTS);

   // Allocate an appropriately typed elements array.
-  MaybeObject* maybe_elms;
   ElementsKind elements_kind = array->GetElementsKind();
+  Handle<FixedArrayBase> elms;
   if (IsFastDoubleElementsKind(elements_kind)) {
-    maybe_elms = heap->AllocateUninitializedFixedDoubleArray(
-        number_of_elements);
+    elms = Handle<FixedArrayBase>::cast(
+        factory->NewFixedDoubleArray(number_of_elements));
   } else {
-    maybe_elms = heap->AllocateFixedArrayWithHoles(number_of_elements);
+    elms = Handle<FixedArrayBase>::cast(
+        factory->NewFixedArrayWithHoles(number_of_elements));
   }
-  FixedArrayBase* elms;
-  if (!maybe_elms->To(&elms)) return maybe_elms;

   // Fill in the content
   switch (array->GetElementsKind()) {
     case FAST_HOLEY_SMI_ELEMENTS:
     case FAST_SMI_ELEMENTS: {
-      FixedArray* smi_elms = FixedArray::cast(elms);
+      Handle<FixedArray> smi_elms = Handle<FixedArray>::cast(elms);
       for (int index = 0; index < number_of_elements; index++) {
         smi_elms->set(index, (*args)[index], SKIP_WRITE_BARRIER);
       }
@@ -1991,7 +1977,7 @@
     case FAST_ELEMENTS: {
       DisallowHeapAllocation no_gc;
       WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc);
-      FixedArray* object_elms = FixedArray::cast(elms);
+      Handle<FixedArray> object_elms = Handle<FixedArray>::cast(elms);
       for (int index = 0; index < number_of_elements; index++) {
         object_elms->set(index, (*args)[index], mode);
       }
@@ -1999,7 +1985,8 @@
     }
     case FAST_HOLEY_DOUBLE_ELEMENTS:
     case FAST_DOUBLE_ELEMENTS: {
-      FixedDoubleArray* double_elms = FixedDoubleArray::cast(elms);
+      Handle<FixedDoubleArray> double_elms =
+          Handle<FixedDoubleArray>::cast(elms);
       for (int index = 0; index < number_of_elements; index++) {
         double_elms->set(index, (*args)[index]->Number());
       }
@@ -2010,7 +1997,7 @@
       break;
   }

-  array->set_elements(elms);
+  array->set_elements(*elms);
   array->set_length(Smi::FromInt(number_of_elements));
   return array;
 }
=======================================
--- /branches/bleeding_edge/src/elements.h      Mon Mar 17 15:01:45 2014 UTC
+++ /branches/bleeding_edge/src/elements.h      Tue Mar 18 11:38:27 2014 UTC
@@ -203,9 +203,6 @@
 Handle<Object> ArrayConstructInitializeElements(Handle<JSArray> array,
                                                 Arguments* args);

-MUST_USE_RESULT MaybeObject* ArrayConstructInitializeElements(
-    JSArray* array, Arguments* args);
-
 } }  // namespace v8::internal

 #endif  // V8_ELEMENTS_H_
=======================================
--- /branches/bleeding_edge/src/objects.cc      Mon Mar 17 15:01:45 2014 UTC
+++ /branches/bleeding_edge/src/objects.cc      Tue Mar 18 11:38:27 2014 UTC
@@ -11348,10 +11348,11 @@
 }


-MaybeObject* JSArray::Initialize(int capacity, int length) {
+// static
+void JSArray::Initialize(Handle<JSArray> array, int capacity, int length) {
   ASSERT(capacity >= 0);
-  return GetHeap()->AllocateJSArrayStorage(this, length, capacity,
- INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
+  array->GetIsolate()->factory()->NewJSArrayStorage(
+      array, length, capacity, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
 }


@@ -11430,6 +11431,16 @@
 }


+// 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) {
   // We should never end in here with a pixel or external array.
   ASSERT(AllowsSetElementsLength());
@@ -11891,6 +11902,21 @@
   ASSERT(size == object->Size());
   return value;
 }
+
+
+// TODO(ishell): temporary wrapper until handilfied.
+// static
+void JSObject::EnsureCanContainElements(Handle<JSObject> object,
+                                        Arguments* args,
+                                        uint32_t first_arg,
+                                        uint32_t arg_count,
+                                        EnsureElementsMode mode) {
+  CALL_HEAP_FUNCTION_VOID(object->GetIsolate(),
+                          object->EnsureCanContainElements(args,
+                                                           first_arg,
+                                                           arg_count,
+                                                           mode));
+}


 MaybeObject* JSObject::EnsureCanContainElements(Arguments* args,
=======================================
--- /branches/bleeding_edge/src/objects.h       Mon Mar 17 15:01:45 2014 UTC
+++ /branches/bleeding_edge/src/objects.h       Tue Mar 18 11:38:27 2014 UTC
@@ -2421,6 +2421,12 @@
   MUST_USE_RESULT inline MaybeObject* EnsureCanContainElements(
       FixedArrayBase* elements,
       uint32_t length,
+      EnsureElementsMode mode);
+  static void EnsureCanContainElements(
+      Handle<JSObject> object,
+      Arguments* arguments,
+      uint32_t first_arg,
+      uint32_t arg_count,
       EnsureElementsMode mode);
   MUST_USE_RESULT MaybeObject* EnsureCanContainElements(
       Arguments* arguments,
@@ -10011,11 +10017,13 @@
   // Initialize the array with the given capacity. The function may
   // fail due to out-of-memory situations, but only if the requested
   // capacity is non-zero.
-  MUST_USE_RESULT MaybeObject* Initialize(int capacity, int length = 0);
+ static void Initialize(Handle<JSArray> array, int capacity, int length = 0);

   // Initializes the array to a certain length.
   inline bool AllowsSetElementsLength();
   // 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.
=======================================
--- /branches/bleeding_edge/test/cctest/test-heap.cc Mon Mar 17 08:31:21 2014 UTC +++ /branches/bleeding_edge/test/cctest/test-heap.cc Tue Mar 18 11:38:27 2014 UTC
@@ -756,7 +756,7 @@
   Handle<JSObject> object = factory->NewJSObject(function);
   Handle<JSArray> array = Handle<JSArray>::cast(object);
   // We just initialized the VM, no heap allocation failure yet.
-  array->Initialize(0)->ToObjectChecked();
+  JSArray::Initialize(array, 0);

   // Set array length to 0.
   array->SetElementsLength(Smi::FromInt(0))->ToObjectChecked();

--
--
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