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 3505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3516 // | 3516 // |
3517 | 3517 |
3518 | 3518 |
3519 namespace { | 3519 namespace { |
3520 | 3520 |
3521 template <bool is_construct> | 3521 template <bool is_construct> |
3522 MUST_USE_RESULT MaybeHandle<Object> HandleApiCallHelper( | 3522 MUST_USE_RESULT MaybeHandle<Object> HandleApiCallHelper( |
3523 Isolate* isolate, BuiltinArguments<BuiltinExtraArguments::kTarget> args) { | 3523 Isolate* isolate, BuiltinArguments<BuiltinExtraArguments::kTarget> args) { |
3524 HandleScope scope(isolate); | 3524 HandleScope scope(isolate); |
3525 Handle<JSFunction> function = args.target(); | 3525 Handle<JSFunction> function = args.target(); |
3526 Handle<JSReceiver> receiver; | 3526 DCHECK(args.receiver()->IsJSReceiver()); |
3527 // TODO(ishell): turn this back to a DCHECK. | 3527 // TODO(ishell): turn this back to a DCHECK. |
3528 CHECK(function->shared()->IsApiFunction()); | 3528 CHECK(function->shared()->IsApiFunction()); |
3529 | 3529 |
3530 Handle<FunctionTemplateInfo> fun_data( | 3530 Handle<FunctionTemplateInfo> fun_data( |
3531 function->shared()->get_api_func_data(), isolate); | 3531 function->shared()->get_api_func_data(), isolate); |
3532 if (is_construct) { | 3532 if (is_construct) { |
3533 DCHECK(args.receiver()->IsTheHole()); | 3533 ASSIGN_RETURN_ON_EXCEPTION( |
3534 if (fun_data->instance_template()->IsUndefined()) { | 3534 isolate, fun_data, |
3535 v8::Local<ObjectTemplate> templ = | 3535 ApiNatives::ConfigureInstance(isolate, fun_data, |
3536 ObjectTemplate::New(reinterpret_cast<v8::Isolate*>(isolate), | 3536 Handle<JSObject>::cast(args.receiver())), |
3537 ToApiHandle<v8::FunctionTemplate>(fun_data)); | 3537 Object); |
3538 fun_data->set_instance_template(*Utils::OpenHandle(*templ)); | |
3539 } | |
3540 Handle<ObjectTemplateInfo> instance_template( | |
3541 ObjectTemplateInfo::cast(fun_data->instance_template()), isolate); | |
3542 ASSIGN_RETURN_ON_EXCEPTION(isolate, receiver, | |
3543 ApiNatives::InstantiateObject(instance_template), | |
3544 Object); | |
3545 args[0] = *receiver; | |
3546 DCHECK_EQ(*receiver, *args.receiver()); | |
3547 } else { | |
3548 DCHECK(args.receiver()->IsJSReceiver()); | |
3549 receiver = args.at<JSReceiver>(0); | |
3550 } | 3538 } |
3551 | 3539 |
3552 if (!is_construct && !fun_data->accept_any_receiver()) { | 3540 if (!is_construct && !fun_data->accept_any_receiver()) { |
| 3541 Handle<JSReceiver> receiver = args.at<JSReceiver>(0); |
3553 if (receiver->IsJSObject() && receiver->IsAccessCheckNeeded()) { | 3542 if (receiver->IsJSObject() && receiver->IsAccessCheckNeeded()) { |
3554 Handle<JSObject> js_receiver = Handle<JSObject>::cast(receiver); | 3543 Handle<JSObject> js_receiver = Handle<JSObject>::cast(receiver); |
3555 if (!isolate->MayAccess(handle(isolate->context()), js_receiver)) { | 3544 if (!isolate->MayAccess(handle(isolate->context()), js_receiver)) { |
3556 isolate->ReportFailedAccessCheck(js_receiver); | 3545 isolate->ReportFailedAccessCheck(js_receiver); |
3557 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); | 3546 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); |
3558 } | 3547 } |
3559 } | 3548 } |
3560 } | 3549 } |
3561 | 3550 |
3562 Object* raw_holder = fun_data->GetCompatibleReceiver(isolate, *receiver); | 3551 Object* raw_holder = fun_data->GetCompatibleReceiver(isolate, args[0]); |
3563 | 3552 |
3564 if (raw_holder->IsNull()) { | 3553 if (raw_holder->IsNull()) { |
3565 // This function cannot be called with the given receiver. Abort! | 3554 // This function cannot be called with the given receiver. Abort! |
3566 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kIllegalInvocation), | 3555 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kIllegalInvocation), |
3567 Object); | 3556 Object); |
3568 } | 3557 } |
3569 | 3558 |
3570 Object* raw_call_data = fun_data->call_code(); | 3559 Object* raw_call_data = fun_data->call_code(); |
3571 if (!raw_call_data->IsUndefined()) { | 3560 if (!raw_call_data->IsUndefined()) { |
3572 // TODO(ishell): remove this debugging code. | 3561 // TODO(ishell): remove this debugging code. |
(...skipping 23 matching lines...) Expand all Loading... |
3596 result = v8::Utils::OpenHandle(*value); | 3585 result = v8::Utils::OpenHandle(*value); |
3597 result->VerifyApiCallResultType(); | 3586 result->VerifyApiCallResultType(); |
3598 } | 3587 } |
3599 | 3588 |
3600 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); | 3589 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); |
3601 if (!is_construct || result->IsJSObject()) { | 3590 if (!is_construct || result->IsJSObject()) { |
3602 return scope.CloseAndEscape(result); | 3591 return scope.CloseAndEscape(result); |
3603 } | 3592 } |
3604 } | 3593 } |
3605 | 3594 |
3606 return scope.CloseAndEscape(receiver); | 3595 return scope.CloseAndEscape(args.receiver()); |
3607 } | 3596 } |
3608 | 3597 |
3609 } // namespace | 3598 } // namespace |
3610 | 3599 |
3611 | 3600 |
3612 BUILTIN(HandleApiCall) { | 3601 BUILTIN(HandleApiCall) { |
3613 HandleScope scope(isolate); | 3602 HandleScope scope(isolate); |
3614 Handle<Object> result; | 3603 Handle<Object> result; |
3615 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, | 3604 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, |
3616 HandleApiCallHelper<false>(isolate, args)); | 3605 HandleApiCallHelper<false>(isolate, args)); |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4166 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 4155 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
4167 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 4156 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
4168 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 4157 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
4169 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 4158 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
4170 #undef DEFINE_BUILTIN_ACCESSOR_C | 4159 #undef DEFINE_BUILTIN_ACCESSOR_C |
4171 #undef DEFINE_BUILTIN_ACCESSOR_A | 4160 #undef DEFINE_BUILTIN_ACCESSOR_A |
4172 | 4161 |
4173 | 4162 |
4174 } // namespace internal | 4163 } // namespace internal |
4175 } // namespace v8 | 4164 } // namespace v8 |
OLD | NEW |