Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: src/builtins.cc

Issue 1642223003: [api] Make ObjectTemplate::SetNativeDataProperty() work even if the ObjectTemplate does not have a … (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 DCHECK(args.receiver()->IsJSReceiver()); 3526 Handle<JSReceiver> receiver;
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) {
Toon Verwaest 2016/01/29 14:37:45 DCHECK(args.receiver()->IsUndefined()) I presume?
Igor Sheludko 2016/02/01 20:43:55 Done.
3533 ASSIGN_RETURN_ON_EXCEPTION( 3533 if (fun_data->instance_template()->IsUndefined()) {
3534 isolate, fun_data, 3534 v8::Local<ObjectTemplate> templ =
3535 ApiNatives::ConfigureInstance(isolate, fun_data, 3535 ObjectTemplate::New(reinterpret_cast<v8::Isolate*>(isolate),
3536 Handle<JSObject>::cast(args.receiver())), 3536 ToApiHandle<v8::FunctionTemplate>(fun_data));
3537 Object); 3537 fun_data->set_instance_template(*Utils::OpenHandle(*templ));
3538 }
3539 Handle<ObjectTemplateInfo> instance_template(
3540 ObjectTemplateInfo::cast(fun_data->instance_template()), isolate);
3541 ASSIGN_RETURN_ON_EXCEPTION(isolate, receiver,
3542 ApiNatives::InstantiateObject(instance_template),
3543 Object);
3544 args[0] = *receiver;
3545 DCHECK_EQ(*receiver, *args.receiver());
3546 } else {
3547 DCHECK(args.receiver()->IsJSReceiver());
3548 receiver = args.at<JSReceiver>(0);
3538 } 3549 }
3539 3550
3540 if (!is_construct && !fun_data->accept_any_receiver()) { 3551 if (!is_construct && !fun_data->accept_any_receiver()) {
3541 Handle<JSReceiver> receiver = args.at<JSReceiver>(0);
3542 if (receiver->IsJSObject() && receiver->IsAccessCheckNeeded()) { 3552 if (receiver->IsJSObject() && receiver->IsAccessCheckNeeded()) {
3543 Handle<JSObject> js_receiver = Handle<JSObject>::cast(receiver); 3553 Handle<JSObject> js_receiver = Handle<JSObject>::cast(receiver);
3544 if (!isolate->MayAccess(handle(isolate->context()), js_receiver)) { 3554 if (!isolate->MayAccess(handle(isolate->context()), js_receiver)) {
3545 isolate->ReportFailedAccessCheck(js_receiver); 3555 isolate->ReportFailedAccessCheck(js_receiver);
3546 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); 3556 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object);
3547 } 3557 }
3548 } 3558 }
3549 } 3559 }
3550 3560
3551 Object* raw_holder = fun_data->GetCompatibleReceiver(isolate, args[0]); 3561 Object* raw_holder = fun_data->GetCompatibleReceiver(isolate, *receiver);
3552 3562
3553 if (raw_holder->IsNull()) { 3563 if (raw_holder->IsNull()) {
3554 // This function cannot be called with the given receiver. Abort! 3564 // This function cannot be called with the given receiver. Abort!
3555 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kIllegalInvocation), 3565 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kIllegalInvocation),
3556 Object); 3566 Object);
3557 } 3567 }
3558 3568
3559 Object* raw_call_data = fun_data->call_code(); 3569 Object* raw_call_data = fun_data->call_code();
3560 if (!raw_call_data->IsUndefined()) { 3570 if (!raw_call_data->IsUndefined()) {
3561 // TODO(ishell): remove this debugging code. 3571 // TODO(ishell): remove this debugging code.
(...skipping 23 matching lines...) Expand all
3585 result = v8::Utils::OpenHandle(*value); 3595 result = v8::Utils::OpenHandle(*value);
3586 result->VerifyApiCallResultType(); 3596 result->VerifyApiCallResultType();
3587 } 3597 }
3588 3598
3589 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); 3599 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object);
3590 if (!is_construct || result->IsJSObject()) { 3600 if (!is_construct || result->IsJSObject()) {
3591 return scope.CloseAndEscape(result); 3601 return scope.CloseAndEscape(result);
3592 } 3602 }
3593 } 3603 }
3594 3604
3595 return scope.CloseAndEscape(args.receiver()); 3605 return scope.CloseAndEscape(receiver);
3596 } 3606 }
3597 3607
3598 } // namespace 3608 } // namespace
3599 3609
3600 3610
3601 BUILTIN(HandleApiCall) { 3611 BUILTIN(HandleApiCall) {
3602 HandleScope scope(isolate); 3612 HandleScope scope(isolate);
3603 Handle<Object> result; 3613 Handle<Object> result;
3604 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, 3614 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
3605 HandleApiCallHelper<false>(isolate, args)); 3615 HandleApiCallHelper<false>(isolate, args));
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
4155 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) 4165 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C)
4156 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) 4166 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A)
4157 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 4167 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
4158 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 4168 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
4159 #undef DEFINE_BUILTIN_ACCESSOR_C 4169 #undef DEFINE_BUILTIN_ACCESSOR_C
4160 #undef DEFINE_BUILTIN_ACCESSOR_A 4170 #undef DEFINE_BUILTIN_ACCESSOR_A
4161 4171
4162 4172
4163 } // namespace internal 4173 } // namespace internal
4164 } // namespace v8 4174 } // namespace v8
OLDNEW
« src/api-natives.cc ('K') | « src/bootstrapper.cc ('k') | src/contexts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698