Reduce memory use for static property maps
[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 void JSTestActiveDOMObject::finishCreation(VM& vm)
125 {
126     Base::finishCreation(vm);
127     ASSERT(inherits(info()));
128 }
129
130 JSObject* JSTestActiveDOMObject::createPrototype(VM& vm, JSGlobalObject* globalObject)
131 {
132     return JSTestActiveDOMObjectPrototype::create(vm, globalObject, JSTestActiveDOMObjectPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
133 }
134
135 void JSTestActiveDOMObject::destroy(JSC::JSCell* cell)
136 {
137     JSTestActiveDOMObject* thisObject = static_cast<JSTestActiveDOMObject*>(cell);
138     thisObject->JSTestActiveDOMObject::~JSTestActiveDOMObject();
139 }
140
141 JSTestActiveDOMObject::~JSTestActiveDOMObject()
142 {
143     releaseImplIfNotNull();
144 }
145
146 bool JSTestActiveDOMObject::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
147 {
148     JSTestActiveDOMObject* thisObject = jsCast<JSTestActiveDOMObject*>(object);
149     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
150     return getStaticValueSlot<JSTestActiveDOMObject, Base>(exec, JSTestActiveDOMObjectTable, thisObject, propertyName, slot);
151 }
152
153 EncodedJSValue jsTestActiveDOMObjectExcitingAttr(ExecState* exec, JSObject* slotBase, EncodedJSValue thisValue, PropertyName)
154 {
155     JSTestActiveDOMObject* castedThis = jsDynamicCast<JSTestActiveDOMObject*>(JSValue::decode(thisValue));
156     UNUSED_PARAM(slotBase);
157     if (UNLIKELY(!castedThis)) {
158         if (jsDynamicCast<JSTestActiveDOMObjectPrototype*>(slotBase)) {
159             ScriptExecutionContext* scriptExecutionContext = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext();
160             scriptExecutionContext->addConsoleMessage(MessageSource::JS, MessageLevel::Error, String("Deprecated attempt to access property 'excitingAttr' on a non-TestActiveDOMObject object."));
161             return JSValue::encode(jsUndefined());
162         }
163         return throwVMTypeError(exec);
164     }
165     if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, castedThis->impl()))
166         return JSValue::encode(jsUndefined());
167     UNUSED_PARAM(exec);
168     TestActiveDOMObject& impl = castedThis->impl();
169     JSValue result = jsNumber(impl.excitingAttr());
170     return JSValue::encode(result);
171 }
172
173
174 EncodedJSValue jsTestActiveDOMObjectConstructor(ExecState* exec, JSObject* baseValue, EncodedJSValue thisValue, PropertyName)
175 {
176     UNUSED_PARAM(baseValue);
177     UNUSED_PARAM(thisValue);
178     JSTestActiveDOMObject* domObject = jsDynamicCast<JSTestActiveDOMObject*>(JSValue::decode(thisValue));
179     if (!domObject)
180         return throwVMTypeError(exec);
181     if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, domObject->impl()))
182         return JSValue::encode(jsUndefined());
183     return JSValue::encode(JSTestActiveDOMObject::getConstructor(exec->vm(), domObject->globalObject()));
184 }
185
186 JSValue JSTestActiveDOMObject::getConstructor(VM& vm, JSGlobalObject* globalObject)
187 {
188     return getDOMConstructor<JSTestActiveDOMObjectConstructor>(vm, jsCast<JSDOMGlobalObject*>(globalObject));
189 }
190
191 EncodedJSValue JSC_HOST_CALL jsTestActiveDOMObjectPrototypeFunctionExcitingFunction(ExecState* exec)
192 {
193     JSValue thisValue = exec->hostThisValue();
194     JSTestActiveDOMObject* castedThis = jsDynamicCast<JSTestActiveDOMObject*>(thisValue);
195     if (UNLIKELY(!castedThis))
196         return throwVMTypeError(exec);
197     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestActiveDOMObject::info());
198     if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, castedThis->impl()))
199         return JSValue::encode(jsUndefined());
200     TestActiveDOMObject& impl = castedThis->impl();
201     if (exec->argumentCount() < 1)
202         return throwVMError(exec, createNotEnoughArgumentsError(exec));
203     Node* nextChild(toNode(exec->argument(0)));
204     if (UNLIKELY(exec->hadException()))
205         return JSValue::encode(jsUndefined());
206     impl.excitingFunction(nextChild);
207     return JSValue::encode(jsUndefined());
208 }
209
210 EncodedJSValue JSC_HOST_CALL jsTestActiveDOMObjectPrototypeFunctionPostMessage(ExecState* exec)
211 {
212     JSValue thisValue = exec->hostThisValue();
213     JSTestActiveDOMObject* castedThis = jsDynamicCast<JSTestActiveDOMObject*>(thisValue);
214     if (UNLIKELY(!castedThis))
215         return throwVMTypeError(exec);
216     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestActiveDOMObject::info());
217     TestActiveDOMObject& impl = castedThis->impl();
218     if (exec->argumentCount() < 1)
219         return throwVMError(exec, createNotEnoughArgumentsError(exec));
220     const String& message(exec->argument(0).isEmpty() ? String() : exec->argument(0).toString(exec)->value(exec));
221     if (UNLIKELY(exec->hadException()))
222         return JSValue::encode(jsUndefined());
223     impl.postMessage(message);
224     return JSValue::encode(jsUndefined());
225 }
226
227 bool JSTestActiveDOMObjectOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
228 {
229     UNUSED_PARAM(handle);
230     UNUSED_PARAM(visitor);
231     return false;
232 }
233
234 void JSTestActiveDOMObjectOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
235 {
236     JSTestActiveDOMObject* jsTestActiveDOMObject = jsCast<JSTestActiveDOMObject*>(handle.get().asCell());
237     DOMWrapperWorld& world = *static_cast<DOMWrapperWorld*>(context);
238     uncacheWrapper(world, &jsTestActiveDOMObject->impl(), jsTestActiveDOMObject);
239     jsTestActiveDOMObject->releaseImpl();
240 }
241
242 #if ENABLE(BINDING_INTEGRITY)
243 #if PLATFORM(WIN)
244 #pragma warning(disable: 4483)
245 extern "C" { extern void (*const __identifier("??_7TestActiveDOMObject@WebCore@@6B@")[])(); }
246 #else
247 extern "C" { extern void* _ZTVN7WebCore19TestActiveDOMObjectE[]; }
248 #endif
249 #endif
250 JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, TestActiveDOMObject* impl)
251 {
252     if (!impl)
253         return jsNull();
254     if (JSValue result = getExistingWrapper<JSTestActiveDOMObject>(exec, impl))
255         return result;
256
257 #if ENABLE(BINDING_INTEGRITY)
258     void* actualVTablePointer = *(reinterpret_cast<void**>(impl));
259 #if PLATFORM(WIN)
260     void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7TestActiveDOMObject@WebCore@@6B@"));
261 #else
262     void* expectedVTablePointer = &_ZTVN7WebCore19TestActiveDOMObjectE[2];
263 #if COMPILER(CLANG)
264     // If this fails TestActiveDOMObject does not have a vtable, so you need to add the
265     // ImplementationLacksVTable attribute to the interface definition
266     COMPILE_ASSERT(__is_polymorphic(TestActiveDOMObject), TestActiveDOMObject_is_not_polymorphic);
267 #endif
268 #endif
269     // If you hit this assertion you either have a use after free bug, or
270     // TestActiveDOMObject has subclasses. If TestActiveDOMObject has subclasses that get passed
271     // to toJS() we currently require TestActiveDOMObject you to opt out of binding hardening
272     // by adding the SkipVTableValidation attribute to the interface IDL definition
273     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
274 #endif
275     return createNewWrapper<JSTestActiveDOMObject>(exec, globalObject, impl);
276 }
277
278 TestActiveDOMObject* toTestActiveDOMObject(JSC::JSValue value)
279 {
280     return value.inherits(JSTestActiveDOMObject::info()) ? &jsCast<JSTestActiveDOMObject*>(value)->impl() : 0;
281 }
282
283 }