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 "JSUndoItem.h" |
23 | |
24 | #include "JSDOMAttribute.h" |
25 | #include "JSDOMBinding.h" |
26 | #include "JSDOMConstructor.h" |
27 | #include "JSDOMConvertCallbacks.h" |
28 | #include "JSDOMConvertInterface.h" |
29 | #include "JSDOMConvertStrings.h" |
30 | #include "JSDOMExceptionHandling.h" |
31 | #include "JSDOMGlobalObject.h" |
32 | #include "JSDOMWrapperCache.h" |
33 | #include "JSVoidCallback.h" |
34 | #include "ScriptExecutionContext.h" |
35 | #include <JavaScriptCore/FunctionPrototype.h> |
36 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
37 | #include <JavaScriptCore/JSCInlines.h> |
38 | #include <wtf/GetPtr.h> |
39 | #include <wtf/PointerPreparations.h> |
40 | #include <wtf/URL.h> |
41 | |
42 | |
43 | namespace WebCore { |
44 | using namespace JSC; |
45 | |
46 | template<> UndoItem::Init convertDictionary<UndoItem::Init>(ExecState& state, JSValue value) |
47 | { |
48 | VM& vm = state.vm(); |
49 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
50 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
51 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
52 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
53 | throwTypeError(&state, throwScope); |
54 | return { }; |
55 | } |
56 | UndoItem::Init result; |
57 | JSValue labelValue; |
58 | if (isNullOrUndefined) |
59 | labelValue = jsUndefined(); |
60 | else { |
61 | labelValue = object->get(&state, Identifier::fromString(&state, "label" )); |
62 | RETURN_IF_EXCEPTION(throwScope, { }); |
63 | } |
64 | if (!labelValue.isUndefined()) { |
65 | result.label = convert<IDLDOMString>(state, labelValue); |
66 | RETURN_IF_EXCEPTION(throwScope, { }); |
67 | } else { |
68 | throwRequiredMemberTypeError(state, throwScope, "label" , "UndoItemInit" , "DOMString" ); |
69 | return { }; |
70 | } |
71 | JSValue redoValue; |
72 | if (isNullOrUndefined) |
73 | redoValue = jsUndefined(); |
74 | else { |
75 | redoValue = object->get(&state, Identifier::fromString(&state, "redo" )); |
76 | RETURN_IF_EXCEPTION(throwScope, { }); |
77 | } |
78 | if (!redoValue.isUndefined()) { |
79 | result.redo = convert<IDLCallbackFunction<JSVoidCallback>>(state, redoValue, *jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject())); |
80 | RETURN_IF_EXCEPTION(throwScope, { }); |
81 | } else { |
82 | throwRequiredMemberTypeError(state, throwScope, "redo" , "UndoItemInit" , "VoidCallback" ); |
83 | return { }; |
84 | } |
85 | JSValue undoValue; |
86 | if (isNullOrUndefined) |
87 | undoValue = jsUndefined(); |
88 | else { |
89 | undoValue = object->get(&state, Identifier::fromString(&state, "undo" )); |
90 | RETURN_IF_EXCEPTION(throwScope, { }); |
91 | } |
92 | if (!undoValue.isUndefined()) { |
93 | result.undo = convert<IDLCallbackFunction<JSVoidCallback>>(state, undoValue, *jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject())); |
94 | RETURN_IF_EXCEPTION(throwScope, { }); |
95 | } else { |
96 | throwRequiredMemberTypeError(state, throwScope, "undo" , "UndoItemInit" , "VoidCallback" ); |
97 | return { }; |
98 | } |
99 | return result; |
100 | } |
101 | |
102 | // Attributes |
103 | |
104 | JSC::EncodedJSValue jsUndoItemConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
105 | bool setJSUndoItemConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
106 | JSC::EncodedJSValue jsUndoItemLabel(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
107 | |
108 | class JSUndoItemPrototype : public JSC::JSNonFinalObject { |
109 | public: |
110 | using Base = JSC::JSNonFinalObject; |
111 | static JSUndoItemPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
112 | { |
113 | JSUndoItemPrototype* ptr = new (NotNull, JSC::allocateCell<JSUndoItemPrototype>(vm.heap)) JSUndoItemPrototype(vm, globalObject, structure); |
114 | ptr->finishCreation(vm); |
115 | return ptr; |
116 | } |
117 | |
118 | DECLARE_INFO; |
119 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
120 | { |
121 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
122 | } |
123 | |
124 | private: |
125 | JSUndoItemPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
126 | : JSC::JSNonFinalObject(vm, structure) |
127 | { |
128 | } |
129 | |
130 | void finishCreation(JSC::VM&); |
131 | }; |
132 | |
133 | using JSUndoItemConstructor = JSDOMConstructor<JSUndoItem>; |
134 | |
135 | template<> EncodedJSValue JSC_HOST_CALL JSUndoItemConstructor::construct(ExecState* state) |
136 | { |
137 | VM& vm = state->vm(); |
138 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
139 | UNUSED_PARAM(throwScope); |
140 | auto* castedThis = jsCast<JSUndoItemConstructor*>(state->jsCallee()); |
141 | ASSERT(castedThis); |
142 | if (UNLIKELY(state->argumentCount() < 1)) |
143 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
144 | auto initDict = convert<IDLDictionary<UndoItem::Init>>(*state, state->uncheckedArgument(0)); |
145 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
146 | auto object = UndoItem::create(WTFMove(initDict)); |
147 | return JSValue::encode(toJSNewlyCreated<IDLInterface<UndoItem>>(*state, *castedThis->globalObject(), WTFMove(object))); |
148 | } |
149 | |
150 | template<> JSValue JSUndoItemConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
151 | { |
152 | UNUSED_PARAM(vm); |
153 | return globalObject.functionPrototype(); |
154 | } |
155 | |
156 | template<> void JSUndoItemConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
157 | { |
158 | putDirect(vm, vm.propertyNames->prototype, JSUndoItem::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
159 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("UndoItem"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
160 | putDirect(vm, vm.propertyNames->length, jsNumber(1), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
161 | } |
162 | |
163 | template<> const ClassInfo JSUndoItemConstructor::s_info = { "UndoItem" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSUndoItemConstructor) }; |
164 | |
165 | /* Hash table for prototype */ |
166 | |
167 | static const HashTableValue JSUndoItemPrototypeTableValues[] = |
168 | { |
169 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsUndoItemConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSUndoItemConstructor) } }, |
170 | { "label" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsUndoItemLabel), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
171 | }; |
172 | |
173 | const ClassInfo JSUndoItemPrototype::s_info = { "UndoItemPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSUndoItemPrototype) }; |
174 | |
175 | void JSUndoItemPrototype::finishCreation(VM& vm) |
176 | { |
177 | Base::finishCreation(vm); |
178 | reifyStaticProperties(vm, JSUndoItem::info(), JSUndoItemPrototypeTableValues, *this); |
179 | } |
180 | |
181 | const ClassInfo JSUndoItem::s_info = { "UndoItem" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSUndoItem) }; |
182 | |
183 | JSUndoItem::JSUndoItem(Structure* structure, JSDOMGlobalObject& globalObject, Ref<UndoItem>&& impl) |
184 | : JSDOMWrapper<UndoItem>(structure, globalObject, WTFMove(impl)) |
185 | { |
186 | } |
187 | |
188 | void JSUndoItem::finishCreation(VM& vm) |
189 | { |
190 | Base::finishCreation(vm); |
191 | ASSERT(inherits(vm, info())); |
192 | |
193 | } |
194 | |
195 | JSObject* JSUndoItem::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
196 | { |
197 | return JSUndoItemPrototype::create(vm, &globalObject, JSUndoItemPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
198 | } |
199 | |
200 | JSObject* JSUndoItem::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
201 | { |
202 | return getDOMPrototype<JSUndoItem>(vm, globalObject); |
203 | } |
204 | |
205 | JSValue JSUndoItem::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
206 | { |
207 | return getDOMConstructor<JSUndoItemConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
208 | } |
209 | |
210 | void JSUndoItem::destroy(JSC::JSCell* cell) |
211 | { |
212 | JSUndoItem* thisObject = static_cast<JSUndoItem*>(cell); |
213 | thisObject->JSUndoItem::~JSUndoItem(); |
214 | } |
215 | |
216 | template<> inline JSUndoItem* IDLAttribute<JSUndoItem>::cast(ExecState& state, EncodedJSValue thisValue) |
217 | { |
218 | return jsDynamicCast<JSUndoItem*>(state.vm(), JSValue::decode(thisValue)); |
219 | } |
220 | |
221 | EncodedJSValue jsUndoItemConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
222 | { |
223 | VM& vm = state->vm(); |
224 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
225 | auto* prototype = jsDynamicCast<JSUndoItemPrototype*>(vm, JSValue::decode(thisValue)); |
226 | if (UNLIKELY(!prototype)) |
227 | return throwVMTypeError(state, throwScope); |
228 | return JSValue::encode(JSUndoItem::getConstructor(state->vm(), prototype->globalObject())); |
229 | } |
230 | |
231 | bool setJSUndoItemConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
232 | { |
233 | VM& vm = state->vm(); |
234 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
235 | auto* prototype = jsDynamicCast<JSUndoItemPrototype*>(vm, JSValue::decode(thisValue)); |
236 | if (UNLIKELY(!prototype)) { |
237 | throwVMTypeError(state, throwScope); |
238 | return false; |
239 | } |
240 | // Shadowing a built-in constructor |
241 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
242 | } |
243 | |
244 | static inline JSValue jsUndoItemLabelGetter(ExecState& state, JSUndoItem& thisObject, ThrowScope& throwScope) |
245 | { |
246 | UNUSED_PARAM(throwScope); |
247 | UNUSED_PARAM(state); |
248 | auto& impl = thisObject.wrapped(); |
249 | JSValue result = toJS<IDLDOMString>(state, throwScope, impl.label()); |
250 | return result; |
251 | } |
252 | |
253 | EncodedJSValue jsUndoItemLabel(ExecState* state, EncodedJSValue thisValue, PropertyName) |
254 | { |
255 | return IDLAttribute<JSUndoItem>::get<jsUndoItemLabelGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "label" ); |
256 | } |
257 | |
258 | void JSUndoItem::visitChildren(JSCell* cell, SlotVisitor& visitor) |
259 | { |
260 | auto* thisObject = jsCast<JSUndoItem*>(cell); |
261 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
262 | Base::visitChildren(thisObject, visitor); |
263 | thisObject->visitAdditionalChildren(visitor); |
264 | } |
265 | |
266 | void JSUndoItem::visitOutputConstraints(JSCell* cell, SlotVisitor& visitor) |
267 | { |
268 | auto* thisObject = jsCast<JSUndoItem*>(cell); |
269 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
270 | Base::visitOutputConstraints(thisObject, visitor); |
271 | thisObject->visitAdditionalChildren(visitor); |
272 | } |
273 | |
274 | void JSUndoItem::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
275 | { |
276 | auto* thisObject = jsCast<JSUndoItem*>(cell); |
277 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
278 | if (thisObject->scriptExecutionContext()) |
279 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
280 | Base::heapSnapshot(cell, builder); |
281 | } |
282 | |
283 | void JSUndoItemOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
284 | { |
285 | auto* jsUndoItem = static_cast<JSUndoItem*>(handle.slot()->asCell()); |
286 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
287 | uncacheWrapper(world, &jsUndoItem->wrapped(), jsUndoItem); |
288 | } |
289 | |
290 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<UndoItem>&& impl) |
291 | { |
292 | // If you hit this failure the interface definition has the ImplementationLacksVTable |
293 | // attribute. You should remove that attribute. If the class has subclasses |
294 | // that may be passed through this toJS() function you should use the SkipVTableValidation |
295 | // attribute to UndoItem. |
296 | static_assert(!std::is_polymorphic<UndoItem>::value, "UndoItem is polymorphic but the IDL claims it is not" ); |
297 | return createWrapper<UndoItem>(globalObject, WTFMove(impl)); |
298 | } |
299 | |
300 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, UndoItem& impl) |
301 | { |
302 | return wrap(state, globalObject, impl); |
303 | } |
304 | |
305 | UndoItem* JSUndoItem::toWrapped(JSC::VM& vm, JSC::JSValue value) |
306 | { |
307 | if (auto* wrapper = jsDynamicCast<JSUndoItem*>(vm, value)) |
308 | return &wrapper->wrapped(); |
309 | return nullptr; |
310 | } |
311 | |
312 | } |
313 | |