fe12c7e9f3403bb123e128d2302f0dde4489dda2
[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 "JSDOMConstructor.h"
27 #include "JSNode.h"
28 #include <runtime/Error.h>
29 #include <runtime/FunctionPrototype.h>
30 #include <wtf/GetPtr.h>
31
32 using namespace JSC;
33
34 namespace WebCore {
35
36 // Functions
37
38 JSC::EncodedJSValue JSC_HOST_CALL jsTestActiveDOMObjectPrototypeFunctionExcitingFunction(JSC::ExecState*);
39 JSC::EncodedJSValue JSC_HOST_CALL jsTestActiveDOMObjectPrototypeFunctionPostMessage(JSC::ExecState*);
40
41 // Attributes
42
43 JSC::EncodedJSValue jsTestActiveDOMObjectExcitingAttr(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
44 JSC::EncodedJSValue jsTestActiveDOMObjectConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
45 bool setJSTestActiveDOMObjectConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
46
47 class JSTestActiveDOMObjectPrototype : public JSC::JSNonFinalObject {
48 public:
49     typedef JSC::JSNonFinalObject Base;
50     static JSTestActiveDOMObjectPrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
51     {
52         JSTestActiveDOMObjectPrototype* ptr = new (NotNull, JSC::allocateCell<JSTestActiveDOMObjectPrototype>(vm.heap)) JSTestActiveDOMObjectPrototype(vm, globalObject, structure);
53         ptr->finishCreation(vm);
54         return ptr;
55     }
56
57     DECLARE_INFO;
58     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
59     {
60         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
61     }
62
63 private:
64     JSTestActiveDOMObjectPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
65         : JSC::JSNonFinalObject(vm, structure)
66     {
67     }
68
69     void finishCreation(JSC::VM&);
70 };
71
72 typedef JSDOMConstructorNotConstructable<JSTestActiveDOMObject> JSTestActiveDOMObjectConstructor;
73
74 /* Hash table */
75
76 static const struct CompactHashIndex JSTestActiveDOMObjectTableIndex[2] = {
77     { 0, -1 },
78     { -1, -1 },
79 };
80
81
82 static const HashTableValue JSTestActiveDOMObjectTableValues[] =
83 {
84     { "excitingAttr", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestActiveDOMObjectExcitingAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
85 };
86
87 static const HashTable JSTestActiveDOMObjectTable = { 1, 1, true, JSTestActiveDOMObjectTableValues, JSTestActiveDOMObjectTableIndex };
88 template<> JSValue JSTestActiveDOMObjectConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
89 {
90     UNUSED_PARAM(vm);
91     return globalObject.functionPrototype();
92 }
93
94 template<> void JSTestActiveDOMObjectConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
95 {
96     putDirect(vm, vm.propertyNames->prototype, JSTestActiveDOMObject::prototype(vm, &globalObject), DontDelete | ReadOnly | DontEnum);
97     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("TestActiveDOMObject"))), ReadOnly | DontEnum);
98     putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontEnum);
99 }
100
101 template<> const ClassInfo JSTestActiveDOMObjectConstructor::s_info = { "TestActiveDOMObject", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestActiveDOMObjectConstructor) };
102
103 /* Hash table for prototype */
104
105 static const HashTableValue JSTestActiveDOMObjectPrototypeTableValues[] =
106 {
107     { "constructor", DontEnum, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestActiveDOMObjectConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestActiveDOMObjectConstructor) } },
108     { "excitingFunction", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestActiveDOMObjectPrototypeFunctionExcitingFunction), (intptr_t) (1) } },
109     { "postMessage", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestActiveDOMObjectPrototypeFunctionPostMessage), (intptr_t) (1) } },
110 };
111
112 const ClassInfo JSTestActiveDOMObjectPrototype::s_info = { "TestActiveDOMObjectPrototype", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestActiveDOMObjectPrototype) };
113
114 void JSTestActiveDOMObjectPrototype::finishCreation(VM& vm)
115 {
116     Base::finishCreation(vm);
117     reifyStaticProperties(vm, JSTestActiveDOMObjectPrototypeTableValues, *this);
118 }
119
120 const ClassInfo JSTestActiveDOMObject::s_info = { "TestActiveDOMObject", &Base::s_info, &JSTestActiveDOMObjectTable, CREATE_METHOD_TABLE(JSTestActiveDOMObject) };
121
122 JSTestActiveDOMObject::JSTestActiveDOMObject(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestActiveDOMObject>&& impl)
123     : JSDOMWrapper<TestActiveDOMObject>(structure, globalObject, WTFMove(impl))
124 {
125 }
126
127 JSObject* JSTestActiveDOMObject::createPrototype(VM& vm, JSGlobalObject* globalObject)
128 {
129     return JSTestActiveDOMObjectPrototype::create(vm, globalObject, JSTestActiveDOMObjectPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
130 }
131
132 JSObject* JSTestActiveDOMObject::prototype(VM& vm, JSGlobalObject* globalObject)
133 {
134     return getDOMPrototype<JSTestActiveDOMObject>(vm, globalObject);
135 }
136
137 void JSTestActiveDOMObject::destroy(JSC::JSCell* cell)
138 {
139     JSTestActiveDOMObject* thisObject = static_cast<JSTestActiveDOMObject*>(cell);
140     thisObject->JSTestActiveDOMObject::~JSTestActiveDOMObject();
141 }
142
143 bool JSTestActiveDOMObject::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot)
144 {
145     auto* thisObject = jsCast<JSTestActiveDOMObject*>(object);
146     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
147     if (getStaticValueSlot<JSTestActiveDOMObject, Base>(state, JSTestActiveDOMObjectTable, thisObject, propertyName, slot))
148         return true;
149     return false;
150 }
151
152 EncodedJSValue jsTestActiveDOMObjectExcitingAttr(ExecState* state, EncodedJSValue thisValue, PropertyName)
153 {
154     UNUSED_PARAM(state);
155     UNUSED_PARAM(thisValue);
156     JSValue decodedThisValue = JSValue::decode(thisValue);
157     auto* castedThis = jsDynamicCast<JSTestActiveDOMObject*>(decodedThisValue);
158     if (UNLIKELY(!castedThis)) {
159         return throwGetterTypeError(*state, "TestActiveDOMObject", "excitingAttr");
160     }
161     if (!BindingSecurity::shouldAllowAccessToDOMWindow(state, castedThis->wrapped()))
162         return JSValue::encode(jsUndefined());
163     auto& impl = castedThis->wrapped();
164     JSValue result = jsNumber(impl.excitingAttr());
165     return JSValue::encode(result);
166 }
167
168
169 EncodedJSValue jsTestActiveDOMObjectConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
170 {
171     JSTestActiveDOMObjectPrototype* domObject = jsDynamicCast<JSTestActiveDOMObjectPrototype*>(JSValue::decode(thisValue));
172     if (!domObject)
173         return throwVMTypeError(state);
174     return JSValue::encode(JSTestActiveDOMObject::getConstructor(state->vm(), domObject->globalObject()));
175 }
176
177 bool setJSTestActiveDOMObjectConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
178 {
179     JSValue value = JSValue::decode(encodedValue);
180     JSTestActiveDOMObjectPrototype* domObject = jsDynamicCast<JSTestActiveDOMObjectPrototype*>(JSValue::decode(thisValue));
181     if (UNLIKELY(!domObject)) {
182         throwVMTypeError(state);
183         return false;
184     }
185     // Shadowing a built-in constructor
186     return domObject->putDirect(state->vm(), state->propertyNames().constructor, value);
187 }
188
189 JSValue JSTestActiveDOMObject::getConstructor(VM& vm, const JSGlobalObject* globalObject)
190 {
191     return getDOMConstructor<JSTestActiveDOMObjectConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
192 }
193
194 EncodedJSValue JSC_HOST_CALL jsTestActiveDOMObjectPrototypeFunctionExcitingFunction(ExecState* state)
195 {
196     JSValue thisValue = state->thisValue();
197     auto castedThis = jsDynamicCast<JSTestActiveDOMObject*>(thisValue);
198     if (UNLIKELY(!castedThis))
199         return throwThisTypeError(*state, "TestActiveDOMObject", "excitingFunction");
200     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestActiveDOMObject::info());
201     if (!BindingSecurity::shouldAllowAccessToDOMWindow(state, castedThis->wrapped()))
202         return JSValue::encode(jsUndefined());
203     auto& impl = castedThis->wrapped();
204     if (UNLIKELY(state->argumentCount() < 1))
205         return throwVMError(state, createNotEnoughArgumentsError(state));
206     Node* nextChild = JSNode::toWrapped(state->argument(0));
207     if (UNLIKELY(state->hadException()))
208         return JSValue::encode(jsUndefined());
209     if (!nextChild)
210         return throwVMTypeError(state);
211     impl.excitingFunction(*nextChild);
212     return JSValue::encode(jsUndefined());
213 }
214
215 EncodedJSValue JSC_HOST_CALL jsTestActiveDOMObjectPrototypeFunctionPostMessage(ExecState* state)
216 {
217     JSValue thisValue = state->thisValue();
218     auto castedThis = jsDynamicCast<JSTestActiveDOMObject*>(thisValue);
219     if (UNLIKELY(!castedThis))
220         return throwThisTypeError(*state, "TestActiveDOMObject", "postMessage");
221     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestActiveDOMObject::info());
222     auto& impl = castedThis->wrapped();
223     if (UNLIKELY(state->argumentCount() < 1))
224         return throwVMError(state, createNotEnoughArgumentsError(state));
225     String message = state->argument(0).toString(state)->value(state);
226     if (UNLIKELY(state->hadException()))
227         return JSValue::encode(jsUndefined());
228     impl.postMessage(message);
229     return JSValue::encode(jsUndefined());
230 }
231
232 bool JSTestActiveDOMObjectOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
233 {
234     UNUSED_PARAM(handle);
235     UNUSED_PARAM(visitor);
236     return false;
237 }
238
239 void JSTestActiveDOMObjectOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
240 {
241     auto* jsTestActiveDOMObject = jsCast<JSTestActiveDOMObject*>(handle.slot()->asCell());
242     auto& world = *static_cast<DOMWrapperWorld*>(context);
243     uncacheWrapper(world, &jsTestActiveDOMObject->wrapped(), jsTestActiveDOMObject);
244 }
245
246 #if ENABLE(BINDING_INTEGRITY)
247 #if PLATFORM(WIN)
248 #pragma warning(disable: 4483)
249 extern "C" { extern void (*const __identifier("??_7TestActiveDOMObject@WebCore@@6B@")[])(); }
250 #else
251 extern "C" { extern void* _ZTVN7WebCore19TestActiveDOMObjectE[]; }
252 #endif
253 #endif
254
255 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, TestActiveDOMObject* impl)
256 {
257     if (!impl)
258         return jsNull();
259     return createNewWrapper<JSTestActiveDOMObject>(globalObject, impl);
260 }
261
262 JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject* globalObject, TestActiveDOMObject* impl)
263 {
264     if (!impl)
265         return jsNull();
266     if (JSValue result = getExistingWrapper<JSTestActiveDOMObject>(globalObject, impl))
267         return result;
268
269 #if ENABLE(BINDING_INTEGRITY)
270     void* actualVTablePointer = *(reinterpret_cast<void**>(impl));
271 #if PLATFORM(WIN)
272     void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7TestActiveDOMObject@WebCore@@6B@"));
273 #else
274     void* expectedVTablePointer = &_ZTVN7WebCore19TestActiveDOMObjectE[2];
275 #if COMPILER(CLANG)
276     // If this fails TestActiveDOMObject does not have a vtable, so you need to add the
277     // ImplementationLacksVTable attribute to the interface definition
278     COMPILE_ASSERT(__is_polymorphic(TestActiveDOMObject), TestActiveDOMObject_is_not_polymorphic);
279 #endif
280 #endif
281     // If you hit this assertion you either have a use after free bug, or
282     // TestActiveDOMObject has subclasses. If TestActiveDOMObject has subclasses that get passed
283     // to toJS() we currently require TestActiveDOMObject you to opt out of binding hardening
284     // by adding the SkipVTableValidation attribute to the interface IDL definition
285     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
286 #endif
287     return createNewWrapper<JSTestActiveDOMObject>(globalObject, impl);
288 }
289
290 TestActiveDOMObject* JSTestActiveDOMObject::toWrapped(JSC::JSValue value)
291 {
292     if (auto* wrapper = jsDynamicCast<JSTestActiveDOMObject*>(value))
293         return &wrapper->wrapped();
294     return nullptr;
295 }
296
297 }