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