aa67a8b98a9a90f3c208ea5e1d18426a7f866b2c
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / JS / JSTestNode.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 "JSTestNode.h"
23
24 #include "ExceptionCode.h"
25 #include "JSDOMBinding.h"
26 #include "JSDOMConstructor.h"
27 #include "JSDOMIterator.h"
28 #include "JSDOMPromise.h"
29 #include "ObjectConstructor.h"
30 #include "RuntimeEnabledFeatures.h"
31 #include "URL.h"
32 #include <runtime/Error.h>
33 #include <runtime/JSString.h>
34 #include <wtf/GetPtr.h>
35
36 using namespace JSC;
37
38 namespace WebCore {
39
40 // Functions
41
42 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionTestWorkerPromise(JSC::ExecState*);
43 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionSymbolIterator(JSC::ExecState*);
44 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionEntries(JSC::ExecState*);
45 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionKeys(JSC::ExecState*);
46 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionValues(JSC::ExecState*);
47 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionForEach(JSC::ExecState*);
48 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionToJSON(JSC::ExecState*);
49
50 // Attributes
51
52 JSC::EncodedJSValue jsTestNodeName(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
53 bool setJSTestNodeName(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
54 JSC::EncodedJSValue jsTestNodeConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
55 bool setJSTestNodeConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
56
57 class JSTestNodePrototype : public JSC::JSNonFinalObject {
58 public:
59     using Base = JSC::JSNonFinalObject;
60     static JSTestNodePrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
61     {
62         JSTestNodePrototype* ptr = new (NotNull, JSC::allocateCell<JSTestNodePrototype>(vm.heap)) JSTestNodePrototype(vm, globalObject, structure);
63         ptr->finishCreation(vm);
64         return ptr;
65     }
66
67     DECLARE_INFO;
68     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
69     {
70         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
71     }
72
73 private:
74     JSTestNodePrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
75         : JSC::JSNonFinalObject(vm, structure)
76     {
77     }
78
79     void finishCreation(JSC::VM&);
80 };
81
82 using JSTestNodeConstructor = JSDOMConstructor<JSTestNode>;
83
84 template<> EncodedJSValue JSC_HOST_CALL JSTestNodeConstructor::construct(ExecState* state)
85 {
86     VM& vm = state->vm();
87     auto throwScope = DECLARE_THROW_SCOPE(vm);
88     UNUSED_PARAM(throwScope);
89     auto* castedThis = jsCast<JSTestNodeConstructor*>(state->callee());
90     ASSERT(castedThis);
91     auto object = TestNode::create();
92     return JSValue::encode(toJSNewlyCreated(state, castedThis->globalObject(), WTFMove(object)));
93 }
94
95 template<> JSValue JSTestNodeConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
96 {
97     return JSNode::getConstructor(vm, &globalObject);
98 }
99
100 template<> void JSTestNodeConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
101 {
102     putDirect(vm, vm.propertyNames->prototype, JSTestNode::prototype(vm, &globalObject), DontDelete | ReadOnly | DontEnum);
103     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("TestNode"))), ReadOnly | DontEnum);
104     putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontEnum);
105 }
106
107 template<> const ClassInfo JSTestNodeConstructor::s_info = { "TestNode", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestNodeConstructor) };
108
109 /* Hash table for prototype */
110
111 static const HashTableValue JSTestNodePrototypeTableValues[] =
112 {
113     { "constructor", DontEnum, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestNodeConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestNodeConstructor) } },
114     { "name", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestNodeName), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestNodeName) } },
115     { "testWorkerPromise", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionTestWorkerPromise), (intptr_t) (0) } },
116     { "entries", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionEntries), (intptr_t) (0) } },
117     { "keys", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionKeys), (intptr_t) (0) } },
118     { "values", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionValues), (intptr_t) (0) } },
119     { "forEach", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionForEach), (intptr_t) (1) } },
120     { "toJSON", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionToJSON), (intptr_t) (0) } },
121 };
122
123 const ClassInfo JSTestNodePrototype::s_info = { "TestNodePrototype", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestNodePrototype) };
124
125 void JSTestNodePrototype::finishCreation(VM& vm)
126 {
127     Base::finishCreation(vm);
128     reifyStaticProperties(vm, JSTestNodePrototypeTableValues, *this);
129     if (!RuntimeEnabledFeatures::sharedFeatures().domIteratorEnabled()) {
130         Identifier propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("entries"), strlen("entries"));
131         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
132         JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
133     }
134     if (!RuntimeEnabledFeatures::sharedFeatures().domIteratorEnabled()) {
135         Identifier propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("keys"), strlen("keys"));
136         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
137         JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
138     }
139     if (!RuntimeEnabledFeatures::sharedFeatures().domIteratorEnabled()) {
140         Identifier propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("values"), strlen("values"));
141         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
142         JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
143     }
144     if (!RuntimeEnabledFeatures::sharedFeatures().domIteratorEnabled()) {
145         Identifier propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("forEach"), strlen("forEach"));
146         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
147         JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
148     }
149     if (RuntimeEnabledFeatures::sharedFeatures().domIteratorEnabled())
150         putDirect(vm, vm.propertyNames->iteratorSymbol, JSFunction::create(vm, globalObject(), 0, ASCIILiteral("[Symbol.Iterator]"), jsTestNodePrototypeFunctionSymbolIterator), DontEnum);
151 }
152
153 const ClassInfo JSTestNode::s_info = { "TestNode", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestNode) };
154
155 JSTestNode::JSTestNode(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestNode>&& impl)
156     : JSNode(structure, globalObject, WTFMove(impl))
157 {
158 }
159
160 JSObject* JSTestNode::createPrototype(VM& vm, JSGlobalObject* globalObject)
161 {
162     return JSTestNodePrototype::create(vm, globalObject, JSTestNodePrototype::createStructure(vm, globalObject, JSNode::prototype(vm, globalObject)));
163 }
164
165 JSObject* JSTestNode::prototype(VM& vm, JSGlobalObject* globalObject)
166 {
167     return getDOMPrototype<JSTestNode>(vm, globalObject);
168 }
169
170 inline JSTestNode* JSTestNode::castForAttribute(JSC::ExecState*, EncodedJSValue thisValue)
171 {
172     return jsDynamicCast<JSTestNode*>(JSValue::decode(thisValue));
173 }
174
175 static inline JSValue jsTestNodeNameGetter(ExecState*, JSTestNode*, ThrowScope& throwScope);
176
177 EncodedJSValue jsTestNodeName(ExecState* state, EncodedJSValue thisValue, PropertyName)
178 {
179     return BindingCaller<JSTestNode>::attribute<jsTestNodeNameGetter>(state, thisValue, "name");
180 }
181
182 static inline JSValue jsTestNodeNameGetter(ExecState* state, JSTestNode* thisObject, ThrowScope& throwScope)
183 {
184     UNUSED_PARAM(throwScope);
185     UNUSED_PARAM(state);
186     auto& impl = thisObject->wrapped();
187     JSValue result = jsStringWithCache(state, impl.name());
188     return result;
189 }
190
191 EncodedJSValue jsTestNodeConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
192 {
193     VM& vm = state->vm();
194     auto throwScope = DECLARE_THROW_SCOPE(vm);
195     JSTestNodePrototype* domObject = jsDynamicCast<JSTestNodePrototype*>(JSValue::decode(thisValue));
196     if (UNLIKELY(!domObject))
197         return throwVMTypeError(state, throwScope);
198     return JSValue::encode(JSTestNode::getConstructor(state->vm(), domObject->globalObject()));
199 }
200
201 bool setJSTestNodeConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
202 {
203     VM& vm = state->vm();
204     auto throwScope = DECLARE_THROW_SCOPE(vm);
205     JSValue value = JSValue::decode(encodedValue);
206     JSTestNodePrototype* domObject = jsDynamicCast<JSTestNodePrototype*>(JSValue::decode(thisValue));
207     if (UNLIKELY(!domObject)) {
208         throwVMTypeError(state, throwScope);
209         return false;
210     }
211     // Shadowing a built-in constructor
212     return domObject->putDirect(state->vm(), state->propertyNames().constructor, value);
213 }
214
215 bool setJSTestNodeName(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
216 {
217     VM& vm = state->vm();
218     auto throwScope = DECLARE_THROW_SCOPE(vm);
219     UNUSED_PARAM(throwScope);
220     JSValue value = JSValue::decode(encodedValue);
221     UNUSED_PARAM(thisValue);
222     JSTestNode* castedThis = jsDynamicCast<JSTestNode*>(JSValue::decode(thisValue));
223     if (UNLIKELY(!castedThis))
224         return throwSetterTypeError(*state, throwScope, "TestNode", "name");
225     auto& impl = castedThis->wrapped();
226     auto nativeValue = value.toWTFString(state);
227     RETURN_IF_EXCEPTION(throwScope, false);
228     impl.setName(WTFMove(nativeValue));
229     return true;
230 }
231
232
233 JSValue JSTestNode::getConstructor(VM& vm, const JSGlobalObject* globalObject)
234 {
235     return getDOMConstructor<JSTestNodeConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
236 }
237
238 static EncodedJSValue jsTestNodePrototypeFunctionTestWorkerPromisePromise(ExecState*, Ref<DeferredPromise>&&);
239
240 EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionTestWorkerPromise(ExecState* state)
241 {
242     ASSERT(state);
243     return JSValue::encode(callPromiseFunction<jsTestNodePrototypeFunctionTestWorkerPromisePromise, PromiseExecutionScope::WindowOrWorker>(*state));
244 }
245
246 static inline EncodedJSValue jsTestNodePrototypeFunctionTestWorkerPromisePromise(ExecState* state, Ref<DeferredPromise>&& promise)
247 {
248     VM& vm = state->vm();
249     auto throwScope = DECLARE_THROW_SCOPE(vm);
250     UNUSED_PARAM(throwScope);
251     JSValue thisValue = state->thisValue();
252     auto castedThis = jsDynamicCast<JSTestNode*>(thisValue);
253     if (UNLIKELY(!castedThis))
254         return throwThisTypeError(*state, throwScope, "TestNode", "testWorkerPromise");
255     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestNode::info());
256     auto& impl = castedThis->wrapped();
257     impl.testWorkerPromise(WTFMove(promise));
258     return JSValue::encode(jsUndefined());
259 }
260
261 using TestNodeIterator = JSDOMIterator<JSTestNode>;
262 using TestNodeIteratorPrototype = JSDOMIteratorPrototype<JSTestNode>;
263
264 template<>
265 const JSC::ClassInfo TestNodeIterator::s_info = { "TestNode Iterator", &Base::s_info, 0, CREATE_METHOD_TABLE(TestNodeIterator) };
266
267 template<>
268 const JSC::ClassInfo TestNodeIteratorPrototype::s_info = { "TestNode Iterator", &Base::s_info, 0, CREATE_METHOD_TABLE(TestNodeIteratorPrototype) };
269
270 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionSymbolIterator(JSC::ExecState* state)
271 {
272     return iteratorCreate<JSTestNode>(*state, IterationKind::Value, "[Symbol.Iterator]");
273 }
274
275 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionEntries(JSC::ExecState* state)
276 {
277     return iteratorCreate<JSTestNode>(*state, IterationKind::KeyValue, "entries");
278 }
279
280 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionKeys(JSC::ExecState* state)
281 {
282     return iteratorCreate<JSTestNode>(*state, IterationKind::Key, "keys");
283 }
284
285 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionValues(JSC::ExecState* state)
286 {
287     return iteratorCreate<JSTestNode>(*state, IterationKind::Value, "values");
288 }
289
290 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionForEach(JSC::ExecState* state)
291 {
292     return iteratorForEach<JSTestNode>(*state, "forEach");
293 }
294
295 EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionToJSON(ExecState* state)
296 {
297     ASSERT(state);
298     auto thisValue = state->thisValue();
299     auto castedThis = jsDynamicCast<JSTestNode*>(thisValue);
300     VM& vm = state->vm();
301     auto throwScope = DECLARE_THROW_SCOPE(vm);
302     if (UNLIKELY(!castedThis))
303         return throwThisTypeError(*state, throwScope, "TestNode", "toJSON");
304     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestNode::info());
305
306     auto* result = constructEmptyObject(state);
307     auto nameValue = jsTestNodeName(state, JSValue::encode(thisValue), Identifier());
308     ASSERT(!throwScope.exception());
309     result->putDirect(vm, Identifier::fromString(&vm, "name"), JSValue::decode(nameValue));
310     return JSValue::encode(result);
311 }
312
313 void JSTestNode::visitChildren(JSCell* cell, SlotVisitor& visitor)
314 {
315     auto* thisObject = jsCast<JSTestNode*>(cell);
316     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
317     Base::visitChildren(thisObject, visitor);
318     thisObject->wrapped().visitJSEventListeners(visitor);
319 }
320
321 #if ENABLE(BINDING_INTEGRITY)
322 #if PLATFORM(WIN)
323 #pragma warning(disable: 4483)
324 extern "C" { extern void (*const __identifier("??_7TestNode@WebCore@@6B@")[])(); }
325 #else
326 extern "C" { extern void* _ZTVN7WebCore8TestNodeE[]; }
327 #endif
328 #endif
329
330 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestNode>&& impl)
331 {
332
333 #if ENABLE(BINDING_INTEGRITY)
334     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
335 #if PLATFORM(WIN)
336     void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7TestNode@WebCore@@6B@"));
337 #else
338     void* expectedVTablePointer = &_ZTVN7WebCore8TestNodeE[2];
339 #if COMPILER(CLANG)
340     // If this fails TestNode does not have a vtable, so you need to add the
341     // ImplementationLacksVTable attribute to the interface definition
342     static_assert(__is_polymorphic(TestNode), "TestNode is not polymorphic");
343 #endif
344 #endif
345     // If you hit this assertion you either have a use after free bug, or
346     // TestNode has subclasses. If TestNode has subclasses that get passed
347     // to toJS() we currently require TestNode you to opt out of binding hardening
348     // by adding the SkipVTableValidation attribute to the interface IDL definition
349     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
350 #endif
351     return createWrapper<TestNode>(globalObject, WTFMove(impl));
352 }
353
354 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestNode& impl)
355 {
356     return wrap(state, globalObject, impl);
357 }
358
359
360 }