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 int args_length = args.length(); | |
1167 CHECK(args_length >= 2); | |
arv (Not doing code reviews)
2015/03/03 18:15:20
Does this need to be a CHECK and not a DCHECK?
Dmitry Lomov (no reviews)
2015/03/03 18:18:08
CHECK is safer (and does not cost us much)
| |
1168 | |
1169 // This variables and checks work around -Werror=strict-overflow. | |
1170 int pre_last_arg_index = args_length - 2; | |
1171 int last_arg_index = args_length - 1; | |
1172 CHECK(pre_last_arg_index >= 0); | |
1173 CHECK(last_arg_index >= 0); | |
1174 | |
1175 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, pre_last_arg_index); | |
1176 CONVERT_ARG_HANDLE_CHECKED(JSFunction, original_constructor, last_arg_index); | |
1177 Arguments caller_args(args_length - 2, args.arguments()); | |
1178 return ArrayConstructorCommon(isolate, constructor, original_constructor, | |
1179 Handle<AllocationSite>::null(), &caller_args); | |
1180 } | |
1181 | |
1182 | |
1149 RUNTIME_FUNCTION(Runtime_InternalArrayConstructor) { | 1183 RUNTIME_FUNCTION(Runtime_InternalArrayConstructor) { |
1150 HandleScope scope(isolate); | 1184 HandleScope scope(isolate); |
1151 Arguments empty_args(0, NULL); | 1185 Arguments empty_args(0, NULL); |
1152 bool no_caller_args = args.length() == 1; | 1186 bool no_caller_args = args.length() == 1; |
1153 DCHECK(no_caller_args || args.length() == 3); | 1187 DCHECK(no_caller_args || args.length() == 3); |
1154 int parameters_start = no_caller_args ? 0 : 1; | 1188 int parameters_start = no_caller_args ? 0 : 1; |
1155 Arguments* caller_args = | 1189 Arguments* caller_args = |
1156 no_caller_args ? &empty_args : reinterpret_cast<Arguments*>(args[0]); | 1190 no_caller_args ? &empty_args : reinterpret_cast<Arguments*>(args[0]); |
1157 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, parameters_start); | 1191 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, parameters_start); |
1158 #ifdef DEBUG | 1192 #ifdef DEBUG |
1159 if (!no_caller_args) { | 1193 if (!no_caller_args) { |
1160 CONVERT_SMI_ARG_CHECKED(arg_count, parameters_start + 1); | 1194 CONVERT_SMI_ARG_CHECKED(arg_count, parameters_start + 1); |
1161 DCHECK(arg_count == caller_args->length()); | 1195 DCHECK(arg_count == caller_args->length()); |
1162 } | 1196 } |
1163 #endif | 1197 #endif |
1164 return ArrayConstructorCommon(isolate, constructor, | 1198 return ArrayConstructorCommon(isolate, constructor, constructor, |
1165 Handle<AllocationSite>::null(), caller_args); | 1199 Handle<AllocationSite>::null(), caller_args); |
1166 } | 1200 } |
1167 | 1201 |
1168 | 1202 |
1169 RUNTIME_FUNCTION(Runtime_NormalizeElements) { | 1203 RUNTIME_FUNCTION(Runtime_NormalizeElements) { |
1170 HandleScope scope(isolate); | 1204 HandleScope scope(isolate); |
1171 DCHECK(args.length() == 1); | 1205 DCHECK(args.length() == 1); |
1172 CONVERT_ARG_HANDLE_CHECKED(JSObject, array, 0); | 1206 CONVERT_ARG_HANDLE_CHECKED(JSObject, array, 0); |
1173 RUNTIME_ASSERT(!array->HasExternalArrayElements() && | 1207 RUNTIME_ASSERT(!array->HasExternalArrayElements() && |
1174 !array->HasFixedTypedArrayElements() && | 1208 !array->HasFixedTypedArrayElements() && |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1310 } | 1344 } |
1311 | 1345 |
1312 | 1346 |
1313 RUNTIME_FUNCTION(RuntimeReference_FastOneByteArrayJoin) { | 1347 RUNTIME_FUNCTION(RuntimeReference_FastOneByteArrayJoin) { |
1314 SealHandleScope shs(isolate); | 1348 SealHandleScope shs(isolate); |
1315 DCHECK(args.length() == 2); | 1349 DCHECK(args.length() == 2); |
1316 return isolate->heap()->undefined_value(); | 1350 return isolate->heap()->undefined_value(); |
1317 } | 1351 } |
1318 } | 1352 } |
1319 } // namespace v8::internal | 1353 } // namespace v8::internal |
OLD | NEW |