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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/conversions-inl.h" | 8 #include "src/conversions-inl.h" |
9 #include "src/elements.h" | 9 #include "src/elements.h" |
10 #include "src/factory.h" | 10 #include "src/factory.h" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 Handle<FixedArray> keys = accumulator.GetKeys(KEEP_NUMBERS); | 228 Handle<FixedArray> keys = accumulator.GetKeys(KEEP_NUMBERS); |
229 for (int i = 0; i < keys->length(); i++) { | 229 for (int i = 0; i < keys->length(); i++) { |
230 if (NumberToUint32(keys->get(i)) >= length) keys->set_undefined(i); | 230 if (NumberToUint32(keys->get(i)) >= length) keys->set_undefined(i); |
231 } | 231 } |
232 return *isolate->factory()->NewJSArrayWithElements(keys); | 232 return *isolate->factory()->NewJSArrayWithElements(keys); |
233 } | 233 } |
234 | 234 |
235 | 235 |
236 static Object* ArrayConstructorCommon(Isolate* isolate, | 236 static Object* ArrayConstructorCommon(Isolate* isolate, |
237 Handle<JSFunction> constructor, | 237 Handle<JSFunction> constructor, |
238 Handle<JSFunction> original_constructor, | 238 Handle<JSFunction> new_target, |
239 Handle<AllocationSite> site, | 239 Handle<AllocationSite> site, |
240 Arguments* caller_args) { | 240 Arguments* caller_args) { |
241 Factory* factory = isolate->factory(); | 241 Factory* factory = isolate->factory(); |
242 | 242 |
243 bool holey = false; | 243 bool holey = false; |
244 bool can_use_type_feedback = true; | 244 bool can_use_type_feedback = true; |
245 bool can_inline_array_constructor = true; | 245 bool can_inline_array_constructor = true; |
246 if (caller_args->length() == 1) { | 246 if (caller_args->length() == 1) { |
247 Handle<Object> argument_one = caller_args->at<Object>(0); | 247 Handle<Object> argument_one = caller_args->at<Object>(0); |
248 if (argument_one->IsSmi()) { | 248 if (argument_one->IsSmi()) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 !can_inline_array_constructor)) { | 310 !can_inline_array_constructor)) { |
311 // The arguments passed in caused a transition. This kind of complexity | 311 // The arguments passed in caused a transition. This kind of complexity |
312 // can't be dealt with in the inlined hydrogen array constructor case. | 312 // can't be dealt with in the inlined hydrogen array constructor case. |
313 // We must mark the allocationsite as un-inlinable. | 313 // We must mark the allocationsite as un-inlinable. |
314 site->SetDoNotInlineCall(); | 314 site->SetDoNotInlineCall(); |
315 } | 315 } |
316 | 316 |
317 // Set up the prototoype using original function. | 317 // Set up the prototoype using original function. |
318 // TODO(dslomov): instead of setting the __proto__, | 318 // TODO(dslomov): instead of setting the __proto__, |
319 // use and cache the correct map. | 319 // use and cache the correct map. |
320 if (*original_constructor != *constructor) { | 320 if (*new_target != *constructor) { |
321 if (original_constructor->has_instance_prototype()) { | 321 if (new_target->has_instance_prototype()) { |
322 Handle<Object> prototype = | 322 Handle<Object> prototype(new_target->instance_prototype(), isolate); |
323 handle(original_constructor->instance_prototype(), isolate); | |
324 MAYBE_RETURN(JSObject::SetPrototype(array, prototype, false, | 323 MAYBE_RETURN(JSObject::SetPrototype(array, prototype, false, |
325 Object::THROW_ON_ERROR), | 324 Object::THROW_ON_ERROR), |
326 isolate->heap()->exception()); | 325 isolate->heap()->exception()); |
327 } | 326 } |
328 } | 327 } |
329 | 328 |
330 return *array; | 329 return *array; |
331 } | 330 } |
332 | 331 |
333 | 332 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 int args_length = args.length(); | 369 int args_length = args.length(); |
371 CHECK(args_length >= 2); | 370 CHECK(args_length >= 2); |
372 | 371 |
373 // This variables and checks work around -Werror=strict-overflow. | 372 // This variables and checks work around -Werror=strict-overflow. |
374 int pre_last_arg_index = args_length - 2; | 373 int pre_last_arg_index = args_length - 2; |
375 int last_arg_index = args_length - 1; | 374 int last_arg_index = args_length - 1; |
376 CHECK(pre_last_arg_index >= 0); | 375 CHECK(pre_last_arg_index >= 0); |
377 CHECK(last_arg_index >= 0); | 376 CHECK(last_arg_index >= 0); |
378 | 377 |
379 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, pre_last_arg_index); | 378 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, pre_last_arg_index); |
380 CONVERT_ARG_HANDLE_CHECKED(JSFunction, original_constructor, last_arg_index); | 379 CONVERT_ARG_HANDLE_CHECKED(JSFunction, new_target, last_arg_index); |
381 Arguments caller_args(args_length - 2, args.arguments()); | 380 Arguments caller_args(args_length - 2, args.arguments()); |
382 return ArrayConstructorCommon(isolate, constructor, original_constructor, | 381 return ArrayConstructorCommon(isolate, constructor, new_target, |
383 Handle<AllocationSite>::null(), &caller_args); | 382 Handle<AllocationSite>::null(), &caller_args); |
384 } | 383 } |
385 | 384 |
386 | 385 |
387 RUNTIME_FUNCTION(Runtime_InternalArrayConstructor) { | 386 RUNTIME_FUNCTION(Runtime_InternalArrayConstructor) { |
388 HandleScope scope(isolate); | 387 HandleScope scope(isolate); |
389 Arguments empty_args(0, NULL); | 388 Arguments empty_args(0, NULL); |
390 bool no_caller_args = args.length() == 1; | 389 bool no_caller_args = args.length() == 1; |
391 DCHECK(no_caller_args || args.length() == 3); | 390 DCHECK(no_caller_args || args.length() == 3); |
392 int parameters_start = no_caller_args ? 0 : 1; | 391 int parameters_start = no_caller_args ? 0 : 1; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 | 492 |
494 RUNTIME_FUNCTION(Runtime_FastOneByteArrayJoin) { | 493 RUNTIME_FUNCTION(Runtime_FastOneByteArrayJoin) { |
495 SealHandleScope shs(isolate); | 494 SealHandleScope shs(isolate); |
496 DCHECK(args.length() == 2); | 495 DCHECK(args.length() == 2); |
497 // Returning undefined means that this fast path fails and one has to resort | 496 // Returning undefined means that this fast path fails and one has to resort |
498 // to a slow path. | 497 // to a slow path. |
499 return isolate->heap()->undefined_value(); | 498 return isolate->heap()->undefined_value(); |
500 } | 499 } |
501 } // namespace internal | 500 } // namespace internal |
502 } // namespace v8 | 501 } // namespace v8 |
OLD | NEW |