| Index: src/builtins.cc
|
| diff --git a/src/builtins.cc b/src/builtins.cc
|
| index 34b370fe664fe416f871bb7cf5d09779ca37211e..4e343da9b04eee134fd96758ef8442ff2e3a8116 100644
|
| --- a/src/builtins.cc
|
| +++ b/src/builtins.cc
|
| @@ -208,12 +208,12 @@ inline bool PrototypeHasNoElements(PrototypeIterator* iter) {
|
| JSObject* current = iter->GetCurrent<JSObject>();
|
| if (current->IsAccessCheckNeeded()) return false;
|
| if (current->HasIndexedInterceptor()) return false;
|
| + if (current->IsJSValue()) return false;
|
| if (current->elements()->length() != 0) return false;
|
| }
|
| return true;
|
| }
|
|
|
| -
|
| inline bool IsJSArrayFastElementMovingAllowed(Isolate* isolate,
|
| JSArray* receiver) {
|
| DisallowHeapAllocation no_gc;
|
| @@ -231,6 +231,37 @@ inline bool IsJSArrayFastElementMovingAllowed(Isolate* isolate,
|
| return PrototypeHasNoElements(&iter);
|
| }
|
|
|
| +inline bool HasSimpleElements(JSObject* current) {
|
| + if (current->IsAccessCheckNeeded()) return false;
|
| + if (current->HasIndexedInterceptor()) return false;
|
| + if (current->IsJSValue()) return false;
|
| + if (current->GetElementsAccessor()->HasAccessors(current)) return false;
|
| + return true;
|
| +}
|
| +
|
| +inline bool HasOnlySimpleReceiverElements(Isolate* isolate,
|
| + JSReceiver* receiver) {
|
| + // Check that we have no accessors on the receiver's elements.
|
| + JSObject* object = JSObject::cast(receiver);
|
| + if (!HasSimpleElements(object)) return false;
|
| + // Check that ther are not elements on the prototype.
|
| + DisallowHeapAllocation no_gc;
|
| + PrototypeIterator iter(isolate, receiver);
|
| + return PrototypeHasNoElements(&iter);
|
| +}
|
| +
|
| +inline bool HasOnlySimpleElements(Isolate* isolate, JSReceiver* receiver) {
|
| + // Check that ther are not elements on the prototype.
|
| + DisallowHeapAllocation no_gc;
|
| + PrototypeIterator iter(isolate, receiver,
|
| + PrototypeIterator::START_AT_RECEIVER);
|
| + for (; !iter.IsAtEnd(); iter.Advance()) {
|
| + if (iter.GetCurrent()->IsJSProxy()) return false;
|
| + JSObject* current = iter.GetCurrent<JSObject>();
|
| + if (!HasSimpleElements(current)) return false;
|
| + }
|
| + return true;
|
| +}
|
|
|
| // Returns empty handle if not applicable.
|
| MUST_USE_RESULT
|
| @@ -1013,9 +1044,10 @@ bool IterateElements(Isolate* isolate, Handle<JSReceiver> receiver,
|
| if (!val->ToUint32(&length)) {
|
| length = 0;
|
| }
|
| + return IterateElementsSlow(isolate, receiver, length, visitor);
|
| }
|
|
|
| - if (!(receiver->IsJSArray() || receiver->IsJSTypedArray())) {
|
| + if (!HasOnlySimpleElements(isolate, *receiver)) {
|
| // For classes which are not known to be safe to access via elements alone,
|
| // use the slow case.
|
| return IterateElementsSlow(isolate, receiver, length, visitor);
|
| @@ -1031,7 +1063,7 @@ bool IterateElements(Isolate* isolate, Handle<JSReceiver> receiver,
|
| // to check the prototype for missing elements.
|
| Handle<FixedArray> elements(FixedArray::cast(array->elements()));
|
| int fast_length = static_cast<int>(length);
|
| - DCHECK(fast_length <= elements->length());
|
| + DCHECK_LE(fast_length, elements->length());
|
| for (int j = 0; j < fast_length; j++) {
|
| HandleScope loop_scope(isolate);
|
| Handle<Object> element_value(elements->get(j), isolate);
|
| @@ -1090,14 +1122,6 @@ bool IterateElements(Isolate* isolate, Handle<JSReceiver> receiver,
|
| break;
|
| }
|
| case DICTIONARY_ELEMENTS: {
|
| - // CollectElementIndices() can't be called when there's a JSProxy
|
| - // on the prototype chain.
|
| - for (PrototypeIterator iter(isolate, array); !iter.IsAtEnd();
|
| - iter.Advance()) {
|
| - if (PrototypeIterator::GetCurrent(iter)->IsJSProxy()) {
|
| - return IterateElementsSlow(isolate, array, length, visitor);
|
| - }
|
| - }
|
| Handle<SeededNumberDictionary> dict(array->element_dictionary());
|
| List<uint32_t> indices(dict->Capacity() / 2);
|
| // Collect all indices in the object and the prototypes less
|
| @@ -1187,7 +1211,6 @@ bool IterateElements(Isolate* isolate, Handle<JSReceiver> receiver,
|
|
|
|
|
| bool HasConcatSpreadableModifier(Isolate* isolate, Handle<JSArray> obj) {
|
| - DCHECK(isolate->IsFastArrayConstructorPrototypeChainIntact());
|
| if (!FLAG_harmony_concat_spreadable) return false;
|
| Handle<Symbol> key(isolate->factory()->is_concat_spreadable_symbol());
|
| Maybe<bool> maybe = JSReceiver::HasProperty(obj, key);
|
| @@ -1232,17 +1255,14 @@ Object* Slow_ArrayConcat(Arguments* args, Isolate* isolate) {
|
| length_estimate = static_cast<uint32_t>(array->length()->Number());
|
| if (length_estimate != 0) {
|
| ElementsKind array_kind =
|
| - GetPackedElementsKind(array->map()->elements_kind());
|
| + GetPackedElementsKind(array->GetElementsKind());
|
| kind = GetMoreGeneralElementsKind(kind, array_kind);
|
| }
|
| element_estimate = EstimateElementCount(array);
|
| } else {
|
| if (obj->IsHeapObject()) {
|
| - if (obj->IsNumber()) {
|
| - kind = GetMoreGeneralElementsKind(kind, FAST_DOUBLE_ELEMENTS);
|
| - } else {
|
| - kind = GetMoreGeneralElementsKind(kind, FAST_ELEMENTS);
|
| - }
|
| + kind = GetMoreGeneralElementsKind(
|
| + kind, obj->IsNumber() ? FAST_DOUBLE_ELEMENTS : FAST_ELEMENTS);
|
| }
|
| length_estimate = 1;
|
| element_estimate = 1;
|
| @@ -1284,7 +1304,7 @@ Object* Slow_ArrayConcat(Arguments* args, Isolate* isolate) {
|
| } else {
|
| JSArray* array = JSArray::cast(*obj);
|
| uint32_t length = static_cast<uint32_t>(array->length()->Number());
|
| - switch (array->map()->elements_kind()) {
|
| + switch (array->GetElementsKind()) {
|
| case FAST_HOLEY_DOUBLE_ELEMENTS:
|
| case FAST_DOUBLE_ELEMENTS: {
|
| // Empty array is FixedArray but not FixedDoubleArray.
|
| @@ -1335,14 +1355,7 @@ Object* Slow_ArrayConcat(Arguments* args, Isolate* isolate) {
|
| }
|
| }
|
| if (!failure) {
|
| - 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;
|
| + return *isolate->factory()->NewJSArrayWithElements(storage, kind, j);
|
| }
|
| // In case of failure, fall through.
|
| }
|
| @@ -1387,23 +1400,23 @@ Object* Slow_ArrayConcat(Arguments* args, Isolate* isolate) {
|
|
|
|
|
| MaybeHandle<JSArray> Fast_ArrayConcat(Isolate* isolate, Arguments* args) {
|
| - if (!isolate->IsFastArrayConstructorPrototypeChainIntact()) {
|
| - return MaybeHandle<JSArray>();
|
| - }
|
| int n_arguments = args->length();
|
| int result_len = 0;
|
| {
|
| DisallowHeapAllocation no_gc;
|
| - Object* array_proto = isolate->array_function()->prototype();
|
| // Iterate through all the arguments performing checks
|
| // and calculating total length.
|
| for (int i = 0; i < n_arguments; i++) {
|
| Object* arg = (*args)[i];
|
| if (!arg->IsJSArray()) return MaybeHandle<JSArray>();
|
| + if (!HasOnlySimpleReceiverElements(isolate, JSObject::cast(arg))) {
|
| + return MaybeHandle<JSArray>();
|
| + }
|
| + // TODO(cbruni): support fast concatenation of DICTIONARY_ELEMENTS.
|
| + if (!JSObject::cast(arg)->HasFastElements()) {
|
| + return MaybeHandle<JSArray>();
|
| + }
|
| Handle<JSArray> array(JSArray::cast(arg), isolate);
|
| - if (!array->HasFastElements()) return MaybeHandle<JSArray>();
|
| - PrototypeIterator iter(isolate, arg);
|
| - if (iter.GetCurrent() != array_proto) return MaybeHandle<JSArray>();
|
| if (HasConcatSpreadableModifier(isolate, array)) {
|
| return MaybeHandle<JSArray>();
|
| }
|
|
|