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