631eca33e954379faf5ea81f0e53054612762a2b
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / JS / JSTestNamedSetterWithIdentifier.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 "JSTestNamedSetterWithIdentifier.h"
23
24 #include "ActiveDOMObject.h"
25 #include "JSDOMAbstractOperations.h"
26 #include "JSDOMBinding.h"
27 #include "JSDOMConstructorNotConstructable.h"
28 #include "JSDOMConvertStrings.h"
29 #include "JSDOMExceptionHandling.h"
30 #include "JSDOMOperation.h"
31 #include "JSDOMWrapperCache.h"
32 #include "ScriptExecutionContext.h"
33 #include <JavaScriptCore/FunctionPrototype.h>
34 #include <JavaScriptCore/HeapAnalyzer.h>
35 #include <JavaScriptCore/JSCInlines.h>
36 #include <wtf/GetPtr.h>
37 #include <wtf/PointerPreparations.h>
38 #include <wtf/URL.h>
39
40
41 namespace WebCore {
42 using namespace JSC;
43
44 // Functions
45
46 JSC::EncodedJSValue JSC_HOST_CALL jsTestNamedSetterWithIdentifierPrototypeFunctionNamedSetter(JSC::JSGlobalObject*, JSC::CallFrame*);
47
48 // Attributes
49
50 JSC::EncodedJSValue jsTestNamedSetterWithIdentifierConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
51 bool setJSTestNamedSetterWithIdentifierConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
52
53 class JSTestNamedSetterWithIdentifierPrototype : public JSC::JSNonFinalObject {
54 public:
55     using Base = JSC::JSNonFinalObject;
56     static JSTestNamedSetterWithIdentifierPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
57     {
58         JSTestNamedSetterWithIdentifierPrototype* ptr = new (NotNull, JSC::allocateCell<JSTestNamedSetterWithIdentifierPrototype>(vm.heap)) JSTestNamedSetterWithIdentifierPrototype(vm, globalObject, structure);
59         ptr->finishCreation(vm);
60         return ptr;
61     }
62
63     DECLARE_INFO;
64     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
65     {
66         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
67     }
68
69 private:
70     JSTestNamedSetterWithIdentifierPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
71         : JSC::JSNonFinalObject(vm, structure)
72     {
73     }
74
75     void finishCreation(JSC::VM&);
76 };
77
78 using JSTestNamedSetterWithIdentifierConstructor = JSDOMConstructorNotConstructable<JSTestNamedSetterWithIdentifier>;
79
80 template<> JSValue JSTestNamedSetterWithIdentifierConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
81 {
82     UNUSED_PARAM(vm);
83     return globalObject.functionPrototype();
84 }
85
86 template<> void JSTestNamedSetterWithIdentifierConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
87 {
88     putDirect(vm, vm.propertyNames->prototype, JSTestNamedSetterWithIdentifier::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
89     putDirect(vm, vm.propertyNames->name, jsNontrivialString(vm, String("TestNamedSetterWithIdentifier"_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 JSTestNamedSetterWithIdentifierConstructor::s_info = { "TestNamedSetterWithIdentifier", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedSetterWithIdentifierConstructor) };
94
95 /* Hash table for prototype */
96
97 static const HashTableValue JSTestNamedSetterWithIdentifierPrototypeTableValues[] =
98 {
99     { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestNamedSetterWithIdentifierConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestNamedSetterWithIdentifierConstructor) } },
100     { "namedSetter", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsTestNamedSetterWithIdentifierPrototypeFunctionNamedSetter), (intptr_t) (2) } },
101 };
102
103 const ClassInfo JSTestNamedSetterWithIdentifierPrototype::s_info = { "TestNamedSetterWithIdentifierPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedSetterWithIdentifierPrototype) };
104
105 void JSTestNamedSetterWithIdentifierPrototype::finishCreation(VM& vm)
106 {
107     Base::finishCreation(vm);
108     reifyStaticProperties(vm, JSTestNamedSetterWithIdentifier::info(), JSTestNamedSetterWithIdentifierPrototypeTableValues, *this);
109 }
110
111 const ClassInfo JSTestNamedSetterWithIdentifier::s_info = { "TestNamedSetterWithIdentifier", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedSetterWithIdentifier) };
112
113 JSTestNamedSetterWithIdentifier::JSTestNamedSetterWithIdentifier(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestNamedSetterWithIdentifier>&& impl)
114     : JSDOMWrapper<TestNamedSetterWithIdentifier>(structure, globalObject, WTFMove(impl))
115 {
116 }
117
118 void JSTestNamedSetterWithIdentifier::finishCreation(VM& vm)
119 {
120     Base::finishCreation(vm);
121     ASSERT(inherits(vm, info()));
122
123     static_assert(!std::is_base_of<ActiveDOMObject, TestNamedSetterWithIdentifier>::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject.");
124
125 }
126
127 JSObject* JSTestNamedSetterWithIdentifier::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
128 {
129     return JSTestNamedSetterWithIdentifierPrototype::create(vm, &globalObject, JSTestNamedSetterWithIdentifierPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
130 }
131
132 JSObject* JSTestNamedSetterWithIdentifier::prototype(VM& vm, JSDOMGlobalObject& globalObject)
133 {
134     return getDOMPrototype<JSTestNamedSetterWithIdentifier>(vm, globalObject);
135 }
136
137 JSValue JSTestNamedSetterWithIdentifier::getConstructor(VM& vm, const JSGlobalObject* globalObject)
138 {
139     return getDOMConstructor<JSTestNamedSetterWithIdentifierConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
140 }
141
142 void JSTestNamedSetterWithIdentifier::destroy(JSC::JSCell* cell)
143 {
144     JSTestNamedSetterWithIdentifier* thisObject = static_cast<JSTestNamedSetterWithIdentifier*>(cell);
145     thisObject->JSTestNamedSetterWithIdentifier::~JSTestNamedSetterWithIdentifier();
146 }
147
148 bool JSTestNamedSetterWithIdentifier::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot)
149 {
150     auto* thisObject = jsCast<JSTestNamedSetterWithIdentifier*>(object);
151     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
152     using GetterIDLType = IDLDOMString;
153     auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> {
154         auto result = thisObject.wrapped().namedItem(propertyNameToAtomString(propertyName));
155         if (!GetterIDLType::isNullValue(result))
156             return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) };
157         return WTF::nullopt;
158     };
159     if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) {
160         auto value = toJS<IDLDOMString>(*state, WTFMove(namedProperty.value()));
161         slot.setValue(thisObject, static_cast<unsigned>(0), value);
162         return true;
163     }
164     return JSObject::getOwnPropertySlot(object, state, propertyName, slot);
165 }
166
167 bool JSTestNamedSetterWithIdentifier::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot)
168 {
169     VM& vm = state->vm();
170     auto* thisObject = jsCast<JSTestNamedSetterWithIdentifier*>(object);
171     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
172     auto propertyName = Identifier::from(vm, index);
173     using GetterIDLType = IDLDOMString;
174     auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> {
175         auto result = thisObject.wrapped().namedItem(propertyNameToAtomString(propertyName));
176         if (!GetterIDLType::isNullValue(result))
177             return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) };
178         return WTF::nullopt;
179     };
180     if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) {
181         auto value = toJS<IDLDOMString>(*state, WTFMove(namedProperty.value()));
182         slot.setValue(thisObject, static_cast<unsigned>(0), value);
183         return true;
184     }
185     return JSObject::getOwnPropertySlotByIndex(object, state, index, slot);
186 }
187
188 void JSTestNamedSetterWithIdentifier::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode)
189 {
190     VM& vm = state->vm();
191     auto* thisObject = jsCast<JSTestNamedSetterWithIdentifier*>(object);
192     ASSERT_GC_OBJECT_INHERITS(object, info());
193     for (auto& propertyName : thisObject->wrapped().supportedPropertyNames())
194         propertyNames.add(Identifier::fromString(vm, propertyName));
195     JSObject::getOwnPropertyNames(object, state, propertyNames, mode);
196 }
197
198 bool JSTestNamedSetterWithIdentifier::put(JSCell* cell, ExecState* state, PropertyName propertyName, JSValue value, PutPropertySlot& putPropertySlot)
199 {
200     auto* thisObject = jsCast<JSTestNamedSetterWithIdentifier*>(cell);
201     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
202
203     if (!propertyName.isSymbol()) {
204         PropertySlot slot { thisObject, PropertySlot::InternalMethodType::VMInquiry };
205         JSValue prototype = thisObject->getPrototypeDirect(state->vm());
206         if (!(prototype.isObject() && asObject(prototype)->getPropertySlot(state, propertyName, slot))) {
207             auto throwScope = DECLARE_THROW_SCOPE(state->vm());
208             auto nativeValue = convert<IDLDOMString>(*state, value);
209             RETURN_IF_EXCEPTION(throwScope, true);
210             thisObject->wrapped().namedSetter(propertyNameToString(propertyName), WTFMove(nativeValue));
211             return true;
212         }
213     }
214
215     return JSObject::put(thisObject, state, propertyName, value, putPropertySlot);
216 }
217
218 bool JSTestNamedSetterWithIdentifier::putByIndex(JSCell* cell, ExecState* state, unsigned index, JSValue value, bool shouldThrow)
219 {
220     VM& vm = state->vm();
221     auto* thisObject = jsCast<JSTestNamedSetterWithIdentifier*>(cell);
222     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
223
224     auto propertyName = Identifier::from(vm, index);
225     PropertySlot slot { thisObject, PropertySlot::InternalMethodType::VMInquiry };
226     JSValue prototype = thisObject->getPrototypeDirect(vm);
227     if (!(prototype.isObject() && asObject(prototype)->getPropertySlot(state, propertyName, slot))) {
228         auto throwScope = DECLARE_THROW_SCOPE(state->vm());
229         auto nativeValue = convert<IDLDOMString>(*state, value);
230         RETURN_IF_EXCEPTION(throwScope, true);
231         thisObject->wrapped().namedSetter(propertyNameToString(propertyName), WTFMove(nativeValue));
232         return true;
233     }
234
235     return JSObject::putByIndex(cell, state, index, value, shouldThrow);
236 }
237
238 bool JSTestNamedSetterWithIdentifier::defineOwnProperty(JSObject* object, ExecState* state, PropertyName propertyName, const PropertyDescriptor& propertyDescriptor, bool shouldThrow)
239 {
240     auto* thisObject = jsCast<JSTestNamedSetterWithIdentifier*>(object);
241     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
242
243     if (!propertyName.isSymbol()) {
244         PropertySlot slot { thisObject, PropertySlot::InternalMethodType::VMInquiry };
245         if (!JSObject::getOwnPropertySlot(thisObject, state, propertyName, slot)) {
246             if (!propertyDescriptor.isDataDescriptor())
247                 return false;
248             auto throwScope = DECLARE_THROW_SCOPE(state->vm());
249             auto nativeValue = convert<IDLDOMString>(*state, propertyDescriptor.value());
250             RETURN_IF_EXCEPTION(throwScope, true);
251             thisObject->wrapped().namedSetter(propertyNameToString(propertyName), WTFMove(nativeValue));
252             return true;
253         }
254     }
255
256     PropertyDescriptor newPropertyDescriptor = propertyDescriptor;
257     newPropertyDescriptor.setConfigurable(true);
258     return JSObject::defineOwnProperty(object, state, propertyName, newPropertyDescriptor, shouldThrow);
259 }
260
261 template<> inline JSTestNamedSetterWithIdentifier* IDLOperation<JSTestNamedSetterWithIdentifier>::cast(ExecState& state)
262 {
263     return jsDynamicCast<JSTestNamedSetterWithIdentifier*>(state.vm(), state.thisValue());
264 }
265
266 EncodedJSValue jsTestNamedSetterWithIdentifierConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
267 {
268     VM& vm = state->vm();
269     auto throwScope = DECLARE_THROW_SCOPE(vm);
270     auto* prototype = jsDynamicCast<JSTestNamedSetterWithIdentifierPrototype*>(vm, JSValue::decode(thisValue));
271     if (UNLIKELY(!prototype))
272         return throwVMTypeError(state, throwScope);
273     return JSValue::encode(JSTestNamedSetterWithIdentifier::getConstructor(state->vm(), prototype->globalObject()));
274 }
275
276 bool setJSTestNamedSetterWithIdentifierConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
277 {
278     VM& vm = state->vm();
279     auto throwScope = DECLARE_THROW_SCOPE(vm);
280     auto* prototype = jsDynamicCast<JSTestNamedSetterWithIdentifierPrototype*>(vm, JSValue::decode(thisValue));
281     if (UNLIKELY(!prototype)) {
282         throwVMTypeError(state, throwScope);
283         return false;
284     }
285     // Shadowing a built-in constructor
286     return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
287 }
288
289 static inline JSC::EncodedJSValue jsTestNamedSetterWithIdentifierPrototypeFunctionNamedSetterBody(JSC::ExecState* state, typename IDLOperation<JSTestNamedSetterWithIdentifier>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
290 {
291     UNUSED_PARAM(state);
292     UNUSED_PARAM(throwScope);
293     auto& impl = castedThis->wrapped();
294     if (UNLIKELY(state->argumentCount() < 2))
295         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
296     auto name = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
297     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
298     auto value = convert<IDLDOMString>(*state, state->uncheckedArgument(1));
299     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
300     impl.namedSetter(WTFMove(name), WTFMove(value));
301     return JSValue::encode(jsUndefined());
302 }
303
304 EncodedJSValue JSC_HOST_CALL jsTestNamedSetterWithIdentifierPrototypeFunctionNamedSetter(JSGlobalObject* globalObject, CallFrame* state)
305 {
306     UNUSED_PARAM(globalObject);
307     return IDLOperation<JSTestNamedSetterWithIdentifier>::call<jsTestNamedSetterWithIdentifierPrototypeFunctionNamedSetterBody>(*state, "namedSetter");
308 }
309
310 void JSTestNamedSetterWithIdentifier::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer)
311 {
312     auto* thisObject = jsCast<JSTestNamedSetterWithIdentifier*>(cell);
313     analyzer.setWrappedObjectForCell(cell, &thisObject->wrapped());
314     if (thisObject->scriptExecutionContext())
315         analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
316     Base::analyzeHeap(cell, analyzer);
317 }
318
319 bool JSTestNamedSetterWithIdentifierOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
320 {
321     UNUSED_PARAM(handle);
322     UNUSED_PARAM(visitor);
323     UNUSED_PARAM(reason);
324     return false;
325 }
326
327 void JSTestNamedSetterWithIdentifierOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
328 {
329     auto* jsTestNamedSetterWithIdentifier = static_cast<JSTestNamedSetterWithIdentifier*>(handle.slot()->asCell());
330     auto& world = *static_cast<DOMWrapperWorld*>(context);
331     uncacheWrapper(world, &jsTestNamedSetterWithIdentifier->wrapped(), jsTestNamedSetterWithIdentifier);
332 }
333
334 #if ENABLE(BINDING_INTEGRITY)
335 #if PLATFORM(WIN)
336 #pragma warning(disable: 4483)
337 extern "C" { extern void (*const __identifier("??_7TestNamedSetterWithIdentifier@WebCore@@6B@")[])(); }
338 #else
339 extern "C" { extern void* _ZTVN7WebCore29TestNamedSetterWithIdentifierE[]; }
340 #endif
341 #endif
342
343 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestNamedSetterWithIdentifier>&& impl)
344 {
345
346 #if ENABLE(BINDING_INTEGRITY)
347     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
348 #if PLATFORM(WIN)
349     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7TestNamedSetterWithIdentifier@WebCore@@6B@"));
350 #else
351     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore29TestNamedSetterWithIdentifierE[2]);
352 #endif
353
354     // If this fails TestNamedSetterWithIdentifier does not have a vtable, so you need to add the
355     // ImplementationLacksVTable attribute to the interface definition
356     static_assert(std::is_polymorphic<TestNamedSetterWithIdentifier>::value, "TestNamedSetterWithIdentifier is not polymorphic");
357
358     // If you hit this assertion you either have a use after free bug, or
359     // TestNamedSetterWithIdentifier has subclasses. If TestNamedSetterWithIdentifier has subclasses that get passed
360     // to toJS() we currently require TestNamedSetterWithIdentifier you to opt out of binding hardening
361     // by adding the SkipVTableValidation attribute to the interface IDL definition
362     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
363 #endif
364     return createWrapper<TestNamedSetterWithIdentifier>(globalObject, WTFMove(impl));
365 }
366
367 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestNamedSetterWithIdentifier& impl)
368 {
369     return wrap(state, globalObject, impl);
370 }
371
372 TestNamedSetterWithIdentifier* JSTestNamedSetterWithIdentifier::toWrapped(JSC::VM& vm, JSC::JSValue value)
373 {
374     if (auto* wrapper = jsDynamicCast<JSTestNamedSetterWithIdentifier*>(vm, value))
375         return &wrapper->wrapped();
376     return nullptr;
377 }
378
379 }