Introduce ExceptionScope::assertNoException() and releaseAssertNoException().
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / JS / JSTestNode.cpp
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 "JSTestNode.h"
23
24 #include "JSDOMBinding.h"
25 #include "JSDOMBindingCaller.h"
26 #include "JSDOMConstructor.h"
27 #include "JSDOMConvert.h"
28 #include "JSDOMExceptionHandling.h"
29 #include "JSDOMIterator.h"
30 #include "JSDOMPromise.h"
31 #include "JSDOMWrapperCache.h"
32 #include "RuntimeEnabledFeatures.h"
33 #include <runtime/Error.h>
34 #include <runtime/ObjectConstructor.h>
35 #include <wtf/GetPtr.h>
36
37 using namespace JSC;
38
39 namespace WebCore {
40
41 // Functions
42
43 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionTestWorkerPromise(JSC::ExecState*);
44 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionSymbolIterator(JSC::ExecState*);
45 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionEntries(JSC::ExecState*);
46 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionKeys(JSC::ExecState*);
47 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionValues(JSC::ExecState*);
48 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionForEach(JSC::ExecState*);
49 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionToJSON(JSC::ExecState*);
50
51 // Attributes
52
53 JSC::EncodedJSValue jsTestNodeName(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
54 bool setJSTestNodeName(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
55 JSC::EncodedJSValue jsTestNodeConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
56 bool setJSTestNodeConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
57
58 class JSTestNodePrototype : public JSC::JSNonFinalObject {
59 public:
60     using Base = JSC::JSNonFinalObject;
61     static JSTestNodePrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
62     {
63         JSTestNodePrototype* ptr = new (NotNull, JSC::allocateCell<JSTestNodePrototype>(vm.heap)) JSTestNodePrototype(vm, globalObject, structure);
64         ptr->finishCreation(vm);
65         return ptr;
66     }
67
68     DECLARE_INFO;
69     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
70     {
71         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
72     }
73
74 private:
75     JSTestNodePrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
76         : JSC::JSNonFinalObject(vm, structure)
77     {
78     }
79
80     void finishCreation(JSC::VM&);
81 };
82
83 using JSTestNodeConstructor = JSDOMConstructor<JSTestNode>;
84
85 template<> EncodedJSValue JSC_HOST_CALL JSTestNodeConstructor::construct(ExecState* state)
86 {
87     VM& vm = state->vm();
88     auto throwScope = DECLARE_THROW_SCOPE(vm);
89     UNUSED_PARAM(throwScope);
90     auto* castedThis = jsCast<JSTestNodeConstructor*>(state->jsCallee());
91     ASSERT(castedThis);
92     auto object = TestNode::create();
93     return JSValue::encode(toJSNewlyCreated<IDLInterface<TestNode>>(*state, *castedThis->globalObject(), WTFMove(object)));
94 }
95
96 template<> JSValue JSTestNodeConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
97 {
98     return JSNode::getConstructor(vm, &globalObject);
99 }
100
101 template<> void JSTestNodeConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
102 {
103     putDirect(vm, vm.propertyNames->prototype, JSTestNode::prototype(vm, globalObject), DontDelete | ReadOnly | DontEnum);
104     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("TestNode"))), ReadOnly | DontEnum);
105     putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontEnum);
106 }
107
108 template<> const ClassInfo JSTestNodeConstructor::s_info = { "TestNode", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestNodeConstructor) };
109
110 /* Hash table for prototype */
111
112 static const HashTableValue JSTestNodePrototypeTableValues[] =
113 {
114     { "constructor", DontEnum, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestNodeConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestNodeConstructor) } },
115     { "name", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestNodeName), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestNodeName) } },
116     { "testWorkerPromise", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionTestWorkerPromise), (intptr_t) (0) } },
117     { "entries", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionEntries), (intptr_t) (0) } },
118     { "keys", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionKeys), (intptr_t) (0) } },
119     { "values", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionValues), (intptr_t) (0) } },
120     { "forEach", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionForEach), (intptr_t) (1) } },
121     { "toJSON", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionToJSON), (intptr_t) (0) } },
122 };
123
124 const ClassInfo JSTestNodePrototype::s_info = { "TestNodePrototype", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestNodePrototype) };
125
126 void JSTestNodePrototype::finishCreation(VM& vm)
127 {
128     Base::finishCreation(vm);
129     reifyStaticProperties(vm, JSTestNodePrototypeTableValues, *this);
130     if (!RuntimeEnabledFeatures::sharedFeatures().domIteratorEnabled()) {
131         Identifier propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("entries"), strlen("entries"));
132         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
133         JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
134     }
135     if (!RuntimeEnabledFeatures::sharedFeatures().domIteratorEnabled()) {
136         Identifier propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("keys"), strlen("keys"));
137         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
138         JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
139     }
140     if (!RuntimeEnabledFeatures::sharedFeatures().domIteratorEnabled()) {
141         Identifier propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("values"), strlen("values"));
142         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
143         JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
144     }
145     if (!RuntimeEnabledFeatures::sharedFeatures().domIteratorEnabled()) {
146         Identifier propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("forEach"), strlen("forEach"));
147         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
148         JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
149     }
150     putDirect(vm, vm.propertyNames->iteratorSymbol, JSFunction::create(vm, globalObject(), 0, ASCIILiteral("[Symbol.Iterator]"), jsTestNodePrototypeFunctionSymbolIterator), DontEnum);
151 }
152
153 const ClassInfo JSTestNode::s_info = { "TestNode", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestNode) };
154
155 JSTestNode::JSTestNode(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestNode>&& impl)
156     : JSNode(structure, globalObject, WTFMove(impl))
157 {
158 }
159
160 void JSTestNode::finishCreation(VM& vm)
161 {
162     Base::finishCreation(vm);
163     ASSERT(inherits(vm, info()));
164
165 }
166
167 JSObject* JSTestNode::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
168 {
169     return JSTestNodePrototype::create(vm, &globalObject, JSTestNodePrototype::createStructure(vm, &globalObject, JSNode::prototype(vm, globalObject)));
170 }
171
172 JSObject* JSTestNode::prototype(VM& vm, JSDOMGlobalObject& globalObject)
173 {
174     return getDOMPrototype<JSTestNode>(vm, globalObject);
175 }
176
177 template<> inline JSTestNode* BindingCaller<JSTestNode>::castForAttribute(ExecState& state, EncodedJSValue thisValue)
178 {
179     return jsDynamicDowncast<JSTestNode*>(state.vm(), JSValue::decode(thisValue));
180 }
181
182 template<> inline JSTestNode* BindingCaller<JSTestNode>::castForOperation(ExecState& state)
183 {
184     return jsDynamicDowncast<JSTestNode*>(state.vm(), state.thisValue());
185 }
186
187 static inline JSValue jsTestNodeNameGetter(ExecState&, JSTestNode&, ThrowScope& throwScope);
188
189 EncodedJSValue jsTestNodeName(ExecState* state, EncodedJSValue thisValue, PropertyName)
190 {
191     return BindingCaller<JSTestNode>::attribute<jsTestNodeNameGetter>(state, thisValue, "name");
192 }
193
194 static inline JSValue jsTestNodeNameGetter(ExecState& state, JSTestNode& thisObject, ThrowScope& throwScope)
195 {
196     UNUSED_PARAM(throwScope);
197     UNUSED_PARAM(state);
198     auto& impl = thisObject.wrapped();
199     JSValue result = toJS<IDLDOMString>(state, impl.name());
200     return result;
201 }
202
203 EncodedJSValue jsTestNodeConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
204 {
205     VM& vm = state->vm();
206     auto throwScope = DECLARE_THROW_SCOPE(vm);
207     JSTestNodePrototype* domObject = jsDynamicDowncast<JSTestNodePrototype*>(vm, JSValue::decode(thisValue));
208     if (UNLIKELY(!domObject))
209         return throwVMTypeError(state, throwScope);
210     return JSValue::encode(JSTestNode::getConstructor(state->vm(), domObject->globalObject()));
211 }
212
213 bool setJSTestNodeConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
214 {
215     VM& vm = state->vm();
216     auto throwScope = DECLARE_THROW_SCOPE(vm);
217     JSValue value = JSValue::decode(encodedValue);
218     JSTestNodePrototype* domObject = jsDynamicDowncast<JSTestNodePrototype*>(vm, JSValue::decode(thisValue));
219     if (UNLIKELY(!domObject)) {
220         throwVMTypeError(state, throwScope);
221         return false;
222     }
223     // Shadowing a built-in constructor
224     return domObject->putDirect(state->vm(), state->propertyNames().constructor, value);
225 }
226
227 static inline bool setJSTestNodeNameFunction(ExecState&, JSTestNode&, JSValue, ThrowScope&);
228
229 bool setJSTestNodeName(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
230 {
231     return BindingCaller<JSTestNode>::setAttribute<setJSTestNodeNameFunction>(state, thisValue, encodedValue, "name");
232 }
233
234 static inline bool setJSTestNodeNameFunction(ExecState& state, JSTestNode& thisObject, JSValue value, ThrowScope& throwScope)
235 {
236     UNUSED_PARAM(state);
237     UNUSED_PARAM(throwScope);
238     auto& impl = thisObject.wrapped();
239     auto nativeValue = convert<IDLDOMString>(state, value);
240     RETURN_IF_EXCEPTION(throwScope, false);
241     impl.setName(WTFMove(nativeValue));
242     return true;
243 }
244
245
246 JSValue JSTestNode::getConstructor(VM& vm, const JSGlobalObject* globalObject)
247 {
248     return getDOMConstructor<JSTestNodeConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
249 }
250
251 static inline JSC::EncodedJSValue jsTestNodePrototypeFunctionTestWorkerPromiseCaller(JSC::ExecState*, JSTestNode*, Ref<DeferredPromise>&&, JSC::ThrowScope&);
252
253 static EncodedJSValue jsTestNodePrototypeFunctionTestWorkerPromisePromise(ExecState*, Ref<DeferredPromise>&&);
254
255 EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionTestWorkerPromise(ExecState* state)
256 {
257     ASSERT(state);
258     return JSValue::encode(callPromiseFunction<jsTestNodePrototypeFunctionTestWorkerPromisePromise, PromiseExecutionScope::WindowOrWorker>(*state));
259 }
260
261 static inline EncodedJSValue jsTestNodePrototypeFunctionTestWorkerPromisePromise(ExecState* state, Ref<DeferredPromise>&& promise)
262 {
263     return BindingCaller<JSTestNode>::callPromiseOperation<jsTestNodePrototypeFunctionTestWorkerPromiseCaller>(state, WTFMove(promise), "testWorkerPromise");
264 }
265
266 static inline JSC::EncodedJSValue jsTestNodePrototypeFunctionTestWorkerPromiseCaller(JSC::ExecState* state, JSTestNode* castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope)
267 {
268     UNUSED_PARAM(state);
269     UNUSED_PARAM(throwScope);
270     auto& impl = castedThis->wrapped();
271     impl.testWorkerPromise(WTFMove(promise));
272     return JSValue::encode(jsUndefined());
273 }
274
275 struct TestNodeIteratorTraits {
276     static constexpr JSDOMIteratorType type = JSDOMIteratorType::Set;
277     using KeyType = void;
278     using ValueType = IDLInterface<TestNode>;
279 };
280
281 using TestNodeIterator = JSDOMIterator<JSTestNode, TestNodeIteratorTraits>;
282 using TestNodeIteratorPrototype = JSDOMIteratorPrototype<JSTestNode, TestNodeIteratorTraits>;
283
284 template<>
285 const JSC::ClassInfo TestNodeIterator::s_info = { "TestNode Iterator", &Base::s_info, 0, CREATE_METHOD_TABLE(TestNodeIterator) };
286
287 template<>
288 const JSC::ClassInfo TestNodeIteratorPrototype::s_info = { "TestNode Iterator", &Base::s_info, 0, CREATE_METHOD_TABLE(TestNodeIteratorPrototype) };
289
290 static inline EncodedJSValue jsTestNodePrototypeFunctionSymbolIteratorCaller(ExecState*, JSTestNode* thisObject, JSC::ThrowScope&)
291 {
292     return JSValue::encode(iteratorCreate<TestNodeIterator>(*thisObject, IterationKind::Value));
293 }
294
295 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionSymbolIterator(JSC::ExecState* state)
296 {
297     return BindingCaller<JSTestNode>::callOperation<jsTestNodePrototypeFunctionSymbolIteratorCaller>(state, "[Symbol.Iterator]");
298 }
299
300 static inline EncodedJSValue jsTestNodePrototypeFunctionEntriesCaller(ExecState*, JSTestNode* thisObject, JSC::ThrowScope&)
301 {
302     return JSValue::encode(iteratorCreate<TestNodeIterator>(*thisObject, IterationKind::KeyValue));
303 }
304
305 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionEntries(JSC::ExecState* state)
306 {
307     return BindingCaller<JSTestNode>::callOperation<jsTestNodePrototypeFunctionEntriesCaller>(state, "entries");
308 }
309
310 static inline EncodedJSValue jsTestNodePrototypeFunctionKeysCaller(ExecState*, JSTestNode* thisObject, JSC::ThrowScope&)
311 {
312     return JSValue::encode(iteratorCreate<TestNodeIterator>(*thisObject, IterationKind::Key));
313 }
314
315 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionKeys(JSC::ExecState* state)
316 {
317     return BindingCaller<JSTestNode>::callOperation<jsTestNodePrototypeFunctionKeysCaller>(state, "keys");
318 }
319
320 static inline EncodedJSValue jsTestNodePrototypeFunctionValuesCaller(ExecState*, JSTestNode* thisObject, JSC::ThrowScope&)
321 {
322     return JSValue::encode(iteratorCreate<TestNodeIterator>(*thisObject, IterationKind::Value));
323 }
324
325 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionValues(JSC::ExecState* state)
326 {
327     return BindingCaller<JSTestNode>::callOperation<jsTestNodePrototypeFunctionValuesCaller>(state, "values");
328 }
329
330 static inline EncodedJSValue jsTestNodePrototypeFunctionForEachCaller(ExecState* state, JSTestNode* thisObject, JSC::ThrowScope& throwScope)
331 {
332     return JSValue::encode(iteratorForEach<TestNodeIterator>(*state, *thisObject, throwScope));
333 }
334
335 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionForEach(JSC::ExecState* state)
336 {
337     return BindingCaller<JSTestNode>::callOperation<jsTestNodePrototypeFunctionForEachCaller>(state, "forEach");
338 }
339
340 JSC::JSObject* JSTestNode::serialize(ExecState* state, JSTestNode* thisObject, ThrowScope& throwScope)
341 {
342     auto& vm = state->vm();
343     auto* result = constructEmptyObject(state);
344
345     auto nameValue = jsTestNodeNameGetter(*state, *thisObject, throwScope);
346     throwScope.assertNoException();
347     result->putDirect(vm, Identifier::fromString(&vm, "name"), nameValue);
348
349     return result;
350 }
351
352 static inline EncodedJSValue jsTestNodePrototypeFunctionToJSONCaller(ExecState* state, JSTestNode* thisObject, JSC::ThrowScope& throwScope)
353 {
354     return JSValue::encode(JSTestNode::serialize(state, thisObject, throwScope));
355 }
356
357 EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionToJSON(ExecState* state)
358 {
359     return BindingCaller<JSTestNode>::callOperation<jsTestNodePrototypeFunctionToJSONCaller>(state, "toJSON");
360 }
361
362 void JSTestNode::visitChildren(JSCell* cell, SlotVisitor& visitor)
363 {
364     auto* thisObject = jsCast<JSTestNode*>(cell);
365     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
366     Base::visitChildren(thisObject, visitor);
367 }
368
369 #if ENABLE(BINDING_INTEGRITY)
370 #if PLATFORM(WIN)
371 #pragma warning(disable: 4483)
372 extern "C" { extern void (*const __identifier("??_7TestNode@WebCore@@6B@")[])(); }
373 #else
374 extern "C" { extern void* _ZTVN7WebCore8TestNodeE[]; }
375 #endif
376 #endif
377
378 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestNode>&& impl)
379 {
380
381 #if ENABLE(BINDING_INTEGRITY)
382     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
383 #if PLATFORM(WIN)
384     void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7TestNode@WebCore@@6B@"));
385 #else
386     void* expectedVTablePointer = &_ZTVN7WebCore8TestNodeE[2];
387 #if COMPILER(CLANG)
388     // If this fails TestNode does not have a vtable, so you need to add the
389     // ImplementationLacksVTable attribute to the interface definition
390     static_assert(__is_polymorphic(TestNode), "TestNode is not polymorphic");
391 #endif
392 #endif
393     // If you hit this assertion you either have a use after free bug, or
394     // TestNode has subclasses. If TestNode has subclasses that get passed
395     // to toJS() we currently require TestNode you to opt out of binding hardening
396     // by adding the SkipVTableValidation attribute to the interface IDL definition
397     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
398 #endif
399     return createWrapper<TestNode>(globalObject, WTFMove(impl));
400 }
401
402 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestNode& impl)
403 {
404     return wrap(state, globalObject, impl);
405 }
406
407
408 }