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