Chromium Code Reviews| Index: src/runtime.cc |
| diff --git a/src/runtime.cc b/src/runtime.cc |
| index f8147a23b69408caa24cb31098d03791e4fe7e79..9ddff3e6f57e90b8fab4264524623b1cd4419266 100644 |
| --- a/src/runtime.cc |
| +++ b/src/runtime.cc |
| @@ -13441,6 +13441,105 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_UnwrapGlobalProxy) { |
| } |
| +static MaybeObject* ArrayConstructorCommon(Isolate* isolate, |
| + Handle<JSFunction> constructor, |
| + Handle<Object> type_info, |
| + Arguments* caller_args) { |
| + bool holey = false; |
| + bool can_use_type_feedback = true; |
| + if (caller_args->length() == 1) { |
| + Object* argument_one = (*caller_args)[0]; |
| + if (argument_one->IsSmi()) { |
| + int value = Smi::cast(argument_one)->value(); |
| + if (value < 0 || value >= JSObject::kInitialMaxFastElementArray) { |
| + // the array is a dictionary in this case. |
| + can_use_type_feedback = false; |
| + } else if (value != 0) { |
| + holey = true; |
| + } |
| + } else { |
| + // Non-smi length argument produces a dictionary |
| + can_use_type_feedback = false; |
| + } |
| + } |
| + |
| + JSArray* array; |
| + MaybeObject* maybe_array; |
| + if (!type_info.is_null() && |
| + *type_info != isolate->heap()->undefined_value() && |
| + JSGlobalPropertyCell::cast(*type_info)->value()->IsSmi() && |
| + can_use_type_feedback) { |
| + JSGlobalPropertyCell* cell = JSGlobalPropertyCell::cast(*type_info); |
| + Smi* smi = Smi::cast(cell->value()); |
| + ElementsKind to_kind = static_cast<ElementsKind>(smi->value()); |
| + if (holey && !IsFastHoleyElementsKind(to_kind)) { |
| + to_kind = GetHoleyElementsKind(to_kind); |
| + // Update the allocation site info to reflect the advice alteration. |
| + cell->set_value(Smi::FromInt(to_kind)); |
| + } |
| + |
| + maybe_array = isolate->heap()->AllocateJSObjectWithAllocationSite( |
| + *constructor, type_info); |
| + if (!maybe_array->To(&array)) return maybe_array; |
| + } else { |
| + maybe_array = isolate->heap()->AllocateJSObject(*constructor); |
| + if (!maybe_array->To(&array)) return maybe_array; |
| + // We might need to transition to holey |
| + ElementsKind kind = constructor->initial_map()->elements_kind(); |
| + if (holey && !IsFastHoleyElementsKind(kind)) { |
| + kind = GetHoleyElementsKind(kind); |
| + maybe_array = array->TransitionElementsKind(kind); |
| + if (maybe_array->IsFailure()) return maybe_array; |
| + } |
| + } |
| + |
| + maybe_array = isolate->heap()->AllocateJSArrayStorage(array, 0, 0, |
| + DONT_INITIALIZE_ARRAY_ELEMENTS); |
| + if (maybe_array->IsFailure()) return maybe_array; |
| + maybe_array = ArrayConstructInitializeElements(array, caller_args); |
| + if (maybe_array->IsFailure()) return maybe_array; |
| + return array; |
| +} |
| + |
| + |
| +RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayConstructor) { |
|
Michael Starzinger
2013/06/06 12:22:52
Each runtime function should have it's own HandleS
mvstanton
2013/06/06 12:30:32
Done.
|
| + // If we get 2 arguments then they are the stub parameters (constructor, type |
| + // info). If we get 3, then the first one is a pointer to the arguments |
| + // passed by the caller. |
| + Arguments empty_args(0, NULL); |
| + bool no_caller_args = args.length() == 2; |
| + ASSERT(no_caller_args || args.length() == 3); |
| + int parameters_start = no_caller_args ? 0 : 1; |
| + Arguments* caller_args = no_caller_args |
| + ? &empty_args |
| + : reinterpret_cast<Arguments*>(args[0]); |
| + Handle<JSFunction> constructor = args.at<JSFunction>(parameters_start); |
|
Michael Starzinger
2013/06/06 12:22:52
Use the CONVERT_ARG_HANDLE_CHECKED macro to access
mvstanton
2013/06/06 12:30:32
Done.
|
| + Handle<Object> type_info = args.at<Object>(parameters_start + 1); |
| + |
| + return ArrayConstructorCommon(isolate, |
| + constructor, |
| + type_info, |
| + caller_args); |
| +} |
| + |
| + |
| +RUNTIME_FUNCTION(MaybeObject*, Runtime_InternalArrayConstructor) { |
|
Michael Starzinger
2013/06/06 12:22:52
Likewise.
mvstanton
2013/06/06 12:30:32
Done.
|
| + Arguments empty_args(0, NULL); |
| + bool no_caller_args = args.length() == 1; |
| + ASSERT(no_caller_args || args.length() == 2); |
| + int parameters_start = no_caller_args ? 0 : 1; |
| + Arguments* caller_args = no_caller_args |
| + ? &empty_args |
| + : reinterpret_cast<Arguments*>(args[0]); |
| + Handle<JSFunction> constructor = args.at<JSFunction>(parameters_start); |
|
Michael Starzinger
2013/06/06 12:22:52
Use the CONVERT_ARG_HANDLE_CHECKED macro to access
mvstanton
2013/06/06 12:30:32
Done.
|
| + |
| + return ArrayConstructorCommon(isolate, |
| + constructor, |
| + Handle<Object>::null(), |
| + caller_args); |
| +} |
| + |
| + |
| // ---------------------------------------------------------------------------- |
| // Implementation of Runtime |