| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/runtime/runtime-utils.h" | 8 #include "src/runtime/runtime-utils.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 RUNTIME_ASSERT(array->HasFastSmiOrObjectElements() || | 1031 RUNTIME_ASSERT(array->HasFastSmiOrObjectElements() || |
| 1032 array->HasFastDoubleElements()); | 1032 array->HasFastDoubleElements()); |
| 1033 uint32_t actual_length = static_cast<uint32_t>(array->elements()->length()); | 1033 uint32_t actual_length = static_cast<uint32_t>(array->elements()->length()); |
| 1034 return *isolate->factory()->NewNumberFromUint(Min(actual_length, length)); | 1034 return *isolate->factory()->NewNumberFromUint(Min(actual_length, length)); |
| 1035 } | 1035 } |
| 1036 } | 1036 } |
| 1037 | 1037 |
| 1038 | 1038 |
| 1039 static Object* ArrayConstructorCommon(Isolate* isolate, | 1039 static Object* ArrayConstructorCommon(Isolate* isolate, |
| 1040 Handle<JSFunction> constructor, | 1040 Handle<JSFunction> constructor, |
| 1041 Handle<JSFunction> original_constructor, |
| 1041 Handle<AllocationSite> site, | 1042 Handle<AllocationSite> site, |
| 1042 Arguments* caller_args) { | 1043 Arguments* caller_args) { |
| 1043 Factory* factory = isolate->factory(); | 1044 Factory* factory = isolate->factory(); |
| 1044 | 1045 |
| 1045 bool holey = false; | 1046 bool holey = false; |
| 1046 bool can_use_type_feedback = true; | 1047 bool can_use_type_feedback = true; |
| 1047 if (caller_args->length() == 1) { | 1048 if (caller_args->length() == 1) { |
| 1048 Handle<Object> argument_one = caller_args->at<Object>(0); | 1049 Handle<Object> argument_one = caller_args->at<Object>(0); |
| 1049 if (argument_one->IsSmi()) { | 1050 if (argument_one->IsSmi()) { |
| 1050 int value = Handle<Smi>::cast(argument_one)->value(); | 1051 int value = Handle<Smi>::cast(argument_one)->value(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1102 ElementsKind old_kind = array->GetElementsKind(); | 1103 ElementsKind old_kind = array->GetElementsKind(); |
| 1103 RETURN_FAILURE_ON_EXCEPTION( | 1104 RETURN_FAILURE_ON_EXCEPTION( |
| 1104 isolate, ArrayConstructInitializeElements(array, caller_args)); | 1105 isolate, ArrayConstructInitializeElements(array, caller_args)); |
| 1105 if (!site.is_null() && | 1106 if (!site.is_null() && |
| 1106 (old_kind != array->GetElementsKind() || !can_use_type_feedback)) { | 1107 (old_kind != array->GetElementsKind() || !can_use_type_feedback)) { |
| 1107 // The arguments passed in caused a transition. This kind of complexity | 1108 // The arguments passed in caused a transition. This kind of complexity |
| 1108 // can't be dealt with in the inlined hydrogen array constructor case. | 1109 // can't be dealt with in the inlined hydrogen array constructor case. |
| 1109 // We must mark the allocationsite as un-inlinable. | 1110 // We must mark the allocationsite as un-inlinable. |
| 1110 site->SetDoNotInlineCall(); | 1111 site->SetDoNotInlineCall(); |
| 1111 } | 1112 } |
| 1113 |
| 1114 // Set up the prototoype using original function. |
| 1115 // TODO(dslomov): instead of setting the __proto__, |
| 1116 // use and cache the correct map. |
| 1117 if (*original_constructor != *constructor) { |
| 1118 if (original_constructor->has_instance_prototype()) { |
| 1119 Handle<Object> prototype = |
| 1120 handle(original_constructor->instance_prototype(), isolate); |
| 1121 RETURN_FAILURE_ON_EXCEPTION( |
| 1122 isolate, JSObject::SetPrototype(array, prototype, false)); |
| 1123 } |
| 1124 } |
| 1125 |
| 1112 return *array; | 1126 return *array; |
| 1113 } | 1127 } |
| 1114 | 1128 |
| 1115 | 1129 |
| 1116 RUNTIME_FUNCTION(Runtime_ArrayConstructor) { | 1130 RUNTIME_FUNCTION(Runtime_ArrayConstructor) { |
| 1117 HandleScope scope(isolate); | 1131 HandleScope scope(isolate); |
| 1118 // If we get 2 arguments then they are the stub parameters (constructor, type | 1132 // If we get 2 arguments then they are the stub parameters (constructor, type |
| 1119 // info). If we get 4, then the first one is a pointer to the arguments | 1133 // info). If we get 4, then the first one is a pointer to the arguments |
| 1120 // passed by the caller, and the last one is the length of the arguments | 1134 // passed by the caller, and the last one is the length of the arguments |
| 1121 // passed to the caller (redundant, but useful to check on the deoptimizer | 1135 // passed to the caller (redundant, but useful to check on the deoptimizer |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1135 } | 1149 } |
| 1136 #endif | 1150 #endif |
| 1137 | 1151 |
| 1138 Handle<AllocationSite> site; | 1152 Handle<AllocationSite> site; |
| 1139 if (!type_info.is_null() && | 1153 if (!type_info.is_null() && |
| 1140 *type_info != isolate->heap()->undefined_value()) { | 1154 *type_info != isolate->heap()->undefined_value()) { |
| 1141 site = Handle<AllocationSite>::cast(type_info); | 1155 site = Handle<AllocationSite>::cast(type_info); |
| 1142 DCHECK(!site->SitePointsToLiteral()); | 1156 DCHECK(!site->SitePointsToLiteral()); |
| 1143 } | 1157 } |
| 1144 | 1158 |
| 1145 return ArrayConstructorCommon(isolate, constructor, site, caller_args); | 1159 return ArrayConstructorCommon(isolate, constructor, constructor, site, |
| 1160 caller_args); |
| 1146 } | 1161 } |
| 1147 | 1162 |
| 1148 | 1163 |
| 1164 RUNTIME_FUNCTION(Runtime_ArrayConstructorWithSubclassing) { |
| 1165 HandleScope scope(isolate); |
| 1166 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, args.length() - 2); |
| 1167 CONVERT_ARG_HANDLE_CHECKED(JSFunction, original_constructor, |
| 1168 args.length() - 1); |
| 1169 Arguments caller_args(args.length() - 2, args.arguments()); |
| 1170 return ArrayConstructorCommon(isolate, constructor, original_constructor, |
| 1171 Handle<AllocationSite>::null(), &caller_args); |
| 1172 } |
| 1173 |
| 1174 |
| 1149 RUNTIME_FUNCTION(Runtime_InternalArrayConstructor) { | 1175 RUNTIME_FUNCTION(Runtime_InternalArrayConstructor) { |
| 1150 HandleScope scope(isolate); | 1176 HandleScope scope(isolate); |
| 1151 Arguments empty_args(0, NULL); | 1177 Arguments empty_args(0, NULL); |
| 1152 bool no_caller_args = args.length() == 1; | 1178 bool no_caller_args = args.length() == 1; |
| 1153 DCHECK(no_caller_args || args.length() == 3); | 1179 DCHECK(no_caller_args || args.length() == 3); |
| 1154 int parameters_start = no_caller_args ? 0 : 1; | 1180 int parameters_start = no_caller_args ? 0 : 1; |
| 1155 Arguments* caller_args = | 1181 Arguments* caller_args = |
| 1156 no_caller_args ? &empty_args : reinterpret_cast<Arguments*>(args[0]); | 1182 no_caller_args ? &empty_args : reinterpret_cast<Arguments*>(args[0]); |
| 1157 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, parameters_start); | 1183 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, parameters_start); |
| 1158 #ifdef DEBUG | 1184 #ifdef DEBUG |
| 1159 if (!no_caller_args) { | 1185 if (!no_caller_args) { |
| 1160 CONVERT_SMI_ARG_CHECKED(arg_count, parameters_start + 1); | 1186 CONVERT_SMI_ARG_CHECKED(arg_count, parameters_start + 1); |
| 1161 DCHECK(arg_count == caller_args->length()); | 1187 DCHECK(arg_count == caller_args->length()); |
| 1162 } | 1188 } |
| 1163 #endif | 1189 #endif |
| 1164 return ArrayConstructorCommon(isolate, constructor, | 1190 return ArrayConstructorCommon(isolate, constructor, constructor, |
| 1165 Handle<AllocationSite>::null(), caller_args); | 1191 Handle<AllocationSite>::null(), caller_args); |
| 1166 } | 1192 } |
| 1167 | 1193 |
| 1168 | 1194 |
| 1169 RUNTIME_FUNCTION(Runtime_NormalizeElements) { | 1195 RUNTIME_FUNCTION(Runtime_NormalizeElements) { |
| 1170 HandleScope scope(isolate); | 1196 HandleScope scope(isolate); |
| 1171 DCHECK(args.length() == 1); | 1197 DCHECK(args.length() == 1); |
| 1172 CONVERT_ARG_HANDLE_CHECKED(JSObject, array, 0); | 1198 CONVERT_ARG_HANDLE_CHECKED(JSObject, array, 0); |
| 1173 RUNTIME_ASSERT(!array->HasExternalArrayElements() && | 1199 RUNTIME_ASSERT(!array->HasExternalArrayElements() && |
| 1174 !array->HasFixedTypedArrayElements() && | 1200 !array->HasFixedTypedArrayElements() && |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1310 } | 1336 } |
| 1311 | 1337 |
| 1312 | 1338 |
| 1313 RUNTIME_FUNCTION(RuntimeReference_FastOneByteArrayJoin) { | 1339 RUNTIME_FUNCTION(RuntimeReference_FastOneByteArrayJoin) { |
| 1314 SealHandleScope shs(isolate); | 1340 SealHandleScope shs(isolate); |
| 1315 DCHECK(args.length() == 2); | 1341 DCHECK(args.length() == 2); |
| 1316 return isolate->heap()->undefined_value(); | 1342 return isolate->heap()->undefined_value(); |
| 1317 } | 1343 } |
| 1318 } | 1344 } |
| 1319 } // namespace v8::internal | 1345 } // namespace v8::internal |
| OLD | NEW |