All prototypes should call didBecomePrototype()
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / JS / JSTestStringifierOperationImplementedAs.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 "JSTestStringifierOperationImplementedAs.h"
23
24 #include "JSDOMBinding.h"
25 #include "JSDOMConstructorNotConstructable.h"
26 #include "JSDOMConvertStrings.h"
27 #include "JSDOMExceptionHandling.h"
28 #include "JSDOMOperation.h"
29 #include "JSDOMWrapperCache.h"
30 #include "ScriptExecutionContext.h"
31 #include <JavaScriptCore/FunctionPrototype.h>
32 #include <JavaScriptCore/HeapSnapshotBuilder.h>
33 #include <JavaScriptCore/JSCInlines.h>
34 #include <wtf/GetPtr.h>
35 #include <wtf/PointerPreparations.h>
36 #include <wtf/URL.h>
37
38
39 namespace WebCore {
40 using namespace JSC;
41
42 // Functions
43
44 JSC::EncodedJSValue JSC_HOST_CALL jsTestStringifierOperationImplementedAsPrototypeFunctionIdentifier(JSC::ExecState*);
45 JSC::EncodedJSValue JSC_HOST_CALL jsTestStringifierOperationImplementedAsPrototypeFunctionToString(JSC::ExecState*);
46
47 // Attributes
48
49 JSC::EncodedJSValue jsTestStringifierOperationImplementedAsConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
50 bool setJSTestStringifierOperationImplementedAsConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
51
52 class JSTestStringifierOperationImplementedAsPrototype : public JSC::JSNonFinalObject {
53 public:
54     using Base = JSC::JSNonFinalObject;
55     static JSTestStringifierOperationImplementedAsPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
56     {
57         JSTestStringifierOperationImplementedAsPrototype* ptr = new (NotNull, JSC::allocateCell<JSTestStringifierOperationImplementedAsPrototype>(vm.heap)) JSTestStringifierOperationImplementedAsPrototype(vm, globalObject, structure);
58         ptr->finishCreation(vm);
59         return ptr;
60     }
61
62     DECLARE_INFO;
63     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
64     {
65         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
66     }
67
68 private:
69     JSTestStringifierOperationImplementedAsPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
70         : JSC::JSNonFinalObject(vm, structure)
71     {
72         didBecomePrototype();
73     }
74
75     void finishCreation(JSC::VM&);
76 };
77
78 using JSTestStringifierOperationImplementedAsConstructor = JSDOMConstructorNotConstructable<JSTestStringifierOperationImplementedAs>;
79
80 template<> JSValue JSTestStringifierOperationImplementedAsConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
81 {
82     UNUSED_PARAM(vm);
83     return globalObject.functionPrototype();
84 }
85
86 template<> void JSTestStringifierOperationImplementedAsConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
87 {
88     putDirect(vm, vm.propertyNames->prototype, JSTestStringifierOperationImplementedAs::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
89     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("TestStringifierOperationImplementedAs"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
90     putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
91 }
92
93 template<> const ClassInfo JSTestStringifierOperationImplementedAsConstructor::s_info = { "TestStringifierOperationImplementedAs", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestStringifierOperationImplementedAsConstructor) };
94
95 /* Hash table for prototype */
96
97 static const HashTableValue JSTestStringifierOperationImplementedAsPrototypeTableValues[] =
98 {
99     { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestStringifierOperationImplementedAsConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestStringifierOperationImplementedAsConstructor) } },
100     { "identifier", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsTestStringifierOperationImplementedAsPrototypeFunctionIdentifier), (intptr_t) (0) } },
101     { "toString", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsTestStringifierOperationImplementedAsPrototypeFunctionToString), (intptr_t) (0) } },
102 };
103
104 const ClassInfo JSTestStringifierOperationImplementedAsPrototype::s_info = { "TestStringifierOperationImplementedAsPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestStringifierOperationImplementedAsPrototype) };
105
106 void JSTestStringifierOperationImplementedAsPrototype::finishCreation(VM& vm)
107 {
108     Base::finishCreation(vm);
109     reifyStaticProperties(vm, JSTestStringifierOperationImplementedAs::info(), JSTestStringifierOperationImplementedAsPrototypeTableValues, *this);
110 }
111
112 const ClassInfo JSTestStringifierOperationImplementedAs::s_info = { "TestStringifierOperationImplementedAs", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestStringifierOperationImplementedAs) };
113
114 JSTestStringifierOperationImplementedAs::JSTestStringifierOperationImplementedAs(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestStringifierOperationImplementedAs>&& impl)
115     : JSDOMWrapper<TestStringifierOperationImplementedAs>(structure, globalObject, WTFMove(impl))
116 {
117 }
118
119 void JSTestStringifierOperationImplementedAs::finishCreation(VM& vm)
120 {
121     Base::finishCreation(vm);
122     ASSERT(inherits(vm, info()));
123
124 }
125
126 JSObject* JSTestStringifierOperationImplementedAs::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
127 {
128     return JSTestStringifierOperationImplementedAsPrototype::create(vm, &globalObject, JSTestStringifierOperationImplementedAsPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
129 }
130
131 JSObject* JSTestStringifierOperationImplementedAs::prototype(VM& vm, JSDOMGlobalObject& globalObject)
132 {
133     return getDOMPrototype<JSTestStringifierOperationImplementedAs>(vm, globalObject);
134 }
135
136 JSValue JSTestStringifierOperationImplementedAs::getConstructor(VM& vm, const JSGlobalObject* globalObject)
137 {
138     return getDOMConstructor<JSTestStringifierOperationImplementedAsConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
139 }
140
141 void JSTestStringifierOperationImplementedAs::destroy(JSC::JSCell* cell)
142 {
143     JSTestStringifierOperationImplementedAs* thisObject = static_cast<JSTestStringifierOperationImplementedAs*>(cell);
144     thisObject->JSTestStringifierOperationImplementedAs::~JSTestStringifierOperationImplementedAs();
145 }
146
147 template<> inline JSTestStringifierOperationImplementedAs* IDLOperation<JSTestStringifierOperationImplementedAs>::cast(ExecState& state)
148 {
149     return jsDynamicCast<JSTestStringifierOperationImplementedAs*>(state.vm(), state.thisValue());
150 }
151
152 EncodedJSValue jsTestStringifierOperationImplementedAsConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
153 {
154     VM& vm = state->vm();
155     auto throwScope = DECLARE_THROW_SCOPE(vm);
156     auto* prototype = jsDynamicCast<JSTestStringifierOperationImplementedAsPrototype*>(vm, JSValue::decode(thisValue));
157     if (UNLIKELY(!prototype))
158         return throwVMTypeError(state, throwScope);
159     return JSValue::encode(JSTestStringifierOperationImplementedAs::getConstructor(state->vm(), prototype->globalObject()));
160 }
161
162 bool setJSTestStringifierOperationImplementedAsConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
163 {
164     VM& vm = state->vm();
165     auto throwScope = DECLARE_THROW_SCOPE(vm);
166     auto* prototype = jsDynamicCast<JSTestStringifierOperationImplementedAsPrototype*>(vm, JSValue::decode(thisValue));
167     if (UNLIKELY(!prototype)) {
168         throwVMTypeError(state, throwScope);
169         return false;
170     }
171     // Shadowing a built-in constructor
172     return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
173 }
174
175 static inline JSC::EncodedJSValue jsTestStringifierOperationImplementedAsPrototypeFunctionIdentifierBody(JSC::ExecState* state, typename IDLOperation<JSTestStringifierOperationImplementedAs>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
176 {
177     UNUSED_PARAM(state);
178     UNUSED_PARAM(throwScope);
179     auto& impl = castedThis->wrapped();
180     return JSValue::encode(toJS<IDLDOMString>(*state, impl.alternateIdentifier()));
181 }
182
183 EncodedJSValue JSC_HOST_CALL jsTestStringifierOperationImplementedAsPrototypeFunctionIdentifier(ExecState* state)
184 {
185     return IDLOperation<JSTestStringifierOperationImplementedAs>::call<jsTestStringifierOperationImplementedAsPrototypeFunctionIdentifierBody>(*state, "identifier");
186 }
187
188 static inline JSC::EncodedJSValue jsTestStringifierOperationImplementedAsPrototypeFunctionToStringBody(JSC::ExecState* state, typename IDLOperation<JSTestStringifierOperationImplementedAs>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
189 {
190     UNUSED_PARAM(state);
191     UNUSED_PARAM(throwScope);
192     auto& impl = castedThis->wrapped();
193     return JSValue::encode(toJS<IDLDOMString>(*state, impl.alternateIdentifier()));
194 }
195
196 EncodedJSValue JSC_HOST_CALL jsTestStringifierOperationImplementedAsPrototypeFunctionToString(ExecState* state)
197 {
198     return IDLOperation<JSTestStringifierOperationImplementedAs>::call<jsTestStringifierOperationImplementedAsPrototypeFunctionToStringBody>(*state, "toString");
199 }
200
201 void JSTestStringifierOperationImplementedAs::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
202 {
203     auto* thisObject = jsCast<JSTestStringifierOperationImplementedAs*>(cell);
204     builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
205     if (thisObject->scriptExecutionContext())
206         builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
207     Base::heapSnapshot(cell, builder);
208 }
209
210 bool JSTestStringifierOperationImplementedAsOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
211 {
212     UNUSED_PARAM(handle);
213     UNUSED_PARAM(visitor);
214     UNUSED_PARAM(reason);
215     return false;
216 }
217
218 void JSTestStringifierOperationImplementedAsOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
219 {
220     auto* jsTestStringifierOperationImplementedAs = static_cast<JSTestStringifierOperationImplementedAs*>(handle.slot()->asCell());
221     auto& world = *static_cast<DOMWrapperWorld*>(context);
222     uncacheWrapper(world, &jsTestStringifierOperationImplementedAs->wrapped(), jsTestStringifierOperationImplementedAs);
223 }
224
225 #if ENABLE(BINDING_INTEGRITY)
226 #if PLATFORM(WIN)
227 #pragma warning(disable: 4483)
228 extern "C" { extern void (*const __identifier("??_7TestStringifierOperationImplementedAs@WebCore@@6B@")[])(); }
229 #else
230 extern "C" { extern void* _ZTVN7WebCore37TestStringifierOperationImplementedAsE[]; }
231 #endif
232 #endif
233
234 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestStringifierOperationImplementedAs>&& impl)
235 {
236
237 #if ENABLE(BINDING_INTEGRITY)
238     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
239 #if PLATFORM(WIN)
240     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7TestStringifierOperationImplementedAs@WebCore@@6B@"));
241 #else
242     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore37TestStringifierOperationImplementedAsE[2]);
243 #endif
244
245     // If this fails TestStringifierOperationImplementedAs does not have a vtable, so you need to add the
246     // ImplementationLacksVTable attribute to the interface definition
247     static_assert(std::is_polymorphic<TestStringifierOperationImplementedAs>::value, "TestStringifierOperationImplementedAs is not polymorphic");
248
249     // If you hit this assertion you either have a use after free bug, or
250     // TestStringifierOperationImplementedAs has subclasses. If TestStringifierOperationImplementedAs has subclasses that get passed
251     // to toJS() we currently require TestStringifierOperationImplementedAs you to opt out of binding hardening
252     // by adding the SkipVTableValidation attribute to the interface IDL definition
253     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
254 #endif
255     return createWrapper<TestStringifierOperationImplementedAs>(globalObject, WTFMove(impl));
256 }
257
258 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestStringifierOperationImplementedAs& impl)
259 {
260     return wrap(state, globalObject, impl);
261 }
262
263 TestStringifierOperationImplementedAs* JSTestStringifierOperationImplementedAs::toWrapped(JSC::VM& vm, JSC::JSValue value)
264 {
265     if (auto* wrapper = jsDynamicCast<JSTestStringifierOperationImplementedAs*>(vm, value))
266         return &wrapper->wrapped();
267     return nullptr;
268 }
269
270 }