cfa281013c1ba1e06af7fb09a2be23a460a843b1
[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/HeapAnalyzer.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::JSGlobalObject*, JSC::CallFrame*);
49 JSC::EncodedJSValue JSC_HOST_CALL jsReadOnlyMapLikePrototypeFunctionHas(JSC::JSGlobalObject*, JSC::CallFrame*);
50 JSC::EncodedJSValue JSC_HOST_CALL jsReadOnlyMapLikePrototypeFunctionEntries(JSC::JSGlobalObject*, JSC::CallFrame*);
51 JSC::EncodedJSValue JSC_HOST_CALL jsReadOnlyMapLikePrototypeFunctionKeys(JSC::JSGlobalObject*, JSC::CallFrame*);
52 JSC::EncodedJSValue JSC_HOST_CALL jsReadOnlyMapLikePrototypeFunctionValues(JSC::JSGlobalObject*, JSC::CallFrame*);
53 JSC::EncodedJSValue JSC_HOST_CALL jsReadOnlyMapLikePrototypeFunctionForEach(JSC::JSGlobalObject*, JSC::CallFrame*);
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(JSGlobalObject* globalObject, CallFrame* state)
220 {
221     UNUSED_PARAM(globalObject);
222     return IDLOperation<JSReadOnlyMapLike>::call<jsReadOnlyMapLikePrototypeFunctionGetBody>(*state, "get");
223 }
224
225 static inline JSC::EncodedJSValue jsReadOnlyMapLikePrototypeFunctionHasBody(JSC::ExecState* state, typename IDLOperation<JSReadOnlyMapLike>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
226 {
227     UNUSED_PARAM(state);
228     UNUSED_PARAM(throwScope);
229     if (UNLIKELY(state->argumentCount() < 1))
230         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
231     auto key = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
232     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
233     return JSValue::encode(toJS<IDLAny>(forwardHasToMapLike(*state, *castedThis, WTFMove(key))));
234 }
235
236 EncodedJSValue JSC_HOST_CALL jsReadOnlyMapLikePrototypeFunctionHas(JSGlobalObject* globalObject, CallFrame* state)
237 {
238     UNUSED_PARAM(globalObject);
239     return IDLOperation<JSReadOnlyMapLike>::call<jsReadOnlyMapLikePrototypeFunctionHasBody>(*state, "has");
240 }
241
242 static inline JSC::EncodedJSValue jsReadOnlyMapLikePrototypeFunctionEntriesBody(JSC::ExecState* state, typename IDLOperation<JSReadOnlyMapLike>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
243 {
244     UNUSED_PARAM(state);
245     UNUSED_PARAM(throwScope);
246     return JSValue::encode(toJS<IDLAny>(forwardEntriesToMapLike(*state, *castedThis)));
247 }
248
249 EncodedJSValue JSC_HOST_CALL jsReadOnlyMapLikePrototypeFunctionEntries(JSGlobalObject* globalObject, CallFrame* state)
250 {
251     UNUSED_PARAM(globalObject);
252     return IDLOperation<JSReadOnlyMapLike>::call<jsReadOnlyMapLikePrototypeFunctionEntriesBody>(*state, "entries");
253 }
254
255 static inline JSC::EncodedJSValue jsReadOnlyMapLikePrototypeFunctionKeysBody(JSC::ExecState* state, typename IDLOperation<JSReadOnlyMapLike>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
256 {
257     UNUSED_PARAM(state);
258     UNUSED_PARAM(throwScope);
259     return JSValue::encode(toJS<IDLAny>(forwardKeysToMapLike(*state, *castedThis)));
260 }
261
262 EncodedJSValue JSC_HOST_CALL jsReadOnlyMapLikePrototypeFunctionKeys(JSGlobalObject* globalObject, CallFrame* state)
263 {
264     UNUSED_PARAM(globalObject);
265     return IDLOperation<JSReadOnlyMapLike>::call<jsReadOnlyMapLikePrototypeFunctionKeysBody>(*state, "keys");
266 }
267
268 static inline JSC::EncodedJSValue jsReadOnlyMapLikePrototypeFunctionValuesBody(JSC::ExecState* state, typename IDLOperation<JSReadOnlyMapLike>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
269 {
270     UNUSED_PARAM(state);
271     UNUSED_PARAM(throwScope);
272     return JSValue::encode(toJS<IDLAny>(forwardValuesToMapLike(*state, *castedThis)));
273 }
274
275 EncodedJSValue JSC_HOST_CALL jsReadOnlyMapLikePrototypeFunctionValues(JSGlobalObject* globalObject, CallFrame* state)
276 {
277     UNUSED_PARAM(globalObject);
278     return IDLOperation<JSReadOnlyMapLike>::call<jsReadOnlyMapLikePrototypeFunctionValuesBody>(*state, "values");
279 }
280
281 static inline JSC::EncodedJSValue jsReadOnlyMapLikePrototypeFunctionForEachBody(JSC::ExecState* state, typename IDLOperation<JSReadOnlyMapLike>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
282 {
283     UNUSED_PARAM(state);
284     UNUSED_PARAM(throwScope);
285     if (UNLIKELY(state->argumentCount() < 1))
286         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
287     auto callback = convert<IDLAny>(*state, state->uncheckedArgument(0));
288     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
289     return JSValue::encode(toJS<IDLAny>(forwardForEachToMapLike(*state, *castedThis, WTFMove(callback))));
290 }
291
292 EncodedJSValue JSC_HOST_CALL jsReadOnlyMapLikePrototypeFunctionForEach(JSGlobalObject* globalObject, CallFrame* state)
293 {
294     UNUSED_PARAM(globalObject);
295     return IDLOperation<JSReadOnlyMapLike>::call<jsReadOnlyMapLikePrototypeFunctionForEachBody>(*state, "forEach");
296 }
297
298 void JSReadOnlyMapLike::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer)
299 {
300     auto* thisObject = jsCast<JSReadOnlyMapLike*>(cell);
301     analyzer.setWrappedObjectForCell(cell, &thisObject->wrapped());
302     if (thisObject->scriptExecutionContext())
303         analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
304     Base::analyzeHeap(cell, analyzer);
305 }
306
307 bool JSReadOnlyMapLikeOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
308 {
309     UNUSED_PARAM(handle);
310     UNUSED_PARAM(visitor);
311     UNUSED_PARAM(reason);
312     return false;
313 }
314
315 void JSReadOnlyMapLikeOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
316 {
317     auto* jsReadOnlyMapLike = static_cast<JSReadOnlyMapLike*>(handle.slot()->asCell());
318     auto& world = *static_cast<DOMWrapperWorld*>(context);
319     uncacheWrapper(world, &jsReadOnlyMapLike->wrapped(), jsReadOnlyMapLike);
320 }
321
322 #if ENABLE(BINDING_INTEGRITY)
323 #if PLATFORM(WIN)
324 #pragma warning(disable: 4483)
325 extern "C" { extern void (*const __identifier("??_7ReadOnlyMapLike@WebCore@@6B@")[])(); }
326 #else
327 extern "C" { extern void* _ZTVN7WebCore15ReadOnlyMapLikeE[]; }
328 #endif
329 #endif
330
331 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<ReadOnlyMapLike>&& impl)
332 {
333
334 #if ENABLE(BINDING_INTEGRITY)
335     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
336 #if PLATFORM(WIN)
337     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7ReadOnlyMapLike@WebCore@@6B@"));
338 #else
339     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore15ReadOnlyMapLikeE[2]);
340 #endif
341
342     // If this fails ReadOnlyMapLike does not have a vtable, so you need to add the
343     // ImplementationLacksVTable attribute to the interface definition
344     static_assert(std::is_polymorphic<ReadOnlyMapLike>::value, "ReadOnlyMapLike is not polymorphic");
345
346     // If you hit this assertion you either have a use after free bug, or
347     // ReadOnlyMapLike has subclasses. If ReadOnlyMapLike has subclasses that get passed
348     // to toJS() we currently require ReadOnlyMapLike you to opt out of binding hardening
349     // by adding the SkipVTableValidation attribute to the interface IDL definition
350     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
351 #endif
352     return createWrapper<ReadOnlyMapLike>(globalObject, WTFMove(impl));
353 }
354
355 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, ReadOnlyMapLike& impl)
356 {
357     return wrap(state, globalObject, impl);
358 }
359
360 ReadOnlyMapLike* JSReadOnlyMapLike::toWrapped(JSC::VM& vm, JSC::JSValue value)
361 {
362     if (auto* wrapper = jsDynamicCast<JSReadOnlyMapLike*>(vm, value))
363         return &wrapper->wrapped();
364     return nullptr;
365 }
366
367 }