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