OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/builtins.h" | 5 #include "src/builtins.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
9 #include "src/arguments.h" | 9 #include "src/arguments.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 if (index >= length()) { | 52 if (index >= length()) { |
53 return isolate->factory()->undefined_value(); | 53 return isolate->factory()->undefined_value(); |
54 } | 54 } |
55 return at<Object>(index); | 55 return at<Object>(index); |
56 } | 56 } |
57 | 57 |
58 Handle<Object> receiver() { | 58 Handle<Object> receiver() { |
59 return Arguments::at<Object>(0); | 59 return Arguments::at<Object>(0); |
60 } | 60 } |
61 | 61 |
62 Handle<JSFunction> target(); | 62 template <class S = JSFunction> |
| 63 Handle<S> target(); |
63 Handle<HeapObject> new_target(); | 64 Handle<HeapObject> new_target(); |
64 | 65 |
65 // Gets the total number of arguments including the receiver (but | 66 // Gets the total number of arguments including the receiver (but |
66 // excluding extra arguments). | 67 // excluding extra arguments). |
67 int length() const; | 68 int length() const; |
68 }; | 69 }; |
69 | 70 |
70 | 71 |
71 // Specialize BuiltinArguments for the extra arguments. | 72 // Specialize BuiltinArguments for the extra arguments. |
72 | 73 |
73 template <> | 74 template <> |
74 int BuiltinArguments<BuiltinExtraArguments::kNone>::length() const { | 75 int BuiltinArguments<BuiltinExtraArguments::kNone>::length() const { |
75 return Arguments::length(); | 76 return Arguments::length(); |
76 } | 77 } |
77 | 78 |
78 template <> | 79 template <> |
79 int BuiltinArguments<BuiltinExtraArguments::kTarget>::length() const { | 80 int BuiltinArguments<BuiltinExtraArguments::kTarget>::length() const { |
80 return Arguments::length() - 1; | 81 return Arguments::length() - 1; |
81 } | 82 } |
82 | 83 |
83 template <> | 84 template <> |
84 Handle<JSFunction> BuiltinArguments<BuiltinExtraArguments::kTarget>::target() { | 85 template <class S> |
85 return Arguments::at<JSFunction>(Arguments::length() - 1); | 86 Handle<S> BuiltinArguments<BuiltinExtraArguments::kTarget>::target() { |
| 87 return Arguments::at<S>(Arguments::length() - 1); |
86 } | 88 } |
87 | 89 |
88 template <> | 90 template <> |
89 int BuiltinArguments<BuiltinExtraArguments::kNewTarget>::length() const { | 91 int BuiltinArguments<BuiltinExtraArguments::kNewTarget>::length() const { |
90 return Arguments::length() - 1; | 92 return Arguments::length() - 1; |
91 } | 93 } |
92 | 94 |
93 template <> | 95 template <> |
94 Handle<HeapObject> | 96 Handle<HeapObject> |
95 BuiltinArguments<BuiltinExtraArguments::kNewTarget>::new_target() { | 97 BuiltinArguments<BuiltinExtraArguments::kNewTarget>::new_target() { |
96 return Arguments::at<HeapObject>(Arguments::length() - 1); | 98 return Arguments::at<HeapObject>(Arguments::length() - 1); |
97 } | 99 } |
98 | 100 |
99 template <> | 101 template <> |
100 int BuiltinArguments<BuiltinExtraArguments::kTargetAndNewTarget>::length() | 102 int BuiltinArguments<BuiltinExtraArguments::kTargetAndNewTarget>::length() |
101 const { | 103 const { |
102 return Arguments::length() - 2; | 104 return Arguments::length() - 2; |
103 } | 105 } |
104 | 106 |
105 template <> | 107 template <> |
106 Handle<JSFunction> | 108 template <class S> |
| 109 Handle<S> |
107 BuiltinArguments<BuiltinExtraArguments::kTargetAndNewTarget>::target() { | 110 BuiltinArguments<BuiltinExtraArguments::kTargetAndNewTarget>::target() { |
108 return Arguments::at<JSFunction>(Arguments::length() - 2); | 111 return Arguments::at<S>(Arguments::length() - 2); |
109 } | 112 } |
110 | 113 |
111 template <> | 114 template <> |
112 Handle<HeapObject> | 115 Handle<HeapObject> |
113 BuiltinArguments<BuiltinExtraArguments::kTargetAndNewTarget>::new_target() { | 116 BuiltinArguments<BuiltinExtraArguments::kTargetAndNewTarget>::new_target() { |
114 return Arguments::at<HeapObject>(Arguments::length() - 1); | 117 return Arguments::at<HeapObject>(Arguments::length() - 1); |
115 } | 118 } |
116 | 119 |
117 | 120 |
118 #define DEF_ARG_TYPE(name, spec) \ | 121 #define DEF_ARG_TYPE(name, spec) \ |
(...skipping 3396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3515 // ----------------------------------------------------------------------------- | 3518 // ----------------------------------------------------------------------------- |
3516 // | 3519 // |
3517 | 3520 |
3518 | 3521 |
3519 namespace { | 3522 namespace { |
3520 | 3523 |
3521 template <bool is_construct> | 3524 template <bool is_construct> |
3522 MUST_USE_RESULT MaybeHandle<Object> HandleApiCallHelper( | 3525 MUST_USE_RESULT MaybeHandle<Object> HandleApiCallHelper( |
3523 Isolate* isolate, BuiltinArguments<BuiltinExtraArguments::kTarget> args) { | 3526 Isolate* isolate, BuiltinArguments<BuiltinExtraArguments::kTarget> args) { |
3524 HandleScope scope(isolate); | 3527 HandleScope scope(isolate); |
3525 Handle<JSFunction> function = args.target(); | 3528 Handle<HeapObject> function = args.target<HeapObject>(); |
3526 DCHECK(args.receiver()->IsJSReceiver()); | 3529 DCHECK(args.receiver()->IsJSReceiver()); |
3527 // TODO(ishell): turn this back to a DCHECK. | 3530 // TODO(ishell): turn this back to a DCHECK. |
3528 CHECK(function->shared()->IsApiFunction()); | 3531 CHECK(function->IsFunctionTemplateInfo() || |
| 3532 Handle<JSFunction>::cast(function)->shared()->IsApiFunction()); |
3529 | 3533 |
3530 Handle<FunctionTemplateInfo> fun_data( | 3534 Handle<FunctionTemplateInfo> fun_data = |
3531 function->shared()->get_api_func_data(), isolate); | 3535 function->IsFunctionTemplateInfo() |
| 3536 ? Handle<FunctionTemplateInfo>::cast(function) |
| 3537 : handle(JSFunction::cast(*function)->shared()->get_api_func_data()); |
3532 if (is_construct) { | 3538 if (is_construct) { |
3533 ASSIGN_RETURN_ON_EXCEPTION( | 3539 ASSIGN_RETURN_ON_EXCEPTION( |
3534 isolate, fun_data, | 3540 isolate, fun_data, |
3535 ApiNatives::ConfigureInstance(isolate, fun_data, | 3541 ApiNatives::ConfigureInstance(isolate, fun_data, |
3536 Handle<JSObject>::cast(args.receiver())), | 3542 Handle<JSObject>::cast(args.receiver())), |
3537 Object); | 3543 Object); |
3538 } | 3544 } |
3539 | 3545 |
3540 if (!is_construct && !fun_data->accept_any_receiver()) { | 3546 if (!is_construct && !fun_data->accept_any_receiver()) { |
3541 Handle<JSReceiver> receiver = args.at<JSReceiver>(0); | 3547 Handle<JSReceiver> receiver = args.at<JSReceiver>(0); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3697 if (length() == 0) return; | 3703 if (length() == 0) return; |
3698 v->VisitPointers(lowest_address(), highest_address() + 1); | 3704 v->VisitPointers(lowest_address(), highest_address() + 1); |
3699 } | 3705 } |
3700 | 3706 |
3701 private: | 3707 private: |
3702 DISALLOW_COPY_AND_ASSIGN(RelocatableArguments); | 3708 DISALLOW_COPY_AND_ASSIGN(RelocatableArguments); |
3703 }; | 3709 }; |
3704 | 3710 |
3705 } // namespace | 3711 } // namespace |
3706 | 3712 |
3707 | 3713 MaybeHandle<Object> Builtins::InvokeApiFunction(Handle<HeapObject> function, |
3708 MaybeHandle<Object> Builtins::InvokeApiFunction(Handle<JSFunction> function, | |
3709 Handle<Object> receiver, | 3714 Handle<Object> receiver, |
3710 int argc, | 3715 int argc, |
3711 Handle<Object> args[]) { | 3716 Handle<Object> args[]) { |
3712 // Construct BuiltinArguments object: function, arguments reversed, receiver. | 3717 // Construct BuiltinArguments object: function, arguments reversed, receiver. |
3713 const int kBufferSize = 32; | 3718 const int kBufferSize = 32; |
3714 Object* small_argv[kBufferSize]; | 3719 Object* small_argv[kBufferSize]; |
3715 Object** argv; | 3720 Object** argv; |
3716 if (argc + 2 <= kBufferSize) { | 3721 if (argc + 2 <= kBufferSize) { |
3717 argv = small_argv; | 3722 argv = small_argv; |
3718 } else { | 3723 } else { |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4155 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 4160 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
4156 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 4161 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
4157 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 4162 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
4158 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 4163 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
4159 #undef DEFINE_BUILTIN_ACCESSOR_C | 4164 #undef DEFINE_BUILTIN_ACCESSOR_C |
4160 #undef DEFINE_BUILTIN_ACCESSOR_A | 4165 #undef DEFINE_BUILTIN_ACCESSOR_A |
4161 | 4166 |
4162 | 4167 |
4163 } // namespace internal | 4168 } // namespace internal |
4164 } // namespace v8 | 4169 } // namespace v8 |
OLD | NEW |