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