| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium 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 "bindings/core/v8/ToV8.h" | 5 #include "bindings/core/v8/ToV8.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/WindowProxy.h" | 7 #include "bindings/core/v8/WindowProxy.h" |
| 8 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | 8 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
| 9 #include "core/events/EventTarget.h" | 9 #include "core/events/EventTarget.h" |
| 10 #include "core/frame/DOMWindow.h" | 10 #include "core/frame/DOMWindow.h" |
| 11 #include "core/frame/Frame.h" | 11 #include "core/frame/Frame.h" |
| 12 #include "core/workers/WorkerOrWorkletGlobalScope.h" | 12 #include "core/workers/WorkerOrWorkletGlobalScope.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 v8::Local<v8::Value> toV8(DOMWindow* window, | 16 v8::Local<v8::Value> ToV8(DOMWindow* window, |
| 17 v8::Local<v8::Object> creationContext, | 17 v8::Local<v8::Object> creationContext, |
| 18 v8::Isolate* isolate) { | 18 v8::Isolate* isolate) { |
| 19 // Notice that we explicitly ignore creationContext because the DOMWindow | 19 // Notice that we explicitly ignore creationContext because the DOMWindow |
| 20 // has its own creationContext. | 20 // has its own creationContext. |
| 21 | 21 |
| 22 if (UNLIKELY(!window)) | 22 if (UNLIKELY(!window)) |
| 23 return v8::Null(isolate); | 23 return v8::Null(isolate); |
| 24 // Initializes environment of a frame, and return the global object | 24 // Initializes environment of a frame, and return the global object |
| 25 // of the frame. | 25 // of the frame. |
| 26 Frame* frame = window->frame(); | 26 Frame* frame = window->frame(); |
| 27 if (!frame) | 27 if (!frame) |
| 28 return v8Undefined(); | 28 return v8Undefined(); |
| 29 | 29 |
| 30 return frame->windowProxy(DOMWrapperWorld::current(isolate)) | 30 return frame->windowProxy(DOMWrapperWorld::current(isolate)) |
| 31 ->globalIfNotDetached(); | 31 ->globalIfNotDetached(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 v8::Local<v8::Value> toV8(EventTarget* impl, | 34 v8::Local<v8::Value> ToV8(EventTarget* impl, |
| 35 v8::Local<v8::Object> creationContext, | 35 v8::Local<v8::Object> creationContext, |
| 36 v8::Isolate* isolate) { | 36 v8::Isolate* isolate) { |
| 37 if (UNLIKELY(!impl)) | 37 if (UNLIKELY(!impl)) |
| 38 return v8::Null(isolate); | 38 return v8::Null(isolate); |
| 39 | 39 |
| 40 if (impl->interfaceName() == EventTargetNames::DOMWindow) | 40 if (impl->interfaceName() == EventTargetNames::DOMWindow) |
| 41 return toV8(static_cast<DOMWindow*>(impl), creationContext, isolate); | 41 return ToV8(static_cast<DOMWindow*>(impl), creationContext, isolate); |
| 42 return toV8(static_cast<ScriptWrappable*>(impl), creationContext, isolate); | 42 return ToV8(static_cast<ScriptWrappable*>(impl), creationContext, isolate); |
| 43 } | 43 } |
| 44 | 44 |
| 45 v8::Local<v8::Value> toV8(WorkerOrWorkletGlobalScope* impl, | 45 v8::Local<v8::Value> ToV8(WorkerOrWorkletGlobalScope* impl, |
| 46 v8::Local<v8::Object> creationContext, | 46 v8::Local<v8::Object> creationContext, |
| 47 v8::Isolate* isolate) { | 47 v8::Isolate* isolate) { |
| 48 // Notice that we explicitly ignore creationContext because the | 48 // Notice that we explicitly ignore creationContext because the |
| 49 // WorkerOrWorkletGlobalScope has its own creationContext. | 49 // WorkerOrWorkletGlobalScope has its own creationContext. |
| 50 | 50 |
| 51 if (UNLIKELY(!impl)) | 51 if (UNLIKELY(!impl)) |
| 52 return v8::Null(isolate); | 52 return v8::Null(isolate); |
| 53 | 53 |
| 54 WorkerOrWorkletScriptController* scriptController = impl->scriptController(); | 54 WorkerOrWorkletScriptController* scriptController = impl->scriptController(); |
| 55 if (!scriptController) | 55 if (!scriptController) |
| 56 return v8::Null(isolate); | 56 return v8::Null(isolate); |
| 57 | 57 |
| 58 v8::Local<v8::Object> global = scriptController->context()->Global(); | 58 v8::Local<v8::Object> global = scriptController->context()->Global(); |
| 59 ASSERT(!global.IsEmpty()); | 59 ASSERT(!global.IsEmpty()); |
| 60 return global; | 60 return global; |
| 61 } | 61 } |
| 62 | 62 |
| 63 } // namespace blink | 63 } // namespace blink |
| OLD | NEW |