Move URL from WebCore to WTF
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / JS / JSReadOnlyMapLike.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 "JSReadOnlyMapLike.h"
23
24 #include "JSDOMAttribute.h"
25 #include "JSDOMBinding.h"
26 #include "JSDOMConstructorNotConstructable.h"
27 #include "JSDOMConvertAny.h"
28 #include "JSDOMConvertStrings.h"
29 #include "JSDOMExceptionHandling.h"
30 #include "JSDOMMapLike.h"
31 #include "JSDOMOperation.h"
32 #include "JSDOMWrapperCache.h"
33 #include "ScriptExecutionContext.h"
34 #include <JavaScriptCore/BuiltinNames.h>
35 #include <JavaScriptCore/FunctionPrototype.h>
36 #include <JavaScriptCore/HeapSnapshotBuilder.h>
37 #include <JavaScriptCore/JSCInlines.h>
38 #include <wtf/GetPtr.h>
39 #include <wtf/PointerPreparations.h>
40 #include <wtf/URL.h>
41
42
43 namespace WebCore {
44 using namespace JSC;
45
46 // Functions
47
48 JSC::EncodedJSValue JSC_HOST_CALL jsReadOnlyMapLikePrototypeFunctionGet(JSC::ExecState*);
49 JSC::EncodedJSValue JSC_HOST_CALL jsReadOnlyMapLikePrototypeFunctionHas(JSC::ExecState*);
50 JSC::EncodedJSValue JSC_HOST_CALL jsReadOnlyMapLikePrototypeFunctionEntries(JSC::ExecState*);
51 JSC::EncodedJSValue JSC_HOST_CALL jsReadOnlyMapLikePrototypeFunctionKeys(JSC::ExecState*);
52 JSC::EncodedJSValue JSC_HOST_CALL jsReadOnlyMapLikePrototypeFunctionValues(JSC::ExecState*);
53 JSC::EncodedJSValue JSC_HOST_CALL jsReadOnlyMapLikePrototypeFunctionForEach(JSC::ExecState*);
54
55 // Attributes
56
57 JSC::EncodedJSValue jsReadOnlyMapLikeConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
58 bool setJSReadOnlyMapLikeConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
59 JSC::EncodedJSValue jsReadOnlyMapLikeSize(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
60
61 class JSReadOnlyMapLikePrototype : public JSC::JSNonFinalObject {
62 public:
63     using Base = JSC::JSNonFinalObject;
64     static JSReadOnlyMapLikePrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
65     {
66         JSReadOnlyMapLikePrototype* ptr = new (NotNull, JSC::allocateCell<JSReadOnlyMapLikePrototype>(vm.heap)) JSReadOnlyMapLikePrototype(vm, globalObject, structure);
67         ptr->finishCreation(vm);
68         return ptr;
69     }
70
71     DECLARE_INFO;
72     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
73     {
74         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
75     }
76
77 private:
78     JSReadOnlyMapLikePrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
79         : JSC::JSNonFinalObject(vm, structure)
80     {
81     }
82
83     void finishCreation(JSC::VM&);
84 };
85
86 using JSReadOnlyMapLikeConstructor = JSDOMConstructorNotConstructable<JSReadOnlyMapLike>;
87
88 template<> JSValue JSReadOnlyMapLikeConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
89 {
90     UNUSED_PARAM(vm);
91     return globalObject.functionPrototype();
92 }
93
94 template<> void JSReadOnlyMapLikeConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
95 {
96     putDirect(vm, vm.propertyNames->prototype, JSReadOnlyMapLike::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
97     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("ReadOnlyMapLike"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
98     putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
99 }
100
101 template<> const ClassInfo JSReadOnlyMapLikeConstructor::s_info = { "ReadOnlyMapLike", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadOnlyMapLikeConstructor) };
102
103 /* Hash table for prototype */
104
105 static const HashTableValue JSReadOnlyMapLikePrototypeTableValues[] =
106 {
107     { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsReadOnlyMapLikeConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSReadOnlyMapLikeConstructor) } },
108     { "size", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsReadOnlyMapLikeSize), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
109     { "get", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsReadOnlyMapLikePrototypeFunctionGet), (intptr_t) (1) } },
110     { "has", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsReadOnlyMapLikePrototypeFunctionHas), (intptr_t) (1) } },
111     { "entries", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsReadOnlyMapLikePrototypeFunctionEntries), (intptr_t) (0) } },
112     { "keys", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsReadOnlyMapLikePrototypeFunctionKeys), (intptr_t) (0) } },
113     { "values", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsReadOnlyMapLikePrototypeFunctionValues), (intptr_t) (0) } },
114     { "forEach", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsReadOnlyMapLikePrototypeFunctionForEach), (intptr_t) (1) } },
115 };
116
117 const ClassInfo JSReadOnlyMapLikePrototype::s_info = { "ReadOnlyMapLikePrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadOnlyMapLikePrototype) };
118
119 void JSReadOnlyMapLikePrototype::finishCreation(VM& vm)
120 {
121     Base::finishCreation(vm);
122     reifyStaticProperties(vm, JSReadOnlyMapLike::info(), JSReadOnlyMapLikePrototypeTableValues, *this);
123     putDirect(vm, vm.propertyNames->iteratorSymbol, getDirect(vm, vm.propertyNames->builtinNames().entriesPublicName()), static_cast<unsigned>(JSC::PropertyAttribute::DontEnum));
124 }
125
126 const ClassInfo JSReadOnlyMapLike::s_info = { "ReadOnlyMapLike", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSReadOnlyMapLike) };
127
128 JSReadOnlyMapLike::JSReadOnlyMapLike(Structure* structure, JSDOMGlobalObject& globalObject, Ref<ReadOnlyMapLike>&& impl)
129     : JSDOMWrapper<ReadOnlyMapLike>(structure, globalObject, WTFMove(impl))
130 {
131 }
132
133 void JSReadOnlyMapLike::finishCreation(VM& vm)
134 {
135     Base::finishCreation(vm);
136     ASSERT(inherits(vm, info()));
137
138     synchronizeBackingMap(*globalObject()->globalExec(), *globalObject(), *this);
139 }
140
141 JSObject* JSReadOnlyMapLike::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
142 {
143     return JSReadOnlyMapLikePrototype::create(vm, &globalObject, JSReadOnlyMapLikePrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
144 }
145
146 JSObject* JSReadOnlyMapLike::prototype(VM& vm, JSDOMGlobalObject& globalObject)
147 {
148     return getDOMPrototype<JSReadOnlyMapLike>(vm, globalObject);
149 }
150
151 JSValue JSReadOnlyMapLike::getConstructor(VM& vm, const JSGlobalObject* globalObject)
152 {
153     return getDOMConstructor<JSReadOnlyMapLikeConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
154 }
155
156 void JSReadOnlyMapLike::destroy(JSC::JSCell* cell)
157 {
158     JSReadOnlyMapLike* thisObject = static_cast<JSReadOnlyMapLike*>(cell);
159     thisObject->JSReadOnlyMapLike::~JSReadOnlyMapLike();
160 }
161
162 template<> inline JSReadOnlyMapLike* IDLAttribute<JSReadOnlyMapLike>::cast(ExecState& state, EncodedJSValue thisValue)
163 {
164     return jsDynamicCast<JSReadOnlyMapLike*>(state.vm(), JSValue::decode(thisValue));
165 }
166
167 template<> inline JSReadOnlyMapLike* IDLOperation<JSReadOnlyMapLike>::cast(ExecState& state)
168 {
169     return jsDynamicCast<JSReadOnlyMapLike*>(state.vm(), state.thisValue());
170 }
171
172 EncodedJSValue jsReadOnlyMapLikeConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
173 {
174     VM& vm = state->vm();
175     auto throwScope = DECLARE_THROW_SCOPE(vm);
176     auto* prototype = jsDynamicCast<JSReadOnlyMapLikePrototype*>(vm, JSValue::decode(thisValue));
177     if (UNLIKELY(!prototype))
178         return throwVMTypeError(state, throwScope);
179     return JSValue::encode(JSReadOnlyMapLike::getConstructor(state->vm(), prototype->globalObject()));
180 }
181
182 bool setJSReadOnlyMapLikeConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
183 {
184     VM& vm = state->vm();
185     auto throwScope = DECLARE_THROW_SCOPE(vm);
186     auto* prototype = jsDynamicCast<JSReadOnlyMapLikePrototype*>(vm, JSValue::decode(thisValue));
187     if (UNLIKELY(!prototype)) {
188         throwVMTypeError(state, throwScope);
189         return false;
190     }
191     // Shadowing a built-in constructor
192     return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
193 }
194
195 static inline JSValue jsReadOnlyMapLikeSizeGetter(ExecState& state, JSReadOnlyMapLike& thisObject, ThrowScope& throwScope)
196 {
197     UNUSED_PARAM(throwScope);
198     UNUSED_PARAM(state);
199     JSValue result = toJS<IDLAny>(state, throwScope, forwardSizeToMapLike(state, thisObject));
200     return result;
201 }
202
203 EncodedJSValue jsReadOnlyMapLikeSize(ExecState* state, EncodedJSValue thisValue, PropertyName)
204 {
205     return IDLAttribute<JSReadOnlyMapLike>::get<jsReadOnlyMapLikeSizeGetter>(*state, thisValue, "size");
206 }
207
208 static inline JSC::EncodedJSValue jsReadOnlyMapLikePrototypeFunctionGetBody(JSC::ExecState* state, typename IDLOperation<JSReadOnlyMapLike>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
209 {
210     UNUSED_PARAM(state);
211     UNUSED_PARAM(throwScope);
212     if (UNLIKELY(state->argumentCount() < 1))
213         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
214     auto key = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
215     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
216     return JSValue::encode(toJS<IDLAny>(forwardGetToMapLike(*state, *castedThis, WTFMove(key))));
217 }
218
219 EncodedJSValue JSC_HOST_CALL jsReadOnlyMapLikePrototypeFunctionGet(ExecState* state)
220 {
221     return IDLOperation<JSReadOnlyMapLike>::call<jsReadOnlyMapLikePrototypeFunctionGetBody>(*state, "get");
222 }
223
224 static inline JSC::EncodedJSValue jsReadOnlyMapLikePrototypeFunctionHasBody(JSC::ExecState* state, typename IDLOperation<JSReadOnlyMapLike>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
225 {
226     UNUSED_PARAM(state);
227     UNUSED_PARAM(throwScope);
228     if (UNLIKELY(state->argumentCount() < 1))
229         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
230     auto key = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
231     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
232     return JSValue::encode(toJS<IDLAny>(forwardHasToMapLike(*state, *castedThis, WTFMove(key))));
233 }
234
235 EncodedJSValue JSC_HOST_CALL jsReadOnlyMapLikePrototypeFunctionHas(ExecState* state)
236 {
237     return IDLOperation<JSReadOnlyMapLike>::call<jsReadOnlyMapLikePrototypeFunctionHasBody>(*state, "has");
238 }
239
240 static inline JSC::EncodedJSValue jsReadOnlyMapLikePrototypeFunctionEntriesBody(JSC::ExecState* state, typename IDLOperation<JSReadOnlyMapLike>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
241 {
242     UNUSED_PARAM(state);
243     UNUSED_PARAM(throwScope);
244     return JSValue::encode(toJS<IDLAny>(forwardEntriesToMapLike(*state, *castedThis)));
245 }
246
247 EncodedJSValue JSC_HOST_CALL jsReadOnlyMapLikePrototypeFunctionEntries(ExecState* state)
248 {
249     return IDLOperation<JSReadOnlyMapLike>::call<jsReadOnlyMapLikePrototypeFunctionEntriesBody>(*state, "entries");
250 }
251
252 static inline JSC::EncodedJSValue jsReadOnlyMapLikePrototypeFunctionKeysBody(JSC::ExecState* state, typename IDLOperation<JSReadOnlyMapLike>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
253 {
254     UNUSED_PARAM(state);
255     UNUSED_PARAM(throwScope);
256     return JSValue::encode(toJS<IDLAny>(forwardKeysToMapLike(*state, *castedThis)));
257 }
258
259 EncodedJSValue JSC_HOST_CALL jsReadOnlyMapLikePrototypeFunctionKeys(ExecState* state)
260 {
261     return IDLOperation<JSReadOnlyMapLike>::call<jsReadOnlyMapLikePrototypeFunctionKeysBody>(*state, "keys");
262 }
263
264 static inline JSC::EncodedJSValue jsReadOnlyMapLikePrototypeFunctionValuesBody(JSC::ExecState* state, typename IDLOperation<JSReadOnlyMapLike>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
265 {
266     UNUSED_PARAM(state);
267     UNUSED_PARAM(throwScope);
268     return JSValue::encode(toJS<IDLAny>(forwardValuesToMapLike(*state, *castedThis)));
269 }
270
271 EncodedJSValue JSC_HOST_CALL jsReadOnlyMapLikePrototypeFunctionValues(ExecState* state)
272 {
273     return IDLOperation<JSReadOnlyMapLike>::call<jsReadOnlyMapLikePrototypeFunctionValuesBody>(*state, "values");
274 }
275
276 static inline JSC::EncodedJSValue jsReadOnlyMapLikePrototypeFunctionForEachBody(JSC::ExecState* state, typename IDLOperation<JSReadOnlyMapLike>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
277 {
278     UNUSED_PARAM(state);
279     UNUSED_PARAM(throwScope);
280     if (UNLIKELY(state->argumentCount() < 1))
281         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
282     auto callback = convert<IDLAny>(*state, state->uncheckedArgument(0));
283     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
284     return JSValue::encode(toJS<IDLAny>(forwardForEachToMapLike(*state, *castedThis, WTFMove(callback))));
285 }
286
287 EncodedJSValue JSC_HOST_CALL jsReadOnlyMapLikePrototypeFunctionForEach(ExecState* state)
288 {
289     return IDLOperation<JSReadOnlyMapLike>::call<jsReadOnlyMapLikePrototypeFunctionForEachBody>(*state, "forEach");
290 }
291
292 void JSReadOnlyMapLike::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
293 {
294     auto* thisObject = jsCast<JSReadOnlyMapLike*>(cell);
295     builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
296     if (thisObject->scriptExecutionContext())
297         builder.setLabelForCell(cell, String::format("url %s", thisObject->scriptExecutionContext()->url().string().utf8().data()));
298     Base::heapSnapshot(cell, builder);
299 }
300
301 bool JSReadOnlyMapLikeOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
302 {
303     UNUSED_PARAM(handle);
304     UNUSED_PARAM(visitor);
305     UNUSED_PARAM(reason);
306     return false;
307 }
308
309 void JSReadOnlyMapLikeOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
310 {
311     auto* jsReadOnlyMapLike = static_cast<JSReadOnlyMapLike*>(handle.slot()->asCell());
312     auto& world = *static_cast<DOMWrapperWorld*>(context);
313     uncacheWrapper(world, &jsReadOnlyMapLike->wrapped(), jsReadOnlyMapLike);
314 }
315
316 #if ENABLE(BINDING_INTEGRITY)
317 #if PLATFORM(WIN)
318 #pragma warning(disable: 4483)
319 extern "C" { extern void (*const __identifier("??_7ReadOnlyMapLike@WebCore@@6B@")[])(); }
320 #else
321 extern "C" { extern void* _ZTVN7WebCore15ReadOnlyMapLikeE[]; }
322 #endif
323 #endif
324
325 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<ReadOnlyMapLike>&& impl)
326 {
327
328 #if ENABLE(BINDING_INTEGRITY)
329     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
330 #if PLATFORM(WIN)
331     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7ReadOnlyMapLike@WebCore@@6B@"));
332 #else
333     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore15ReadOnlyMapLikeE[2]);
334 #endif
335
336     // If this fails ReadOnlyMapLike does not have a vtable, so you need to add the
337     // ImplementationLacksVTable attribute to the interface definition
338     static_assert(std::is_polymorphic<ReadOnlyMapLike>::value, "ReadOnlyMapLike is not polymorphic");
339
340     // If you hit this assertion you either have a use after free bug, or
341     // ReadOnlyMapLike has subclasses. If ReadOnlyMapLike has subclasses that get passed
342     // to toJS() we currently require ReadOnlyMapLike you to opt out of binding hardening
343     // by adding the SkipVTableValidation attribute to the interface IDL definition
344     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
345 #endif
346     return createWrapper<ReadOnlyMapLike>(globalObject, WTFMove(impl));
347 }
348
349 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, ReadOnlyMapLike& impl)
350 {
351     return wrap(state, globalObject, impl);
352 }
353
354 ReadOnlyMapLike* JSReadOnlyMapLike::toWrapped(JSC::VM& vm, JSC::JSValue value)
355 {
356     if (auto* wrapper = jsDynamicCast<JSReadOnlyMapLike*>(vm, value))
357         return &wrapper->wrapped();
358     return nullptr;
359 }
360
361 }