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