| /* |
| This file is part of the WebKit open source project. |
| This file has been generated by generate-bindings.pl. DO NOT MODIFY! |
| |
| This library is free software; you can redistribute it and/or |
| modify it under the terms of the GNU Library General Public |
| License as published by the Free Software Foundation; either |
| version 2 of the License, or (at your option) any later version. |
| |
| This library is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| Library General Public License for more details. |
| |
| You should have received a copy of the GNU Library General Public License |
| along with this library; see the file COPYING.LIB. If not, write to |
| the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| Boston, MA 02110-1301, USA. |
| */ |
| |
| #include "config.h" |
| #include "JSEvent.h" |
| |
| #include "ExceptionCode.h" |
| #include "JSDOMBinding.h" |
| #include "JSDOMConstructor.h" |
| #include "JSDictionary.h" |
| #include "JSEventTarget.h" |
| #include "JSNode.h" |
| #include "Node.h" |
| #include "RuntimeEnabledFeatures.h" |
| #include "URL.h" |
| #include <runtime/Error.h> |
| #include <runtime/FunctionPrototype.h> |
| #include <runtime/JSArray.h> |
| #include <runtime/JSString.h> |
| #include <wtf/GetPtr.h> |
| |
| using namespace JSC; |
| |
| namespace WebCore { |
| |
| // Functions |
| |
| JSC::EncodedJSValue JSC_HOST_CALL jsEventPrototypeFunctionComposedPath(JSC::ExecState*); |
| JSC::EncodedJSValue JSC_HOST_CALL jsEventPrototypeFunctionStopPropagation(JSC::ExecState*); |
| JSC::EncodedJSValue JSC_HOST_CALL jsEventPrototypeFunctionPreventDefault(JSC::ExecState*); |
| JSC::EncodedJSValue JSC_HOST_CALL jsEventPrototypeFunctionInitEvent(JSC::ExecState*); |
| JSC::EncodedJSValue JSC_HOST_CALL jsEventPrototypeFunctionStopImmediatePropagation(JSC::ExecState*); |
| |
| // Attributes |
| |
| JSC::EncodedJSValue jsEventType(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsEventTarget(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsEventCurrentTarget(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsEventEventPhase(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsEventBubbles(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsEventCancelable(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsEventComposed(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsEventTimeStamp(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsEventDefaultPrevented(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsEventIsTrusted(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsEventSrcElement(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsEventReturnValue(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSEventReturnValue(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| JSC::EncodedJSValue jsEventCancelBubble(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSEventCancelBubble(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| JSC::EncodedJSValue jsEventClipboardData(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsEventConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSEventConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| |
| class JSEventPrototype : public JSC::JSNonFinalObject { |
| public: |
| typedef JSC::JSNonFinalObject Base; |
| static JSEventPrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure) |
| { |
| JSEventPrototype* ptr = new (NotNull, JSC::allocateCell<JSEventPrototype>(vm.heap)) JSEventPrototype(vm, globalObject, structure); |
| ptr->finishCreation(vm); |
| return ptr; |
| } |
| |
| DECLARE_INFO; |
| static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
| { |
| return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
| } |
| |
| private: |
| JSEventPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
| : JSC::JSNonFinalObject(vm, structure) |
| { |
| } |
| |
| void finishCreation(JSC::VM&); |
| }; |
| |
| typedef JSDOMConstructor<JSEvent> JSEventConstructor; |
| |
| /* Hash table */ |
| |
| static const struct CompactHashIndex JSEventTableIndex[2] = { |
| { 0, -1 }, |
| { -1, -1 }, |
| }; |
| |
| |
| static const HashTableValue JSEventTableValues[] = |
| { |
| { "isTrusted", DontDelete | ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventIsTrusted), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| }; |
| |
| static const HashTable JSEventTable = { 1, 1, true, JSEventTableValues, JSEventTableIndex }; |
| /* Hash table for constructor */ |
| |
| static const HashTableValue JSEventConstructorTableValues[] = |
| { |
| { "NONE", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(0) } }, |
| { "CAPTURING_PHASE", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(1) } }, |
| { "AT_TARGET", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(2) } }, |
| { "BUBBLING_PHASE", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(3) } }, |
| { "MOUSEDOWN", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(1) } }, |
| { "MOUSEUP", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(2) } }, |
| { "MOUSEOVER", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(4) } }, |
| { "MOUSEOUT", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(8) } }, |
| { "MOUSEMOVE", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(16) } }, |
| { "MOUSEDRAG", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(32) } }, |
| { "CLICK", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(64) } }, |
| { "DBLCLICK", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(128) } }, |
| { "KEYDOWN", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(256) } }, |
| { "KEYUP", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(512) } }, |
| { "KEYPRESS", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(1024) } }, |
| { "DRAGDROP", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(2048) } }, |
| { "FOCUS", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(4096) } }, |
| { "BLUR", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(8192) } }, |
| { "SELECT", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(16384) } }, |
| { "CHANGE", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(32768) } }, |
| }; |
| |
| static_assert(Event::NONE == 0, "NONE in Event does not match value from IDL"); |
| static_assert(Event::CAPTURING_PHASE == 1, "CAPTURING_PHASE in Event does not match value from IDL"); |
| static_assert(Event::AT_TARGET == 2, "AT_TARGET in Event does not match value from IDL"); |
| static_assert(Event::BUBBLING_PHASE == 3, "BUBBLING_PHASE in Event does not match value from IDL"); |
| static_assert(Event::MOUSEDOWN == 1, "MOUSEDOWN in Event does not match value from IDL"); |
| static_assert(Event::MOUSEUP == 2, "MOUSEUP in Event does not match value from IDL"); |
| static_assert(Event::MOUSEOVER == 4, "MOUSEOVER in Event does not match value from IDL"); |
| static_assert(Event::MOUSEOUT == 8, "MOUSEOUT in Event does not match value from IDL"); |
| static_assert(Event::MOUSEMOVE == 16, "MOUSEMOVE in Event does not match value from IDL"); |
| static_assert(Event::MOUSEDRAG == 32, "MOUSEDRAG in Event does not match value from IDL"); |
| static_assert(Event::CLICK == 64, "CLICK in Event does not match value from IDL"); |
| static_assert(Event::DBLCLICK == 128, "DBLCLICK in Event does not match value from IDL"); |
| static_assert(Event::KEYDOWN == 256, "KEYDOWN in Event does not match value from IDL"); |
| static_assert(Event::KEYUP == 512, "KEYUP in Event does not match value from IDL"); |
| static_assert(Event::KEYPRESS == 1024, "KEYPRESS in Event does not match value from IDL"); |
| static_assert(Event::DRAGDROP == 2048, "DRAGDROP in Event does not match value from IDL"); |
| static_assert(Event::FOCUS == 4096, "FOCUS in Event does not match value from IDL"); |
| static_assert(Event::BLUR == 8192, "BLUR in Event does not match value from IDL"); |
| static_assert(Event::SELECT == 16384, "SELECT in Event does not match value from IDL"); |
| static_assert(Event::CHANGE == 32768, "CHANGE in Event does not match value from IDL"); |
| |
| template<> EncodedJSValue JSC_HOST_CALL JSEventConstructor::construct(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| auto* jsConstructor = jsCast<JSEventConstructor*>(state->callee()); |
| ASSERT(jsConstructor); |
| |
| if (!jsConstructor->scriptExecutionContext()) |
| return throwConstructorScriptExecutionContextUnavailableError(*state, throwScope, "Event"); |
| |
| if (UNLIKELY(state->argumentCount() < 1)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| |
| AtomicString eventType = state->uncheckedArgument(0).toString(state)->toAtomicString(state); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| |
| EventInit eventInit; |
| |
| JSValue initializerValue = state->argument(1); |
| if (!initializerValue.isUndefinedOrNull()) { |
| // Given the above test, this will always yield an object. |
| JSObject* initializerObject = initializerValue.toObject(state); |
| ASSERT(!throwScope.exception()); |
| |
| // Create the dictionary wrapper from the initializer object. |
| JSDictionary dictionary(state, initializerObject); |
| |
| // Attempt to fill in the EventInit. |
| if (!fillEventInit(eventInit, dictionary)) |
| return JSValue::encode(jsUndefined()); |
| } |
| |
| Ref<Event> event = Event::createForBindings(eventType, eventInit); |
| return JSValue::encode(createWrapper<Event>(jsConstructor->globalObject(), WTFMove(event))); |
| } |
| |
| bool fillEventInit(EventInit& eventInit, JSDictionary& dictionary) |
| { |
| if (!dictionary.tryGetProperty("bubbles", eventInit.bubbles)) |
| return false; |
| if (!dictionary.tryGetProperty("cancelable", eventInit.cancelable)) |
| return false; |
| if (!dictionary.tryGetProperty("composed", eventInit.composed)) |
| return false; |
| return true; |
| } |
| |
| template<> JSValue JSEventConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| { |
| UNUSED_PARAM(vm); |
| return globalObject.functionPrototype(); |
| } |
| |
| template<> void JSEventConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
| { |
| putDirect(vm, vm.propertyNames->prototype, JSEvent::prototype(vm, &globalObject), DontDelete | ReadOnly | DontEnum); |
| putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("Event"))), ReadOnly | DontEnum); |
| putDirect(vm, vm.propertyNames->length, jsNumber(1), ReadOnly | DontEnum); |
| reifyStaticProperties(vm, JSEventConstructorTableValues, *this); |
| } |
| |
| template<> const ClassInfo JSEventConstructor::s_info = { "Event", &Base::s_info, 0, CREATE_METHOD_TABLE(JSEventConstructor) }; |
| |
| /* Hash table for prototype */ |
| |
| static const HashTableValue JSEventPrototypeTableValues[] = |
| { |
| { "constructor", DontEnum, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSEventConstructor) } }, |
| { "type", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventType), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "target", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventTarget), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "currentTarget", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventCurrentTarget), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "eventPhase", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventEventPhase), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "bubbles", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventBubbles), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "cancelable", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventCancelable), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "composed", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventComposed), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "timeStamp", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventTimeStamp), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "defaultPrevented", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventDefaultPrevented), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "srcElement", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventSrcElement), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "returnValue", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventReturnValue), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSEventReturnValue) } }, |
| { "cancelBubble", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventCancelBubble), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSEventCancelBubble) } }, |
| { "clipboardData", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventClipboardData), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "composedPath", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsEventPrototypeFunctionComposedPath), (intptr_t) (0) } }, |
| { "stopPropagation", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsEventPrototypeFunctionStopPropagation), (intptr_t) (0) } }, |
| { "preventDefault", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsEventPrototypeFunctionPreventDefault), (intptr_t) (0) } }, |
| { "initEvent", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsEventPrototypeFunctionInitEvent), (intptr_t) (3) } }, |
| { "stopImmediatePropagation", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsEventPrototypeFunctionStopImmediatePropagation), (intptr_t) (0) } }, |
| { "NONE", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(0) } }, |
| { "CAPTURING_PHASE", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(1) } }, |
| { "AT_TARGET", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(2) } }, |
| { "BUBBLING_PHASE", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(3) } }, |
| { "MOUSEDOWN", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(1) } }, |
| { "MOUSEUP", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(2) } }, |
| { "MOUSEOVER", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(4) } }, |
| { "MOUSEOUT", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(8) } }, |
| { "MOUSEMOVE", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(16) } }, |
| { "MOUSEDRAG", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(32) } }, |
| { "CLICK", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(64) } }, |
| { "DBLCLICK", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(128) } }, |
| { "KEYDOWN", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(256) } }, |
| { "KEYUP", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(512) } }, |
| { "KEYPRESS", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(1024) } }, |
| { "DRAGDROP", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(2048) } }, |
| { "FOCUS", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(4096) } }, |
| { "BLUR", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(8192) } }, |
| { "SELECT", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(16384) } }, |
| { "CHANGE", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(32768) } }, |
| }; |
| |
| const ClassInfo JSEventPrototype::s_info = { "EventPrototype", &Base::s_info, 0, CREATE_METHOD_TABLE(JSEventPrototype) }; |
| |
| void JSEventPrototype::finishCreation(VM& vm) |
| { |
| Base::finishCreation(vm); |
| reifyStaticProperties(vm, JSEventPrototypeTableValues, *this); |
| if (!RuntimeEnabledFeatures::sharedFeatures().shadowDOMEnabled()) { |
| Identifier propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("composedPath"), strlen("composedPath")); |
| VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable); |
| JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName); |
| } |
| if (!RuntimeEnabledFeatures::sharedFeatures().shadowDOMEnabled()) { |
| Identifier propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("composed"), strlen("composed")); |
| VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable); |
| JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName); |
| } |
| } |
| |
| const ClassInfo JSEvent::s_info = { "Event", &Base::s_info, &JSEventTable, CREATE_METHOD_TABLE(JSEvent) }; |
| |
| JSEvent::JSEvent(Structure* structure, JSDOMGlobalObject& globalObject, Ref<Event>&& impl) |
| : JSDOMWrapper<Event>(structure, globalObject, WTFMove(impl)) |
| { |
| } |
| |
| JSObject* JSEvent::createPrototype(VM& vm, JSGlobalObject* globalObject) |
| { |
| return JSEventPrototype::create(vm, globalObject, JSEventPrototype::createStructure(vm, globalObject, globalObject->objectPrototype())); |
| } |
| |
| JSObject* JSEvent::prototype(VM& vm, JSGlobalObject* globalObject) |
| { |
| return getDOMPrototype<JSEvent>(vm, globalObject); |
| } |
| |
| void JSEvent::destroy(JSC::JSCell* cell) |
| { |
| JSEvent* thisObject = static_cast<JSEvent*>(cell); |
| thisObject->JSEvent::~JSEvent(); |
| } |
| |
| EncodedJSValue jsEventType(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSEvent*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Event", "type"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsStringWithCache(state, impl.type()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsEventTarget(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSEvent*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Event", "target"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = toJS(state, castedThis->globalObject(), impl.target()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsEventCurrentTarget(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSEvent*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Event", "currentTarget"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = toJS(state, castedThis->globalObject(), impl.currentTarget()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsEventEventPhase(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSEvent*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Event", "eventPhase"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsNumber(impl.eventPhase()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsEventBubbles(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSEvent*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Event", "bubbles"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsBoolean(impl.bubbles()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsEventCancelable(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSEvent*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Event", "cancelable"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsBoolean(impl.cancelable()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsEventComposed(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSEvent*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Event", "composed"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsBoolean(impl.composed()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsEventTimeStamp(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSEvent*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Event", "timeStamp"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsNumber(impl.timeStamp()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsEventDefaultPrevented(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSEvent*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Event", "defaultPrevented"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsBoolean(impl.defaultPrevented()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsEventIsTrusted(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSEvent*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Event", "isTrusted"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsBoolean(impl.isTrusted()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsEventSrcElement(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSEvent*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Event", "srcElement"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = toJS(state, castedThis->globalObject(), impl.srcElement()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsEventReturnValue(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSEvent*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Event", "returnValue"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsBoolean(impl.legacyReturnValue()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsEventCancelBubble(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSEvent*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Event", "cancelBubble"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsBoolean(impl.cancelBubble()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsEventClipboardData(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSEvent*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "Event", "clipboardData"); |
| } |
| return JSValue::encode(castedThis->clipboardData(*state)); |
| } |
| |
| |
| EncodedJSValue jsEventConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| JSEventPrototype* domObject = jsDynamicCast<JSEventPrototype*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!domObject)) |
| return throwVMTypeError(state, throwScope); |
| return JSValue::encode(JSEvent::getConstructor(state->vm(), domObject->globalObject())); |
| } |
| |
| bool setJSEventConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| JSValue value = JSValue::decode(encodedValue); |
| JSEventPrototype* domObject = jsDynamicCast<JSEventPrototype*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!domObject)) { |
| throwVMTypeError(state, throwScope); |
| return false; |
| } |
| // Shadowing a built-in constructor |
| return domObject->putDirect(state->vm(), state->propertyNames().constructor, value); |
| } |
| |
| bool setJSEventReturnValue(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue value = JSValue::decode(encodedValue); |
| UNUSED_PARAM(thisValue); |
| JSEvent* castedThis = jsDynamicCast<JSEvent*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!castedThis)) { |
| return throwSetterTypeError(*state, throwScope, "Event", "returnValue"); |
| } |
| auto& impl = castedThis->wrapped(); |
| auto nativeValue = value.toBoolean(state); |
| RETURN_IF_EXCEPTION(throwScope, false); |
| impl.setLegacyReturnValue(WTFMove(nativeValue)); |
| return true; |
| } |
| |
| |
| bool setJSEventCancelBubble(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue value = JSValue::decode(encodedValue); |
| UNUSED_PARAM(thisValue); |
| JSEvent* castedThis = jsDynamicCast<JSEvent*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!castedThis)) { |
| return throwSetterTypeError(*state, throwScope, "Event", "cancelBubble"); |
| } |
| auto& impl = castedThis->wrapped(); |
| auto nativeValue = value.toBoolean(state); |
| RETURN_IF_EXCEPTION(throwScope, false); |
| impl.setCancelBubble(WTFMove(nativeValue)); |
| return true; |
| } |
| |
| |
| JSValue JSEvent::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| { |
| return getDOMConstructor<JSEventConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsEventPrototypeFunctionComposedPath(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSEvent*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "Event", "composedPath"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSEvent::info()); |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsArray(state, castedThis->globalObject(), impl.composedPath()); |
| return JSValue::encode(result); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsEventPrototypeFunctionStopPropagation(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSEvent*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "Event", "stopPropagation"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSEvent::info()); |
| auto& impl = castedThis->wrapped(); |
| impl.stopPropagation(); |
| return JSValue::encode(jsUndefined()); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsEventPrototypeFunctionPreventDefault(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSEvent*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "Event", "preventDefault"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSEvent::info()); |
| auto& impl = castedThis->wrapped(); |
| impl.preventDefault(); |
| return JSValue::encode(jsUndefined()); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsEventPrototypeFunctionInitEvent(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSEvent*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "Event", "initEvent"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSEvent::info()); |
| auto& impl = castedThis->wrapped(); |
| if (UNLIKELY(state->argumentCount() < 3)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| auto eventTypeArg = state->uncheckedArgument(0).toWTFString(state); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| auto canBubbleArg = state->uncheckedArgument(1).toBoolean(state); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| auto cancelableArg = state->uncheckedArgument(2).toBoolean(state); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| impl.initEvent(WTFMove(eventTypeArg), WTFMove(canBubbleArg), WTFMove(cancelableArg)); |
| return JSValue::encode(jsUndefined()); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsEventPrototypeFunctionStopImmediatePropagation(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSEvent*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "Event", "stopImmediatePropagation"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSEvent::info()); |
| auto& impl = castedThis->wrapped(); |
| impl.stopImmediatePropagation(); |
| return JSValue::encode(jsUndefined()); |
| } |
| |
| bool JSEventOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor) |
| { |
| UNUSED_PARAM(handle); |
| UNUSED_PARAM(visitor); |
| return false; |
| } |
| |
| void JSEventOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
| { |
| auto* jsEvent = jsCast<JSEvent*>(handle.slot()->asCell()); |
| auto& world = *static_cast<DOMWrapperWorld*>(context); |
| uncacheWrapper(world, &jsEvent->wrapped(), jsEvent); |
| } |
| |
| Event* JSEvent::toWrapped(JSC::JSValue value) |
| { |
| if (auto* wrapper = jsDynamicCast<JSEvent*>(value)) |
| return &wrapper->wrapped(); |
| return nullptr; |
| } |
| |
| } |