ae18f8da960efd0957332608eb9a564a686ce0c2
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / JS / JSTestSerializedScriptValueInterface.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
23 #if ENABLE(Condition1) || ENABLE(Condition2)
24
25 #include "JSTestSerializedScriptValueInterface.h"
26
27 #include "JSDOMBinding.h"
28 #include "JSDOMConstructor.h"
29 #include "JSMessagePort.h"
30 #include "SerializedScriptValue.h"
31 #include <runtime/FunctionPrototype.h>
32 #include <wtf/GetPtr.h>
33
34 using namespace JSC;
35
36 namespace WebCore {
37
38 // Attributes
39
40 JSC::EncodedJSValue jsTestSerializedScriptValueInterfaceValue(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
41 bool setJSTestSerializedScriptValueInterfaceValue(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
42 JSC::EncodedJSValue jsTestSerializedScriptValueInterfaceReadonlyValue(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
43 JSC::EncodedJSValue jsTestSerializedScriptValueInterfaceCachedValue(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
44 bool setJSTestSerializedScriptValueInterfaceCachedValue(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
45 JSC::EncodedJSValue jsTestSerializedScriptValueInterfacePorts(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
46 JSC::EncodedJSValue jsTestSerializedScriptValueInterfaceCachedReadonlyValue(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
47 JSC::EncodedJSValue jsTestSerializedScriptValueInterfaceConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
48 bool setJSTestSerializedScriptValueInterfaceConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
49
50 class JSTestSerializedScriptValueInterfacePrototype : public JSC::JSNonFinalObject {
51 public:
52     using Base = JSC::JSNonFinalObject;
53     static JSTestSerializedScriptValueInterfacePrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
54     {
55         JSTestSerializedScriptValueInterfacePrototype* ptr = new (NotNull, JSC::allocateCell<JSTestSerializedScriptValueInterfacePrototype>(vm.heap)) JSTestSerializedScriptValueInterfacePrototype(vm, globalObject, structure);
56         ptr->finishCreation(vm);
57         return ptr;
58     }
59
60     DECLARE_INFO;
61     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
62     {
63         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
64     }
65
66 private:
67     JSTestSerializedScriptValueInterfacePrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
68         : JSC::JSNonFinalObject(vm, structure)
69     {
70     }
71
72     void finishCreation(JSC::VM&);
73 };
74
75 using JSTestSerializedScriptValueInterfaceConstructor = JSDOMConstructorNotConstructable<JSTestSerializedScriptValueInterface>;
76
77 template<> JSValue JSTestSerializedScriptValueInterfaceConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
78 {
79     UNUSED_PARAM(vm);
80     return globalObject.functionPrototype();
81 }
82
83 template<> void JSTestSerializedScriptValueInterfaceConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
84 {
85     putDirect(vm, vm.propertyNames->prototype, JSTestSerializedScriptValueInterface::prototype(vm, &globalObject), DontDelete | ReadOnly | DontEnum);
86     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("TestSerializedScriptValueInterface"))), ReadOnly | DontEnum);
87     putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontEnum);
88 }
89
90 template<> const ClassInfo JSTestSerializedScriptValueInterfaceConstructor::s_info = { "TestSerializedScriptValueInterface", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestSerializedScriptValueInterfaceConstructor) };
91
92 /* Hash table for prototype */
93
94 static const HashTableValue JSTestSerializedScriptValueInterfacePrototypeTableValues[] =
95 {
96     { "constructor", DontEnum, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestSerializedScriptValueInterfaceConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestSerializedScriptValueInterfaceConstructor) } },
97     { "value", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestSerializedScriptValueInterfaceValue), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestSerializedScriptValueInterfaceValue) } },
98     { "readonlyValue", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestSerializedScriptValueInterfaceReadonlyValue), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
99     { "cachedValue", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestSerializedScriptValueInterfaceCachedValue), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestSerializedScriptValueInterfaceCachedValue) } },
100     { "ports", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestSerializedScriptValueInterfacePorts), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
101     { "cachedReadonlyValue", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestSerializedScriptValueInterfaceCachedReadonlyValue), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
102 };
103
104 const ClassInfo JSTestSerializedScriptValueInterfacePrototype::s_info = { "TestSerializedScriptValueInterfacePrototype", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestSerializedScriptValueInterfacePrototype) };
105
106 void JSTestSerializedScriptValueInterfacePrototype::finishCreation(VM& vm)
107 {
108     Base::finishCreation(vm);
109     reifyStaticProperties(vm, JSTestSerializedScriptValueInterfacePrototypeTableValues, *this);
110 }
111
112 const ClassInfo JSTestSerializedScriptValueInterface::s_info = { "TestSerializedScriptValueInterface", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestSerializedScriptValueInterface) };
113
114 JSTestSerializedScriptValueInterface::JSTestSerializedScriptValueInterface(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestSerializedScriptValueInterface>&& impl)
115     : JSDOMWrapper<TestSerializedScriptValueInterface>(structure, globalObject, WTFMove(impl))
116 {
117 }
118
119 JSObject* JSTestSerializedScriptValueInterface::createPrototype(VM& vm, JSGlobalObject* globalObject)
120 {
121     return JSTestSerializedScriptValueInterfacePrototype::create(vm, globalObject, JSTestSerializedScriptValueInterfacePrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
122 }
123
124 JSObject* JSTestSerializedScriptValueInterface::prototype(VM& vm, JSGlobalObject* globalObject)
125 {
126     return getDOMPrototype<JSTestSerializedScriptValueInterface>(vm, globalObject);
127 }
128
129 void JSTestSerializedScriptValueInterface::destroy(JSC::JSCell* cell)
130 {
131     JSTestSerializedScriptValueInterface* thisObject = static_cast<JSTestSerializedScriptValueInterface*>(cell);
132     thisObject->JSTestSerializedScriptValueInterface::~JSTestSerializedScriptValueInterface();
133 }
134
135 inline JSTestSerializedScriptValueInterface* JSTestSerializedScriptValueInterface::castForAttribute(JSC::ExecState*, EncodedJSValue thisValue)
136 {
137     return jsDynamicCast<JSTestSerializedScriptValueInterface*>(JSValue::decode(thisValue));
138 }
139
140 static inline JSValue jsTestSerializedScriptValueInterfaceValueGetter(ExecState*, JSTestSerializedScriptValueInterface*, ThrowScope& throwScope);
141
142 EncodedJSValue jsTestSerializedScriptValueInterfaceValue(ExecState* state, EncodedJSValue thisValue, PropertyName)
143 {
144     return BindingCaller<JSTestSerializedScriptValueInterface>::attribute<jsTestSerializedScriptValueInterfaceValueGetter>(state, thisValue, "value");
145 }
146
147 static inline JSValue jsTestSerializedScriptValueInterfaceValueGetter(ExecState* state, JSTestSerializedScriptValueInterface* thisObject, ThrowScope& throwScope)
148 {
149     UNUSED_PARAM(throwScope);
150     UNUSED_PARAM(state);
151     auto& impl = thisObject->wrapped();
152     JSValue result = impl.value() ? impl.value()->deserialize(state, thisObject->globalObject(), 0) : jsNull();
153     return result;
154 }
155
156 static inline JSValue jsTestSerializedScriptValueInterfaceReadonlyValueGetter(ExecState*, JSTestSerializedScriptValueInterface*, ThrowScope& throwScope);
157
158 EncodedJSValue jsTestSerializedScriptValueInterfaceReadonlyValue(ExecState* state, EncodedJSValue thisValue, PropertyName)
159 {
160     return BindingCaller<JSTestSerializedScriptValueInterface>::attribute<jsTestSerializedScriptValueInterfaceReadonlyValueGetter>(state, thisValue, "readonlyValue");
161 }
162
163 static inline JSValue jsTestSerializedScriptValueInterfaceReadonlyValueGetter(ExecState* state, JSTestSerializedScriptValueInterface* thisObject, ThrowScope& throwScope)
164 {
165     UNUSED_PARAM(throwScope);
166     UNUSED_PARAM(state);
167     auto& impl = thisObject->wrapped();
168     JSValue result = impl.readonlyValue() ? impl.readonlyValue()->deserialize(state, thisObject->globalObject(), 0) : jsNull();
169     return result;
170 }
171
172 static inline JSValue jsTestSerializedScriptValueInterfaceCachedValueGetter(ExecState*, JSTestSerializedScriptValueInterface*, ThrowScope& throwScope);
173
174 EncodedJSValue jsTestSerializedScriptValueInterfaceCachedValue(ExecState* state, EncodedJSValue thisValue, PropertyName)
175 {
176     return BindingCaller<JSTestSerializedScriptValueInterface>::attribute<jsTestSerializedScriptValueInterfaceCachedValueGetter>(state, thisValue, "cachedValue");
177 }
178
179 static inline JSValue jsTestSerializedScriptValueInterfaceCachedValueGetter(ExecState* state, JSTestSerializedScriptValueInterface* thisObject, ThrowScope& throwScope)
180 {
181     UNUSED_PARAM(throwScope);
182     UNUSED_PARAM(state);
183     if (JSValue cachedValue = thisObject->m_cachedValue.get())
184         return cachedValue;
185     auto& impl = thisObject->wrapped();
186     JSValue result = impl.cachedValue() ? impl.cachedValue()->deserialize(state, thisObject->globalObject(), 0) : jsNull();
187     thisObject->m_cachedValue.set(state->vm(), thisObject, result);
188     return result;
189 }
190
191 static inline JSValue jsTestSerializedScriptValueInterfacePortsGetter(ExecState*, JSTestSerializedScriptValueInterface*, ThrowScope& throwScope);
192
193 EncodedJSValue jsTestSerializedScriptValueInterfacePorts(ExecState* state, EncodedJSValue thisValue, PropertyName)
194 {
195     return BindingCaller<JSTestSerializedScriptValueInterface>::attribute<jsTestSerializedScriptValueInterfacePortsGetter>(state, thisValue, "ports");
196 }
197
198 static inline JSValue jsTestSerializedScriptValueInterfacePortsGetter(ExecState* state, JSTestSerializedScriptValueInterface* thisObject, ThrowScope& throwScope)
199 {
200     UNUSED_PARAM(throwScope);
201     UNUSED_PARAM(state);
202     auto& impl = thisObject->wrapped();
203     JSValue result = jsArray(state, thisObject->globalObject(), impl.ports());
204     return result;
205 }
206
207 static inline JSValue jsTestSerializedScriptValueInterfaceCachedReadonlyValueGetter(ExecState*, JSTestSerializedScriptValueInterface*, ThrowScope& throwScope);
208
209 EncodedJSValue jsTestSerializedScriptValueInterfaceCachedReadonlyValue(ExecState* state, EncodedJSValue thisValue, PropertyName)
210 {
211     return BindingCaller<JSTestSerializedScriptValueInterface>::attribute<jsTestSerializedScriptValueInterfaceCachedReadonlyValueGetter>(state, thisValue, "cachedReadonlyValue");
212 }
213
214 static inline JSValue jsTestSerializedScriptValueInterfaceCachedReadonlyValueGetter(ExecState* state, JSTestSerializedScriptValueInterface* thisObject, ThrowScope& throwScope)
215 {
216     UNUSED_PARAM(throwScope);
217     UNUSED_PARAM(state);
218     if (JSValue cachedValue = thisObject->m_cachedReadonlyValue.get())
219         return cachedValue;
220     auto& impl = thisObject->wrapped();
221     JSValue result = impl.cachedReadonlyValue() ? impl.cachedReadonlyValue()->deserialize(state, thisObject->globalObject(), 0) : jsNull();
222     thisObject->m_cachedReadonlyValue.set(state->vm(), thisObject, result);
223     return result;
224 }
225
226 EncodedJSValue jsTestSerializedScriptValueInterfaceConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
227 {
228     VM& vm = state->vm();
229     auto throwScope = DECLARE_THROW_SCOPE(vm);
230     JSTestSerializedScriptValueInterfacePrototype* domObject = jsDynamicCast<JSTestSerializedScriptValueInterfacePrototype*>(JSValue::decode(thisValue));
231     if (UNLIKELY(!domObject))
232         return throwVMTypeError(state, throwScope);
233     return JSValue::encode(JSTestSerializedScriptValueInterface::getConstructor(state->vm(), domObject->globalObject()));
234 }
235
236 bool setJSTestSerializedScriptValueInterfaceConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
237 {
238     VM& vm = state->vm();
239     auto throwScope = DECLARE_THROW_SCOPE(vm);
240     JSValue value = JSValue::decode(encodedValue);
241     JSTestSerializedScriptValueInterfacePrototype* domObject = jsDynamicCast<JSTestSerializedScriptValueInterfacePrototype*>(JSValue::decode(thisValue));
242     if (UNLIKELY(!domObject)) {
243         throwVMTypeError(state, throwScope);
244         return false;
245     }
246     // Shadowing a built-in constructor
247     return domObject->putDirect(state->vm(), state->propertyNames().constructor, value);
248 }
249
250 bool setJSTestSerializedScriptValueInterfaceValue(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
251 {
252     VM& vm = state->vm();
253     auto throwScope = DECLARE_THROW_SCOPE(vm);
254     UNUSED_PARAM(throwScope);
255     JSValue value = JSValue::decode(encodedValue);
256     UNUSED_PARAM(thisValue);
257     JSTestSerializedScriptValueInterface* castedThis = jsDynamicCast<JSTestSerializedScriptValueInterface*>(JSValue::decode(thisValue));
258     if (UNLIKELY(!castedThis))
259         return throwSetterTypeError(*state, throwScope, "TestSerializedScriptValueInterface", "value");
260     auto& impl = castedThis->wrapped();
261     auto nativeValue = SerializedScriptValue::create(state, value, 0, 0);
262     RETURN_IF_EXCEPTION(throwScope, false);
263     impl.setValue(WTFMove(nativeValue));
264     return true;
265 }
266
267
268 bool setJSTestSerializedScriptValueInterfaceCachedValue(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
269 {
270     VM& vm = state->vm();
271     auto throwScope = DECLARE_THROW_SCOPE(vm);
272     UNUSED_PARAM(throwScope);
273     JSValue value = JSValue::decode(encodedValue);
274     UNUSED_PARAM(thisValue);
275     JSTestSerializedScriptValueInterface* castedThis = jsDynamicCast<JSTestSerializedScriptValueInterface*>(JSValue::decode(thisValue));
276     if (UNLIKELY(!castedThis))
277         return throwSetterTypeError(*state, throwScope, "TestSerializedScriptValueInterface", "cachedValue");
278     auto& impl = castedThis->wrapped();
279     auto nativeValue = SerializedScriptValue::create(state, value, 0, 0);
280     RETURN_IF_EXCEPTION(throwScope, false);
281     impl.setCachedValue(WTFMove(nativeValue));
282     return true;
283 }
284
285
286 JSValue JSTestSerializedScriptValueInterface::getConstructor(VM& vm, const JSGlobalObject* globalObject)
287 {
288     return getDOMConstructor<JSTestSerializedScriptValueInterfaceConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
289 }
290
291 void JSTestSerializedScriptValueInterface::visitChildren(JSCell* cell, SlotVisitor& visitor)
292 {
293     auto* thisObject = jsCast<JSTestSerializedScriptValueInterface*>(cell);
294     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
295     Base::visitChildren(thisObject, visitor);
296     visitor.append(&thisObject->m_cachedValue);
297     visitor.append(&thisObject->m_cachedReadonlyValue);
298 }
299
300 bool JSTestSerializedScriptValueInterfaceOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
301 {
302     UNUSED_PARAM(handle);
303     UNUSED_PARAM(visitor);
304     return false;
305 }
306
307 void JSTestSerializedScriptValueInterfaceOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
308 {
309     auto* jsTestSerializedScriptValueInterface = jsCast<JSTestSerializedScriptValueInterface*>(handle.slot()->asCell());
310     auto& world = *static_cast<DOMWrapperWorld*>(context);
311     uncacheWrapper(world, &jsTestSerializedScriptValueInterface->wrapped(), jsTestSerializedScriptValueInterface);
312 }
313
314 #if ENABLE(BINDING_INTEGRITY)
315 #if PLATFORM(WIN)
316 #pragma warning(disable: 4483)
317 extern "C" { extern void (*const __identifier("??_7TestSerializedScriptValueInterface@WebCore@@6B@")[])(); }
318 #else
319 extern "C" { extern void* _ZTVN7WebCore34TestSerializedScriptValueInterfaceE[]; }
320 #endif
321 #endif
322
323 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestSerializedScriptValueInterface>&& impl)
324 {
325
326 #if ENABLE(BINDING_INTEGRITY)
327     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
328 #if PLATFORM(WIN)
329     void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7TestSerializedScriptValueInterface@WebCore@@6B@"));
330 #else
331     void* expectedVTablePointer = &_ZTVN7WebCore34TestSerializedScriptValueInterfaceE[2];
332 #if COMPILER(CLANG)
333     // If this fails TestSerializedScriptValueInterface does not have a vtable, so you need to add the
334     // ImplementationLacksVTable attribute to the interface definition
335     static_assert(__is_polymorphic(TestSerializedScriptValueInterface), "TestSerializedScriptValueInterface is not polymorphic");
336 #endif
337 #endif
338     // If you hit this assertion you either have a use after free bug, or
339     // TestSerializedScriptValueInterface has subclasses. If TestSerializedScriptValueInterface has subclasses that get passed
340     // to toJS() we currently require TestSerializedScriptValueInterface you to opt out of binding hardening
341     // by adding the SkipVTableValidation attribute to the interface IDL definition
342     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
343 #endif
344     return createWrapper<TestSerializedScriptValueInterface>(globalObject, WTFMove(impl));
345 }
346
347 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestSerializedScriptValueInterface& impl)
348 {
349     return wrap(state, globalObject, impl);
350 }
351
352 TestSerializedScriptValueInterface* JSTestSerializedScriptValueInterface::toWrapped(JSC::JSValue value)
353 {
354     if (auto* wrapper = jsDynamicCast<JSTestSerializedScriptValueInterface*>(value))
355         return &wrapper->wrapped();
356     return nullptr;
357 }
358
359 }
360
361 #endif // ENABLE(Condition1) || ENABLE(Condition2)