Revision: 20918
Author: [email protected]
Date: Thu Apr 24 05:29:00 2014 UTC
Log: Fix C++ type of Factory::NewFixedDoubleArray.
The change fixes the C++ type of Factory::NewFixedDoubleArray to
reflect the empty array case, where we return an empty
FixedArray (rather than FixedDoubleArray).
[email protected]
BUG=
Review URL: https://codereview.chromium.org/249593002
http://code.google.com/p/v8/source/detail?r=20918
Added:
/branches/bleeding_edge/test/mjsunit/regress/regress-empty-fixed-double-array.js
Modified:
/branches/bleeding_edge/src/builtins.cc
/branches/bleeding_edge/src/factory.cc
/branches/bleeding_edge/src/factory.h
/branches/bleeding_edge/src/runtime.cc
=======================================
--- /dev/null
+++
/branches/bleeding_edge/test/mjsunit/regress/regress-empty-fixed-double-array.js
Thu Apr 24 05:29:00 2014 UTC
@@ -0,0 +1,15 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --allow-natives-syntax --enable-slow-asserts
+
+function f(a, x) {
+ a.shift();
+ a[0] = x;
+}
+
+f([1], 1.1);
+f([1], 1.1);
+%OptimizeFunctionOnNextCall(f);
+f([1], 1.1);
=======================================
--- /branches/bleeding_edge/src/builtins.cc Tue Apr 22 14:55:47 2014 UTC
+++ /branches/bleeding_edge/src/builtins.cc Thu Apr 24 05:29:00 2014 UTC
@@ -470,7 +470,10 @@
if (new_length > elms_len) {
// New backing storage is needed.
int capacity = new_length + (new_length >> 1) + 16;
- new_elms = isolate->factory()->NewFixedDoubleArray(capacity);
+ // Create new backing store; since capacity > 0, we can
+ // safely cast to FixedDoubleArray.
+ new_elms = Handle<FixedDoubleArray>::cast(
+ isolate->factory()->NewFixedDoubleArray(capacity));
ElementsAccessor* accessor = array->GetElementsAccessor();
accessor->CopyElements(
=======================================
--- /branches/bleeding_edge/src/factory.cc Wed Apr 23 15:43:39 2014 UTC
+++ /branches/bleeding_edge/src/factory.cc Thu Apr 24 05:29:00 2014 UTC
@@ -88,23 +88,27 @@
}
-Handle<FixedDoubleArray> Factory::NewFixedDoubleArray(int size,
+Handle<FixedArrayBase> Factory::NewFixedDoubleArray(int size,
PretenureFlag
pretenure) {
ASSERT(0 <= size);
CALL_HEAP_FUNCTION(
isolate(),
isolate()->heap()->AllocateUninitializedFixedDoubleArray(size,
pretenure),
- FixedDoubleArray);
+ FixedArrayBase);
}
-Handle<FixedDoubleArray> Factory::NewFixedDoubleArrayWithHoles(
+Handle<FixedArrayBase> Factory::NewFixedDoubleArrayWithHoles(
int size,
PretenureFlag pretenure) {
ASSERT(0 <= size);
- Handle<FixedDoubleArray> array = NewFixedDoubleArray(size, pretenure);
- for (int i = 0; i < size; ++i) {
- array->set_the_hole(i);
+ Handle<FixedArrayBase> array = NewFixedDoubleArray(size, pretenure);
+ if (size > 0) {
+ Handle<FixedDoubleArray> double_array =
+ Handle<FixedDoubleArray>::cast(array);
+ for (int i = 0; i < size; ++i) {
+ double_array->set_the_hole(i);
+ }
}
return array;
}
=======================================
--- /branches/bleeding_edge/src/factory.h Wed Apr 23 15:43:39 2014 UTC
+++ /branches/bleeding_edge/src/factory.h Thu Apr 24 05:29:00 2014 UTC
@@ -33,12 +33,14 @@
Handle<FixedArray> NewUninitializedFixedArray(int size);
// Allocate a new uninitialized fixed double array.
- Handle<FixedDoubleArray> NewFixedDoubleArray(
+ // The function returns a pre-allocated empty fixed array for capacity =
0,
+ // so the return type must be the general fixed array class.
+ Handle<FixedArrayBase> NewFixedDoubleArray(
int size,
PretenureFlag pretenure = NOT_TENURED);
// Allocate a new fixed double array with hole values.
- Handle<FixedDoubleArray> NewFixedDoubleArrayWithHoles(
+ Handle<FixedArrayBase> NewFixedDoubleArrayWithHoles(
int size,
PretenureFlag pretenure = NOT_TENURED);
=======================================
--- /branches/bleeding_edge/src/runtime.cc Wed Apr 23 13:05:38 2014 UTC
+++ /branches/bleeding_edge/src/runtime.cc Thu Apr 24 05:29:00 2014 UTC
@@ -10484,12 +10484,13 @@
// dictionary.
bool fast_case = (estimate_nof_elements * 2) >= estimate_result_length;
- Handle<FixedArray> storage;
- if (fast_case) {
- if (kind == FAST_DOUBLE_ELEMENTS) {
+ if (fast_case && kind == FAST_DOUBLE_ELEMENTS) {
+ Handle<FixedArrayBase> storage =
+ isolate->factory()->NewFixedDoubleArray(estimate_result_length);
+ int j = 0;
+ if (estimate_result_length > 0) {
Handle<FixedDoubleArray> double_storage =
- isolate->factory()->NewFixedDoubleArray(estimate_result_length);
- int j = 0;
+ Handle<FixedDoubleArray>::cast(storage);
bool failure = false;
for (int i = 0; i < argument_count; i++) {
Handle<Object> obj(elements->get(i), isolate);
@@ -10545,15 +10546,19 @@
}
if (failure) break;
}
- Handle<JSArray> array = isolate->factory()->NewJSArray(0);
- Smi* length = Smi::FromInt(j);
- Handle<Map> map;
- map = JSObject::GetElementsTransitionMap(array, kind);
- array->set_map(*map);
- array->set_length(length);
- array->set_elements(*double_storage);
- return *array;
}
+ Handle<JSArray> array = isolate->factory()->NewJSArray(0);
+ Smi* length = Smi::FromInt(j);
+ Handle<Map> map;
+ map = JSObject::GetElementsTransitionMap(array, kind);
+ array->set_map(*map);
+ array->set_length(length);
+ array->set_elements(*storage);
+ return *array;
+ }
+
+ Handle<FixedArray> storage;
+ if (fast_case) {
// The backing storage array must have non-existing elements to
preserve
// holes across concat operations.
storage = isolate->factory()->NewFixedArrayWithHoles(
--
--
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.