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