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 <stdlib.h> | 5 #include <stdlib.h> |
6 | 6 |
7 #include <fstream> // NOLINT(readability/streams) | 7 #include <fstream> // NOLINT(readability/streams) |
8 #include <sstream> | 8 #include <sstream> |
9 | 9 |
10 #include "src/v8.h" | 10 #include "src/v8.h" |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 | 711 |
712 | 712 |
713 void Isolate::SetFailedAccessCheckCallback( | 713 void Isolate::SetFailedAccessCheckCallback( |
714 v8::FailedAccessCheckCallback callback) { | 714 v8::FailedAccessCheckCallback callback) { |
715 thread_local_top()->failed_access_check_callback_ = callback; | 715 thread_local_top()->failed_access_check_callback_ = callback; |
716 } | 716 } |
717 | 717 |
718 | 718 |
719 static inline AccessCheckInfo* GetAccessCheckInfo(Isolate* isolate, | 719 static inline AccessCheckInfo* GetAccessCheckInfo(Isolate* isolate, |
720 Handle<JSObject> receiver) { | 720 Handle<JSObject> receiver) { |
721 JSFunction* constructor = JSFunction::cast(receiver->map()->GetConstructor()); | 721 Object* maybe_constructor = receiver->map()->GetConstructor(); |
| 722 if (!maybe_constructor->IsJSFunction()) return NULL; |
| 723 JSFunction* constructor = JSFunction::cast(maybe_constructor); |
722 if (!constructor->shared()->IsApiFunction()) return NULL; | 724 if (!constructor->shared()->IsApiFunction()) return NULL; |
723 | 725 |
724 Object* data_obj = | 726 Object* data_obj = |
725 constructor->shared()->get_api_func_data()->access_check_info(); | 727 constructor->shared()->get_api_func_data()->access_check_info(); |
726 if (data_obj == isolate->heap()->undefined_value()) return NULL; | 728 if (data_obj == isolate->heap()->undefined_value()) return NULL; |
727 | 729 |
728 return AccessCheckInfo::cast(data_obj); | 730 return AccessCheckInfo::cast(data_obj); |
729 } | 731 } |
730 | 732 |
731 | 733 |
| 734 static void ThrowAccessCheckError(Isolate* isolate) { |
| 735 Handle<String> message = |
| 736 isolate->factory()->InternalizeUtf8String("no access"); |
| 737 isolate->ScheduleThrow(*isolate->factory()->NewTypeError(message)); |
| 738 } |
| 739 |
| 740 |
732 void Isolate::ReportFailedAccessCheck(Handle<JSObject> receiver) { | 741 void Isolate::ReportFailedAccessCheck(Handle<JSObject> receiver) { |
733 if (!thread_local_top()->failed_access_check_callback_) { | 742 if (!thread_local_top()->failed_access_check_callback_) { |
734 Handle<String> message = factory()->InternalizeUtf8String("no access"); | 743 return ThrowAccessCheckError(this); |
735 ScheduleThrow(*factory()->NewTypeError(message)); | |
736 return; | |
737 } | 744 } |
738 | 745 |
739 DCHECK(receiver->IsAccessCheckNeeded()); | 746 DCHECK(receiver->IsAccessCheckNeeded()); |
740 DCHECK(context()); | 747 DCHECK(context()); |
741 | 748 |
742 // Get the data object from access check info. | 749 // Get the data object from access check info. |
743 HandleScope scope(this); | 750 HandleScope scope(this); |
744 Handle<Object> data; | 751 Handle<Object> data; |
745 { DisallowHeapAllocation no_gc; | 752 { DisallowHeapAllocation no_gc; |
746 AccessCheckInfo* access_check_info = GetAccessCheckInfo(this, receiver); | 753 AccessCheckInfo* access_check_info = GetAccessCheckInfo(this, receiver); |
747 if (!access_check_info) return; | 754 if (!access_check_info) { |
| 755 AllowHeapAllocation doesnt_matter_anymore; |
| 756 return ThrowAccessCheckError(this); |
| 757 } |
748 data = handle(access_check_info->data(), this); | 758 data = handle(access_check_info->data(), this); |
749 } | 759 } |
750 | 760 |
751 // Leaving JavaScript. | 761 // Leaving JavaScript. |
752 VMState<EXTERNAL> state(this); | 762 VMState<EXTERNAL> state(this); |
753 thread_local_top()->failed_access_check_callback_( | 763 thread_local_top()->failed_access_check_callback_( |
754 v8::Utils::ToLocal(receiver), v8::ACCESS_HAS, v8::Utils::ToLocal(data)); | 764 v8::Utils::ToLocal(receiver), v8::ACCESS_HAS, v8::Utils::ToLocal(data)); |
755 } | 765 } |
756 | 766 |
757 | 767 |
(...skipping 1891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2649 if (prev_ && prev_->Intercept(flag)) return true; | 2659 if (prev_ && prev_->Intercept(flag)) return true; |
2650 // Then check whether this scope intercepts. | 2660 // Then check whether this scope intercepts. |
2651 if ((flag & intercept_mask_)) { | 2661 if ((flag & intercept_mask_)) { |
2652 intercepted_flags_ |= flag; | 2662 intercepted_flags_ |= flag; |
2653 return true; | 2663 return true; |
2654 } | 2664 } |
2655 return false; | 2665 return false; |
2656 } | 2666 } |
2657 | 2667 |
2658 } } // namespace v8::internal | 2668 } } // namespace v8::internal |
OLD | NEW |