Move URL from WebCore to WTF
[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     }
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::ExecState* state)
202 {
203     return IDLOperation<JSTestIterable>::call<jsTestIterablePrototypeFunctionEntriesCaller>(*state, "entries");
204 }
205
206 static inline EncodedJSValue jsTestIterablePrototypeFunctionKeysCaller(ExecState*, JSTestIterable* thisObject, JSC::ThrowScope&)
207 {
208     return JSValue::encode(iteratorCreate<TestIterableIterator>(*thisObject, IterationKind::Key));
209 }
210
211 JSC::EncodedJSValue JSC_HOST_CALL jsTestIterablePrototypeFunctionKeys(JSC::ExecState* state)
212 {
213     return IDLOperation<JSTestIterable>::call<jsTestIterablePrototypeFunctionKeysCaller>(*state, "keys");
214 }
215
216 static inline EncodedJSValue jsTestIterablePrototypeFunctionValuesCaller(ExecState*, JSTestIterable* thisObject, JSC::ThrowScope&)
217 {
218     return JSValue::encode(iteratorCreate<TestIterableIterator>(*thisObject, IterationKind::Value));
219 }
220
221 JSC::EncodedJSValue JSC_HOST_CALL jsTestIterablePrototypeFunctionValues(JSC::ExecState* state)
222 {
223     return IDLOperation<JSTestIterable>::call<jsTestIterablePrototypeFunctionValuesCaller>(*state, "values");
224 }
225
226 static inline EncodedJSValue jsTestIterablePrototypeFunctionForEachCaller(ExecState* state, JSTestIterable* thisObject, JSC::ThrowScope& throwScope)
227 {
228     return JSValue::encode(iteratorForEach<TestIterableIterator>(*state, *thisObject, throwScope));
229 }
230
231 JSC::EncodedJSValue JSC_HOST_CALL jsTestIterablePrototypeFunctionForEach(JSC::ExecState* state)
232 {
233     return IDLOperation<JSTestIterable>::call<jsTestIterablePrototypeFunctionForEachCaller>(*state, "forEach");
234 }
235
236 void JSTestIterable::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
237 {
238     auto* thisObject = jsCast<JSTestIterable*>(cell);
239     builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
240     if (thisObject->scriptExecutionContext())
241         builder.setLabelForCell(cell, String::format("url %s", thisObject->scriptExecutionContext()->url().string().utf8().data()));
242     Base::heapSnapshot(cell, builder);
243 }
244
245 bool JSTestIterableOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
246 {
247     UNUSED_PARAM(handle);
248     UNUSED_PARAM(visitor);
249     UNUSED_PARAM(reason);
250     return false;
251 }
252
253 void JSTestIterableOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
254 {
255     auto* jsTestIterable = static_cast<JSTestIterable*>(handle.slot()->asCell());
256     auto& world = *static_cast<DOMWrapperWorld*>(context);
257     uncacheWrapper(world, &jsTestIterable->wrapped(), jsTestIterable);
258 }
259
260 #if ENABLE(BINDING_INTEGRITY)
261 #if PLATFORM(WIN)
262 #pragma warning(disable: 4483)
263 extern "C" { extern void (*const __identifier("??_7TestIterable@WebCore@@6B@")[])(); }
264 #else
265 extern "C" { extern void* _ZTVN7WebCore12TestIterableE[]; }
266 #endif
267 #endif
268
269 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestIterable>&& impl)
270 {
271
272 #if ENABLE(BINDING_INTEGRITY)
273     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
274 #if PLATFORM(WIN)
275     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7TestIterable@WebCore@@6B@"));
276 #else
277     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore12TestIterableE[2]);
278 #endif
279
280     // If this fails TestIterable does not have a vtable, so you need to add the
281     // ImplementationLacksVTable attribute to the interface definition
282     static_assert(std::is_polymorphic<TestIterable>::value, "TestIterable is not polymorphic");
283
284     // If you hit this assertion you either have a use after free bug, or
285     // TestIterable has subclasses. If TestIterable has subclasses that get passed
286     // to toJS() we currently require TestIterable you to opt out of binding hardening
287     // by adding the SkipVTableValidation attribute to the interface IDL definition
288     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
289 #endif
290     return createWrapper<TestIterable>(globalObject, WTFMove(impl));
291 }
292
293 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestIterable& impl)
294 {
295     return wrap(state, globalObject, impl);
296 }
297
298 TestIterable* JSTestIterable::toWrapped(JSC::VM& vm, JSC::JSValue value)
299 {
300     if (auto* wrapper = jsDynamicCast<JSTestIterable*>(vm, value))
301         return &wrapper->wrapped();
302     return nullptr;
303 }
304
305 }