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