f18230cb7d7b70f47e2e6836a46e2932afde6bae
[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 EncodedJSValue jsTestActiveDOMObjectExcitingAttr(ExecState* state, EncodedJSValue thisValue, PropertyName)
144 {
145     VM& vm = state->vm();
146     auto throwScope = DECLARE_THROW_SCOPE(vm);
147     UNUSED_PARAM(throwScope);
148     UNUSED_PARAM(thisValue);
149     JSValue decodedThisValue = JSValue::decode(thisValue);
150     auto* castedThis = jsDynamicCast<JSTestActiveDOMObject*>(decodedThisValue);
151     if (UNLIKELY(!castedThis)) {
152         return throwGetterTypeError(*state, throwScope, "TestActiveDOMObject", "excitingAttr");
153     }
154     if (!BindingSecurity::shouldAllowAccessToFrame(state, castedThis->wrapped().frame(), ThrowSecurityError))
155         return JSValue::encode(jsUndefined());
156     auto& impl = castedThis->wrapped();
157     JSValue result = jsNumber(impl.excitingAttr());
158     return JSValue::encode(result);
159 }
160
161
162 EncodedJSValue jsTestActiveDOMObjectConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
163 {
164     VM& vm = state->vm();
165     auto throwScope = DECLARE_THROW_SCOPE(vm);
166     JSTestActiveDOMObjectPrototype* domObject = jsDynamicCast<JSTestActiveDOMObjectPrototype*>(JSValue::decode(thisValue));
167     if (UNLIKELY(!domObject))
168         return throwVMTypeError(state, throwScope);
169     return JSValue::encode(JSTestActiveDOMObject::getConstructor(state->vm(), domObject->globalObject()));
170 }
171
172 bool setJSTestActiveDOMObjectConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
173 {
174     VM& vm = state->vm();
175     auto throwScope = DECLARE_THROW_SCOPE(vm);
176     JSValue value = JSValue::decode(encodedValue);
177     JSTestActiveDOMObjectPrototype* domObject = jsDynamicCast<JSTestActiveDOMObjectPrototype*>(JSValue::decode(thisValue));
178     if (UNLIKELY(!domObject)) {
179         throwVMTypeError(state, throwScope);
180         return false;
181     }
182     // Shadowing a built-in constructor
183     return domObject->putDirect(state->vm(), state->propertyNames().constructor, value);
184 }
185
186 JSValue JSTestActiveDOMObject::getConstructor(VM& vm, const JSGlobalObject* globalObject)
187 {
188     return getDOMConstructor<JSTestActiveDOMObjectConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
189 }
190
191 EncodedJSValue JSC_HOST_CALL jsTestActiveDOMObjectPrototypeFunctionExcitingFunction(ExecState* state)
192 {
193     VM& vm = state->vm();
194     auto throwScope = DECLARE_THROW_SCOPE(vm);
195     UNUSED_PARAM(throwScope);
196     JSValue thisValue = state->thisValue();
197     auto castedThis = jsDynamicCast<JSTestActiveDOMObject*>(thisValue);
198     if (UNLIKELY(!castedThis))
199         return throwThisTypeError(*state, throwScope, "TestActiveDOMObject", "excitingFunction");
200     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestActiveDOMObject::info());
201     if (!BindingSecurity::shouldAllowAccessToFrame(state, castedThis->wrapped().frame(), ThrowSecurityError))
202         return JSValue::encode(jsUndefined());
203     auto& impl = castedThis->wrapped();
204     if (UNLIKELY(state->argumentCount() < 1))
205         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
206     auto nextChild = JSNode::toWrapped(state->uncheckedArgument(0));
207     if (UNLIKELY(!nextChild))
208         return throwArgumentTypeError(*state, throwScope, 0, "nextChild", "TestActiveDOMObject", "excitingFunction", "Node");
209     impl.excitingFunction(*nextChild);
210     return JSValue::encode(jsUndefined());
211 }
212
213 EncodedJSValue JSC_HOST_CALL jsTestActiveDOMObjectPrototypeFunctionPostMessage(ExecState* state)
214 {
215     VM& vm = state->vm();
216     auto throwScope = DECLARE_THROW_SCOPE(vm);
217     UNUSED_PARAM(throwScope);
218     JSValue thisValue = state->thisValue();
219     auto castedThis = jsDynamicCast<JSTestActiveDOMObject*>(thisValue);
220     if (UNLIKELY(!castedThis))
221         return throwThisTypeError(*state, throwScope, "TestActiveDOMObject", "postMessage");
222     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestActiveDOMObject::info());
223     auto& impl = castedThis->wrapped();
224     if (UNLIKELY(state->argumentCount() < 1))
225         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
226     auto message = state->uncheckedArgument(0).toWTFString(state);
227     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
228     impl.postMessage(WTFMove(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, Ref<TestActiveDOMObject>&& impl)
256 {
257
258 #if ENABLE(BINDING_INTEGRITY)
259     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
260 #if PLATFORM(WIN)
261     void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7TestActiveDOMObject@WebCore@@6B@"));
262 #else
263     void* expectedVTablePointer = &_ZTVN7WebCore19TestActiveDOMObjectE[2];
264 #if COMPILER(CLANG)
265     // If this fails TestActiveDOMObject does not have a vtable, so you need to add the
266     // ImplementationLacksVTable attribute to the interface definition
267     static_assert(__is_polymorphic(TestActiveDOMObject), "TestActiveDOMObject is not polymorphic");
268 #endif
269 #endif
270     // If you hit this assertion you either have a use after free bug, or
271     // TestActiveDOMObject has subclasses. If TestActiveDOMObject has subclasses that get passed
272     // to toJS() we currently require TestActiveDOMObject you to opt out of binding hardening
273     // by adding the SkipVTableValidation attribute to the interface IDL definition
274     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
275 #endif
276     return createWrapper<TestActiveDOMObject>(globalObject, WTFMove(impl));
277 }
278
279 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestActiveDOMObject& impl)
280 {
281     return wrap(state, globalObject, impl);
282 }
283
284 TestActiveDOMObject* JSTestActiveDOMObject::toWrapped(JSC::JSValue value)
285 {
286     if (auto* wrapper = jsDynamicCast<JSTestActiveDOMObject*>(value))
287         return &wrapper->wrapped();
288     return nullptr;
289 }
290
291 }