| 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 13 matching lines...) Expand all Loading... |
| 24 Object* length = prototype->length(); | 24 Object* length = prototype->length(); |
| 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::kZero; | 31 return Smi::kZero; |
| 32 } | 32 } |
| 33 | 33 |
| 34 static void InstallCode(Isolate* isolate, Handle<JSObject> holder, | 34 static void InstallCode( |
| 35 const char* name, Handle<Code> code, int argc = -1) { | 35 Isolate* isolate, Handle<JSObject> holder, const char* name, |
| 36 Handle<Code> code, int argc = -1, |
| 37 BuiltinFunctionId id = static_cast<BuiltinFunctionId>(-1)) { |
| 36 Handle<String> key = isolate->factory()->InternalizeUtf8String(name); | 38 Handle<String> key = isolate->factory()->InternalizeUtf8String(name); |
| 37 Handle<JSFunction> optimized = | 39 Handle<JSFunction> optimized = |
| 38 isolate->factory()->NewFunctionWithoutPrototype(key, code); | 40 isolate->factory()->NewFunctionWithoutPrototype(key, code); |
| 39 if (argc < 0) { | 41 if (argc < 0) { |
| 40 optimized->shared()->DontAdaptArguments(); | 42 optimized->shared()->DontAdaptArguments(); |
| 41 } else { | 43 } else { |
| 42 optimized->shared()->set_internal_formal_parameter_count(argc); | 44 optimized->shared()->set_internal_formal_parameter_count(argc); |
| 43 } | 45 } |
| 46 if (id >= 0) { |
| 47 optimized->shared()->set_builtin_function_id(id); |
| 48 } |
| 44 JSObject::AddProperty(holder, key, optimized, NONE); | 49 JSObject::AddProperty(holder, key, optimized, NONE); |
| 45 } | 50 } |
| 46 | 51 |
| 47 static void InstallBuiltin(Isolate* isolate, Handle<JSObject> holder, | 52 static void InstallBuiltin( |
| 48 const char* name, Builtins::Name builtin_name, | 53 Isolate* isolate, Handle<JSObject> holder, const char* name, |
| 49 int argc = -1) { | 54 Builtins::Name builtin_name, int argc = -1, |
| 55 BuiltinFunctionId id = static_cast<BuiltinFunctionId>(-1)) { |
| 50 InstallCode(isolate, holder, name, | 56 InstallCode(isolate, holder, name, |
| 51 handle(isolate->builtins()->builtin(builtin_name), isolate), | 57 handle(isolate->builtins()->builtin(builtin_name), isolate), argc, |
| 52 argc); | 58 id); |
| 53 } | 59 } |
| 54 | 60 |
| 55 RUNTIME_FUNCTION(Runtime_SpecialArrayFunctions) { | 61 RUNTIME_FUNCTION(Runtime_SpecialArrayFunctions) { |
| 56 HandleScope scope(isolate); | 62 HandleScope scope(isolate); |
| 57 DCHECK(args.length() == 0); | 63 DCHECK(args.length() == 0); |
| 58 Handle<JSObject> holder = | 64 Handle<JSObject> holder = |
| 59 isolate->factory()->NewJSObject(isolate->object_function()); | 65 isolate->factory()->NewJSObject(isolate->object_function()); |
| 60 | 66 |
| 61 InstallBuiltin(isolate, holder, "pop", Builtins::kArrayPop); | 67 InstallBuiltin(isolate, holder, "pop", Builtins::kArrayPop); |
| 62 if (FLAG_minimal) { | 68 if (FLAG_minimal) { |
| 63 InstallBuiltin(isolate, holder, "push", Builtins::kArrayPush); | 69 InstallBuiltin(isolate, holder, "push", Builtins::kArrayPush); |
| 64 } else { | 70 } else { |
| 65 FastArrayPushStub stub(isolate); | 71 FastArrayPushStub stub(isolate); |
| 66 InstallCode(isolate, holder, "push", stub.GetCode()); | 72 InstallCode(isolate, holder, "push", stub.GetCode()); |
| 67 } | 73 } |
| 68 InstallBuiltin(isolate, holder, "shift", Builtins::kArrayShift); | 74 InstallBuiltin(isolate, holder, "shift", Builtins::kArrayShift); |
| 69 InstallBuiltin(isolate, holder, "unshift", Builtins::kArrayUnshift); | 75 InstallBuiltin(isolate, holder, "unshift", Builtins::kArrayUnshift); |
| 70 InstallBuiltin(isolate, holder, "slice", Builtins::kArraySlice); | 76 InstallBuiltin(isolate, holder, "slice", Builtins::kArraySlice); |
| 71 InstallBuiltin(isolate, holder, "splice", Builtins::kArraySplice); | 77 InstallBuiltin(isolate, holder, "splice", Builtins::kArraySplice); |
| 72 InstallBuiltin(isolate, holder, "includes", Builtins::kArrayIncludes, 2); | 78 InstallBuiltin(isolate, holder, "includes", Builtins::kArrayIncludes, 2); |
| 73 InstallBuiltin(isolate, holder, "indexOf", Builtins::kArrayIndexOf, 2); | 79 InstallBuiltin(isolate, holder, "indexOf", Builtins::kArrayIndexOf, 2); |
| 74 InstallBuiltin(isolate, holder, "keys", Builtins::kArrayPrototypeKeys, 0); | 80 InstallBuiltin(isolate, holder, "keys", Builtins::kArrayPrototypeKeys, 0, |
| 75 InstallBuiltin(isolate, holder, "values", Builtins::kArrayPrototypeValues, 0); | 81 kArrayKeys); |
| 82 InstallBuiltin(isolate, holder, "values", Builtins::kArrayPrototypeValues, 0, |
| 83 kArrayValues); |
| 76 InstallBuiltin(isolate, holder, "entries", Builtins::kArrayPrototypeEntries, | 84 InstallBuiltin(isolate, holder, "entries", Builtins::kArrayPrototypeEntries, |
| 77 0); | 85 0, kArrayEntries); |
| 78 | 86 |
| 79 return *holder; | 87 return *holder; |
| 80 } | 88 } |
| 81 | 89 |
| 82 | 90 |
| 83 RUNTIME_FUNCTION(Runtime_FixedArrayGet) { | 91 RUNTIME_FUNCTION(Runtime_FixedArrayGet) { |
| 84 SealHandleScope shs(isolate); | 92 SealHandleScope shs(isolate); |
| 85 DCHECK(args.length() == 2); | 93 DCHECK(args.length() == 2); |
| 86 CONVERT_ARG_CHECKED(FixedArray, object, 0); | 94 CONVERT_ARG_CHECKED(FixedArray, object, 0); |
| 87 CONVERT_SMI_ARG_CHECKED(index, 1); | 95 CONVERT_SMI_ARG_CHECKED(index, 1); |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 if (search_element->StrictEquals(*element_k)) { | 631 if (search_element->StrictEquals(*element_k)) { |
| 624 return *index_obj; | 632 return *index_obj; |
| 625 } | 633 } |
| 626 } | 634 } |
| 627 } | 635 } |
| 628 return Smi::FromInt(-1); | 636 return Smi::FromInt(-1); |
| 629 } | 637 } |
| 630 | 638 |
| 631 } // namespace internal | 639 } // namespace internal |
| 632 } // namespace v8 | 640 } // namespace v8 |
| OLD | NEW |