1/*
2 This file is part of the WebKit open source project.
3 This file has been generated by generate-bindings.pl. DO NOT MODIFY!
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include "config.h"
22#include "JSEvent.h"
23
24#include "JSDOMAttribute.h"
25#include "JSDOMBinding.h"
26#include "JSDOMConstructor.h"
27#include "JSDOMConvertBoolean.h"
28#include "JSDOMConvertDictionary.h"
29#include "JSDOMConvertInterface.h"
30#include "JSDOMConvertNullable.h"
31#include "JSDOMConvertNumbers.h"
32#include "JSDOMConvertSequences.h"
33#include "JSDOMConvertStrings.h"
34#include "JSDOMExceptionHandling.h"
35#include "JSDOMGlobalObject.h"
36#include "JSDOMOperation.h"
37#include "JSDOMWrapperCache.h"
38#include "JSEventInit.h"
39#include "JSEventTarget.h"
40#include "RuntimeEnabledFeatures.h"
41#include "ScriptExecutionContext.h"
42#include <JavaScriptCore/FunctionPrototype.h>
43#include <JavaScriptCore/HeapSnapshotBuilder.h>
44#include <JavaScriptCore/JSArray.h>
45#include <JavaScriptCore/JSCInlines.h>
46#include <wtf/GetPtr.h>
47#include <wtf/PointerPreparations.h>
48#include <wtf/URL.h>
49
50
51namespace WebCore {
52using namespace JSC;
53
54// Functions
55
56JSC::EncodedJSValue JSC_HOST_CALL jsEventPrototypeFunctionComposedPath(JSC::ExecState*);
57JSC::EncodedJSValue JSC_HOST_CALL jsEventPrototypeFunctionStopPropagation(JSC::ExecState*);
58JSC::EncodedJSValue JSC_HOST_CALL jsEventPrototypeFunctionStopImmediatePropagation(JSC::ExecState*);
59JSC::EncodedJSValue JSC_HOST_CALL jsEventPrototypeFunctionPreventDefault(JSC::ExecState*);
60JSC::EncodedJSValue JSC_HOST_CALL jsEventPrototypeFunctionInitEvent(JSC::ExecState*);
61
62// Attributes
63
64JSC::EncodedJSValue jsEventConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
65bool setJSEventConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
66JSC::EncodedJSValue jsEventType(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
67JSC::EncodedJSValue jsEventTarget(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
68JSC::EncodedJSValue jsEventCurrentTarget(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
69JSC::EncodedJSValue jsEventEventPhase(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
70JSC::EncodedJSValue jsEventCancelBubble(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
71bool setJSEventCancelBubble(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
72JSC::EncodedJSValue jsEventBubbles(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
73JSC::EncodedJSValue jsEventCancelable(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
74JSC::EncodedJSValue jsEventDefaultPrevented(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
75JSC::EncodedJSValue jsEventComposed(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
76JSC::EncodedJSValue jsEventIsTrusted(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
77JSC::EncodedJSValue jsEventTimeStamp(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
78JSC::EncodedJSValue jsEventSrcElement(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
79JSC::EncodedJSValue jsEventReturnValue(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
80bool setJSEventReturnValue(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
81
82class JSEventPrototype : public JSC::JSNonFinalObject {
83public:
84 using Base = JSC::JSNonFinalObject;
85 static JSEventPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
86 {
87 JSEventPrototype* ptr = new (NotNull, JSC::allocateCell<JSEventPrototype>(vm.heap)) JSEventPrototype(vm, globalObject, structure);
88 ptr->finishCreation(vm);
89 return ptr;
90 }
91
92 DECLARE_INFO;
93 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
94 {
95 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
96 }
97
98private:
99 JSEventPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
100 : JSC::JSNonFinalObject(vm, structure)
101 {
102 }
103
104 void finishCreation(JSC::VM&);
105};
106
107using JSEventConstructor = JSDOMConstructor<JSEvent>;
108
109/* Hash table */
110
111static const struct CompactHashIndex JSEventTableIndex[2] = {
112 { 0, -1 },
113 { -1, -1 },
114};
115
116
117static const HashTableValue JSEventTableValues[] =
118{
119 { "isTrusted", static_cast<unsigned>(JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventIsTrusted), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
120};
121
122static const HashTable JSEventTable = { 1, 1, true, JSEvent::info(), JSEventTableValues, JSEventTableIndex };
123/* Hash table for constructor */
124
125static const HashTableValue JSEventConstructorTableValues[] =
126{
127 { "NONE", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(0) } },
128 { "CAPTURING_PHASE", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(1) } },
129 { "AT_TARGET", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(2) } },
130 { "BUBBLING_PHASE", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(3) } },
131};
132
133static_assert(Event::NONE == 0, "NONE in Event does not match value from IDL");
134static_assert(Event::CAPTURING_PHASE == 1, "CAPTURING_PHASE in Event does not match value from IDL");
135static_assert(Event::AT_TARGET == 2, "AT_TARGET in Event does not match value from IDL");
136static_assert(Event::BUBBLING_PHASE == 3, "BUBBLING_PHASE in Event does not match value from IDL");
137
138template<> EncodedJSValue JSC_HOST_CALL JSEventConstructor::construct(ExecState* state)
139{
140 VM& vm = state->vm();
141 auto throwScope = DECLARE_THROW_SCOPE(vm);
142 UNUSED_PARAM(throwScope);
143 auto* castedThis = jsCast<JSEventConstructor*>(state->jsCallee());
144 ASSERT(castedThis);
145 if (UNLIKELY(state->argumentCount() < 1))
146 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
147 auto type = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
148 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
149 auto eventInitDict = convert<IDLDictionary<EventInit>>(*state, state->argument(1));
150 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
151 auto object = Event::create(WTFMove(type), WTFMove(eventInitDict));
152 return JSValue::encode(toJSNewlyCreated<IDLInterface<Event>>(*state, *castedThis->globalObject(), WTFMove(object)));
153}
154
155template<> JSValue JSEventConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
156{
157 UNUSED_PARAM(vm);
158 return globalObject.functionPrototype();
159}
160
161template<> void JSEventConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
162{
163 putDirect(vm, vm.propertyNames->prototype, JSEvent::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
164 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("Event"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
165 putDirect(vm, vm.propertyNames->length, jsNumber(1), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
166 reifyStaticProperties(vm, JSEvent::info(), JSEventConstructorTableValues, *this);
167}
168
169template<> const ClassInfo JSEventConstructor::s_info = { "Event", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSEventConstructor) };
170
171/* Hash table for prototype */
172
173static const HashTableValue JSEventPrototypeTableValues[] =
174{
175 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSEventConstructor) } },
176 { "type", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventType), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
177 { "target", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventTarget), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
178 { "currentTarget", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventCurrentTarget), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
179 { "eventPhase", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventEventPhase), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
180 { "cancelBubble", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventCancelBubble), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSEventCancelBubble) } },
181 { "bubbles", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventBubbles), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
182 { "cancelable", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventCancelable), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
183 { "defaultPrevented", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventDefaultPrevented), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
184 { "composed", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventComposed), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
185 { "timeStamp", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventTimeStamp), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
186 { "srcElement", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventSrcElement), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
187 { "returnValue", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventReturnValue), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSEventReturnValue) } },
188 { "composedPath", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsEventPrototypeFunctionComposedPath), (intptr_t) (0) } },
189 { "stopPropagation", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsEventPrototypeFunctionStopPropagation), (intptr_t) (0) } },
190 { "stopImmediatePropagation", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsEventPrototypeFunctionStopImmediatePropagation), (intptr_t) (0) } },
191 { "preventDefault", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsEventPrototypeFunctionPreventDefault), (intptr_t) (0) } },
192 { "initEvent", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsEventPrototypeFunctionInitEvent), (intptr_t) (1) } },
193 { "NONE", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(0) } },
194 { "CAPTURING_PHASE", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(1) } },
195 { "AT_TARGET", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(2) } },
196 { "BUBBLING_PHASE", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(3) } },
197};
198
199const ClassInfo JSEventPrototype::s_info = { "EventPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSEventPrototype) };
200
201void JSEventPrototype::finishCreation(VM& vm)
202{
203 Base::finishCreation(vm);
204 reifyStaticProperties(vm, JSEvent::info(), JSEventPrototypeTableValues, *this);
205 bool hasDisabledRuntimeProperties = false;
206 if (!RuntimeEnabledFeatures::sharedFeatures().shadowDOMEnabled()) {
207 hasDisabledRuntimeProperties = true;
208 auto propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("composedPath"), strlen("composedPath"));
209 VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
210 JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
211 }
212 if (!RuntimeEnabledFeatures::sharedFeatures().shadowDOMEnabled()) {
213 hasDisabledRuntimeProperties = true;
214 auto propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("composed"), strlen("composed"));
215 VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
216 JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
217 }
218 if (hasDisabledRuntimeProperties && structure()->isDictionary())
219 flattenDictionaryObject(vm);
220}
221
222const ClassInfo JSEvent::s_info = { "Event", &Base::s_info, &JSEventTable
223#if ENABLE(JIT)
224, &checkSubClassSnippetForJSEvent
225#else
226, nullptr
227#endif
228, CREATE_METHOD_TABLE(JSEvent) };
229
230JSEvent::JSEvent(Structure* structure, JSDOMGlobalObject& globalObject, Ref<Event>&& impl)
231 : JSDOMWrapper<Event>(structure, globalObject, WTFMove(impl))
232{
233}
234
235void JSEvent::finishCreation(VM& vm)
236{
237 Base::finishCreation(vm);
238 ASSERT(inherits(vm, info()));
239
240}
241
242JSObject* JSEvent::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
243{
244 return JSEventPrototype::create(vm, &globalObject, JSEventPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
245}
246
247JSObject* JSEvent::prototype(VM& vm, JSDOMGlobalObject& globalObject)
248{
249 return getDOMPrototype<JSEvent>(vm, globalObject);
250}
251
252JSValue JSEvent::getConstructor(VM& vm, const JSGlobalObject* globalObject)
253{
254 return getDOMConstructor<JSEventConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
255}
256
257void JSEvent::destroy(JSC::JSCell* cell)
258{
259 JSEvent* thisObject = static_cast<JSEvent*>(cell);
260 thisObject->JSEvent::~JSEvent();
261}
262
263template<> inline JSEvent* IDLAttribute<JSEvent>::cast(ExecState& state, EncodedJSValue thisValue)
264{
265 return jsDynamicCast<JSEvent*>(state.vm(), JSValue::decode(thisValue));
266}
267
268template<> inline JSEvent* IDLOperation<JSEvent>::cast(ExecState& state)
269{
270 return jsDynamicCast<JSEvent*>(state.vm(), state.thisValue());
271}
272
273EncodedJSValue jsEventConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
274{
275 VM& vm = state->vm();
276 auto throwScope = DECLARE_THROW_SCOPE(vm);
277 auto* prototype = jsDynamicCast<JSEventPrototype*>(vm, JSValue::decode(thisValue));
278 if (UNLIKELY(!prototype))
279 return throwVMTypeError(state, throwScope);
280 return JSValue::encode(JSEvent::getConstructor(state->vm(), prototype->globalObject()));
281}
282
283bool setJSEventConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
284{
285 VM& vm = state->vm();
286 auto throwScope = DECLARE_THROW_SCOPE(vm);
287 auto* prototype = jsDynamicCast<JSEventPrototype*>(vm, JSValue::decode(thisValue));
288 if (UNLIKELY(!prototype)) {
289 throwVMTypeError(state, throwScope);
290 return false;
291 }
292 // Shadowing a built-in constructor
293 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
294}
295
296static inline JSValue jsEventTypeGetter(ExecState& state, JSEvent& thisObject, ThrowScope& throwScope)
297{
298 UNUSED_PARAM(throwScope);
299 UNUSED_PARAM(state);
300 auto& impl = thisObject.wrapped();
301 JSValue result = toJS<IDLDOMString>(state, throwScope, impl.type());
302 return result;
303}
304
305EncodedJSValue jsEventType(ExecState* state, EncodedJSValue thisValue, PropertyName)
306{
307 return IDLAttribute<JSEvent>::get<jsEventTypeGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "type");
308}
309
310static inline JSValue jsEventTargetGetter(ExecState& state, JSEvent& thisObject, ThrowScope& throwScope)
311{
312 UNUSED_PARAM(throwScope);
313 UNUSED_PARAM(state);
314 auto& impl = thisObject.wrapped();
315 JSValue result = toJS<IDLNullable<IDLInterface<EventTarget>>>(state, *thisObject.globalObject(), throwScope, impl.target());
316 return result;
317}
318
319EncodedJSValue jsEventTarget(ExecState* state, EncodedJSValue thisValue, PropertyName)
320{
321 return IDLAttribute<JSEvent>::get<jsEventTargetGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "target");
322}
323
324static inline JSValue jsEventCurrentTargetGetter(ExecState& state, JSEvent& thisObject, ThrowScope& throwScope)
325{
326 UNUSED_PARAM(throwScope);
327 UNUSED_PARAM(state);
328 auto& impl = thisObject.wrapped();
329 JSValue result = toJS<IDLNullable<IDLInterface<EventTarget>>>(state, *thisObject.globalObject(), throwScope, impl.currentTarget());
330 return result;
331}
332
333EncodedJSValue jsEventCurrentTarget(ExecState* state, EncodedJSValue thisValue, PropertyName)
334{
335 return IDLAttribute<JSEvent>::get<jsEventCurrentTargetGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "currentTarget");
336}
337
338static inline JSValue jsEventEventPhaseGetter(ExecState& state, JSEvent& thisObject, ThrowScope& throwScope)
339{
340 UNUSED_PARAM(throwScope);
341 UNUSED_PARAM(state);
342 auto& impl = thisObject.wrapped();
343 JSValue result = toJS<IDLUnsignedShort>(state, throwScope, impl.eventPhase());
344 return result;
345}
346
347EncodedJSValue jsEventEventPhase(ExecState* state, EncodedJSValue thisValue, PropertyName)
348{
349 return IDLAttribute<JSEvent>::get<jsEventEventPhaseGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "eventPhase");
350}
351
352static inline JSValue jsEventCancelBubbleGetter(ExecState& state, JSEvent& thisObject, ThrowScope& throwScope)
353{
354 UNUSED_PARAM(throwScope);
355 UNUSED_PARAM(state);
356 auto& impl = thisObject.wrapped();
357 JSValue result = toJS<IDLBoolean>(state, throwScope, impl.cancelBubble());
358 return result;
359}
360
361EncodedJSValue jsEventCancelBubble(ExecState* state, EncodedJSValue thisValue, PropertyName)
362{
363 return IDLAttribute<JSEvent>::get<jsEventCancelBubbleGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "cancelBubble");
364}
365
366static inline bool setJSEventCancelBubbleSetter(ExecState& state, JSEvent& thisObject, JSValue value, ThrowScope& throwScope)
367{
368 UNUSED_PARAM(throwScope);
369 auto& impl = thisObject.wrapped();
370 auto nativeValue = convert<IDLBoolean>(state, value);
371 RETURN_IF_EXCEPTION(throwScope, false);
372 AttributeSetter::call(state, throwScope, [&] {
373 return impl.setCancelBubble(WTFMove(nativeValue));
374 });
375 return true;
376}
377
378bool setJSEventCancelBubble(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
379{
380 return IDLAttribute<JSEvent>::set<setJSEventCancelBubbleSetter>(*state, thisValue, encodedValue, "cancelBubble");
381}
382
383static inline JSValue jsEventBubblesGetter(ExecState& state, JSEvent& thisObject, ThrowScope& throwScope)
384{
385 UNUSED_PARAM(throwScope);
386 UNUSED_PARAM(state);
387 auto& impl = thisObject.wrapped();
388 JSValue result = toJS<IDLBoolean>(state, throwScope, impl.bubbles());
389 return result;
390}
391
392EncodedJSValue jsEventBubbles(ExecState* state, EncodedJSValue thisValue, PropertyName)
393{
394 return IDLAttribute<JSEvent>::get<jsEventBubblesGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "bubbles");
395}
396
397static inline JSValue jsEventCancelableGetter(ExecState& state, JSEvent& thisObject, ThrowScope& throwScope)
398{
399 UNUSED_PARAM(throwScope);
400 UNUSED_PARAM(state);
401 auto& impl = thisObject.wrapped();
402 JSValue result = toJS<IDLBoolean>(state, throwScope, impl.cancelable());
403 return result;
404}
405
406EncodedJSValue jsEventCancelable(ExecState* state, EncodedJSValue thisValue, PropertyName)
407{
408 return IDLAttribute<JSEvent>::get<jsEventCancelableGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "cancelable");
409}
410
411static inline JSValue jsEventDefaultPreventedGetter(ExecState& state, JSEvent& thisObject, ThrowScope& throwScope)
412{
413 UNUSED_PARAM(throwScope);
414 UNUSED_PARAM(state);
415 auto& impl = thisObject.wrapped();
416 JSValue result = toJS<IDLBoolean>(state, throwScope, impl.defaultPrevented());
417 return result;
418}
419
420EncodedJSValue jsEventDefaultPrevented(ExecState* state, EncodedJSValue thisValue, PropertyName)
421{
422 return IDLAttribute<JSEvent>::get<jsEventDefaultPreventedGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "defaultPrevented");
423}
424
425static inline JSValue jsEventComposedGetter(ExecState& state, JSEvent& thisObject, ThrowScope& throwScope)
426{
427 UNUSED_PARAM(throwScope);
428 UNUSED_PARAM(state);
429 auto& impl = thisObject.wrapped();
430 JSValue result = toJS<IDLBoolean>(state, throwScope, impl.composed());
431 return result;
432}
433
434EncodedJSValue jsEventComposed(ExecState* state, EncodedJSValue thisValue, PropertyName)
435{
436 return IDLAttribute<JSEvent>::get<jsEventComposedGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "composed");
437}
438
439static inline JSValue jsEventIsTrustedGetter(ExecState& state, JSEvent& thisObject, ThrowScope& throwScope)
440{
441 UNUSED_PARAM(throwScope);
442 UNUSED_PARAM(state);
443 auto& impl = thisObject.wrapped();
444 JSValue result = toJS<IDLBoolean>(state, throwScope, impl.isTrusted());
445 return result;
446}
447
448EncodedJSValue jsEventIsTrusted(ExecState* state, EncodedJSValue thisValue, PropertyName)
449{
450 return IDLAttribute<JSEvent>::get<jsEventIsTrustedGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "isTrusted");
451}
452
453static inline JSValue jsEventTimeStampGetter(ExecState& state, JSEvent& thisObject, ThrowScope& throwScope)
454{
455 UNUSED_PARAM(throwScope);
456 UNUSED_PARAM(state);
457 auto* context = jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject())->scriptExecutionContext();
458 if (UNLIKELY(!context))
459 return jsUndefined();
460 auto& impl = thisObject.wrapped();
461 JSValue result = toJS<IDLDouble>(state, throwScope, impl.timeStampForBindings(*context));
462 return result;
463}
464
465EncodedJSValue jsEventTimeStamp(ExecState* state, EncodedJSValue thisValue, PropertyName)
466{
467 return IDLAttribute<JSEvent>::get<jsEventTimeStampGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "timeStamp");
468}
469
470static inline JSValue jsEventSrcElementGetter(ExecState& state, JSEvent& thisObject, ThrowScope& throwScope)
471{
472 UNUSED_PARAM(throwScope);
473 UNUSED_PARAM(state);
474 auto& impl = thisObject.wrapped();
475 JSValue result = toJS<IDLInterface<EventTarget>>(state, *thisObject.globalObject(), throwScope, impl.target());
476 return result;
477}
478
479EncodedJSValue jsEventSrcElement(ExecState* state, EncodedJSValue thisValue, PropertyName)
480{
481 return IDLAttribute<JSEvent>::get<jsEventSrcElementGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "srcElement");
482}
483
484static inline JSValue jsEventReturnValueGetter(ExecState& state, JSEvent& thisObject, ThrowScope& throwScope)
485{
486 UNUSED_PARAM(throwScope);
487 UNUSED_PARAM(state);
488 auto& impl = thisObject.wrapped();
489 JSValue result = toJS<IDLBoolean>(state, throwScope, impl.legacyReturnValue());
490 return result;
491}
492
493EncodedJSValue jsEventReturnValue(ExecState* state, EncodedJSValue thisValue, PropertyName)
494{
495 return IDLAttribute<JSEvent>::get<jsEventReturnValueGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "returnValue");
496}
497
498static inline bool setJSEventReturnValueSetter(ExecState& state, JSEvent& thisObject, JSValue value, ThrowScope& throwScope)
499{
500 UNUSED_PARAM(throwScope);
501 auto& impl = thisObject.wrapped();
502 auto nativeValue = convert<IDLBoolean>(state, value);
503 RETURN_IF_EXCEPTION(throwScope, false);
504 AttributeSetter::call(state, throwScope, [&] {
505 return impl.setLegacyReturnValue(WTFMove(nativeValue));
506 });
507 return true;
508}
509
510bool setJSEventReturnValue(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
511{
512 return IDLAttribute<JSEvent>::set<setJSEventReturnValueSetter>(*state, thisValue, encodedValue, "returnValue");
513}
514
515static inline JSC::EncodedJSValue jsEventPrototypeFunctionComposedPathBody(JSC::ExecState* state, typename IDLOperation<JSEvent>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
516{
517 UNUSED_PARAM(state);
518 UNUSED_PARAM(throwScope);
519 auto& impl = castedThis->wrapped();
520 return JSValue::encode(toJS<IDLSequence<IDLInterface<EventTarget>>>(*state, *castedThis->globalObject(), impl.composedPath()));
521}
522
523EncodedJSValue JSC_HOST_CALL jsEventPrototypeFunctionComposedPath(ExecState* state)
524{
525 return IDLOperation<JSEvent>::call<jsEventPrototypeFunctionComposedPathBody>(*state, "composedPath");
526}
527
528static inline JSC::EncodedJSValue jsEventPrototypeFunctionStopPropagationBody(JSC::ExecState* state, typename IDLOperation<JSEvent>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
529{
530 UNUSED_PARAM(state);
531 UNUSED_PARAM(throwScope);
532 auto& impl = castedThis->wrapped();
533 impl.stopPropagation();
534 return JSValue::encode(jsUndefined());
535}
536
537EncodedJSValue JSC_HOST_CALL jsEventPrototypeFunctionStopPropagation(ExecState* state)
538{
539 return IDLOperation<JSEvent>::call<jsEventPrototypeFunctionStopPropagationBody>(*state, "stopPropagation");
540}
541
542static inline JSC::EncodedJSValue jsEventPrototypeFunctionStopImmediatePropagationBody(JSC::ExecState* state, typename IDLOperation<JSEvent>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
543{
544 UNUSED_PARAM(state);
545 UNUSED_PARAM(throwScope);
546 auto& impl = castedThis->wrapped();
547 impl.stopImmediatePropagation();
548 return JSValue::encode(jsUndefined());
549}
550
551EncodedJSValue JSC_HOST_CALL jsEventPrototypeFunctionStopImmediatePropagation(ExecState* state)
552{
553 return IDLOperation<JSEvent>::call<jsEventPrototypeFunctionStopImmediatePropagationBody>(*state, "stopImmediatePropagation");
554}
555
556static inline JSC::EncodedJSValue jsEventPrototypeFunctionPreventDefaultBody(JSC::ExecState* state, typename IDLOperation<JSEvent>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
557{
558 UNUSED_PARAM(state);
559 UNUSED_PARAM(throwScope);
560 auto& impl = castedThis->wrapped();
561 impl.preventDefault();
562 return JSValue::encode(jsUndefined());
563}
564
565EncodedJSValue JSC_HOST_CALL jsEventPrototypeFunctionPreventDefault(ExecState* state)
566{
567 return IDLOperation<JSEvent>::call<jsEventPrototypeFunctionPreventDefaultBody>(*state, "preventDefault");
568}
569
570static inline JSC::EncodedJSValue jsEventPrototypeFunctionInitEventBody(JSC::ExecState* state, typename IDLOperation<JSEvent>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
571{
572 UNUSED_PARAM(state);
573 UNUSED_PARAM(throwScope);
574 auto& impl = castedThis->wrapped();
575 if (UNLIKELY(state->argumentCount() < 1))
576 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
577 auto type = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
578 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
579 auto bubbles = convert<IDLBoolean>(*state, state->argument(1));
580 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
581 auto cancelable = convert<IDLBoolean>(*state, state->argument(2));
582 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
583 impl.initEvent(WTFMove(type), WTFMove(bubbles), WTFMove(cancelable));
584 return JSValue::encode(jsUndefined());
585}
586
587EncodedJSValue JSC_HOST_CALL jsEventPrototypeFunctionInitEvent(ExecState* state)
588{
589 return IDLOperation<JSEvent>::call<jsEventPrototypeFunctionInitEventBody>(*state, "initEvent");
590}
591
592void JSEvent::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
593{
594 auto* thisObject = jsCast<JSEvent*>(cell);
595 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
596 if (thisObject->scriptExecutionContext())
597 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
598 Base::heapSnapshot(cell, builder);
599}
600
601bool JSEventOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
602{
603 UNUSED_PARAM(handle);
604 UNUSED_PARAM(visitor);
605 UNUSED_PARAM(reason);
606 return false;
607}
608
609void JSEventOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
610{
611 auto* jsEvent = static_cast<JSEvent*>(handle.slot()->asCell());
612 auto& world = *static_cast<DOMWrapperWorld*>(context);
613 uncacheWrapper(world, &jsEvent->wrapped(), jsEvent);
614}
615
616Event* JSEvent::toWrapped(JSC::VM& vm, JSC::JSValue value)
617{
618 if (auto* wrapper = jsDynamicCast<JSEvent*>(vm, value))
619 return &wrapper->wrapped();
620 return nullptr;
621}
622
623}
624