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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8Binding.cpp

Issue 2723973002: Make V8Binding helpers return LocalFrame/LocalDOMWindow as appropriate (Closed)
Patch Set: Created 3 years, 9 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 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 if (value.IsEmpty() || !value->IsObject()) 710 if (value.IsEmpty() || !value->IsObject())
711 return 0; 711 return 0;
712 712
713 v8::Local<v8::Object> windowWrapper = V8Window::findInstanceInPrototypeChain( 713 v8::Local<v8::Object> windowWrapper = V8Window::findInstanceInPrototypeChain(
714 v8::Local<v8::Object>::Cast(value), isolate); 714 v8::Local<v8::Object>::Cast(value), isolate);
715 if (!windowWrapper.IsEmpty()) 715 if (!windowWrapper.IsEmpty())
716 return V8Window::toImpl(windowWrapper); 716 return V8Window::toImpl(windowWrapper);
717 return 0; 717 return 0;
718 } 718 }
719 719
720 DOMWindow* toDOMWindow(v8::Local<v8::Context> context) { 720 LocalDOMWindow* toDOMWindow(v8::Local<v8::Context> context) {
721 if (context.IsEmpty()) 721 if (context.IsEmpty())
722 return 0; 722 return 0;
723 return toDOMWindow(context->GetIsolate(), context->Global()); 723 return toLocalDOMWindow(
724 toDOMWindow(context->GetIsolate(), context->Global()));
724 } 725 }
725 726
726 LocalDOMWindow* enteredDOMWindow(v8::Isolate* isolate) { 727 LocalDOMWindow* enteredDOMWindow(v8::Isolate* isolate) {
727 LocalDOMWindow* window = 728 LocalDOMWindow* window = toDOMWindow(isolate->GetEnteredContext());
728 toLocalDOMWindow(toDOMWindow(isolate->GetEnteredContext()));
729 if (!window) { 729 if (!window) {
730 // We don't always have an entered DOM window, for example during microtask 730 // We don't always have an entered DOM window, for example during microtask
731 // callbacks from V8 (where the entered context may be the DOM-in-JS 731 // callbacks from V8 (where the entered context may be the DOM-in-JS
732 // context). In that case, we fall back to the current context. 732 // context). In that case, we fall back to the current context.
733 // 733 //
734 // TODO(haraken): It's nasty to return a current window from 734 // TODO(haraken): It's nasty to return a current window from
735 // enteredDOMWindow. All call sites should be updated so that it works even 735 // enteredDOMWindow. All call sites should be updated so that it works even
736 // if it doesn't have an entered window. 736 // if it doesn't have an entered window.
737 window = currentDOMWindow(isolate); 737 window = currentDOMWindow(isolate);
738 ASSERT(window); 738 ASSERT(window);
739 } 739 }
740 return window; 740 return window;
741 } 741 }
742 742
743 LocalDOMWindow* currentDOMWindow(v8::Isolate* isolate) { 743 LocalDOMWindow* currentDOMWindow(v8::Isolate* isolate) {
744 return toLocalDOMWindow(toDOMWindow(isolate->GetCurrentContext())); 744 return toDOMWindow(isolate->GetCurrentContext());
745 } 745 }
746 746
747 ExecutionContext* toExecutionContext(v8::Local<v8::Context> context) { 747 ExecutionContext* toExecutionContext(v8::Local<v8::Context> context) {
748 if (context.IsEmpty()) 748 if (context.IsEmpty())
749 return 0; 749 return 0;
750 v8::Local<v8::Object> global = context->Global(); 750 v8::Local<v8::Object> global = context->Global();
751 v8::Local<v8::Object> windowWrapper = 751 v8::Local<v8::Object> windowWrapper =
752 V8Window::findInstanceInPrototypeChain(global, context->GetIsolate()); 752 V8Window::findInstanceInPrototypeChain(global, context->GetIsolate());
753 if (!windowWrapper.IsEmpty()) 753 if (!windowWrapper.IsEmpty())
754 return V8Window::toImpl(windowWrapper)->getExecutionContext(); 754 return V8Window::toImpl(windowWrapper)->getExecutionContext();
755 v8::Local<v8::Object> workerWrapper = 755 v8::Local<v8::Object> workerWrapper =
756 V8WorkerGlobalScope::findInstanceInPrototypeChain(global, 756 V8WorkerGlobalScope::findInstanceInPrototypeChain(global,
757 context->GetIsolate()); 757 context->GetIsolate());
758 if (!workerWrapper.IsEmpty()) 758 if (!workerWrapper.IsEmpty())
759 return V8WorkerGlobalScope::toImpl(workerWrapper)->getExecutionContext(); 759 return V8WorkerGlobalScope::toImpl(workerWrapper)->getExecutionContext();
760 v8::Local<v8::Object> workletWrapper = 760 v8::Local<v8::Object> workletWrapper =
761 V8WorkletGlobalScope::findInstanceInPrototypeChain(global, 761 V8WorkletGlobalScope::findInstanceInPrototypeChain(global,
762 context->GetIsolate()); 762 context->GetIsolate());
763 if (!workletWrapper.IsEmpty()) 763 if (!workletWrapper.IsEmpty())
764 return V8WorkletGlobalScope::toImpl(workletWrapper); 764 return V8WorkletGlobalScope::toImpl(workletWrapper);
765 // FIXME: Is this line of code reachable? 765 // FIXME: Is this line of code reachable?
766 return nullptr; 766 return nullptr;
767 } 767 }
768 768
769 ExecutionContext* currentExecutionContext(v8::Isolate* isolate) { 769 ExecutionContext* currentExecutionContext(v8::Isolate* isolate) {
770 return toExecutionContext(isolate->GetCurrentContext()); 770 return toExecutionContext(isolate->GetCurrentContext());
771 } 771 }
772 772
773 Frame* toFrameIfNotDetached(v8::Local<v8::Context> context) { 773 LocalFrame* toFrameIfNotDetached(v8::Local<v8::Context> context) {
774 DOMWindow* window = toDOMWindow(context); 774 LocalDOMWindow* window = toDOMWindow(context);
775 if (window && window->isCurrentlyDisplayedInFrame()) 775 if (window && window->isCurrentlyDisplayedInFrame())
776 return window->frame(); 776 return window->frame();
777 // We return 0 here because |context| is detached from the Frame. If we 777 // We return 0 here because |context| is detached from the Frame. If we
778 // did return |frame| we could get in trouble because the frame could be 778 // did return |frame| we could get in trouble because the frame could be
779 // navigated to another security origin. 779 // navigated to another security origin.
780 return nullptr; 780 return nullptr;
781 } 781 }
782 782
783 void toFlexibleArrayBufferView(v8::Isolate* isolate, 783 void toFlexibleArrayBufferView(v8::Isolate* isolate,
784 v8::Local<v8::Value> value, 784 v8::Local<v8::Value> value,
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 if (!v8Call(v8::JSON::Parse(isolate, v8String(isolate, stringifiedJSON)), 981 if (!v8Call(v8::JSON::Parse(isolate, v8String(isolate, stringifiedJSON)),
982 parsed, tryCatch)) { 982 parsed, tryCatch)) {
983 if (tryCatch.HasCaught()) 983 if (tryCatch.HasCaught())
984 exceptionState.rethrowV8Exception(tryCatch.Exception()); 984 exceptionState.rethrowV8Exception(tryCatch.Exception());
985 } 985 }
986 986
987 return parsed; 987 return parsed;
988 } 988 }
989 989
990 } // namespace blink 990 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698