diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/bindings/js/JSEventTargetCustom.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/bindings/js/JSEventTargetCustom.cpp')
-rw-r--r-- | Source/WebCore/bindings/js/JSEventTargetCustom.cpp | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/Source/WebCore/bindings/js/JSEventTargetCustom.cpp b/Source/WebCore/bindings/js/JSEventTargetCustom.cpp index 5210f12bb..07b46899e 100644 --- a/Source/WebCore/bindings/js/JSEventTargetCustom.cpp +++ b/Source/WebCore/bindings/js/JSEventTargetCustom.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * Copyright (C) 2008-2017 Apple Inc. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,10 +26,15 @@ #include "config.h" #include "JSEventTarget.h" +#include "DOMWindow.h" +#include "EventTarget.h" #include "EventTargetHeaders.h" #include "EventTargetInterfaces.h" +#include "JSDOMWindow.h" #include "JSDOMWindowShell.h" #include "JSEventListener.h" +#include "JSWorkerGlobalScope.h" +#include "WorkerGlobalScope.h" using namespace JSC; @@ -37,14 +42,11 @@ namespace WebCore { #define TRY_TO_WRAP_WITH_INTERFACE(interfaceName) \ case interfaceName##EventTargetInterfaceType: \ - return toJS(exec, globalObject, static_cast<interfaceName*>(target)); + return toJS(exec, globalObject, static_cast<interfaceName&>(target)); -JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, EventTarget* target) +JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, EventTarget& target) { - if (!target) - return jsNull(); - - switch (target->eventTargetInterface()) { + switch (target.eventTargetInterface()) { DOM_EVENT_TARGET_INTERFACES_FOR_EACH(TRY_TO_WRAP_WITH_INTERFACE) } @@ -55,18 +57,34 @@ JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, EventTarget* targ #undef TRY_TO_WRAP_WITH_INTERFACE #define TRY_TO_UNWRAP_WITH_INTERFACE(interfaceName) \ - if (value.inherits(JS##interfaceName::info())) \ - return &jsCast<JS##interfaceName*>(asObject(value))->impl(); + if (value.inherits(vm, JS##interfaceName::info())) \ + return &jsCast<JS##interfaceName*>(asObject(value))->wrapped(); -EventTarget* toEventTarget(JSC::JSValue value) +EventTarget* JSEventTarget::toWrapped(VM& vm, JSValue value) { TRY_TO_UNWRAP_WITH_INTERFACE(DOMWindowShell) + TRY_TO_UNWRAP_WITH_INTERFACE(DOMWindow) + TRY_TO_UNWRAP_WITH_INTERFACE(WorkerGlobalScope) TRY_TO_UNWRAP_WITH_INTERFACE(EventTarget) - // FIXME: Remove this once all event targets extend EventTarget - DOM_EVENT_TARGET_INTERFACES_FOR_EACH(TRY_TO_UNWRAP_WITH_INTERFACE) - return 0; + return nullptr; } #undef TRY_TO_UNWRAP_WITH_INTERFACE +std::unique_ptr<JSEventTargetWrapper> jsEventTargetCast(VM& vm, JSValue thisValue) +{ + if (auto* target = jsDynamicDowncast<JSEventTarget*>(vm, thisValue)) + return std::make_unique<JSEventTargetWrapper>(target->wrapped(), *target); + if (auto* window = toJSDOMWindow(vm, thisValue)) + return std::make_unique<JSEventTargetWrapper>(window->wrapped(), *window); + if (auto* scope = toJSWorkerGlobalScope(vm, thisValue)) + return std::make_unique<JSEventTargetWrapper>(scope->wrapped(), *scope); + return nullptr; +} + +void JSEventTarget::visitAdditionalChildren(SlotVisitor& visitor) +{ + wrapped().visitJSEventListeners(visitor); +} + } // namespace WebCore |