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/conversions-inl.h" | 9 #include "src/conversions-inl.h" |
9 #include "src/elements.h" | 10 #include "src/elements.h" |
10 #include "src/factory.h" | 11 #include "src/factory.h" |
11 #include "src/isolate-inl.h" | 12 #include "src/isolate-inl.h" |
12 #include "src/keys.h" | 13 #include "src/keys.h" |
13 #include "src/messages.h" | 14 #include "src/messages.h" |
14 #include "src/prototype.h" | 15 #include "src/prototype.h" |
15 | 16 |
16 namespace v8 { | 17 namespace v8 { |
17 namespace internal { | 18 namespace internal { |
18 | 19 |
19 RUNTIME_FUNCTION(Runtime_FinishArrayPrototypeSetup) { | 20 RUNTIME_FUNCTION(Runtime_FinishArrayPrototypeSetup) { |
20 HandleScope scope(isolate); | 21 HandleScope scope(isolate); |
21 DCHECK(args.length() == 1); | 22 DCHECK(args.length() == 1); |
22 CONVERT_ARG_HANDLE_CHECKED(JSArray, prototype, 0); | 23 CONVERT_ARG_HANDLE_CHECKED(JSArray, prototype, 0); |
23 Object* length = prototype->length(); | 24 Object* length = prototype->length(); |
24 RUNTIME_ASSERT(length->IsSmi() && Smi::cast(length)->value() == 0); | 25 RUNTIME_ASSERT(length->IsSmi() && Smi::cast(length)->value() == 0); |
25 RUNTIME_ASSERT(prototype->HasFastSmiOrObjectElements()); | 26 RUNTIME_ASSERT(prototype->HasFastSmiOrObjectElements()); |
26 // This is necessary to enable fast checks for absence of elements | 27 // This is necessary to enable fast checks for absence of elements |
27 // on Array.prototype and below. | 28 // on Array.prototype and below. |
28 prototype->set_elements(isolate->heap()->empty_fixed_array()); | 29 prototype->set_elements(isolate->heap()->empty_fixed_array()); |
29 return Smi::FromInt(0); | 30 return Smi::FromInt(0); |
30 } | 31 } |
31 | 32 |
32 | 33 static void InstallCode(Isolate* isolate, Handle<JSObject> holder, |
33 static void InstallBuiltin(Isolate* isolate, Handle<JSObject> holder, | 34 const char* name, Handle<Code> code) { |
34 const char* name, Builtins::Name builtin_name) { | |
35 Handle<String> key = isolate->factory()->InternalizeUtf8String(name); | 35 Handle<String> key = isolate->factory()->InternalizeUtf8String(name); |
36 Handle<Code> code(isolate->builtins()->builtin(builtin_name)); | |
37 Handle<JSFunction> optimized = | 36 Handle<JSFunction> optimized = |
38 isolate->factory()->NewFunctionWithoutPrototype(key, code); | 37 isolate->factory()->NewFunctionWithoutPrototype(key, code); |
39 optimized->shared()->DontAdaptArguments(); | 38 optimized->shared()->DontAdaptArguments(); |
40 JSObject::AddProperty(holder, key, optimized, NONE); | 39 JSObject::AddProperty(holder, key, optimized, NONE); |
41 } | 40 } |
42 | 41 |
| 42 static void InstallBuiltin(Isolate* isolate, Handle<JSObject> holder, |
| 43 const char* name, Builtins::Name builtin_name) { |
| 44 InstallCode(isolate, holder, name, |
| 45 handle(isolate->builtins()->builtin(builtin_name), isolate)); |
| 46 } |
43 | 47 |
44 RUNTIME_FUNCTION(Runtime_SpecialArrayFunctions) { | 48 RUNTIME_FUNCTION(Runtime_SpecialArrayFunctions) { |
45 HandleScope scope(isolate); | 49 HandleScope scope(isolate); |
46 DCHECK(args.length() == 0); | 50 DCHECK(args.length() == 0); |
47 Handle<JSObject> holder = | 51 Handle<JSObject> holder = |
48 isolate->factory()->NewJSObject(isolate->object_function()); | 52 isolate->factory()->NewJSObject(isolate->object_function()); |
49 | 53 |
50 InstallBuiltin(isolate, holder, "pop", Builtins::kArrayPop); | 54 InstallBuiltin(isolate, holder, "pop", Builtins::kArrayPop); |
51 InstallBuiltin(isolate, holder, "push", Builtins::kArrayPush); | 55 FastArrayPushStub stub(isolate); |
| 56 InstallCode(isolate, holder, "push", stub.GetCode()); |
52 InstallBuiltin(isolate, holder, "shift", Builtins::kArrayShift); | 57 InstallBuiltin(isolate, holder, "shift", Builtins::kArrayShift); |
53 InstallBuiltin(isolate, holder, "unshift", Builtins::kArrayUnshift); | 58 InstallBuiltin(isolate, holder, "unshift", Builtins::kArrayUnshift); |
54 InstallBuiltin(isolate, holder, "slice", Builtins::kArraySlice); | 59 InstallBuiltin(isolate, holder, "slice", Builtins::kArraySlice); |
55 InstallBuiltin(isolate, holder, "splice", Builtins::kArraySplice); | 60 InstallBuiltin(isolate, holder, "splice", Builtins::kArraySplice); |
56 | 61 |
57 return *holder; | 62 return *holder; |
58 } | 63 } |
59 | 64 |
60 | 65 |
61 RUNTIME_FUNCTION(Runtime_FixedArrayGet) { | 66 RUNTIME_FUNCTION(Runtime_FixedArrayGet) { |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 if (!type_info.is_null() && | 358 if (!type_info.is_null() && |
354 *type_info != isolate->heap()->undefined_value()) { | 359 *type_info != isolate->heap()->undefined_value()) { |
355 site = Handle<AllocationSite>::cast(type_info); | 360 site = Handle<AllocationSite>::cast(type_info); |
356 DCHECK(!site->SitePointsToLiteral()); | 361 DCHECK(!site->SitePointsToLiteral()); |
357 } | 362 } |
358 | 363 |
359 return ArrayConstructorCommon(isolate, constructor, constructor, site, | 364 return ArrayConstructorCommon(isolate, constructor, constructor, site, |
360 caller_args); | 365 caller_args); |
361 } | 366 } |
362 | 367 |
363 | |
364 RUNTIME_FUNCTION(Runtime_InternalArrayConstructor) { | 368 RUNTIME_FUNCTION(Runtime_InternalArrayConstructor) { |
365 HandleScope scope(isolate); | 369 HandleScope scope(isolate); |
366 Arguments empty_args(0, NULL); | 370 Arguments empty_args(0, NULL); |
367 bool no_caller_args = args.length() == 1; | 371 bool no_caller_args = args.length() == 1; |
368 DCHECK(no_caller_args || args.length() == 3); | 372 DCHECK(no_caller_args || args.length() == 3); |
369 int parameters_start = no_caller_args ? 0 : 1; | 373 int parameters_start = no_caller_args ? 0 : 1; |
370 Arguments* caller_args = | 374 Arguments* caller_args = |
371 no_caller_args ? &empty_args : reinterpret_cast<Arguments*>(args[0]); | 375 no_caller_args ? &empty_args : reinterpret_cast<Arguments*>(args[0]); |
372 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, parameters_start); | 376 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, parameters_start); |
373 #ifdef DEBUG | 377 #ifdef DEBUG |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 CONVERT_ARG_HANDLE_CHECKED(Object, original_array, 0); | 478 CONVERT_ARG_HANDLE_CHECKED(Object, original_array, 0); |
475 Handle<Object> constructor; | 479 Handle<Object> constructor; |
476 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 480 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
477 isolate, constructor, | 481 isolate, constructor, |
478 Object::ArraySpeciesConstructor(isolate, original_array)); | 482 Object::ArraySpeciesConstructor(isolate, original_array)); |
479 return *constructor; | 483 return *constructor; |
480 } | 484 } |
481 | 485 |
482 } // namespace internal | 486 } // namespace internal |
483 } // namespace v8 | 487 } // namespace v8 |
OLD | NEW |