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