Use LIKELY() / UNLIKELY() hints when suitable in the JavaScript bindings
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / JS / JSTestCustomConstructorWithNoInterfaceObject.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 "JSTestCustomConstructorWithNoInterfaceObject.h"
23
24 #include "JSDOMBinding.h"
25 #include "JSDOMConstructor.h"
26 #include <runtime/FunctionPrototype.h>
27 #include <wtf/GetPtr.h>
28
29 using namespace JSC;
30
31 namespace WebCore {
32
33 // Attributes
34
35 JSC::EncodedJSValue jsTestCustomConstructorWithNoInterfaceObjectConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
36 bool setJSTestCustomConstructorWithNoInterfaceObjectConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
37
38 class JSTestCustomConstructorWithNoInterfaceObjectPrototype : public JSC::JSNonFinalObject {
39 public:
40     typedef JSC::JSNonFinalObject Base;
41     static JSTestCustomConstructorWithNoInterfaceObjectPrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
42     {
43         JSTestCustomConstructorWithNoInterfaceObjectPrototype* ptr = new (NotNull, JSC::allocateCell<JSTestCustomConstructorWithNoInterfaceObjectPrototype>(vm.heap)) JSTestCustomConstructorWithNoInterfaceObjectPrototype(vm, globalObject, structure);
44         ptr->finishCreation(vm);
45         return ptr;
46     }
47
48     DECLARE_INFO;
49     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
50     {
51         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
52     }
53
54 private:
55     JSTestCustomConstructorWithNoInterfaceObjectPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
56         : JSC::JSNonFinalObject(vm, structure)
57     {
58     }
59
60     void finishCreation(JSC::VM&);
61 };
62
63 typedef JSDOMConstructor<JSTestCustomConstructorWithNoInterfaceObject> JSTestCustomConstructorWithNoInterfaceObjectConstructor;
64
65 template<> JSC::EncodedJSValue JSC_HOST_CALL JSTestCustomConstructorWithNoInterfaceObjectConstructor::construct(JSC::ExecState* state)
66 {
67     return constructJSTestCustomConstructorWithNoInterfaceObject(state);
68 }
69
70 template<> JSValue JSTestCustomConstructorWithNoInterfaceObjectConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
71 {
72     UNUSED_PARAM(vm);
73     return globalObject.functionPrototype();
74 }
75
76 template<> void JSTestCustomConstructorWithNoInterfaceObjectConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
77 {
78     putDirect(vm, vm.propertyNames->prototype, JSTestCustomConstructorWithNoInterfaceObject::prototype(vm, &globalObject), DontDelete | ReadOnly | DontEnum);
79     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("TestCustomConstructorWithNoInterfaceObject"))), ReadOnly | DontEnum);
80     putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontEnum);
81 }
82
83 template<> const ClassInfo JSTestCustomConstructorWithNoInterfaceObjectConstructor::s_info = { "TestCustomConstructorWithNoInterfaceObject", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestCustomConstructorWithNoInterfaceObjectConstructor) };
84
85 /* Hash table for prototype */
86
87 static const HashTableValue JSTestCustomConstructorWithNoInterfaceObjectPrototypeTableValues[] =
88 {
89     { "constructor", DontEnum, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestCustomConstructorWithNoInterfaceObjectConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestCustomConstructorWithNoInterfaceObjectConstructor) } },
90 };
91
92 const ClassInfo JSTestCustomConstructorWithNoInterfaceObjectPrototype::s_info = { "TestCustomConstructorWithNoInterfaceObjectPrototype", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestCustomConstructorWithNoInterfaceObjectPrototype) };
93
94 void JSTestCustomConstructorWithNoInterfaceObjectPrototype::finishCreation(VM& vm)
95 {
96     Base::finishCreation(vm);
97     reifyStaticProperties(vm, JSTestCustomConstructorWithNoInterfaceObjectPrototypeTableValues, *this);
98 }
99
100 const ClassInfo JSTestCustomConstructorWithNoInterfaceObject::s_info = { "TestCustomConstructorWithNoInterfaceObject", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestCustomConstructorWithNoInterfaceObject) };
101
102 JSTestCustomConstructorWithNoInterfaceObject::JSTestCustomConstructorWithNoInterfaceObject(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestCustomConstructorWithNoInterfaceObject>&& impl)
103     : JSDOMWrapper<TestCustomConstructorWithNoInterfaceObject>(structure, globalObject, WTFMove(impl))
104 {
105 }
106
107 JSObject* JSTestCustomConstructorWithNoInterfaceObject::createPrototype(VM& vm, JSGlobalObject* globalObject)
108 {
109     return JSTestCustomConstructorWithNoInterfaceObjectPrototype::create(vm, globalObject, JSTestCustomConstructorWithNoInterfaceObjectPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
110 }
111
112 JSObject* JSTestCustomConstructorWithNoInterfaceObject::prototype(VM& vm, JSGlobalObject* globalObject)
113 {
114     return getDOMPrototype<JSTestCustomConstructorWithNoInterfaceObject>(vm, globalObject);
115 }
116
117 void JSTestCustomConstructorWithNoInterfaceObject::destroy(JSC::JSCell* cell)
118 {
119     JSTestCustomConstructorWithNoInterfaceObject* thisObject = static_cast<JSTestCustomConstructorWithNoInterfaceObject*>(cell);
120     thisObject->JSTestCustomConstructorWithNoInterfaceObject::~JSTestCustomConstructorWithNoInterfaceObject();
121 }
122
123 EncodedJSValue jsTestCustomConstructorWithNoInterfaceObjectConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
124 {
125     JSTestCustomConstructorWithNoInterfaceObjectPrototype* domObject = jsDynamicCast<JSTestCustomConstructorWithNoInterfaceObjectPrototype*>(JSValue::decode(thisValue));
126     if (UNLIKELY(!domObject))
127         return throwVMTypeError(state);
128     JSValue constructor = JSTestCustomConstructorWithNoInterfaceObjectConstructor::create(state->vm(), JSTestCustomConstructorWithNoInterfaceObjectConstructor::createStructure(state->vm(), *domObject->globalObject(), domObject->globalObject()->objectPrototype()), *jsCast<JSDOMGlobalObject*>(domObject->globalObject()));
129     // Shadowing constructor property to ensure reusing the same constructor object
130     domObject->putDirect(state->vm(), state->propertyNames().constructor, constructor, DontEnum | ReadOnly);
131     return JSValue::encode(constructor);
132 }
133
134 bool setJSTestCustomConstructorWithNoInterfaceObjectConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
135 {
136     JSValue value = JSValue::decode(encodedValue);
137     JSTestCustomConstructorWithNoInterfaceObjectPrototype* domObject = jsDynamicCast<JSTestCustomConstructorWithNoInterfaceObjectPrototype*>(JSValue::decode(thisValue));
138     if (UNLIKELY(!domObject)) {
139         throwVMTypeError(state);
140         return false;
141     }
142     // Shadowing a built-in constructor
143     return domObject->putDirect(state->vm(), state->propertyNames().constructor, value);
144 }
145
146 bool JSTestCustomConstructorWithNoInterfaceObjectOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
147 {
148     UNUSED_PARAM(handle);
149     UNUSED_PARAM(visitor);
150     return false;
151 }
152
153 void JSTestCustomConstructorWithNoInterfaceObjectOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
154 {
155     auto* jsTestCustomConstructorWithNoInterfaceObject = jsCast<JSTestCustomConstructorWithNoInterfaceObject*>(handle.slot()->asCell());
156     auto& world = *static_cast<DOMWrapperWorld*>(context);
157     uncacheWrapper(world, &jsTestCustomConstructorWithNoInterfaceObject->wrapped(), jsTestCustomConstructorWithNoInterfaceObject);
158 }
159
160 #if ENABLE(BINDING_INTEGRITY)
161 #if PLATFORM(WIN)
162 #pragma warning(disable: 4483)
163 extern "C" { extern void (*const __identifier("??_7TestCustomConstructorWithNoInterfaceObject@WebCore@@6B@")[])(); }
164 #else
165 extern "C" { extern void* _ZTVN7WebCore42TestCustomConstructorWithNoInterfaceObjectE[]; }
166 #endif
167 #endif
168
169 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, TestCustomConstructorWithNoInterfaceObject* impl)
170 {
171     if (!impl)
172         return jsNull();
173     return createNewWrapper<JSTestCustomConstructorWithNoInterfaceObject>(globalObject, impl);
174 }
175
176 JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject* globalObject, TestCustomConstructorWithNoInterfaceObject* impl)
177 {
178     if (!impl)
179         return jsNull();
180     if (JSValue result = getExistingWrapper<JSTestCustomConstructorWithNoInterfaceObject>(globalObject, impl))
181         return result;
182
183 #if ENABLE(BINDING_INTEGRITY)
184     void* actualVTablePointer = *(reinterpret_cast<void**>(impl));
185 #if PLATFORM(WIN)
186     void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7TestCustomConstructorWithNoInterfaceObject@WebCore@@6B@"));
187 #else
188     void* expectedVTablePointer = &_ZTVN7WebCore42TestCustomConstructorWithNoInterfaceObjectE[2];
189 #if COMPILER(CLANG)
190     // If this fails TestCustomConstructorWithNoInterfaceObject does not have a vtable, so you need to add the
191     // ImplementationLacksVTable attribute to the interface definition
192     COMPILE_ASSERT(__is_polymorphic(TestCustomConstructorWithNoInterfaceObject), TestCustomConstructorWithNoInterfaceObject_is_not_polymorphic);
193 #endif
194 #endif
195     // If you hit this assertion you either have a use after free bug, or
196     // TestCustomConstructorWithNoInterfaceObject has subclasses. If TestCustomConstructorWithNoInterfaceObject has subclasses that get passed
197     // to toJS() we currently require TestCustomConstructorWithNoInterfaceObject you to opt out of binding hardening
198     // by adding the SkipVTableValidation attribute to the interface IDL definition
199     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
200 #endif
201     return createNewWrapper<JSTestCustomConstructorWithNoInterfaceObject>(globalObject, impl);
202 }
203
204 TestCustomConstructorWithNoInterfaceObject* JSTestCustomConstructorWithNoInterfaceObject::toWrapped(JSC::JSValue value)
205 {
206     if (auto* wrapper = jsDynamicCast<JSTestCustomConstructorWithNoInterfaceObject*>(value))
207         return &wrapper->wrapped();
208     return nullptr;
209 }
210
211 }