Update serializer and iterator binding generated code
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / JS / JSTestIterable.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 "JSTestIterable.h"
23
24 #include "JSDOMBinding.h"
25 #include "JSDOMConstructor.h"
26 #include "JSDOMIterator.h"
27 #include <runtime/FunctionPrototype.h>
28 #include <wtf/GetPtr.h>
29
30 using namespace JSC;
31
32 namespace WebCore {
33
34 // Functions
35
36 JSC::EncodedJSValue JSC_HOST_CALL jsTestIterablePrototypeFunctionSymbolIterator(JSC::ExecState*);
37 JSC::EncodedJSValue JSC_HOST_CALL jsTestIterablePrototypeFunctionEntries(JSC::ExecState*);
38 JSC::EncodedJSValue JSC_HOST_CALL jsTestIterablePrototypeFunctionKeys(JSC::ExecState*);
39 JSC::EncodedJSValue JSC_HOST_CALL jsTestIterablePrototypeFunctionValues(JSC::ExecState*);
40 JSC::EncodedJSValue JSC_HOST_CALL jsTestIterablePrototypeFunctionForEach(JSC::ExecState*);
41
42 // Attributes
43
44 JSC::EncodedJSValue jsTestIterableConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
45 bool setJSTestIterableConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
46
47 class JSTestIterablePrototype : public JSC::JSNonFinalObject {
48 public:
49     using Base = JSC::JSNonFinalObject;
50     static JSTestIterablePrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
51     {
52         JSTestIterablePrototype* ptr = new (NotNull, JSC::allocateCell<JSTestIterablePrototype>(vm.heap)) JSTestIterablePrototype(vm, globalObject, structure);
53         ptr->finishCreation(vm);
54         return ptr;
55     }
56
57     DECLARE_INFO;
58     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
59     {
60         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
61     }
62
63 private:
64     JSTestIterablePrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
65         : JSC::JSNonFinalObject(vm, structure)
66     {
67     }
68
69     void finishCreation(JSC::VM&);
70 };
71
72 using JSTestIterableConstructor = JSDOMConstructorNotConstructable<JSTestIterable>;
73
74 template<> JSValue JSTestIterableConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
75 {
76     UNUSED_PARAM(vm);
77     return globalObject.functionPrototype();
78 }
79
80 template<> void JSTestIterableConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
81 {
82     putDirect(vm, vm.propertyNames->prototype, JSTestIterable::prototype(vm, &globalObject), DontDelete | ReadOnly | DontEnum);
83     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("TestIterable"))), ReadOnly | DontEnum);
84     putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontEnum);
85 }
86
87 template<> const ClassInfo JSTestIterableConstructor::s_info = { "TestIterable", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestIterableConstructor) };
88
89 /* Hash table for prototype */
90
91 static const HashTableValue JSTestIterablePrototypeTableValues[] =
92 {
93     { "constructor", DontEnum, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestIterableConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestIterableConstructor) } },
94     { "entries", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestIterablePrototypeFunctionEntries), (intptr_t) (0) } },
95     { "keys", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestIterablePrototypeFunctionKeys), (intptr_t) (0) } },
96     { "values", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestIterablePrototypeFunctionValues), (intptr_t) (0) } },
97     { "forEach", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestIterablePrototypeFunctionForEach), (intptr_t) (1) } },
98 };
99
100 const ClassInfo JSTestIterablePrototype::s_info = { "TestIterablePrototype", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestIterablePrototype) };
101
102 void JSTestIterablePrototype::finishCreation(VM& vm)
103 {
104     Base::finishCreation(vm);
105     reifyStaticProperties(vm, JSTestIterablePrototypeTableValues, *this);
106     putDirect(vm, vm.propertyNames->iteratorSymbol, JSFunction::create(vm, globalObject(), 0, ASCIILiteral("[Symbol.Iterator]"), jsTestIterablePrototypeFunctionSymbolIterator), DontEnum);
107 }
108
109 const ClassInfo JSTestIterable::s_info = { "TestIterable", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestIterable) };
110
111 JSTestIterable::JSTestIterable(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestIterable>&& impl)
112     : JSDOMWrapper<TestIterable>(structure, globalObject, WTFMove(impl))
113 {
114 }
115
116 JSObject* JSTestIterable::createPrototype(VM& vm, JSGlobalObject* globalObject)
117 {
118     return JSTestIterablePrototype::create(vm, globalObject, JSTestIterablePrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
119 }
120
121 JSObject* JSTestIterable::prototype(VM& vm, JSGlobalObject* globalObject)
122 {
123     return getDOMPrototype<JSTestIterable>(vm, globalObject);
124 }
125
126 void JSTestIterable::destroy(JSC::JSCell* cell)
127 {
128     JSTestIterable* thisObject = static_cast<JSTestIterable*>(cell);
129     thisObject->JSTestIterable::~JSTestIterable();
130 }
131
132 template<> inline JSTestIterable* BindingCaller<JSTestIterable>::castForOperation(ExecState& state)
133 {
134     return jsDynamicCast<JSTestIterable*>(state.thisValue());
135 }
136
137 EncodedJSValue jsTestIterableConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
138 {
139     VM& vm = state->vm();
140     auto throwScope = DECLARE_THROW_SCOPE(vm);
141     JSTestIterablePrototype* domObject = jsDynamicCast<JSTestIterablePrototype*>(JSValue::decode(thisValue));
142     if (UNLIKELY(!domObject))
143         return throwVMTypeError(state, throwScope);
144     return JSValue::encode(JSTestIterable::getConstructor(state->vm(), domObject->globalObject()));
145 }
146
147 bool setJSTestIterableConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
148 {
149     VM& vm = state->vm();
150     auto throwScope = DECLARE_THROW_SCOPE(vm);
151     JSValue value = JSValue::decode(encodedValue);
152     JSTestIterablePrototype* domObject = jsDynamicCast<JSTestIterablePrototype*>(JSValue::decode(thisValue));
153     if (UNLIKELY(!domObject)) {
154         throwVMTypeError(state, throwScope);
155         return false;
156     }
157     // Shadowing a built-in constructor
158     return domObject->putDirect(state->vm(), state->propertyNames().constructor, value);
159 }
160
161 JSValue JSTestIterable::getConstructor(VM& vm, const JSGlobalObject* globalObject)
162 {
163     return getDOMConstructor<JSTestIterableConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
164 }
165
166 using TestIterableIterator = JSDOMIterator<JSTestIterable>;
167 using TestIterableIteratorPrototype = JSDOMIteratorPrototype<JSTestIterable>;
168
169 template<>
170 const JSC::ClassInfo TestIterableIterator::s_info = { "TestIterable Iterator", &Base::s_info, 0, CREATE_METHOD_TABLE(TestIterableIterator) };
171
172 template<>
173 const JSC::ClassInfo TestIterableIteratorPrototype::s_info = { "TestIterable Iterator", &Base::s_info, 0, CREATE_METHOD_TABLE(TestIterableIteratorPrototype) };
174
175 static inline EncodedJSValue jsTestIterablePrototypeFunctionSymbolIteratorCaller(ExecState*, JSTestIterable* thisObject, JSC::ThrowScope&)
176 {
177     return JSValue::encode(iteratorCreate<JSTestIterable>(*thisObject, IterationKind::Value));
178 }
179
180 JSC::EncodedJSValue JSC_HOST_CALL jsTestIterablePrototypeFunctionSymbolIterator(JSC::ExecState* state)
181 {
182     return BindingCaller<JSTestIterable>::callOperation<jsTestIterablePrototypeFunctionSymbolIteratorCaller>(state, "[Symbol.Iterator]");
183 }
184
185 static inline EncodedJSValue jsTestIterablePrototypeFunctionEntriesCaller(ExecState*, JSTestIterable* thisObject, JSC::ThrowScope&)
186 {
187     return JSValue::encode(iteratorCreate<JSTestIterable>(*thisObject, IterationKind::KeyValue));
188 }
189
190 JSC::EncodedJSValue JSC_HOST_CALL jsTestIterablePrototypeFunctionEntries(JSC::ExecState* state)
191 {
192     return BindingCaller<JSTestIterable>::callOperation<jsTestIterablePrototypeFunctionEntriesCaller>(state, "entries");
193 }
194
195 static inline EncodedJSValue jsTestIterablePrototypeFunctionKeysCaller(ExecState*, JSTestIterable* thisObject, JSC::ThrowScope&)
196 {
197     return JSValue::encode(iteratorCreate<JSTestIterable>(*thisObject, IterationKind::Key));
198 }
199
200 JSC::EncodedJSValue JSC_HOST_CALL jsTestIterablePrototypeFunctionKeys(JSC::ExecState* state)
201 {
202     return BindingCaller<JSTestIterable>::callOperation<jsTestIterablePrototypeFunctionKeysCaller>(state, "keys");
203 }
204
205 static inline EncodedJSValue jsTestIterablePrototypeFunctionValuesCaller(ExecState*, JSTestIterable* thisObject, JSC::ThrowScope&)
206 {
207     return JSValue::encode(iteratorCreate<JSTestIterable>(*thisObject, IterationKind::Value));
208 }
209
210 JSC::EncodedJSValue JSC_HOST_CALL jsTestIterablePrototypeFunctionValues(JSC::ExecState* state)
211 {
212     return BindingCaller<JSTestIterable>::callOperation<jsTestIterablePrototypeFunctionValuesCaller>(state, "values");
213 }
214
215 static inline EncodedJSValue jsTestIterablePrototypeFunctionForEachCaller(ExecState* state, JSTestIterable* thisObject, JSC::ThrowScope& throwScope)
216 {
217     return JSValue::encode(iteratorForEach<JSTestIterable>(*state, *thisObject, throwScope));
218 }
219
220 JSC::EncodedJSValue JSC_HOST_CALL jsTestIterablePrototypeFunctionForEach(JSC::ExecState* state)
221 {
222     return BindingCaller<JSTestIterable>::callOperation<jsTestIterablePrototypeFunctionForEachCaller>(state, "forEach");
223 }
224
225 bool JSTestIterableOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
226 {
227     UNUSED_PARAM(handle);
228     UNUSED_PARAM(visitor);
229     return false;
230 }
231
232 void JSTestIterableOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
233 {
234     auto* jsTestIterable = jsCast<JSTestIterable*>(handle.slot()->asCell());
235     auto& world = *static_cast<DOMWrapperWorld*>(context);
236     uncacheWrapper(world, &jsTestIterable->wrapped(), jsTestIterable);
237 }
238
239 #if ENABLE(BINDING_INTEGRITY)
240 #if PLATFORM(WIN)
241 #pragma warning(disable: 4483)
242 extern "C" { extern void (*const __identifier("??_7TestIterable@WebCore@@6B@")[])(); }
243 #else
244 extern "C" { extern void* _ZTVN7WebCore12TestIterableE[]; }
245 #endif
246 #endif
247
248 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestIterable>&& impl)
249 {
250
251 #if ENABLE(BINDING_INTEGRITY)
252     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
253 #if PLATFORM(WIN)
254     void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7TestIterable@WebCore@@6B@"));
255 #else
256     void* expectedVTablePointer = &_ZTVN7WebCore12TestIterableE[2];
257 #if COMPILER(CLANG)
258     // If this fails TestIterable does not have a vtable, so you need to add the
259     // ImplementationLacksVTable attribute to the interface definition
260     static_assert(__is_polymorphic(TestIterable), "TestIterable is not polymorphic");
261 #endif
262 #endif
263     // If you hit this assertion you either have a use after free bug, or
264     // TestIterable has subclasses. If TestIterable has subclasses that get passed
265     // to toJS() we currently require TestIterable you to opt out of binding hardening
266     // by adding the SkipVTableValidation attribute to the interface IDL definition
267     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
268 #endif
269     return createWrapper<TestIterable>(globalObject, WTFMove(impl));
270 }
271
272 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestIterable& impl)
273 {
274     return wrap(state, globalObject, impl);
275 }
276
277 TestIterable* JSTestIterable::toWrapped(JSC::JSValue value)
278 {
279     if (auto* wrapper = jsDynamicCast<JSTestIterable*>(value))
280         return &wrapper->wrapped();
281     return nullptr;
282 }
283
284 }