ce60eb441f705bcf94f20ee8a918756508e1326a
[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     typedef JSC::JSNonFinalObject Base;
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 typedef JSDOMConstructorNotConstructable<JSTestSerializedScriptValueInterface> JSTestSerializedScriptValueInterfaceConstructor;
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 EncodedJSValue jsTestSerializedScriptValueInterfaceValue(ExecState* state, EncodedJSValue thisValue, PropertyName)
136 {
137     VM& vm = state->vm();
138     auto throwScope = DECLARE_THROW_SCOPE(vm);
139     UNUSED_PARAM(throwScope);
140     UNUSED_PARAM(thisValue);
141     JSValue decodedThisValue = JSValue::decode(thisValue);
142     auto* castedThis = jsDynamicCast<JSTestSerializedScriptValueInterface*>(decodedThisValue);
143     if (UNLIKELY(!castedThis)) {
144         return throwGetterTypeError(*state, throwScope, "TestSerializedScriptValueInterface", "value");
145     }
146     auto& impl = castedThis->wrapped();
147     JSValue result = impl.value() ? impl.value()->deserialize(state, castedThis->globalObject(), 0) : jsNull();
148     return JSValue::encode(result);
149 }
150
151
152 EncodedJSValue jsTestSerializedScriptValueInterfaceReadonlyValue(ExecState* state, EncodedJSValue thisValue, PropertyName)
153 {
154     VM& vm = state->vm();
155     auto throwScope = DECLARE_THROW_SCOPE(vm);
156     UNUSED_PARAM(throwScope);
157     UNUSED_PARAM(thisValue);
158     JSValue decodedThisValue = JSValue::decode(thisValue);
159     auto* castedThis = jsDynamicCast<JSTestSerializedScriptValueInterface*>(decodedThisValue);
160     if (UNLIKELY(!castedThis)) {
161         return throwGetterTypeError(*state, throwScope, "TestSerializedScriptValueInterface", "readonlyValue");
162     }
163     auto& impl = castedThis->wrapped();
164     JSValue result = impl.readonlyValue() ? impl.readonlyValue()->deserialize(state, castedThis->globalObject(), 0) : jsNull();
165     return JSValue::encode(result);
166 }
167
168
169 EncodedJSValue jsTestSerializedScriptValueInterfaceCachedValue(ExecState* state, EncodedJSValue thisValue, PropertyName)
170 {
171     VM& vm = state->vm();
172     auto throwScope = DECLARE_THROW_SCOPE(vm);
173     UNUSED_PARAM(throwScope);
174     UNUSED_PARAM(thisValue);
175     JSValue decodedThisValue = JSValue::decode(thisValue);
176     auto* castedThis = jsDynamicCast<JSTestSerializedScriptValueInterface*>(decodedThisValue);
177     if (UNLIKELY(!castedThis)) {
178         return throwGetterTypeError(*state, throwScope, "TestSerializedScriptValueInterface", "cachedValue");
179     }
180     if (JSValue cachedValue = castedThis->m_cachedValue.get())
181         return JSValue::encode(cachedValue);
182     auto& impl = castedThis->wrapped();
183     JSValue result = impl.cachedValue() ? impl.cachedValue()->deserialize(state, castedThis->globalObject(), 0) : jsNull();
184     castedThis->m_cachedValue.set(state->vm(), castedThis, result);
185     return JSValue::encode(result);
186 }
187
188
189 EncodedJSValue jsTestSerializedScriptValueInterfacePorts(ExecState* state, EncodedJSValue thisValue, PropertyName)
190 {
191     VM& vm = state->vm();
192     auto throwScope = DECLARE_THROW_SCOPE(vm);
193     UNUSED_PARAM(throwScope);
194     UNUSED_PARAM(thisValue);
195     JSValue decodedThisValue = JSValue::decode(thisValue);
196     auto* castedThis = jsDynamicCast<JSTestSerializedScriptValueInterface*>(decodedThisValue);
197     if (UNLIKELY(!castedThis)) {
198         return throwGetterTypeError(*state, throwScope, "TestSerializedScriptValueInterface", "ports");
199     }
200     auto& impl = castedThis->wrapped();
201     JSValue result = jsArray(state, castedThis->globalObject(), impl.ports());
202     return JSValue::encode(result);
203 }
204
205
206 EncodedJSValue jsTestSerializedScriptValueInterfaceCachedReadonlyValue(ExecState* state, EncodedJSValue thisValue, PropertyName)
207 {
208     VM& vm = state->vm();
209     auto throwScope = DECLARE_THROW_SCOPE(vm);
210     UNUSED_PARAM(throwScope);
211     UNUSED_PARAM(thisValue);
212     JSValue decodedThisValue = JSValue::decode(thisValue);
213     auto* castedThis = jsDynamicCast<JSTestSerializedScriptValueInterface*>(decodedThisValue);
214     if (UNLIKELY(!castedThis)) {
215         return throwGetterTypeError(*state, throwScope, "TestSerializedScriptValueInterface", "cachedReadonlyValue");
216     }
217     if (JSValue cachedValue = castedThis->m_cachedReadonlyValue.get())
218         return JSValue::encode(cachedValue);
219     auto& impl = castedThis->wrapped();
220     JSValue result = impl.cachedReadonlyValue() ? impl.cachedReadonlyValue()->deserialize(state, castedThis->globalObject(), 0) : jsNull();
221     castedThis->m_cachedReadonlyValue.set(state->vm(), castedThis, result);
222     return JSValue::encode(result);
223 }
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     }
261     auto& impl = castedThis->wrapped();
262     auto nativeValue = SerializedScriptValue::create(state, value, 0, 0);
263     RETURN_IF_EXCEPTION(throwScope, false);
264     impl.setValue(WTFMove(nativeValue));
265     return true;
266 }
267
268
269 bool setJSTestSerializedScriptValueInterfaceCachedValue(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
270 {
271     VM& vm = state->vm();
272     auto throwScope = DECLARE_THROW_SCOPE(vm);
273     UNUSED_PARAM(throwScope);
274     JSValue value = JSValue::decode(encodedValue);
275     UNUSED_PARAM(thisValue);
276     JSTestSerializedScriptValueInterface* castedThis = jsDynamicCast<JSTestSerializedScriptValueInterface*>(JSValue::decode(thisValue));
277     if (UNLIKELY(!castedThis)) {
278         return throwSetterTypeError(*state, throwScope, "TestSerializedScriptValueInterface", "cachedValue");
279     }
280     auto& impl = castedThis->wrapped();
281     auto nativeValue = SerializedScriptValue::create(state, value, 0, 0);
282     RETURN_IF_EXCEPTION(throwScope, false);
283     impl.setCachedValue(WTFMove(nativeValue));
284     return true;
285 }
286
287
288 JSValue JSTestSerializedScriptValueInterface::getConstructor(VM& vm, const JSGlobalObject* globalObject)
289 {
290     return getDOMConstructor<JSTestSerializedScriptValueInterfaceConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
291 }
292
293 void JSTestSerializedScriptValueInterface::visitChildren(JSCell* cell, SlotVisitor& visitor)
294 {
295     auto* thisObject = jsCast<JSTestSerializedScriptValueInterface*>(cell);
296     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
297     Base::visitChildren(thisObject, visitor);
298     visitor.append(&thisObject->m_cachedValue);
299     visitor.append(&thisObject->m_cachedReadonlyValue);
300 }
301
302 bool JSTestSerializedScriptValueInterfaceOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
303 {
304     UNUSED_PARAM(handle);
305     UNUSED_PARAM(visitor);
306     return false;
307 }
308
309 void JSTestSerializedScriptValueInterfaceOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
310 {
311     auto* jsTestSerializedScriptValueInterface = jsCast<JSTestSerializedScriptValueInterface*>(handle.slot()->asCell());
312     auto& world = *static_cast<DOMWrapperWorld*>(context);
313     uncacheWrapper(world, &jsTestSerializedScriptValueInterface->wrapped(), jsTestSerializedScriptValueInterface);
314 }
315
316 #if ENABLE(BINDING_INTEGRITY)
317 #if PLATFORM(WIN)
318 #pragma warning(disable: 4483)
319 extern "C" { extern void (*const __identifier("??_7TestSerializedScriptValueInterface@WebCore@@6B@")[])(); }
320 #else
321 extern "C" { extern void* _ZTVN7WebCore34TestSerializedScriptValueInterfaceE[]; }
322 #endif
323 #endif
324
325 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestSerializedScriptValueInterface>&& impl)
326 {
327
328 #if ENABLE(BINDING_INTEGRITY)
329     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
330 #if PLATFORM(WIN)
331     void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7TestSerializedScriptValueInterface@WebCore@@6B@"));
332 #else
333     void* expectedVTablePointer = &_ZTVN7WebCore34TestSerializedScriptValueInterfaceE[2];
334 #if COMPILER(CLANG)
335     // If this fails TestSerializedScriptValueInterface does not have a vtable, so you need to add the
336     // ImplementationLacksVTable attribute to the interface definition
337     static_assert(__is_polymorphic(TestSerializedScriptValueInterface), "TestSerializedScriptValueInterface is not polymorphic");
338 #endif
339 #endif
340     // If you hit this assertion you either have a use after free bug, or
341     // TestSerializedScriptValueInterface has subclasses. If TestSerializedScriptValueInterface has subclasses that get passed
342     // to toJS() we currently require TestSerializedScriptValueInterface 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<TestSerializedScriptValueInterface>(globalObject, WTFMove(impl));
347 }
348
349 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestSerializedScriptValueInterface& impl)
350 {
351     return wrap(state, globalObject, impl);
352 }
353
354 TestSerializedScriptValueInterface* JSTestSerializedScriptValueInterface::toWrapped(JSC::JSValue value)
355 {
356     if (auto* wrapper = jsDynamicCast<JSTestSerializedScriptValueInterface*>(value))
357         return &wrapper->wrapped();
358     return nullptr;
359 }
360
361 }
362
363 #endif // ENABLE(Condition1) || ENABLE(Condition2)