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 3541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3552 // | 3552 // |
3553 | 3553 |
3554 | 3554 |
3555 namespace { | 3555 namespace { |
3556 | 3556 |
3557 template <bool is_construct> | 3557 template <bool is_construct> |
3558 MUST_USE_RESULT MaybeHandle<Object> HandleApiCallHelper( | 3558 MUST_USE_RESULT MaybeHandle<Object> HandleApiCallHelper( |
3559 Isolate* isolate, BuiltinArguments<BuiltinExtraArguments::kTarget> args) { | 3559 Isolate* isolate, BuiltinArguments<BuiltinExtraArguments::kTarget> args) { |
3560 HandleScope scope(isolate); | 3560 HandleScope scope(isolate); |
3561 Handle<JSFunction> function = args.target(); | 3561 Handle<JSFunction> function = args.target(); |
3562 Handle<JSReceiver> receiver; | 3562 DCHECK(args.receiver()->IsJSReceiver()); |
3563 // TODO(ishell): turn this back to a DCHECK. | 3563 // TODO(ishell): turn this back to a DCHECK. |
3564 CHECK(function->shared()->IsApiFunction()); | 3564 CHECK(function->shared()->IsApiFunction()); |
3565 | 3565 |
3566 Handle<FunctionTemplateInfo> fun_data( | 3566 Handle<FunctionTemplateInfo> fun_data( |
3567 function->shared()->get_api_func_data(), isolate); | 3567 function->shared()->get_api_func_data(), isolate); |
3568 if (is_construct) { | 3568 if (is_construct) { |
3569 DCHECK(args.receiver()->IsTheHole()); | 3569 ASSIGN_RETURN_ON_EXCEPTION( |
3570 if (fun_data->instance_template()->IsUndefined()) { | 3570 isolate, fun_data, |
3571 v8::Local<ObjectTemplate> templ = | 3571 ApiNatives::ConfigureInstance(isolate, fun_data, |
3572 ObjectTemplate::New(reinterpret_cast<v8::Isolate*>(isolate), | 3572 Handle<JSObject>::cast(args.receiver())), |
3573 ToApiHandle<v8::FunctionTemplate>(fun_data)); | 3573 Object); |
3574 fun_data->set_instance_template(*Utils::OpenHandle(*templ)); | |
3575 } | |
3576 Handle<ObjectTemplateInfo> instance_template( | |
3577 ObjectTemplateInfo::cast(fun_data->instance_template()), isolate); | |
3578 ASSIGN_RETURN_ON_EXCEPTION(isolate, receiver, | |
3579 ApiNatives::InstantiateObject(instance_template), | |
3580 Object); | |
3581 args[0] = *receiver; | |
3582 DCHECK_EQ(*receiver, *args.receiver()); | |
3583 } else { | |
3584 DCHECK(args.receiver()->IsJSReceiver()); | |
3585 receiver = args.at<JSReceiver>(0); | |
3586 } | 3574 } |
3587 | 3575 |
3588 if (!is_construct && !fun_data->accept_any_receiver()) { | 3576 if (!is_construct && !fun_data->accept_any_receiver()) { |
| 3577 Handle<JSReceiver> receiver = args.at<JSReceiver>(0); |
3589 if (receiver->IsJSObject() && receiver->IsAccessCheckNeeded()) { | 3578 if (receiver->IsJSObject() && receiver->IsAccessCheckNeeded()) { |
3590 Handle<JSObject> js_receiver = Handle<JSObject>::cast(receiver); | 3579 Handle<JSObject> js_receiver = Handle<JSObject>::cast(receiver); |
3591 if (!isolate->MayAccess(handle(isolate->context()), js_receiver)) { | 3580 if (!isolate->MayAccess(handle(isolate->context()), js_receiver)) { |
3592 isolate->ReportFailedAccessCheck(js_receiver); | 3581 isolate->ReportFailedAccessCheck(js_receiver); |
3593 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); | 3582 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); |
3594 } | 3583 } |
3595 } | 3584 } |
3596 } | 3585 } |
3597 | 3586 |
3598 Object* raw_holder = fun_data->GetCompatibleReceiver(isolate, *receiver); | 3587 Object* raw_holder = fun_data->GetCompatibleReceiver(isolate, args[0]); |
3599 | 3588 |
3600 if (raw_holder->IsNull()) { | 3589 if (raw_holder->IsNull()) { |
3601 // This function cannot be called with the given receiver. Abort! | 3590 // This function cannot be called with the given receiver. Abort! |
3602 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kIllegalInvocation), | 3591 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kIllegalInvocation), |
3603 Object); | 3592 Object); |
3604 } | 3593 } |
3605 | 3594 |
3606 Object* raw_call_data = fun_data->call_code(); | 3595 Object* raw_call_data = fun_data->call_code(); |
3607 if (!raw_call_data->IsUndefined()) { | 3596 if (!raw_call_data->IsUndefined()) { |
3608 // TODO(ishell): remove this debugging code. | 3597 // TODO(ishell): remove this debugging code. |
(...skipping 23 matching lines...) Expand all Loading... |
3632 result = v8::Utils::OpenHandle(*value); | 3621 result = v8::Utils::OpenHandle(*value); |
3633 result->VerifyApiCallResultType(); | 3622 result->VerifyApiCallResultType(); |
3634 } | 3623 } |
3635 | 3624 |
3636 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); | 3625 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); |
3637 if (!is_construct || result->IsJSObject()) { | 3626 if (!is_construct || result->IsJSObject()) { |
3638 return scope.CloseAndEscape(result); | 3627 return scope.CloseAndEscape(result); |
3639 } | 3628 } |
3640 } | 3629 } |
3641 | 3630 |
3642 return scope.CloseAndEscape(receiver); | 3631 return scope.CloseAndEscape(args.receiver()); |
3643 } | 3632 } |
3644 | 3633 |
3645 } // namespace | 3634 } // namespace |
3646 | 3635 |
3647 | 3636 |
3648 BUILTIN(HandleApiCall) { | 3637 BUILTIN(HandleApiCall) { |
3649 HandleScope scope(isolate); | 3638 HandleScope scope(isolate); |
3650 Handle<Object> result; | 3639 Handle<Object> result; |
3651 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, | 3640 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, |
3652 HandleApiCallHelper<false>(isolate, args)); | 3641 HandleApiCallHelper<false>(isolate, args)); |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4202 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 4191 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
4203 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 4192 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
4204 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 4193 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
4205 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 4194 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
4206 #undef DEFINE_BUILTIN_ACCESSOR_C | 4195 #undef DEFINE_BUILTIN_ACCESSOR_C |
4207 #undef DEFINE_BUILTIN_ACCESSOR_A | 4196 #undef DEFINE_BUILTIN_ACCESSOR_A |
4208 | 4197 |
4209 | 4198 |
4210 } // namespace internal | 4199 } // namespace internal |
4211 } // namespace v8 | 4200 } // namespace v8 |
OLD | NEW |