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 "JSCustomEvent.h" |
23 | |
24 | #include "JSDOMAttribute.h" |
25 | #include "JSDOMBinding.h" |
26 | #include "JSDOMConstructor.h" |
27 | #include "JSDOMConvertAny.h" |
28 | #include "JSDOMConvertBoolean.h" |
29 | #include "JSDOMConvertInterface.h" |
30 | #include "JSDOMConvertStrings.h" |
31 | #include "JSDOMExceptionHandling.h" |
32 | #include "JSDOMOperation.h" |
33 | #include "JSDOMWrapperCache.h" |
34 | #include "ScriptExecutionContext.h" |
35 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
36 | #include <JavaScriptCore/JSCInlines.h> |
37 | #include <wtf/GetPtr.h> |
38 | #include <wtf/PointerPreparations.h> |
39 | #include <wtf/URL.h> |
40 | |
41 | |
42 | namespace WebCore { |
43 | using namespace JSC; |
44 | |
45 | template<> CustomEvent::Init convertDictionary<CustomEvent::Init>(ExecState& state, JSValue value) |
46 | { |
47 | VM& vm = state.vm(); |
48 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
49 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
50 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
51 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
52 | throwTypeError(&state, throwScope); |
53 | return { }; |
54 | } |
55 | CustomEvent::Init result; |
56 | JSValue bubblesValue; |
57 | if (isNullOrUndefined) |
58 | bubblesValue = jsUndefined(); |
59 | else { |
60 | bubblesValue = object->get(&state, Identifier::fromString(&state, "bubbles" )); |
61 | RETURN_IF_EXCEPTION(throwScope, { }); |
62 | } |
63 | if (!bubblesValue.isUndefined()) { |
64 | result.bubbles = convert<IDLBoolean>(state, bubblesValue); |
65 | RETURN_IF_EXCEPTION(throwScope, { }); |
66 | } else |
67 | result.bubbles = false; |
68 | JSValue cancelableValue; |
69 | if (isNullOrUndefined) |
70 | cancelableValue = jsUndefined(); |
71 | else { |
72 | cancelableValue = object->get(&state, Identifier::fromString(&state, "cancelable" )); |
73 | RETURN_IF_EXCEPTION(throwScope, { }); |
74 | } |
75 | if (!cancelableValue.isUndefined()) { |
76 | result.cancelable = convert<IDLBoolean>(state, cancelableValue); |
77 | RETURN_IF_EXCEPTION(throwScope, { }); |
78 | } else |
79 | result.cancelable = false; |
80 | JSValue composedValue; |
81 | if (isNullOrUndefined) |
82 | composedValue = jsUndefined(); |
83 | else { |
84 | composedValue = object->get(&state, Identifier::fromString(&state, "composed" )); |
85 | RETURN_IF_EXCEPTION(throwScope, { }); |
86 | } |
87 | if (!composedValue.isUndefined()) { |
88 | result.composed = convert<IDLBoolean>(state, composedValue); |
89 | RETURN_IF_EXCEPTION(throwScope, { }); |
90 | } else |
91 | result.composed = false; |
92 | JSValue detailValue; |
93 | if (isNullOrUndefined) |
94 | detailValue = jsUndefined(); |
95 | else { |
96 | detailValue = object->get(&state, Identifier::fromString(&state, "detail" )); |
97 | RETURN_IF_EXCEPTION(throwScope, { }); |
98 | } |
99 | if (!detailValue.isUndefined()) { |
100 | result.detail = convert<IDLAny>(state, detailValue); |
101 | RETURN_IF_EXCEPTION(throwScope, { }); |
102 | } else |
103 | result.detail = jsNull(); |
104 | return result; |
105 | } |
106 | |
107 | // Functions |
108 | |
109 | JSC::EncodedJSValue JSC_HOST_CALL jsCustomEventPrototypeFunctionInitCustomEvent(JSC::ExecState*); |
110 | |
111 | // Attributes |
112 | |
113 | JSC::EncodedJSValue jsCustomEventConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
114 | bool setJSCustomEventConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
115 | JSC::EncodedJSValue jsCustomEventDetail(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
116 | |
117 | class JSCustomEventPrototype : public JSC::JSNonFinalObject { |
118 | public: |
119 | using Base = JSC::JSNonFinalObject; |
120 | static JSCustomEventPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
121 | { |
122 | JSCustomEventPrototype* ptr = new (NotNull, JSC::allocateCell<JSCustomEventPrototype>(vm.heap)) JSCustomEventPrototype(vm, globalObject, structure); |
123 | ptr->finishCreation(vm); |
124 | return ptr; |
125 | } |
126 | |
127 | DECLARE_INFO; |
128 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
129 | { |
130 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
131 | } |
132 | |
133 | private: |
134 | JSCustomEventPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
135 | : JSC::JSNonFinalObject(vm, structure) |
136 | { |
137 | } |
138 | |
139 | void finishCreation(JSC::VM&); |
140 | }; |
141 | |
142 | using JSCustomEventConstructor = JSDOMConstructor<JSCustomEvent>; |
143 | |
144 | template<> EncodedJSValue JSC_HOST_CALL JSCustomEventConstructor::construct(ExecState* state) |
145 | { |
146 | VM& vm = state->vm(); |
147 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
148 | UNUSED_PARAM(throwScope); |
149 | auto* castedThis = jsCast<JSCustomEventConstructor*>(state->jsCallee()); |
150 | ASSERT(castedThis); |
151 | if (UNLIKELY(state->argumentCount() < 1)) |
152 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
153 | auto type = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
154 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
155 | auto eventInitDict = convert<IDLDictionary<CustomEvent::Init>>(*state, state->argument(1)); |
156 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
157 | auto object = CustomEvent::create(WTFMove(type), WTFMove(eventInitDict)); |
158 | return JSValue::encode(toJSNewlyCreated<IDLInterface<CustomEvent>>(*state, *castedThis->globalObject(), WTFMove(object))); |
159 | } |
160 | |
161 | template<> JSValue JSCustomEventConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
162 | { |
163 | return JSEvent::getConstructor(vm, &globalObject); |
164 | } |
165 | |
166 | template<> void JSCustomEventConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
167 | { |
168 | putDirect(vm, vm.propertyNames->prototype, JSCustomEvent::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
169 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("CustomEvent"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
170 | putDirect(vm, vm.propertyNames->length, jsNumber(1), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
171 | } |
172 | |
173 | template<> const ClassInfo JSCustomEventConstructor::s_info = { "CustomEvent" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCustomEventConstructor) }; |
174 | |
175 | /* Hash table for prototype */ |
176 | |
177 | static const HashTableValue JSCustomEventPrototypeTableValues[] = |
178 | { |
179 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCustomEventConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSCustomEventConstructor) } }, |
180 | { "detail" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCustomEventDetail), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
181 | { "initCustomEvent" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsCustomEventPrototypeFunctionInitCustomEvent), (intptr_t) (1) } }, |
182 | }; |
183 | |
184 | const ClassInfo JSCustomEventPrototype::s_info = { "CustomEventPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCustomEventPrototype) }; |
185 | |
186 | void JSCustomEventPrototype::finishCreation(VM& vm) |
187 | { |
188 | Base::finishCreation(vm); |
189 | reifyStaticProperties(vm, JSCustomEvent::info(), JSCustomEventPrototypeTableValues, *this); |
190 | } |
191 | |
192 | const ClassInfo JSCustomEvent::s_info = { "CustomEvent" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCustomEvent) }; |
193 | |
194 | JSCustomEvent::JSCustomEvent(Structure* structure, JSDOMGlobalObject& globalObject, Ref<CustomEvent>&& impl) |
195 | : JSEvent(structure, globalObject, WTFMove(impl)) |
196 | { |
197 | } |
198 | |
199 | void JSCustomEvent::finishCreation(VM& vm) |
200 | { |
201 | Base::finishCreation(vm); |
202 | ASSERT(inherits(vm, info())); |
203 | |
204 | } |
205 | |
206 | JSObject* JSCustomEvent::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
207 | { |
208 | return JSCustomEventPrototype::create(vm, &globalObject, JSCustomEventPrototype::createStructure(vm, &globalObject, JSEvent::prototype(vm, globalObject))); |
209 | } |
210 | |
211 | JSObject* JSCustomEvent::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
212 | { |
213 | return getDOMPrototype<JSCustomEvent>(vm, globalObject); |
214 | } |
215 | |
216 | JSValue JSCustomEvent::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
217 | { |
218 | return getDOMConstructor<JSCustomEventConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
219 | } |
220 | |
221 | template<> inline JSCustomEvent* IDLAttribute<JSCustomEvent>::cast(ExecState& state, EncodedJSValue thisValue) |
222 | { |
223 | return jsDynamicCast<JSCustomEvent*>(state.vm(), JSValue::decode(thisValue)); |
224 | } |
225 | |
226 | template<> inline JSCustomEvent* IDLOperation<JSCustomEvent>::cast(ExecState& state) |
227 | { |
228 | return jsDynamicCast<JSCustomEvent*>(state.vm(), state.thisValue()); |
229 | } |
230 | |
231 | EncodedJSValue jsCustomEventConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
232 | { |
233 | VM& vm = state->vm(); |
234 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
235 | auto* prototype = jsDynamicCast<JSCustomEventPrototype*>(vm, JSValue::decode(thisValue)); |
236 | if (UNLIKELY(!prototype)) |
237 | return throwVMTypeError(state, throwScope); |
238 | return JSValue::encode(JSCustomEvent::getConstructor(state->vm(), prototype->globalObject())); |
239 | } |
240 | |
241 | bool setJSCustomEventConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
242 | { |
243 | VM& vm = state->vm(); |
244 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
245 | auto* prototype = jsDynamicCast<JSCustomEventPrototype*>(vm, JSValue::decode(thisValue)); |
246 | if (UNLIKELY(!prototype)) { |
247 | throwVMTypeError(state, throwScope); |
248 | return false; |
249 | } |
250 | // Shadowing a built-in constructor |
251 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
252 | } |
253 | |
254 | static inline JSValue jsCustomEventDetailGetter(ExecState& state, JSCustomEvent& thisObject, ThrowScope& throwScope) |
255 | { |
256 | UNUSED_PARAM(throwScope); |
257 | UNUSED_PARAM(state); |
258 | return thisObject.detail(state); |
259 | } |
260 | |
261 | EncodedJSValue jsCustomEventDetail(ExecState* state, EncodedJSValue thisValue, PropertyName) |
262 | { |
263 | return IDLAttribute<JSCustomEvent>::get<jsCustomEventDetailGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "detail" ); |
264 | } |
265 | |
266 | static inline JSC::EncodedJSValue jsCustomEventPrototypeFunctionInitCustomEventBody(JSC::ExecState* state, typename IDLOperation<JSCustomEvent>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
267 | { |
268 | UNUSED_PARAM(state); |
269 | UNUSED_PARAM(throwScope); |
270 | auto& impl = castedThis->wrapped(); |
271 | if (UNLIKELY(state->argumentCount() < 1)) |
272 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
273 | auto type = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
274 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
275 | auto bubbles = convert<IDLBoolean>(*state, state->argument(1)); |
276 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
277 | auto cancelable = convert<IDLBoolean>(*state, state->argument(2)); |
278 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
279 | auto detail = state->argument(3).isUndefined() ? jsNull() : convert<IDLAny>(*state, state->uncheckedArgument(3)); |
280 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
281 | impl.initCustomEvent(WTFMove(type), WTFMove(bubbles), WTFMove(cancelable), WTFMove(detail)); |
282 | return JSValue::encode(jsUndefined()); |
283 | } |
284 | |
285 | EncodedJSValue JSC_HOST_CALL jsCustomEventPrototypeFunctionInitCustomEvent(ExecState* state) |
286 | { |
287 | return IDLOperation<JSCustomEvent>::call<jsCustomEventPrototypeFunctionInitCustomEventBody>(*state, "initCustomEvent" ); |
288 | } |
289 | |
290 | void JSCustomEvent::visitChildren(JSCell* cell, SlotVisitor& visitor) |
291 | { |
292 | auto* thisObject = jsCast<JSCustomEvent*>(cell); |
293 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
294 | Base::visitChildren(thisObject, visitor); |
295 | thisObject->visitAdditionalChildren(visitor); |
296 | } |
297 | |
298 | void JSCustomEvent::visitOutputConstraints(JSCell* cell, SlotVisitor& visitor) |
299 | { |
300 | auto* thisObject = jsCast<JSCustomEvent*>(cell); |
301 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
302 | Base::visitOutputConstraints(thisObject, visitor); |
303 | thisObject->visitAdditionalChildren(visitor); |
304 | } |
305 | |
306 | void JSCustomEvent::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
307 | { |
308 | auto* thisObject = jsCast<JSCustomEvent*>(cell); |
309 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
310 | if (thisObject->scriptExecutionContext()) |
311 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
312 | Base::heapSnapshot(cell, builder); |
313 | } |
314 | |
315 | #if ENABLE(BINDING_INTEGRITY) |
316 | #if PLATFORM(WIN) |
317 | #pragma warning(disable: 4483) |
318 | extern "C" { extern void (*const __identifier("??_7CustomEvent@WebCore@@6B@" )[])(); } |
319 | #else |
320 | extern "C" { extern void* _ZTVN7WebCore11CustomEventE[]; } |
321 | #endif |
322 | #endif |
323 | |
324 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<CustomEvent>&& impl) |
325 | { |
326 | |
327 | #if ENABLE(BINDING_INTEGRITY) |
328 | void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr())); |
329 | #if PLATFORM(WIN) |
330 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7CustomEvent@WebCore@@6B@" )); |
331 | #else |
332 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore11CustomEventE[2]); |
333 | #endif |
334 | |
335 | // If this fails CustomEvent does not have a vtable, so you need to add the |
336 | // ImplementationLacksVTable attribute to the interface definition |
337 | static_assert(std::is_polymorphic<CustomEvent>::value, "CustomEvent is not polymorphic" ); |
338 | |
339 | // If you hit this assertion you either have a use after free bug, or |
340 | // CustomEvent has subclasses. If CustomEvent has subclasses that get passed |
341 | // to toJS() we currently require CustomEvent you to opt out of binding hardening |
342 | // by adding the SkipVTableValidation attribute to the interface IDL definition |
343 | RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer); |
344 | #endif |
345 | return createWrapper<CustomEvent>(globalObject, WTFMove(impl)); |
346 | } |
347 | |
348 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, CustomEvent& impl) |
349 | { |
350 | return wrap(state, globalObject, impl); |
351 | } |
352 | |
353 | |
354 | } |
355 | |