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