| 1 | /* |
| 2 | * Copyright (C) 2018 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "JSRemoteDOMWindowBase.h" |
| 28 | |
| 29 | #include "JSRemoteDOMWindow.h" |
| 30 | #include "JSWindowProxy.h" |
| 31 | |
| 32 | using namespace JSC; |
| 33 | |
| 34 | namespace WebCore { |
| 35 | |
| 36 | const ClassInfo JSRemoteDOMWindowBase::s_info = { "Window" , &JSDOMGlobalObject::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSRemoteDOMWindowBase) }; |
| 37 | |
| 38 | const GlobalObjectMethodTable JSRemoteDOMWindowBase::s_globalObjectMethodTable = { |
| 39 | nullptr, // shellSupportsRichSourceInfo |
| 40 | nullptr, // shouldInterruptScript |
| 41 | &javaScriptRuntimeFlags, |
| 42 | nullptr, // queueTaskToEventLoop |
| 43 | nullptr, // shouldInterruptScriptBeforeTimeout |
| 44 | nullptr, // moduleLoaderImportModule |
| 45 | nullptr, // moduleLoaderResolve |
| 46 | nullptr, // moduleLoaderFetch |
| 47 | nullptr, // moduleLoaderCreateImportMetaProperties |
| 48 | nullptr, // moduleLoaderEvaluate |
| 49 | nullptr, // promiseRejectionTracker |
| 50 | nullptr, // defaultLanguage |
| 51 | nullptr, // compileStreaming |
| 52 | nullptr, // instantiateStreaming |
| 53 | }; |
| 54 | |
| 55 | JSRemoteDOMWindowBase::JSRemoteDOMWindowBase(VM& vm, Structure* structure, RefPtr<RemoteDOMWindow>&& window, JSWindowProxy* proxy) |
| 56 | : JSDOMGlobalObject(vm, structure, proxy->world(), &s_globalObjectMethodTable) |
| 57 | , m_wrapped(WTFMove(window)) |
| 58 | { |
| 59 | } |
| 60 | |
| 61 | void JSRemoteDOMWindowBase::destroy(JSCell* cell) |
| 62 | { |
| 63 | static_cast<JSRemoteDOMWindowBase*>(cell)->JSRemoteDOMWindowBase::~JSRemoteDOMWindowBase(); |
| 64 | } |
| 65 | |
| 66 | RuntimeFlags JSRemoteDOMWindowBase::javaScriptRuntimeFlags(const JSGlobalObject*) |
| 67 | { |
| 68 | return RuntimeFlags { }; |
| 69 | } |
| 70 | |
| 71 | JSRemoteDOMWindow* toJSRemoteDOMWindow(JSC::VM& vm, JSValue value) |
| 72 | { |
| 73 | if (!value.isObject()) |
| 74 | return nullptr; |
| 75 | |
| 76 | while (!value.isNull()) { |
| 77 | JSObject* object = asObject(value); |
| 78 | const ClassInfo* classInfo = object->classInfo(vm); |
| 79 | if (classInfo == JSRemoteDOMWindow::info()) |
| 80 | return jsCast<JSRemoteDOMWindow*>(object); |
| 81 | if (classInfo == JSWindowProxy::info()) |
| 82 | return jsDynamicCast<JSRemoteDOMWindow*>(vm, jsCast<JSWindowProxy*>(object)->window()); |
| 83 | value = object->getPrototypeDirect(vm); |
| 84 | } |
| 85 | return nullptr; |
| 86 | } |
| 87 | |
| 88 | } // namespace WebCore |
| 89 | |