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/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 #include "src/conversions-inl.h" | 9 #include "src/conversions-inl.h" |
10 #include "src/elements.h" | 10 #include "src/elements.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 CHECK(length->IsSmi()); | 25 CHECK(length->IsSmi()); |
26 CHECK(Smi::cast(length)->value() == 0); | 26 CHECK(Smi::cast(length)->value() == 0); |
27 CHECK(prototype->HasFastSmiOrObjectElements()); | 27 CHECK(prototype->HasFastSmiOrObjectElements()); |
28 // This is necessary to enable fast checks for absence of elements | 28 // This is necessary to enable fast checks for absence of elements |
29 // on Array.prototype and below. | 29 // on Array.prototype and below. |
30 prototype->set_elements(isolate->heap()->empty_fixed_array()); | 30 prototype->set_elements(isolate->heap()->empty_fixed_array()); |
31 return Smi::FromInt(0); | 31 return Smi::FromInt(0); |
32 } | 32 } |
33 | 33 |
34 static void InstallCode(Isolate* isolate, Handle<JSObject> holder, | 34 static void InstallCode(Isolate* isolate, Handle<JSObject> holder, |
35 const char* name, Handle<Code> code) { | 35 const char* name, Handle<Code> code, int argc = -1) { |
36 Handle<String> key = isolate->factory()->InternalizeUtf8String(name); | 36 Handle<String> key = isolate->factory()->InternalizeUtf8String(name); |
37 Handle<JSFunction> optimized = | 37 Handle<JSFunction> optimized = |
38 isolate->factory()->NewFunctionWithoutPrototype(key, code); | 38 isolate->factory()->NewFunctionWithoutPrototype(key, code); |
39 optimized->shared()->DontAdaptArguments(); | 39 if (argc < 0) { |
caitp
2016/07/14 18:01:18
These changes are needed for any of these runtime
| |
40 optimized->shared()->DontAdaptArguments(); | |
41 } else { | |
42 optimized->shared()->set_internal_formal_parameter_count(argc); | |
43 } | |
40 JSObject::AddProperty(holder, key, optimized, NONE); | 44 JSObject::AddProperty(holder, key, optimized, NONE); |
41 } | 45 } |
42 | 46 |
43 static void InstallBuiltin(Isolate* isolate, Handle<JSObject> holder, | 47 static void InstallBuiltin(Isolate* isolate, Handle<JSObject> holder, |
44 const char* name, Builtins::Name builtin_name) { | 48 const char* name, Builtins::Name builtin_name, |
49 int argc = -1) { | |
45 InstallCode(isolate, holder, name, | 50 InstallCode(isolate, holder, name, |
46 handle(isolate->builtins()->builtin(builtin_name), isolate)); | 51 handle(isolate->builtins()->builtin(builtin_name), isolate), |
52 argc); | |
47 } | 53 } |
48 | 54 |
49 RUNTIME_FUNCTION(Runtime_SpecialArrayFunctions) { | 55 RUNTIME_FUNCTION(Runtime_SpecialArrayFunctions) { |
50 HandleScope scope(isolate); | 56 HandleScope scope(isolate); |
51 DCHECK(args.length() == 0); | 57 DCHECK(args.length() == 0); |
52 Handle<JSObject> holder = | 58 Handle<JSObject> holder = |
53 isolate->factory()->NewJSObject(isolate->object_function()); | 59 isolate->factory()->NewJSObject(isolate->object_function()); |
54 | 60 |
55 InstallBuiltin(isolate, holder, "pop", Builtins::kArrayPop); | 61 InstallBuiltin(isolate, holder, "pop", Builtins::kArrayPop); |
56 FastArrayPushStub stub(isolate); | 62 FastArrayPushStub stub(isolate); |
57 InstallCode(isolate, holder, "push", stub.GetCode()); | 63 InstallCode(isolate, holder, "push", stub.GetCode()); |
58 InstallBuiltin(isolate, holder, "shift", Builtins::kArrayShift); | 64 InstallBuiltin(isolate, holder, "shift", Builtins::kArrayShift); |
59 InstallBuiltin(isolate, holder, "unshift", Builtins::kArrayUnshift); | 65 InstallBuiltin(isolate, holder, "unshift", Builtins::kArrayUnshift); |
60 InstallBuiltin(isolate, holder, "slice", Builtins::kArraySlice); | 66 InstallBuiltin(isolate, holder, "slice", Builtins::kArraySlice); |
61 InstallBuiltin(isolate, holder, "splice", Builtins::kArraySplice); | 67 InstallBuiltin(isolate, holder, "splice", Builtins::kArraySplice); |
68 InstallBuiltin(isolate, holder, "includes", Builtins::kArrayIncludes, 2); | |
62 | 69 |
63 return *holder; | 70 return *holder; |
64 } | 71 } |
65 | 72 |
66 | 73 |
67 RUNTIME_FUNCTION(Runtime_FixedArrayGet) { | 74 RUNTIME_FUNCTION(Runtime_FixedArrayGet) { |
68 SealHandleScope shs(isolate); | 75 SealHandleScope shs(isolate); |
69 DCHECK(args.length() == 2); | 76 DCHECK(args.length() == 2); |
70 CONVERT_ARG_CHECKED(FixedArray, object, 0); | 77 CONVERT_ARG_CHECKED(FixedArray, object, 0); |
71 CONVERT_SMI_ARG_CHECKED(index, 1); | 78 CONVERT_SMI_ARG_CHECKED(index, 1); |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
431 | 438 |
432 | 439 |
433 RUNTIME_FUNCTION(Runtime_ArraySpeciesConstructor) { | 440 RUNTIME_FUNCTION(Runtime_ArraySpeciesConstructor) { |
434 HandleScope scope(isolate); | 441 HandleScope scope(isolate); |
435 DCHECK(args.length() == 1); | 442 DCHECK(args.length() == 1); |
436 CONVERT_ARG_HANDLE_CHECKED(Object, original_array, 0); | 443 CONVERT_ARG_HANDLE_CHECKED(Object, original_array, 0); |
437 RETURN_RESULT_OR_FAILURE( | 444 RETURN_RESULT_OR_FAILURE( |
438 isolate, Object::ArraySpeciesConstructor(isolate, original_array)); | 445 isolate, Object::ArraySpeciesConstructor(isolate, original_array)); |
439 } | 446 } |
440 | 447 |
448 // ES7 22.1.3.11 Array.prototype.includes | |
449 RUNTIME_FUNCTION(Runtime_ArrayIncludes_Slow) { | |
450 HandleScope shs(isolate); | |
451 DCHECK(args.length() == 3); | |
452 CONVERT_ARG_HANDLE_CHECKED(Object, search_element, 1); | |
453 CONVERT_ARG_HANDLE_CHECKED(Object, from_index_, 2); | |
454 | |
455 ::printf("ArrayIncludes_Slow()\n"); | |
456 // 1. Let O be ? ToObject(this value). | |
457 Handle<JSReceiver> object; | |
458 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
459 isolate, object, Object::ToObject(isolate, handle(args[0], isolate))); | |
460 | |
461 // 2. Let len be ? ToLength(? Get(O, "length")). | |
462 Handle<Object> len_; | |
463 Handle<String> length_string = | |
464 handle(isolate->heap()->length_string(), isolate); | |
465 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
466 isolate, len_, Object::GetProperty(object, length_string)); | |
467 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, len_, | |
468 Object::ToLength(isolate, len_)); | |
469 int64_t len = static_cast<int64_t>(len_->Number()); | |
470 DCHECK_EQ(len, len_->Number()); | |
471 | |
472 // 3. If len is 0, return false. | |
473 if (len == 0) return isolate->heap()->false_value(); | |
474 | |
475 // 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, | |
476 // this step produces the value 0.) | |
477 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, from_index_, | |
478 Object::ToInteger(isolate, from_index_)); | |
479 if (std::isinf(from_index_->Number()) && from_index_->Number() > 0.0) { | |
480 return isolate->heap()->false_value(); | |
481 } | |
482 int64_t from_index = static_cast<int64_t>(from_index_->Number()); | |
483 | |
484 int64_t k; | |
485 if (from_index >= 0) { | |
486 k = from_index; | |
487 } else { | |
488 k = len + from_index; | |
489 if (k < 0) { | |
490 k = 0; | |
491 } | |
492 } | |
493 | |
494 if (IsFastPackedElementsKind(object->map()->elements_kind()) && | |
495 len < std::numeric_limits<uint32_t>::max()) { | |
496 uint32_t i = static_cast<uint32_t>(k); | |
497 for (; i < static_cast<uint32_t>(len); ++i) { | |
498 Handle<Object> element_k; | |
499 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
500 isolate, element_k, Object::GetElement(isolate, object, i)); | |
501 if (search_element->SameValueZero(*element_k)) { | |
502 return isolate->heap()->true_value(); | |
503 } | |
504 } | |
505 return isolate->heap()->false_value(); | |
506 } | |
507 | |
508 bool stable = !object->IsJSProxy() && | |
509 IsFastElementsKind(object->map()->elements_kind()); | |
510 Handle<Map> original_map = handle(object->map(), isolate); | |
511 for (; k < len; ++k) { | |
512 Handle<Object> element_k; | |
513 if (stable && k < std::numeric_limits<uint32_t>::max()) { | |
514 uint32_t index = static_cast<uint32_t>(k); | |
515 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
516 isolate, element_k, Object::GetElement(isolate, object, index)); | |
517 stable = object->map() == *original_map; | |
518 } else { | |
519 Handle<String> name; | |
520 Handle<Object> num = | |
521 isolate->factory()->NewNumber(static_cast<double>(k)); | |
522 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name, | |
523 Object::ToString(isolate, num)); | |
524 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
525 isolate, element_k, Object::GetPropertyOrElement(object, name)); | |
526 } | |
527 | |
528 if (search_element->SameValueZero(*element_k)) { | |
529 return isolate->heap()->true_value(); | |
530 } | |
531 } | |
532 return isolate->heap()->false_value(); | |
533 } | |
534 | |
441 } // namespace internal | 535 } // namespace internal |
442 } // namespace v8 | 536 } // namespace v8 |
OLD | NEW |