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