JSGenerateToNativeObject should use fast JSNode/JSElement casts.
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / JS / JSTestActiveDOMObject.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 "JSTestActiveDOMObject.h"
23
24 #include "ExceptionCode.h"
25 #include "JSDOMBinding.h"
26 #include "JSNode.h"
27 #include "ScriptExecutionContext.h"
28 #include "TestActiveDOMObject.h"
29 #include <runtime/Error.h>
30 #include <wtf/GetPtr.h>
31
32 using namespace JSC;
33
34 namespace WebCore {
35
36 /* Hash table */
37
38 static const struct CompactHashIndex JSTestActiveDOMObjectTableIndex[4] = {
39     { 1, -1 },
40     { 0, -1 },
41     { -1, -1 },
42     { -1, -1 },
43 };
44
45
46 static const HashTableValue JSTestActiveDOMObjectTableValues[] =
47 {
48     { "constructor", DontEnum | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestActiveDOMObjectConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
49     { "excitingAttr", DontDelete | ReadOnly | CustomAccessor, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestActiveDOMObjectExcitingAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
50 };
51
52 static const HashTable JSTestActiveDOMObjectTable = { 2, 3, true, JSTestActiveDOMObjectTableValues, 0, JSTestActiveDOMObjectTableIndex };
53 /* Hash table for constructor */
54
55 static const struct CompactHashIndex JSTestActiveDOMObjectConstructorTableIndex[1] = {
56     { -1, -1 },
57 };
58
59
60 static const HashTableValue JSTestActiveDOMObjectConstructorTableValues[] =
61 {
62     { 0, 0, NoIntrinsic, 0, 0 }
63 };
64
65 static const HashTable JSTestActiveDOMObjectConstructorTable = { 0, 0, false, JSTestActiveDOMObjectConstructorTableValues, 0, JSTestActiveDOMObjectConstructorTableIndex };
66 const ClassInfo JSTestActiveDOMObjectConstructor::s_info = { "TestActiveDOMObjectConstructor", &Base::s_info, &JSTestActiveDOMObjectConstructorTable, 0, CREATE_METHOD_TABLE(JSTestActiveDOMObjectConstructor) };
67
68 JSTestActiveDOMObjectConstructor::JSTestActiveDOMObjectConstructor(Structure* structure, JSDOMGlobalObject* globalObject)
69     : DOMConstructorObject(structure, globalObject)
70 {
71 }
72
73 void JSTestActiveDOMObjectConstructor::finishCreation(VM& vm, JSDOMGlobalObject* globalObject)
74 {
75     Base::finishCreation(vm);
76     ASSERT(inherits(info()));
77     putDirect(vm, vm.propertyNames->prototype, JSTestActiveDOMObjectPrototype::self(vm, globalObject), DontDelete | ReadOnly);
78     putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontDelete | DontEnum);
79 }
80
81 bool JSTestActiveDOMObjectConstructor::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
82 {
83     return getStaticValueSlot<JSTestActiveDOMObjectConstructor, JSDOMWrapper>(exec, JSTestActiveDOMObjectConstructorTable, jsCast<JSTestActiveDOMObjectConstructor*>(object), propertyName, slot);
84 }
85
86 /* Hash table for prototype */
87
88 static const struct CompactHashIndex JSTestActiveDOMObjectPrototypeTableIndex[4] = {
89     { 0, -1 },
90     { 1, -1 },
91     { -1, -1 },
92     { -1, -1 },
93 };
94
95
96 static const HashTableValue JSTestActiveDOMObjectPrototypeTableValues[] =
97 {
98     { "excitingFunction", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsTestActiveDOMObjectPrototypeFunctionExcitingFunction), (intptr_t) (1) },
99     { "postMessage", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsTestActiveDOMObjectPrototypeFunctionPostMessage), (intptr_t) (1) },
100 };
101
102 static const HashTable JSTestActiveDOMObjectPrototypeTable = { 2, 3, false, JSTestActiveDOMObjectPrototypeTableValues, 0, JSTestActiveDOMObjectPrototypeTableIndex };
103 const ClassInfo JSTestActiveDOMObjectPrototype::s_info = { "TestActiveDOMObjectPrototype", &Base::s_info, &JSTestActiveDOMObjectPrototypeTable, 0, CREATE_METHOD_TABLE(JSTestActiveDOMObjectPrototype) };
104
105 JSObject* JSTestActiveDOMObjectPrototype::self(VM& vm, JSGlobalObject* globalObject)
106 {
107     return getDOMPrototype<JSTestActiveDOMObject>(vm, globalObject);
108 }
109
110 bool JSTestActiveDOMObjectPrototype::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
111 {
112     JSTestActiveDOMObjectPrototype* thisObject = jsCast<JSTestActiveDOMObjectPrototype*>(object);
113     return getStaticFunctionSlot<JSObject>(exec, JSTestActiveDOMObjectPrototypeTable, thisObject, propertyName, slot);
114 }
115
116 const ClassInfo JSTestActiveDOMObject::s_info = { "TestActiveDOMObject", &Base::s_info, &JSTestActiveDOMObjectTable, 0 , CREATE_METHOD_TABLE(JSTestActiveDOMObject) };
117
118 JSTestActiveDOMObject::JSTestActiveDOMObject(Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<TestActiveDOMObject> impl)
119     : JSDOMWrapper(structure, globalObject)
120     , m_impl(impl.leakRef())
121 {
122 }
123
124 JSObject* JSTestActiveDOMObject::createPrototype(VM& vm, JSGlobalObject* globalObject)
125 {
126     return JSTestActiveDOMObjectPrototype::create(vm, globalObject, JSTestActiveDOMObjectPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
127 }
128
129 void JSTestActiveDOMObject::destroy(JSC::JSCell* cell)
130 {
131     JSTestActiveDOMObject* thisObject = static_cast<JSTestActiveDOMObject*>(cell);
132     thisObject->JSTestActiveDOMObject::~JSTestActiveDOMObject();
133 }
134
135 JSTestActiveDOMObject::~JSTestActiveDOMObject()
136 {
137     releaseImplIfNotNull();
138 }
139
140 bool JSTestActiveDOMObject::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
141 {
142     JSTestActiveDOMObject* thisObject = jsCast<JSTestActiveDOMObject*>(object);
143     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
144     return getStaticValueSlot<JSTestActiveDOMObject, Base>(exec, JSTestActiveDOMObjectTable, thisObject, propertyName, slot);
145 }
146
147 EncodedJSValue jsTestActiveDOMObjectExcitingAttr(ExecState* exec, JSObject* slotBase, EncodedJSValue thisValue, PropertyName)
148 {
149     JSTestActiveDOMObject* castedThis = jsDynamicCast<JSTestActiveDOMObject*>(JSValue::decode(thisValue));
150     UNUSED_PARAM(slotBase);
151     if (UNLIKELY(!castedThis)) {
152         if (jsDynamicCast<JSTestActiveDOMObjectPrototype*>(slotBase)) {
153             ScriptExecutionContext* scriptExecutionContext = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext();
154             scriptExecutionContext->addConsoleMessage(MessageSource::JS, MessageLevel::Error, String("Deprecated attempt to access property 'excitingAttr' on a non-TestActiveDOMObject object."));
155             return JSValue::encode(jsUndefined());
156         }
157         return throwVMTypeError(exec, makeDOMBindingsTypeErrorString("The ", "TestActiveDOMObject", ".", "excitingAttr", " getter can only be used on instances of ", "TestActiveDOMObject"));
158     }
159     if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, castedThis->impl()))
160         return JSValue::encode(jsUndefined());
161     UNUSED_PARAM(exec);
162     TestActiveDOMObject& impl = castedThis->impl();
163     JSValue result = jsNumber(impl.excitingAttr());
164     return JSValue::encode(result);
165 }
166
167
168 EncodedJSValue jsTestActiveDOMObjectConstructor(ExecState* exec, JSObject* baseValue, EncodedJSValue thisValue, PropertyName)
169 {
170     UNUSED_PARAM(baseValue);
171     UNUSED_PARAM(thisValue);
172     JSTestActiveDOMObject* domObject = jsDynamicCast<JSTestActiveDOMObject*>(JSValue::decode(thisValue));
173     if (!domObject)
174         return throwVMTypeError(exec);
175     if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, domObject->impl()))
176         return JSValue::encode(jsUndefined());
177     return JSValue::encode(JSTestActiveDOMObject::getConstructor(exec->vm(), domObject->globalObject()));
178 }
179
180 JSValue JSTestActiveDOMObject::getConstructor(VM& vm, JSGlobalObject* globalObject)
181 {
182     return getDOMConstructor<JSTestActiveDOMObjectConstructor>(vm, jsCast<JSDOMGlobalObject*>(globalObject));
183 }
184
185 EncodedJSValue JSC_HOST_CALL jsTestActiveDOMObjectPrototypeFunctionExcitingFunction(ExecState* exec)
186 {
187     JSValue thisValue = exec->thisValue();
188     JSTestActiveDOMObject* castedThis = jsDynamicCast<JSTestActiveDOMObject*>(thisValue);
189     if (UNLIKELY(!castedThis))
190         return throwVMTypeError(exec, makeDOMBindingsTypeErrorString("Can only call ", "TestActiveDOMObject", ".", "excitingFunction", " on instances of ", "TestActiveDOMObject"));
191     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestActiveDOMObject::info());
192     if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, castedThis->impl()))
193         return JSValue::encode(jsUndefined());
194     TestActiveDOMObject& impl = castedThis->impl();
195     if (exec->argumentCount() < 1)
196         return throwVMError(exec, createNotEnoughArgumentsError(exec));
197     Node* nextChild(toNode(exec->argument(0)));
198     if (UNLIKELY(exec->hadException()))
199         return JSValue::encode(jsUndefined());
200     impl.excitingFunction(nextChild);
201     return JSValue::encode(jsUndefined());
202 }
203
204 EncodedJSValue JSC_HOST_CALL jsTestActiveDOMObjectPrototypeFunctionPostMessage(ExecState* exec)
205 {
206     JSValue thisValue = exec->thisValue();
207     JSTestActiveDOMObject* castedThis = jsDynamicCast<JSTestActiveDOMObject*>(thisValue);
208     if (UNLIKELY(!castedThis))
209         return throwVMTypeError(exec, makeDOMBindingsTypeErrorString("Can only call ", "TestActiveDOMObject", ".", "postMessage", " on instances of ", "TestActiveDOMObject"));
210     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestActiveDOMObject::info());
211     TestActiveDOMObject& impl = castedThis->impl();
212     if (exec->argumentCount() < 1)
213         return throwVMError(exec, createNotEnoughArgumentsError(exec));
214     const String& message(exec->argument(0).isEmpty() ? String() : exec->argument(0).toString(exec)->value(exec));
215     if (UNLIKELY(exec->hadException()))
216         return JSValue::encode(jsUndefined());
217     impl.postMessage(message);
218     return JSValue::encode(jsUndefined());
219 }
220
221 bool JSTestActiveDOMObjectOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
222 {
223     UNUSED_PARAM(handle);
224     UNUSED_PARAM(visitor);
225     return false;
226 }
227
228 void JSTestActiveDOMObjectOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
229 {
230     JSTestActiveDOMObject* jsTestActiveDOMObject = jsCast<JSTestActiveDOMObject*>(handle.slot()->asCell());
231     DOMWrapperWorld& world = *static_cast<DOMWrapperWorld*>(context);
232     uncacheWrapper(world, &jsTestActiveDOMObject->impl(), jsTestActiveDOMObject);
233     jsTestActiveDOMObject->releaseImpl();
234 }
235
236 #if ENABLE(BINDING_INTEGRITY)
237 #if PLATFORM(WIN)
238 #pragma warning(disable: 4483)
239 extern "C" { extern void (*const __identifier("??_7TestActiveDOMObject@WebCore@@6B@")[])(); }
240 #else
241 extern "C" { extern void* _ZTVN7WebCore19TestActiveDOMObjectE[]; }
242 #endif
243 #endif
244 JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject* globalObject, TestActiveDOMObject* impl)
245 {
246     if (!impl)
247         return jsNull();
248     if (JSValue result = getExistingWrapper<JSTestActiveDOMObject>(globalObject, impl))
249         return result;
250
251 #if ENABLE(BINDING_INTEGRITY)
252     void* actualVTablePointer = *(reinterpret_cast<void**>(impl));
253 #if PLATFORM(WIN)
254     void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7TestActiveDOMObject@WebCore@@6B@"));
255 #else
256     void* expectedVTablePointer = &_ZTVN7WebCore19TestActiveDOMObjectE[2];
257 #if COMPILER(CLANG)
258     // If this fails TestActiveDOMObject does not have a vtable, so you need to add the
259     // ImplementationLacksVTable attribute to the interface definition
260     COMPILE_ASSERT(__is_polymorphic(TestActiveDOMObject), TestActiveDOMObject_is_not_polymorphic);
261 #endif
262 #endif
263     // If you hit this assertion you either have a use after free bug, or
264     // TestActiveDOMObject has subclasses. If TestActiveDOMObject has subclasses that get passed
265     // to toJS() we currently require TestActiveDOMObject you to opt out of binding hardening
266     // by adding the SkipVTableValidation attribute to the interface IDL definition
267     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
268 #endif
269     return createNewWrapper<JSTestActiveDOMObject>(globalObject, impl);
270 }
271
272 TestActiveDOMObject* toTestActiveDOMObject(JSC::JSValue value)
273 {
274     if (auto* wrapper = jsDynamicCast<JSTestActiveDOMObject*>(value))
275         return &wrapper->impl();
276     return nullptr;
277 }
278
279 }