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