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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 if (!type_info.is_null() && | 365 if (!type_info.is_null() && |
361 *type_info != isolate->heap()->undefined_value()) { | 366 *type_info != isolate->heap()->undefined_value()) { |
362 site = Handle<AllocationSite>::cast(type_info); | 367 site = Handle<AllocationSite>::cast(type_info); |
363 DCHECK(!site->SitePointsToLiteral()); | 368 DCHECK(!site->SitePointsToLiteral()); |
364 } | 369 } |
365 | 370 |
366 return ArrayConstructorCommon(isolate, constructor, constructor, site, | 371 return ArrayConstructorCommon(isolate, constructor, constructor, site, |
367 caller_args); | 372 caller_args); |
368 } | 373 } |
369 | 374 |
370 | |
371 RUNTIME_FUNCTION(Runtime_InternalArrayConstructor) { | 375 RUNTIME_FUNCTION(Runtime_InternalArrayConstructor) { |
372 HandleScope scope(isolate); | 376 HandleScope scope(isolate); |
373 Arguments empty_args(0, NULL); | 377 Arguments empty_args(0, NULL); |
374 bool no_caller_args = args.length() == 1; | 378 bool no_caller_args = args.length() == 1; |
375 DCHECK(no_caller_args || args.length() == 3); | 379 DCHECK(no_caller_args || args.length() == 3); |
376 int parameters_start = no_caller_args ? 0 : 1; | 380 int parameters_start = no_caller_args ? 0 : 1; |
377 Arguments* caller_args = | 381 Arguments* caller_args = |
378 no_caller_args ? &empty_args : reinterpret_cast<Arguments*>(args[0]); | 382 no_caller_args ? &empty_args : reinterpret_cast<Arguments*>(args[0]); |
379 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, parameters_start); | 383 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, parameters_start); |
380 #ifdef DEBUG | 384 #ifdef DEBUG |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 CONVERT_ARG_HANDLE_CHECKED(Object, original_array, 0); | 485 CONVERT_ARG_HANDLE_CHECKED(Object, original_array, 0); |
482 Handle<Object> constructor; | 486 Handle<Object> constructor; |
483 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 487 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
484 isolate, constructor, | 488 isolate, constructor, |
485 Object::ArraySpeciesConstructor(isolate, original_array)); | 489 Object::ArraySpeciesConstructor(isolate, original_array)); |
486 return *constructor; | 490 return *constructor; |
487 } | 491 } |
488 | 492 |
489 } // namespace internal | 493 } // namespace internal |
490 } // namespace v8 | 494 } // namespace v8 |
OLD | NEW |