Move URL from WebCore to WTF
[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/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     }
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(ExecState* state)
231 {
232     return IDLOperation<JSTestActiveDOMObject>::call<jsTestActiveDOMObjectPrototypeFunctionExcitingFunctionBody>(*state, "excitingFunction");
233 }
234
235 static inline JSC::EncodedJSValue jsTestActiveDOMObjectPrototypeFunctionPostMessageBody(JSC::ExecState* state, typename IDLOperation<JSTestActiveDOMObject>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
236 {
237     UNUSED_PARAM(state);
238     UNUSED_PARAM(throwScope);
239     auto& impl = castedThis->wrapped();
240     if (UNLIKELY(state->argumentCount() < 1))
241         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
242     auto message = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
243     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
244     impl.postMessage(WTFMove(message));
245     return JSValue::encode(jsUndefined());
246 }
247
248 EncodedJSValue JSC_HOST_CALL jsTestActiveDOMObjectPrototypeFunctionPostMessage(ExecState* state)
249 {
250     return IDLOperation<JSTestActiveDOMObject>::call<jsTestActiveDOMObjectPrototypeFunctionPostMessageBody>(*state, "postMessage");
251 }
252
253 void JSTestActiveDOMObject::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
254 {
255     auto* thisObject = jsCast<JSTestActiveDOMObject*>(cell);
256     builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
257     if (thisObject->scriptExecutionContext())
258         builder.setLabelForCell(cell, String::format("url %s", thisObject->scriptExecutionContext()->url().string().utf8().data()));
259     Base::heapSnapshot(cell, builder);
260 }
261
262 bool JSTestActiveDOMObjectOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
263 {
264     UNUSED_PARAM(handle);
265     UNUSED_PARAM(visitor);
266     UNUSED_PARAM(reason);
267     return false;
268 }
269
270 void JSTestActiveDOMObjectOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
271 {
272     auto* jsTestActiveDOMObject = static_cast<JSTestActiveDOMObject*>(handle.slot()->asCell());
273     auto& world = *static_cast<DOMWrapperWorld*>(context);
274     uncacheWrapper(world, &jsTestActiveDOMObject->wrapped(), jsTestActiveDOMObject);
275 }
276
277 #if ENABLE(BINDING_INTEGRITY)
278 #if PLATFORM(WIN)
279 #pragma warning(disable: 4483)
280 extern "C" { extern void (*const __identifier("??_7TestActiveDOMObject@WebCore@@6B@")[])(); }
281 #else
282 extern "C" { extern void* _ZTVN7WebCore19TestActiveDOMObjectE[]; }
283 #endif
284 #endif
285
286 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestActiveDOMObject>&& impl)
287 {
288
289 #if ENABLE(BINDING_INTEGRITY)
290     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
291 #if PLATFORM(WIN)
292     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7TestActiveDOMObject@WebCore@@6B@"));
293 #else
294     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore19TestActiveDOMObjectE[2]);
295 #endif
296
297     // If this fails TestActiveDOMObject does not have a vtable, so you need to add the
298     // ImplementationLacksVTable attribute to the interface definition
299     static_assert(std::is_polymorphic<TestActiveDOMObject>::value, "TestActiveDOMObject is not polymorphic");
300
301     // If you hit this assertion you either have a use after free bug, or
302     // TestActiveDOMObject has subclasses. If TestActiveDOMObject has subclasses that get passed
303     // to toJS() we currently require TestActiveDOMObject you to opt out of binding hardening
304     // by adding the SkipVTableValidation attribute to the interface IDL definition
305     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
306 #endif
307     return createWrapper<TestActiveDOMObject>(globalObject, WTFMove(impl));
308 }
309
310 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestActiveDOMObject& impl)
311 {
312     return wrap(state, globalObject, impl);
313 }
314
315 TestActiveDOMObject* JSTestActiveDOMObject::toWrapped(JSC::VM& vm, JSC::JSValue value)
316 {
317     if (auto* wrapper = jsDynamicCast<JSTestActiveDOMObject*>(vm, value))
318         return &wrapper->wrapped();
319     return nullptr;
320 }
321
322 }