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> |
| 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 1813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1932 RelocInfo::kNoPosition); | 1935 RelocInfo::kNoPosition); |
1933 } | 1936 } |
1934 | 1937 |
1935 } // namespace | 1938 } // namespace |
1936 | 1939 |
1937 | 1940 |
1938 // ES6 section 18.2.1 eval (x) | 1941 // ES6 section 18.2.1 eval (x) |
1939 BUILTIN(GlobalEval) { | 1942 BUILTIN(GlobalEval) { |
1940 HandleScope scope(isolate); | 1943 HandleScope scope(isolate); |
1941 Handle<Object> x = args.atOrUndefined(isolate, 1); | 1944 Handle<Object> x = args.atOrUndefined(isolate, 1); |
1942 Handle<JSFunction> target = args.target(); | 1945 Handle<JSFunction> target = args.target<JSFunction>(); |
1943 Handle<JSObject> target_global_proxy(target->global_proxy(), isolate); | 1946 Handle<JSObject> target_global_proxy(target->global_proxy(), isolate); |
1944 if (!x->IsString()) return *x; | 1947 if (!x->IsString()) return *x; |
1945 Handle<JSFunction> function; | 1948 Handle<JSFunction> function; |
1946 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1949 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
1947 isolate, function, | 1950 isolate, function, |
1948 CompileString(handle(target->native_context(), isolate), | 1951 CompileString(handle(target->native_context(), isolate), |
1949 Handle<String>::cast(x), NO_PARSE_RESTRICTION)); | 1952 Handle<String>::cast(x), NO_PARSE_RESTRICTION)); |
1950 Handle<Object> result; | 1953 Handle<Object> result; |
1951 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1954 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
1952 isolate, result, | 1955 isolate, result, |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2428 Vector<char> str(buffer, arraysize(buffer)); | 2431 Vector<char> str(buffer, arraysize(buffer)); |
2429 ToDateString(time_val, str, isolate->date_cache()); | 2432 ToDateString(time_val, str, isolate->date_cache()); |
2430 return *isolate->factory()->NewStringFromAsciiChecked(str.start()); | 2433 return *isolate->factory()->NewStringFromAsciiChecked(str.start()); |
2431 } | 2434 } |
2432 | 2435 |
2433 | 2436 |
2434 // ES6 section 20.3.2 The Date Constructor for the [[Construct]] case. | 2437 // ES6 section 20.3.2 The Date Constructor for the [[Construct]] case. |
2435 BUILTIN(DateConstructor_ConstructStub) { | 2438 BUILTIN(DateConstructor_ConstructStub) { |
2436 HandleScope scope(isolate); | 2439 HandleScope scope(isolate); |
2437 int const argc = args.length() - 1; | 2440 int const argc = args.length() - 1; |
2438 Handle<JSFunction> target = args.target(); | 2441 Handle<JSFunction> target = args.target<JSFunction>(); |
2439 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); | 2442 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); |
2440 double time_val; | 2443 double time_val; |
2441 if (argc == 0) { | 2444 if (argc == 0) { |
2442 time_val = JSDate::CurrentTimeValue(isolate); | 2445 time_val = JSDate::CurrentTimeValue(isolate); |
2443 } else if (argc == 1) { | 2446 } else if (argc == 1) { |
2444 Handle<Object> value = args.at<Object>(1); | 2447 Handle<Object> value = args.at<Object>(1); |
2445 if (value->IsJSDate()) { | 2448 if (value->IsJSDate()) { |
2446 time_val = Handle<JSDate>::cast(value)->value()->Number(); | 2449 time_val = Handle<JSDate>::cast(value)->value()->Number(); |
2447 } else { | 2450 } else { |
2448 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, | 2451 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, |
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3312 // conversions are done. | 3315 // conversions are done. |
3313 if (parenthesis_in_arg_string) { | 3316 if (parenthesis_in_arg_string) { |
3314 THROW_NEW_ERROR(isolate, | 3317 THROW_NEW_ERROR(isolate, |
3315 NewSyntaxError(MessageTemplate::kParenthesisInArgString), | 3318 NewSyntaxError(MessageTemplate::kParenthesisInArgString), |
3316 JSFunction); | 3319 JSFunction); |
3317 } | 3320 } |
3318 } | 3321 } |
3319 | 3322 |
3320 // Compile the string in the constructor and not a helper so that errors to | 3323 // Compile the string in the constructor and not a helper so that errors to |
3321 // come from here. | 3324 // come from here. |
3322 Handle<JSFunction> target = args.target(); | 3325 Handle<JSFunction> target = args.target<JSFunction>(); |
3323 Handle<JSObject> target_global_proxy(target->global_proxy(), isolate); | 3326 Handle<JSObject> target_global_proxy(target->global_proxy(), isolate); |
3324 Handle<JSFunction> function; | 3327 Handle<JSFunction> function; |
3325 { | 3328 { |
3326 ASSIGN_RETURN_ON_EXCEPTION( | 3329 ASSIGN_RETURN_ON_EXCEPTION( |
3327 isolate, function, | 3330 isolate, function, |
3328 CompileString(handle(target->native_context(), isolate), source, | 3331 CompileString(handle(target->native_context(), isolate), source, |
3329 ONLY_SINGLE_FUNCTION_LITERAL), | 3332 ONLY_SINGLE_FUNCTION_LITERAL), |
3330 JSFunction); | 3333 JSFunction); |
3331 Handle<Object> result; | 3334 Handle<Object> result; |
3332 ASSIGN_RETURN_ON_EXCEPTION( | 3335 ASSIGN_RETURN_ON_EXCEPTION( |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3497 Handle<String> result; | 3500 Handle<String> result; |
3498 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 3501 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
3499 isolate, result, JSObject::ObjectProtoToString(isolate, object)); | 3502 isolate, result, JSObject::ObjectProtoToString(isolate, object)); |
3500 return *result; | 3503 return *result; |
3501 } | 3504 } |
3502 | 3505 |
3503 | 3506 |
3504 // ES6 section 24.1.2.1 ArrayBuffer ( length ) for the [[Call]] case. | 3507 // ES6 section 24.1.2.1 ArrayBuffer ( length ) for the [[Call]] case. |
3505 BUILTIN(ArrayBufferConstructor) { | 3508 BUILTIN(ArrayBufferConstructor) { |
3506 HandleScope scope(isolate); | 3509 HandleScope scope(isolate); |
3507 Handle<JSFunction> target = args.target(); | 3510 Handle<JSFunction> target = args.target<JSFunction>(); |
3508 DCHECK(*target == target->native_context()->array_buffer_fun() || | 3511 DCHECK(*target == target->native_context()->array_buffer_fun() || |
3509 *target == target->native_context()->shared_array_buffer_fun()); | 3512 *target == target->native_context()->shared_array_buffer_fun()); |
3510 THROW_NEW_ERROR_RETURN_FAILURE( | 3513 THROW_NEW_ERROR_RETURN_FAILURE( |
3511 isolate, NewTypeError(MessageTemplate::kConstructorNotFunction, | 3514 isolate, NewTypeError(MessageTemplate::kConstructorNotFunction, |
3512 handle(target->shared()->name(), isolate))); | 3515 handle(target->shared()->name(), isolate))); |
3513 } | 3516 } |
3514 | 3517 |
3515 | 3518 |
3516 // ES6 section 24.1.2.1 ArrayBuffer ( length ) for the [[Construct]] case. | 3519 // ES6 section 24.1.2.1 ArrayBuffer ( length ) for the [[Construct]] case. |
3517 BUILTIN(ArrayBufferConstructor_ConstructStub) { | 3520 BUILTIN(ArrayBufferConstructor_ConstructStub) { |
3518 HandleScope scope(isolate); | 3521 HandleScope scope(isolate); |
3519 Handle<JSFunction> target = args.target(); | 3522 Handle<JSFunction> target = args.target<JSFunction>(); |
3520 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); | 3523 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); |
3521 Handle<Object> length = args.atOrUndefined(isolate, 1); | 3524 Handle<Object> length = args.atOrUndefined(isolate, 1); |
3522 DCHECK(*target == target->native_context()->array_buffer_fun() || | 3525 DCHECK(*target == target->native_context()->array_buffer_fun() || |
3523 *target == target->native_context()->shared_array_buffer_fun()); | 3526 *target == target->native_context()->shared_array_buffer_fun()); |
3524 Handle<Object> number_length; | 3527 Handle<Object> number_length; |
3525 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, number_length, | 3528 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, number_length, |
3526 Object::ToInteger(isolate, length)); | 3529 Object::ToInteger(isolate, length)); |
3527 if (number_length->Number() < 0.0) { | 3530 if (number_length->Number() < 0.0) { |
3528 THROW_NEW_ERROR_RETURN_FAILURE( | 3531 THROW_NEW_ERROR_RETURN_FAILURE( |
3529 isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength)); | 3532 isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength)); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3606 // ----------------------------------------------------------------------------- | 3609 // ----------------------------------------------------------------------------- |
3607 // | 3610 // |
3608 | 3611 |
3609 | 3612 |
3610 namespace { | 3613 namespace { |
3611 | 3614 |
3612 template <bool is_construct> | 3615 template <bool is_construct> |
3613 MUST_USE_RESULT MaybeHandle<Object> HandleApiCallHelper( | 3616 MUST_USE_RESULT MaybeHandle<Object> HandleApiCallHelper( |
3614 Isolate* isolate, BuiltinArguments<BuiltinExtraArguments::kTarget> args) { | 3617 Isolate* isolate, BuiltinArguments<BuiltinExtraArguments::kTarget> args) { |
3615 HandleScope scope(isolate); | 3618 HandleScope scope(isolate); |
3616 Handle<JSFunction> function = args.target(); | 3619 Handle<HeapObject> function = args.target<HeapObject>(); |
3617 Handle<JSReceiver> receiver; | 3620 Handle<JSReceiver> receiver; |
3618 // TODO(ishell): turn this back to a DCHECK. | 3621 // TODO(ishell): turn this back to a DCHECK. |
3619 CHECK(function->shared()->IsApiFunction()); | 3622 CHECK(function->IsFunctionTemplateInfo() || |
| 3623 Handle<JSFunction>::cast(function)->shared()->IsApiFunction()); |
3620 | 3624 |
3621 Handle<FunctionTemplateInfo> fun_data( | 3625 Handle<FunctionTemplateInfo> fun_data = |
3622 function->shared()->get_api_func_data(), isolate); | 3626 function->IsFunctionTemplateInfo() |
| 3627 ? Handle<FunctionTemplateInfo>::cast(function) |
| 3628 : handle(JSFunction::cast(*function)->shared()->get_api_func_data()); |
3623 if (is_construct) { | 3629 if (is_construct) { |
3624 DCHECK(args.receiver()->IsTheHole()); | 3630 DCHECK(args.receiver()->IsTheHole()); |
3625 if (fun_data->instance_template()->IsUndefined()) { | 3631 if (fun_data->instance_template()->IsUndefined()) { |
3626 v8::Local<ObjectTemplate> templ = | 3632 v8::Local<ObjectTemplate> templ = |
3627 ObjectTemplate::New(reinterpret_cast<v8::Isolate*>(isolate), | 3633 ObjectTemplate::New(reinterpret_cast<v8::Isolate*>(isolate), |
3628 ToApiHandle<v8::FunctionTemplate>(fun_data)); | 3634 ToApiHandle<v8::FunctionTemplate>(fun_data)); |
3629 fun_data->set_instance_template(*Utils::OpenHandle(*templ)); | 3635 fun_data->set_instance_template(*Utils::OpenHandle(*templ)); |
3630 } | 3636 } |
3631 Handle<ObjectTemplateInfo> instance_template( | 3637 Handle<ObjectTemplateInfo> instance_template( |
3632 ObjectTemplateInfo::cast(fun_data->instance_template()), isolate); | 3638 ObjectTemplateInfo::cast(fun_data->instance_template()), isolate); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3799 if (length() == 0) return; | 3805 if (length() == 0) return; |
3800 v->VisitPointers(lowest_address(), highest_address() + 1); | 3806 v->VisitPointers(lowest_address(), highest_address() + 1); |
3801 } | 3807 } |
3802 | 3808 |
3803 private: | 3809 private: |
3804 DISALLOW_COPY_AND_ASSIGN(RelocatableArguments); | 3810 DISALLOW_COPY_AND_ASSIGN(RelocatableArguments); |
3805 }; | 3811 }; |
3806 | 3812 |
3807 } // namespace | 3813 } // namespace |
3808 | 3814 |
3809 | 3815 MaybeHandle<Object> Builtins::InvokeApiFunction(Handle<HeapObject> function, |
3810 MaybeHandle<Object> Builtins::InvokeApiFunction(Handle<JSFunction> function, | |
3811 Handle<Object> receiver, | 3816 Handle<Object> receiver, |
3812 int argc, | 3817 int argc, |
3813 Handle<Object> args[]) { | 3818 Handle<Object> args[]) { |
3814 // Construct BuiltinArguments object: function, arguments reversed, receiver. | 3819 // Construct BuiltinArguments object: function, arguments reversed, receiver. |
3815 const int kBufferSize = 32; | 3820 const int kBufferSize = 32; |
3816 Object* small_argv[kBufferSize]; | 3821 Object* small_argv[kBufferSize]; |
3817 Object** argv; | 3822 Object** argv; |
3818 if (argc + 2 <= kBufferSize) { | 3823 if (argc + 2 <= kBufferSize) { |
3819 argv = small_argv; | 3824 argv = small_argv; |
3820 } else { | 3825 } else { |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4257 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 4262 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
4258 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 4263 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
4259 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 4264 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
4260 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 4265 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
4261 #undef DEFINE_BUILTIN_ACCESSOR_C | 4266 #undef DEFINE_BUILTIN_ACCESSOR_C |
4262 #undef DEFINE_BUILTIN_ACCESSOR_A | 4267 #undef DEFINE_BUILTIN_ACCESSOR_A |
4263 | 4268 |
4264 | 4269 |
4265 } // namespace internal | 4270 } // namespace internal |
4266 } // namespace v8 | 4271 } // namespace v8 |
OLD | NEW |