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 "JSUndoManager.h"
23
24#include "JSDOMBinding.h"
25#include "JSDOMConstructorNotConstructable.h"
26#include "JSDOMConvertInterface.h"
27#include "JSDOMExceptionHandling.h"
28#include "JSDOMOperation.h"
29#include "JSDOMWrapperCache.h"
30#include "JSUndoItem.h"
31#include "ScriptExecutionContext.h"
32#include <JavaScriptCore/FunctionPrototype.h>
33#include <JavaScriptCore/HeapSnapshotBuilder.h>
34#include <JavaScriptCore/JSCInlines.h>
35#include <wtf/GetPtr.h>
36#include <wtf/PointerPreparations.h>
37#include <wtf/URL.h>
38
39
40namespace WebCore {
41using namespace JSC;
42
43// Functions
44
45JSC::EncodedJSValue JSC_HOST_CALL jsUndoManagerPrototypeFunctionAddItem(JSC::ExecState*);
46
47// Attributes
48
49JSC::EncodedJSValue jsUndoManagerConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
50bool setJSUndoManagerConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
51
52class JSUndoManagerPrototype : public JSC::JSNonFinalObject {
53public:
54 using Base = JSC::JSNonFinalObject;
55 static JSUndoManagerPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
56 {
57 JSUndoManagerPrototype* ptr = new (NotNull, JSC::allocateCell<JSUndoManagerPrototype>(vm.heap)) JSUndoManagerPrototype(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
68private:
69 JSUndoManagerPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
70 : JSC::JSNonFinalObject(vm, structure)
71 {
72 }
73
74 void finishCreation(JSC::VM&);
75};
76
77using JSUndoManagerConstructor = JSDOMConstructorNotConstructable<JSUndoManager>;
78
79template<> JSValue JSUndoManagerConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
80{
81 UNUSED_PARAM(vm);
82 return globalObject.functionPrototype();
83}
84
85template<> void JSUndoManagerConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
86{
87 putDirect(vm, vm.propertyNames->prototype, JSUndoManager::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
88 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("UndoManager"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
89 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
90}
91
92template<> const ClassInfo JSUndoManagerConstructor::s_info = { "UndoManager", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSUndoManagerConstructor) };
93
94/* Hash table for prototype */
95
96static const HashTableValue JSUndoManagerPrototypeTableValues[] =
97{
98 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsUndoManagerConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSUndoManagerConstructor) } },
99 { "addItem", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsUndoManagerPrototypeFunctionAddItem), (intptr_t) (1) } },
100};
101
102const ClassInfo JSUndoManagerPrototype::s_info = { "UndoManagerPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSUndoManagerPrototype) };
103
104void JSUndoManagerPrototype::finishCreation(VM& vm)
105{
106 Base::finishCreation(vm);
107 reifyStaticProperties(vm, JSUndoManager::info(), JSUndoManagerPrototypeTableValues, *this);
108}
109
110const ClassInfo JSUndoManager::s_info = { "UndoManager", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSUndoManager) };
111
112JSUndoManager::JSUndoManager(Structure* structure, JSDOMGlobalObject& globalObject, Ref<UndoManager>&& impl)
113 : JSDOMWrapper<UndoManager>(structure, globalObject, WTFMove(impl))
114{
115}
116
117void JSUndoManager::finishCreation(VM& vm)
118{
119 Base::finishCreation(vm);
120 ASSERT(inherits(vm, info()));
121
122}
123
124JSObject* JSUndoManager::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
125{
126 return JSUndoManagerPrototype::create(vm, &globalObject, JSUndoManagerPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
127}
128
129JSObject* JSUndoManager::prototype(VM& vm, JSDOMGlobalObject& globalObject)
130{
131 return getDOMPrototype<JSUndoManager>(vm, globalObject);
132}
133
134JSValue JSUndoManager::getConstructor(VM& vm, const JSGlobalObject* globalObject)
135{
136 return getDOMConstructor<JSUndoManagerConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
137}
138
139void JSUndoManager::destroy(JSC::JSCell* cell)
140{
141 JSUndoManager* thisObject = static_cast<JSUndoManager*>(cell);
142 thisObject->JSUndoManager::~JSUndoManager();
143}
144
145template<> inline JSUndoManager* IDLOperation<JSUndoManager>::cast(ExecState& state)
146{
147 return jsDynamicCast<JSUndoManager*>(state.vm(), state.thisValue());
148}
149
150EncodedJSValue jsUndoManagerConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
151{
152 VM& vm = state->vm();
153 auto throwScope = DECLARE_THROW_SCOPE(vm);
154 auto* prototype = jsDynamicCast<JSUndoManagerPrototype*>(vm, JSValue::decode(thisValue));
155 if (UNLIKELY(!prototype))
156 return throwVMTypeError(state, throwScope);
157 return JSValue::encode(JSUndoManager::getConstructor(state->vm(), prototype->globalObject()));
158}
159
160bool setJSUndoManagerConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
161{
162 VM& vm = state->vm();
163 auto throwScope = DECLARE_THROW_SCOPE(vm);
164 auto* prototype = jsDynamicCast<JSUndoManagerPrototype*>(vm, JSValue::decode(thisValue));
165 if (UNLIKELY(!prototype)) {
166 throwVMTypeError(state, throwScope);
167 return false;
168 }
169 // Shadowing a built-in constructor
170 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
171}
172
173static inline JSC::EncodedJSValue jsUndoManagerPrototypeFunctionAddItemBody(JSC::ExecState* state, typename IDLOperation<JSUndoManager>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
174{
175 UNUSED_PARAM(state);
176 UNUSED_PARAM(throwScope);
177 auto& impl = castedThis->wrapped();
178 if (UNLIKELY(state->argumentCount() < 1))
179 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
180 auto item = convert<IDLInterface<UndoItem>>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentTypeError(state, scope, 0, "item", "UndoManager", "addItem", "UndoItem"); });
181 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
182 propagateException(*state, throwScope, impl.addItem(*item));
183 return JSValue::encode(jsUndefined());
184}
185
186EncodedJSValue JSC_HOST_CALL jsUndoManagerPrototypeFunctionAddItem(ExecState* state)
187{
188 return IDLOperation<JSUndoManager>::call<jsUndoManagerPrototypeFunctionAddItemBody>(*state, "addItem");
189}
190
191void JSUndoManager::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
192{
193 auto* thisObject = jsCast<JSUndoManager*>(cell);
194 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
195 if (thisObject->scriptExecutionContext())
196 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
197 Base::heapSnapshot(cell, builder);
198}
199
200bool JSUndoManagerOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
201{
202 auto* jsUndoManager = jsCast<JSUndoManager*>(handle.slot()->asCell());
203 Document* root = WTF::getPtr(jsUndoManager->wrapped().document());
204 if (!root)
205 return false;
206 if (UNLIKELY(reason))
207 *reason = "Reachable from Document";
208 return visitor.containsOpaqueRoot(root);
209}
210
211void JSUndoManagerOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
212{
213 auto* jsUndoManager = static_cast<JSUndoManager*>(handle.slot()->asCell());
214 auto& world = *static_cast<DOMWrapperWorld*>(context);
215 uncacheWrapper(world, &jsUndoManager->wrapped(), jsUndoManager);
216}
217
218JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<UndoManager>&& impl)
219{
220 // If you hit this failure the interface definition has the ImplementationLacksVTable
221 // attribute. You should remove that attribute. If the class has subclasses
222 // that may be passed through this toJS() function you should use the SkipVTableValidation
223 // attribute to UndoManager.
224 static_assert(!std::is_polymorphic<UndoManager>::value, "UndoManager is polymorphic but the IDL claims it is not");
225 return createWrapper<UndoManager>(globalObject, WTFMove(impl));
226}
227
228JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, UndoManager& impl)
229{
230 return wrap(state, globalObject, impl);
231}
232
233UndoManager* JSUndoManager::toWrapped(JSC::VM& vm, JSC::JSValue value)
234{
235 if (auto* wrapper = jsDynamicCast<JSUndoManager*>(vm, value))
236 return &wrapper->wrapped();
237 return nullptr;
238}
239
240}
241