| OLD | NEW |
| 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 Loading... |
| 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* toLocalDOMWindow(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 = |
| 728 toLocalDOMWindow(toDOMWindow(isolate->GetEnteredOrMicrotaskContext())); | 729 toLocalDOMWindow(isolate->GetEnteredOrMicrotaskContext()); |
| 729 DCHECK(window); | 730 DCHECK(window); |
| 730 return window; | 731 return window; |
| 731 } | 732 } |
| 732 | 733 |
| 733 LocalDOMWindow* currentDOMWindow(v8::Isolate* isolate) { | 734 LocalDOMWindow* currentDOMWindow(v8::Isolate* isolate) { |
| 734 return toLocalDOMWindow(toDOMWindow(isolate->GetCurrentContext())); | 735 return toLocalDOMWindow(isolate->GetCurrentContext()); |
| 735 } | 736 } |
| 736 | 737 |
| 737 ExecutionContext* toExecutionContext(v8::Local<v8::Context> context) { | 738 ExecutionContext* toExecutionContext(v8::Local<v8::Context> context) { |
| 738 if (context.IsEmpty()) | 739 if (context.IsEmpty()) |
| 739 return 0; | 740 return 0; |
| 740 v8::Local<v8::Object> global = context->Global(); | 741 v8::Local<v8::Object> global = context->Global(); |
| 741 v8::Local<v8::Object> windowWrapper = | 742 v8::Local<v8::Object> windowWrapper = |
| 742 V8Window::findInstanceInPrototypeChain(global, context->GetIsolate()); | 743 V8Window::findInstanceInPrototypeChain(global, context->GetIsolate()); |
| 743 if (!windowWrapper.IsEmpty()) | 744 if (!windowWrapper.IsEmpty()) |
| 744 return V8Window::toImpl(windowWrapper)->getExecutionContext(); | 745 return V8Window::toImpl(windowWrapper)->getExecutionContext(); |
| 745 v8::Local<v8::Object> workerWrapper = | 746 v8::Local<v8::Object> workerWrapper = |
| 746 V8WorkerGlobalScope::findInstanceInPrototypeChain(global, | 747 V8WorkerGlobalScope::findInstanceInPrototypeChain(global, |
| 747 context->GetIsolate()); | 748 context->GetIsolate()); |
| 748 if (!workerWrapper.IsEmpty()) | 749 if (!workerWrapper.IsEmpty()) |
| 749 return V8WorkerGlobalScope::toImpl(workerWrapper)->getExecutionContext(); | 750 return V8WorkerGlobalScope::toImpl(workerWrapper)->getExecutionContext(); |
| 750 v8::Local<v8::Object> workletWrapper = | 751 v8::Local<v8::Object> workletWrapper = |
| 751 V8WorkletGlobalScope::findInstanceInPrototypeChain(global, | 752 V8WorkletGlobalScope::findInstanceInPrototypeChain(global, |
| 752 context->GetIsolate()); | 753 context->GetIsolate()); |
| 753 if (!workletWrapper.IsEmpty()) | 754 if (!workletWrapper.IsEmpty()) |
| 754 return V8WorkletGlobalScope::toImpl(workletWrapper); | 755 return V8WorkletGlobalScope::toImpl(workletWrapper); |
| 755 // FIXME: Is this line of code reachable? | 756 // FIXME: Is this line of code reachable? |
| 756 return nullptr; | 757 return nullptr; |
| 757 } | 758 } |
| 758 | 759 |
| 759 ExecutionContext* currentExecutionContext(v8::Isolate* isolate) { | 760 ExecutionContext* currentExecutionContext(v8::Isolate* isolate) { |
| 760 return toExecutionContext(isolate->GetCurrentContext()); | 761 return toExecutionContext(isolate->GetCurrentContext()); |
| 761 } | 762 } |
| 762 | 763 |
| 763 Frame* toFrameIfNotDetached(v8::Local<v8::Context> context) { | 764 LocalFrame* toLocalFrameIfNotDetached(v8::Local<v8::Context> context) { |
| 764 DOMWindow* window = toDOMWindow(context); | 765 LocalDOMWindow* window = toLocalDOMWindow(context); |
| 765 if (window && window->isCurrentlyDisplayedInFrame()) | 766 if (window && window->isCurrentlyDisplayedInFrame()) |
| 766 return window->frame(); | 767 return window->frame(); |
| 767 // We return 0 here because |context| is detached from the Frame. If we | 768 // We return 0 here because |context| is detached from the Frame. If we |
| 768 // did return |frame| we could get in trouble because the frame could be | 769 // did return |frame| we could get in trouble because the frame could be |
| 769 // navigated to another security origin. | 770 // navigated to another security origin. |
| 770 return nullptr; | 771 return nullptr; |
| 771 } | 772 } |
| 772 | 773 |
| 773 void toFlexibleArrayBufferView(v8::Isolate* isolate, | 774 void toFlexibleArrayBufferView(v8::Isolate* isolate, |
| 774 v8::Local<v8::Value> value, | 775 v8::Local<v8::Value> value, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 794 } else if (context->isWorkerGlobalScope()) { | 795 } else if (context->isWorkerGlobalScope()) { |
| 795 if (WorkerOrWorkletScriptController* script = | 796 if (WorkerOrWorkletScriptController* script = |
| 796 toWorkerOrWorkletGlobalScope(context)->scriptController()) { | 797 toWorkerOrWorkletGlobalScope(context)->scriptController()) { |
| 797 if (script->getScriptState()->contextIsValid()) | 798 if (script->getScriptState()->contextIsValid()) |
| 798 return script->getScriptState()->context(); | 799 return script->getScriptState()->context(); |
| 799 } | 800 } |
| 800 } | 801 } |
| 801 return v8::Local<v8::Context>(); | 802 return v8::Local<v8::Context>(); |
| 802 } | 803 } |
| 803 | 804 |
| 804 v8::Local<v8::Context> toV8Context(Frame* frame, DOMWrapperWorld& world) { | 805 v8::Local<v8::Context> toV8Context(LocalFrame* frame, DOMWrapperWorld& world) { |
| 805 if (!frame) | 806 if (!frame) |
| 806 return v8::Local<v8::Context>(); | 807 return v8::Local<v8::Context>(); |
| 807 v8::Local<v8::Context> context = toV8ContextEvenIfDetached(frame, world); | 808 v8::Local<v8::Context> context = toV8ContextEvenIfDetached(frame, world); |
| 808 if (context.IsEmpty()) | 809 if (context.IsEmpty()) |
| 809 return v8::Local<v8::Context>(); | 810 return v8::Local<v8::Context>(); |
| 810 ScriptState* scriptState = ScriptState::from(context); | 811 ScriptState* scriptState = ScriptState::from(context); |
| 811 if (scriptState->contextIsValid()) { | 812 if (scriptState->contextIsValid()) { |
| 812 ASSERT(toFrameIfNotDetached(context) == frame); | 813 DCHECK_EQ(frame, toLocalFrameIfNotDetached(context)); |
| 813 return scriptState->context(); | 814 return scriptState->context(); |
| 814 } | 815 } |
| 815 return v8::Local<v8::Context>(); | 816 return v8::Local<v8::Context>(); |
| 816 } | 817 } |
| 817 | 818 |
| 818 v8::Local<v8::Context> toV8ContextEvenIfDetached(Frame* frame, | 819 v8::Local<v8::Context> toV8ContextEvenIfDetached(LocalFrame* frame, |
| 819 DOMWrapperWorld& world) { | 820 DOMWrapperWorld& world) { |
| 820 ASSERT(frame); | 821 ASSERT(frame); |
| 821 return frame->windowProxy(world)->contextIfInitialized(); | 822 return frame->windowProxy(world)->contextIfInitialized(); |
| 822 } | 823 } |
| 823 | 824 |
| 824 bool isValidEnum(const String& value, | 825 bool isValidEnum(const String& value, |
| 825 const char** validValues, | 826 const char** validValues, |
| 826 size_t length, | 827 size_t length, |
| 827 const String& enumName, | 828 const String& enumName, |
| 828 ExceptionState& exceptionState) { | 829 ExceptionState& exceptionState) { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 if (!v8Call(v8::JSON::Parse(isolate, v8String(isolate, stringifiedJSON)), | 972 if (!v8Call(v8::JSON::Parse(isolate, v8String(isolate, stringifiedJSON)), |
| 972 parsed, tryCatch)) { | 973 parsed, tryCatch)) { |
| 973 if (tryCatch.HasCaught()) | 974 if (tryCatch.HasCaught()) |
| 974 exceptionState.rethrowV8Exception(tryCatch.Exception()); | 975 exceptionState.rethrowV8Exception(tryCatch.Exception()); |
| 975 } | 976 } |
| 976 | 977 |
| 977 return parsed; | 978 return parsed; |
| 978 } | 979 } |
| 979 | 980 |
| 980 } // namespace blink | 981 } // namespace blink |
| OLD | NEW |