| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
| 9 #include "src/ast.h" | 9 #include "src/ast.h" |
| 10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 | 539 |
| 540 // Throw a reference error. | 540 // Throw a reference error. |
| 541 Handle<Name> name_handle(name); | 541 Handle<Name> name_handle(name); |
| 542 Handle<Object> error = | 542 Handle<Object> error = |
| 543 isolate->factory()->NewReferenceError("not_defined", | 543 isolate->factory()->NewReferenceError("not_defined", |
| 544 HandleVector(&name_handle, 1)); | 544 HandleVector(&name_handle, 1)); |
| 545 return isolate->Throw(*error); | 545 return isolate->Throw(*error); |
| 546 } | 546 } |
| 547 | 547 |
| 548 | 548 |
| 549 MUST_USE_RESULT static MaybeHandle<Object> LoadWithInterceptor( | |
| 550 Arguments* args, | |
| 551 PropertyAttributes* attrs) { | |
| 552 ASSERT(args->length() == StubCache::kInterceptorArgsLength); | |
| 553 Handle<Name> name_handle = | |
| 554 args->at<Name>(StubCache::kInterceptorArgsNameIndex); | |
| 555 Handle<InterceptorInfo> interceptor_info = | |
| 556 args->at<InterceptorInfo>(StubCache::kInterceptorArgsInfoIndex); | |
| 557 Handle<JSObject> receiver_handle = | |
| 558 args->at<JSObject>(StubCache::kInterceptorArgsThisIndex); | |
| 559 Handle<JSObject> holder_handle = | |
| 560 args->at<JSObject>(StubCache::kInterceptorArgsHolderIndex); | |
| 561 | |
| 562 Isolate* isolate = receiver_handle->GetIsolate(); | |
| 563 | |
| 564 // TODO(rossberg): Support symbols in the API. | |
| 565 if (name_handle->IsSymbol()) { | |
| 566 return JSObject::GetPropertyPostInterceptor( | |
| 567 holder_handle, receiver_handle, name_handle, attrs); | |
| 568 } | |
| 569 Handle<String> name = Handle<String>::cast(name_handle); | |
| 570 | |
| 571 Address getter_address = v8::ToCData<Address>(interceptor_info->getter()); | |
| 572 v8::NamedPropertyGetterCallback getter = | |
| 573 FUNCTION_CAST<v8::NamedPropertyGetterCallback>(getter_address); | |
| 574 ASSERT(getter != NULL); | |
| 575 | |
| 576 PropertyCallbackArguments callback_args(isolate, | |
| 577 interceptor_info->data(), | |
| 578 *receiver_handle, | |
| 579 *holder_handle); | |
| 580 { | |
| 581 HandleScope scope(isolate); | |
| 582 // Use the interceptor getter. | |
| 583 v8::Handle<v8::Value> r = | |
| 584 callback_args.Call(getter, v8::Utils::ToLocal(name)); | |
| 585 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); | |
| 586 if (!r.IsEmpty()) { | |
| 587 *attrs = NONE; | |
| 588 Handle<Object> result = v8::Utils::OpenHandle(*r); | |
| 589 result->VerifyApiCallResultType(); | |
| 590 return scope.CloseAndEscape(result); | |
| 591 } | |
| 592 } | |
| 593 | |
| 594 return JSObject::GetPropertyPostInterceptor( | |
| 595 holder_handle, receiver_handle, name_handle, attrs); | |
| 596 } | |
| 597 | |
| 598 | |
| 599 /** | 549 /** |
| 600 * Loads a property with an interceptor performing post interceptor | 550 * Loads a property with an interceptor performing post interceptor |
| 601 * lookup if interceptor failed. | 551 * lookup if interceptor failed. |
| 602 */ | 552 */ |
| 603 RUNTIME_FUNCTION(LoadPropertyWithInterceptorForLoad) { | 553 RUNTIME_FUNCTION(LoadPropertyWithInterceptor) { |
| 604 PropertyAttributes attr = NONE; | |
| 605 HandleScope scope(isolate); | 554 HandleScope scope(isolate); |
| 555 ASSERT(args.length() == StubCache::kInterceptorArgsLength); |
| 556 Handle<Name> name = |
| 557 args.at<Name>(StubCache::kInterceptorArgsNameIndex); |
| 558 Handle<JSObject> receiver = |
| 559 args.at<JSObject>(StubCache::kInterceptorArgsThisIndex); |
| 560 Handle<JSObject> holder = |
| 561 args.at<JSObject>(StubCache::kInterceptorArgsHolderIndex); |
| 562 |
| 606 Handle<Object> result; | 563 Handle<Object> result; |
| 564 LookupIterator it(receiver, name, holder); |
| 607 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 565 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 608 isolate, result, LoadWithInterceptor(&args, &attr)); | 566 isolate, result, JSObject::GetProperty(&it)); |
| 609 | 567 |
| 610 // If the property is present, return it. | 568 if (it.IsFound()) return *result; |
| 611 if (attr != ABSENT) return *result; | 569 |
| 612 return ThrowReferenceError(isolate, Name::cast(args[0])); | 570 return ThrowReferenceError(isolate, Name::cast(args[0])); |
| 613 } | 571 } |
| 614 | 572 |
| 615 | 573 |
| 616 RUNTIME_FUNCTION(LoadPropertyWithInterceptorForCall) { | |
| 617 PropertyAttributes attr; | |
| 618 HandleScope scope(isolate); | |
| 619 Handle<Object> result; | |
| 620 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 621 isolate, result, LoadWithInterceptor(&args, &attr)); | |
| 622 // This is call IC. In this case, we simply return the undefined result which | |
| 623 // will lead to an exception when trying to invoke the result as a | |
| 624 // function. | |
| 625 return *result; | |
| 626 } | |
| 627 | |
| 628 | |
| 629 RUNTIME_FUNCTION(StoreInterceptorProperty) { | 574 RUNTIME_FUNCTION(StoreInterceptorProperty) { |
| 630 HandleScope scope(isolate); | 575 HandleScope scope(isolate); |
| 631 ASSERT(args.length() == 3); | 576 ASSERT(args.length() == 3); |
| 632 StoreIC ic(IC::NO_EXTRA_FRAME, isolate); | 577 StoreIC ic(IC::NO_EXTRA_FRAME, isolate); |
| 633 Handle<JSObject> receiver = args.at<JSObject>(0); | 578 Handle<JSObject> receiver = args.at<JSObject>(0); |
| 634 Handle<Name> name = args.at<Name>(1); | 579 Handle<Name> name = args.at<Name>(1); |
| 635 Handle<Object> value = args.at<Object>(2); | 580 Handle<Object> value = args.at<Object>(2); |
| 636 ASSERT(receiver->HasNamedInterceptor()); | 581 ASSERT(receiver->HasNamedInterceptor()); |
| 637 PropertyAttributes attr = NONE; | 582 PropertyAttributes attr = NONE; |
| 638 Handle<Object> result; | 583 Handle<Object> result; |
| (...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1481 Handle<FunctionTemplateInfo>( | 1426 Handle<FunctionTemplateInfo>( |
| 1482 FunctionTemplateInfo::cast(signature->receiver())); | 1427 FunctionTemplateInfo::cast(signature->receiver())); |
| 1483 } | 1428 } |
| 1484 } | 1429 } |
| 1485 | 1430 |
| 1486 is_simple_api_call_ = true; | 1431 is_simple_api_call_ = true; |
| 1487 } | 1432 } |
| 1488 | 1433 |
| 1489 | 1434 |
| 1490 } } // namespace v8::internal | 1435 } } // namespace v8::internal |
| OLD | NEW |