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 "JSErrorEvent.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 "JSDOMConvertNumbers.h"
31#include "JSDOMConvertStrings.h"
32#include "JSDOMExceptionHandling.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
42namespace WebCore {
43using namespace JSC;
44
45template<> ErrorEvent::Init convertDictionary<ErrorEvent::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 ErrorEvent::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 colnoValue;
93 if (isNullOrUndefined)
94 colnoValue = jsUndefined();
95 else {
96 colnoValue = object->get(&state, Identifier::fromString(&state, "colno"));
97 RETURN_IF_EXCEPTION(throwScope, { });
98 }
99 if (!colnoValue.isUndefined()) {
100 result.colno = convert<IDLUnsignedLong>(state, colnoValue);
101 RETURN_IF_EXCEPTION(throwScope, { });
102 } else
103 result.colno = 0;
104 JSValue errorValue;
105 if (isNullOrUndefined)
106 errorValue = jsUndefined();
107 else {
108 errorValue = object->get(&state, Identifier::fromString(&state, "error"));
109 RETURN_IF_EXCEPTION(throwScope, { });
110 }
111 if (!errorValue.isUndefined()) {
112 result.error = convert<IDLAny>(state, errorValue);
113 RETURN_IF_EXCEPTION(throwScope, { });
114 } else
115 result.error = jsNull();
116 JSValue filenameValue;
117 if (isNullOrUndefined)
118 filenameValue = jsUndefined();
119 else {
120 filenameValue = object->get(&state, Identifier::fromString(&state, "filename"));
121 RETURN_IF_EXCEPTION(throwScope, { });
122 }
123 if (!filenameValue.isUndefined()) {
124 result.filename = convert<IDLUSVString>(state, filenameValue);
125 RETURN_IF_EXCEPTION(throwScope, { });
126 } else
127 result.filename = emptyString();
128 JSValue linenoValue;
129 if (isNullOrUndefined)
130 linenoValue = jsUndefined();
131 else {
132 linenoValue = object->get(&state, Identifier::fromString(&state, "lineno"));
133 RETURN_IF_EXCEPTION(throwScope, { });
134 }
135 if (!linenoValue.isUndefined()) {
136 result.lineno = convert<IDLUnsignedLong>(state, linenoValue);
137 RETURN_IF_EXCEPTION(throwScope, { });
138 } else
139 result.lineno = 0;
140 JSValue messageValue;
141 if (isNullOrUndefined)
142 messageValue = jsUndefined();
143 else {
144 messageValue = object->get(&state, Identifier::fromString(&state, "message"));
145 RETURN_IF_EXCEPTION(throwScope, { });
146 }
147 if (!messageValue.isUndefined()) {
148 result.message = convert<IDLDOMString>(state, messageValue);
149 RETURN_IF_EXCEPTION(throwScope, { });
150 } else
151 result.message = emptyString();
152 return result;
153}
154
155// Attributes
156
157JSC::EncodedJSValue jsErrorEventConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
158bool setJSErrorEventConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
159JSC::EncodedJSValue jsErrorEventMessage(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
160JSC::EncodedJSValue jsErrorEventFilename(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
161JSC::EncodedJSValue jsErrorEventLineno(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
162JSC::EncodedJSValue jsErrorEventColno(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
163JSC::EncodedJSValue jsErrorEventError(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
164
165class JSErrorEventPrototype : public JSC::JSNonFinalObject {
166public:
167 using Base = JSC::JSNonFinalObject;
168 static JSErrorEventPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
169 {
170 JSErrorEventPrototype* ptr = new (NotNull, JSC::allocateCell<JSErrorEventPrototype>(vm.heap)) JSErrorEventPrototype(vm, globalObject, structure);
171 ptr->finishCreation(vm);
172 return ptr;
173 }
174
175 DECLARE_INFO;
176 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
177 {
178 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
179 }
180
181private:
182 JSErrorEventPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
183 : JSC::JSNonFinalObject(vm, structure)
184 {
185 }
186
187 void finishCreation(JSC::VM&);
188};
189
190using JSErrorEventConstructor = JSDOMConstructor<JSErrorEvent>;
191
192template<> EncodedJSValue JSC_HOST_CALL JSErrorEventConstructor::construct(ExecState* state)
193{
194 VM& vm = state->vm();
195 auto throwScope = DECLARE_THROW_SCOPE(vm);
196 UNUSED_PARAM(throwScope);
197 auto* castedThis = jsCast<JSErrorEventConstructor*>(state->jsCallee());
198 ASSERT(castedThis);
199 if (UNLIKELY(state->argumentCount() < 1))
200 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
201 auto type = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
202 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
203 auto eventInitDict = convert<IDLDictionary<ErrorEvent::Init>>(*state, state->argument(1));
204 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
205 auto object = ErrorEvent::create(WTFMove(type), WTFMove(eventInitDict));
206 return JSValue::encode(toJSNewlyCreated<IDLInterface<ErrorEvent>>(*state, *castedThis->globalObject(), WTFMove(object)));
207}
208
209template<> JSValue JSErrorEventConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
210{
211 return JSEvent::getConstructor(vm, &globalObject);
212}
213
214template<> void JSErrorEventConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
215{
216 putDirect(vm, vm.propertyNames->prototype, JSErrorEvent::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
217 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("ErrorEvent"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
218 putDirect(vm, vm.propertyNames->length, jsNumber(1), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
219}
220
221template<> const ClassInfo JSErrorEventConstructor::s_info = { "ErrorEvent", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSErrorEventConstructor) };
222
223/* Hash table for prototype */
224
225static const HashTableValue JSErrorEventPrototypeTableValues[] =
226{
227 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsErrorEventConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSErrorEventConstructor) } },
228 { "message", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsErrorEventMessage), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
229 { "filename", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsErrorEventFilename), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
230 { "lineno", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsErrorEventLineno), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
231 { "colno", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsErrorEventColno), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
232 { "error", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsErrorEventError), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
233};
234
235const ClassInfo JSErrorEventPrototype::s_info = { "ErrorEventPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSErrorEventPrototype) };
236
237void JSErrorEventPrototype::finishCreation(VM& vm)
238{
239 Base::finishCreation(vm);
240 reifyStaticProperties(vm, JSErrorEvent::info(), JSErrorEventPrototypeTableValues, *this);
241}
242
243const ClassInfo JSErrorEvent::s_info = { "ErrorEvent", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSErrorEvent) };
244
245JSErrorEvent::JSErrorEvent(Structure* structure, JSDOMGlobalObject& globalObject, Ref<ErrorEvent>&& impl)
246 : JSEvent(structure, globalObject, WTFMove(impl))
247{
248}
249
250void JSErrorEvent::finishCreation(VM& vm)
251{
252 Base::finishCreation(vm);
253 ASSERT(inherits(vm, info()));
254
255}
256
257JSObject* JSErrorEvent::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
258{
259 return JSErrorEventPrototype::create(vm, &globalObject, JSErrorEventPrototype::createStructure(vm, &globalObject, JSEvent::prototype(vm, globalObject)));
260}
261
262JSObject* JSErrorEvent::prototype(VM& vm, JSDOMGlobalObject& globalObject)
263{
264 return getDOMPrototype<JSErrorEvent>(vm, globalObject);
265}
266
267JSValue JSErrorEvent::getConstructor(VM& vm, const JSGlobalObject* globalObject)
268{
269 return getDOMConstructor<JSErrorEventConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
270}
271
272template<> inline JSErrorEvent* IDLAttribute<JSErrorEvent>::cast(ExecState& state, EncodedJSValue thisValue)
273{
274 return jsDynamicCast<JSErrorEvent*>(state.vm(), JSValue::decode(thisValue));
275}
276
277EncodedJSValue jsErrorEventConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
278{
279 VM& vm = state->vm();
280 auto throwScope = DECLARE_THROW_SCOPE(vm);
281 auto* prototype = jsDynamicCast<JSErrorEventPrototype*>(vm, JSValue::decode(thisValue));
282 if (UNLIKELY(!prototype))
283 return throwVMTypeError(state, throwScope);
284 return JSValue::encode(JSErrorEvent::getConstructor(state->vm(), prototype->globalObject()));
285}
286
287bool setJSErrorEventConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
288{
289 VM& vm = state->vm();
290 auto throwScope = DECLARE_THROW_SCOPE(vm);
291 auto* prototype = jsDynamicCast<JSErrorEventPrototype*>(vm, JSValue::decode(thisValue));
292 if (UNLIKELY(!prototype)) {
293 throwVMTypeError(state, throwScope);
294 return false;
295 }
296 // Shadowing a built-in constructor
297 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
298}
299
300static inline JSValue jsErrorEventMessageGetter(ExecState& state, JSErrorEvent& thisObject, ThrowScope& throwScope)
301{
302 UNUSED_PARAM(throwScope);
303 UNUSED_PARAM(state);
304 auto& impl = thisObject.wrapped();
305 JSValue result = toJS<IDLDOMString>(state, throwScope, impl.message());
306 return result;
307}
308
309EncodedJSValue jsErrorEventMessage(ExecState* state, EncodedJSValue thisValue, PropertyName)
310{
311 return IDLAttribute<JSErrorEvent>::get<jsErrorEventMessageGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "message");
312}
313
314static inline JSValue jsErrorEventFilenameGetter(ExecState& state, JSErrorEvent& thisObject, ThrowScope& throwScope)
315{
316 UNUSED_PARAM(throwScope);
317 UNUSED_PARAM(state);
318 auto& impl = thisObject.wrapped();
319 JSValue result = toJS<IDLUSVString>(state, throwScope, impl.filename());
320 return result;
321}
322
323EncodedJSValue jsErrorEventFilename(ExecState* state, EncodedJSValue thisValue, PropertyName)
324{
325 return IDLAttribute<JSErrorEvent>::get<jsErrorEventFilenameGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "filename");
326}
327
328static inline JSValue jsErrorEventLinenoGetter(ExecState& state, JSErrorEvent& thisObject, ThrowScope& throwScope)
329{
330 UNUSED_PARAM(throwScope);
331 UNUSED_PARAM(state);
332 auto& impl = thisObject.wrapped();
333 JSValue result = toJS<IDLUnsignedLong>(state, throwScope, impl.lineno());
334 return result;
335}
336
337EncodedJSValue jsErrorEventLineno(ExecState* state, EncodedJSValue thisValue, PropertyName)
338{
339 return IDLAttribute<JSErrorEvent>::get<jsErrorEventLinenoGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "lineno");
340}
341
342static inline JSValue jsErrorEventColnoGetter(ExecState& state, JSErrorEvent& thisObject, ThrowScope& throwScope)
343{
344 UNUSED_PARAM(throwScope);
345 UNUSED_PARAM(state);
346 auto& impl = thisObject.wrapped();
347 JSValue result = toJS<IDLUnsignedLong>(state, throwScope, impl.colno());
348 return result;
349}
350
351EncodedJSValue jsErrorEventColno(ExecState* state, EncodedJSValue thisValue, PropertyName)
352{
353 return IDLAttribute<JSErrorEvent>::get<jsErrorEventColnoGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "colno");
354}
355
356static inline JSValue jsErrorEventErrorGetter(ExecState& state, JSErrorEvent& thisObject, ThrowScope& throwScope)
357{
358 UNUSED_PARAM(throwScope);
359 UNUSED_PARAM(state);
360 auto& impl = thisObject.wrapped();
361 JSValue result = toJS<IDLAny>(state, throwScope, impl.error(state, *jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject())));
362 return result;
363}
364
365EncodedJSValue jsErrorEventError(ExecState* state, EncodedJSValue thisValue, PropertyName)
366{
367 return IDLAttribute<JSErrorEvent>::get<jsErrorEventErrorGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "error");
368}
369
370void JSErrorEvent::visitChildren(JSCell* cell, SlotVisitor& visitor)
371{
372 auto* thisObject = jsCast<JSErrorEvent*>(cell);
373 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
374 Base::visitChildren(thisObject, visitor);
375 thisObject->visitAdditionalChildren(visitor);
376}
377
378void JSErrorEvent::visitOutputConstraints(JSCell* cell, SlotVisitor& visitor)
379{
380 auto* thisObject = jsCast<JSErrorEvent*>(cell);
381 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
382 Base::visitOutputConstraints(thisObject, visitor);
383 thisObject->visitAdditionalChildren(visitor);
384}
385
386void JSErrorEvent::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
387{
388 auto* thisObject = jsCast<JSErrorEvent*>(cell);
389 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
390 if (thisObject->scriptExecutionContext())
391 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
392 Base::heapSnapshot(cell, builder);
393}
394
395#if ENABLE(BINDING_INTEGRITY)
396#if PLATFORM(WIN)
397#pragma warning(disable: 4483)
398extern "C" { extern void (*const __identifier("??_7ErrorEvent@WebCore@@6B@")[])(); }
399#else
400extern "C" { extern void* _ZTVN7WebCore10ErrorEventE[]; }
401#endif
402#endif
403
404JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<ErrorEvent>&& impl)
405{
406
407#if ENABLE(BINDING_INTEGRITY)
408 void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
409#if PLATFORM(WIN)
410 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7ErrorEvent@WebCore@@6B@"));
411#else
412 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore10ErrorEventE[2]);
413#endif
414
415 // If this fails ErrorEvent does not have a vtable, so you need to add the
416 // ImplementationLacksVTable attribute to the interface definition
417 static_assert(std::is_polymorphic<ErrorEvent>::value, "ErrorEvent is not polymorphic");
418
419 // If you hit this assertion you either have a use after free bug, or
420 // ErrorEvent has subclasses. If ErrorEvent has subclasses that get passed
421 // to toJS() we currently require ErrorEvent you to opt out of binding hardening
422 // by adding the SkipVTableValidation attribute to the interface IDL definition
423 RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
424#endif
425 return createWrapper<ErrorEvent>(globalObject, WTFMove(impl));
426}
427
428JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, ErrorEvent& impl)
429{
430 return wrap(state, globalObject, impl);
431}
432
433
434}
435