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 "JSFileSystemDirectoryEntry.h" |
23 | |
24 | #include "JSDOMBinding.h" |
25 | #include "JSDOMConstructorNotConstructable.h" |
26 | #include "JSDOMConvertBoolean.h" |
27 | #include "JSDOMConvertCallbacks.h" |
28 | #include "JSDOMConvertInterface.h" |
29 | #include "JSDOMConvertNullable.h" |
30 | #include "JSDOMConvertStrings.h" |
31 | #include "JSDOMExceptionHandling.h" |
32 | #include "JSDOMGlobalObject.h" |
33 | #include "JSDOMOperation.h" |
34 | #include "JSDOMWrapperCache.h" |
35 | #include "JSErrorCallback.h" |
36 | #include "JSFileSystemDirectoryReader.h" |
37 | #include "JSFileSystemEntryCallback.h" |
38 | #include "ScriptExecutionContext.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 | template<> FileSystemDirectoryEntry::Flags convertDictionary<FileSystemDirectoryEntry::Flags>(ExecState& state, JSValue value) |
50 | { |
51 | VM& vm = state.vm(); |
52 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
53 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
54 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
55 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
56 | throwTypeError(&state, throwScope); |
57 | return { }; |
58 | } |
59 | FileSystemDirectoryEntry::Flags result; |
60 | JSValue createValue; |
61 | if (isNullOrUndefined) |
62 | createValue = jsUndefined(); |
63 | else { |
64 | createValue = object->get(&state, Identifier::fromString(&state, "create" )); |
65 | RETURN_IF_EXCEPTION(throwScope, { }); |
66 | } |
67 | if (!createValue.isUndefined()) { |
68 | result.create = convert<IDLBoolean>(state, createValue); |
69 | RETURN_IF_EXCEPTION(throwScope, { }); |
70 | } else |
71 | result.create = false; |
72 | JSValue exclusiveValue; |
73 | if (isNullOrUndefined) |
74 | exclusiveValue = jsUndefined(); |
75 | else { |
76 | exclusiveValue = object->get(&state, Identifier::fromString(&state, "exclusive" )); |
77 | RETURN_IF_EXCEPTION(throwScope, { }); |
78 | } |
79 | if (!exclusiveValue.isUndefined()) { |
80 | result.exclusive = convert<IDLBoolean>(state, exclusiveValue); |
81 | RETURN_IF_EXCEPTION(throwScope, { }); |
82 | } else |
83 | result.exclusive = false; |
84 | return result; |
85 | } |
86 | |
87 | // Functions |
88 | |
89 | JSC::EncodedJSValue JSC_HOST_CALL jsFileSystemDirectoryEntryPrototypeFunctionCreateReader(JSC::ExecState*); |
90 | JSC::EncodedJSValue JSC_HOST_CALL jsFileSystemDirectoryEntryPrototypeFunctionGetFile(JSC::ExecState*); |
91 | JSC::EncodedJSValue JSC_HOST_CALL jsFileSystemDirectoryEntryPrototypeFunctionGetDirectory(JSC::ExecState*); |
92 | |
93 | // Attributes |
94 | |
95 | JSC::EncodedJSValue jsFileSystemDirectoryEntryConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
96 | bool setJSFileSystemDirectoryEntryConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
97 | |
98 | class JSFileSystemDirectoryEntryPrototype : public JSC::JSNonFinalObject { |
99 | public: |
100 | using Base = JSC::JSNonFinalObject; |
101 | static JSFileSystemDirectoryEntryPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
102 | { |
103 | JSFileSystemDirectoryEntryPrototype* ptr = new (NotNull, JSC::allocateCell<JSFileSystemDirectoryEntryPrototype>(vm.heap)) JSFileSystemDirectoryEntryPrototype(vm, globalObject, structure); |
104 | ptr->finishCreation(vm); |
105 | return ptr; |
106 | } |
107 | |
108 | DECLARE_INFO; |
109 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
110 | { |
111 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
112 | } |
113 | |
114 | private: |
115 | JSFileSystemDirectoryEntryPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
116 | : JSC::JSNonFinalObject(vm, structure) |
117 | { |
118 | } |
119 | |
120 | void finishCreation(JSC::VM&); |
121 | }; |
122 | |
123 | using JSFileSystemDirectoryEntryConstructor = JSDOMConstructorNotConstructable<JSFileSystemDirectoryEntry>; |
124 | |
125 | template<> JSValue JSFileSystemDirectoryEntryConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
126 | { |
127 | return JSFileSystemEntry::getConstructor(vm, &globalObject); |
128 | } |
129 | |
130 | template<> void JSFileSystemDirectoryEntryConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
131 | { |
132 | putDirect(vm, vm.propertyNames->prototype, JSFileSystemDirectoryEntry::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
133 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("FileSystemDirectoryEntry"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
134 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
135 | } |
136 | |
137 | template<> const ClassInfo JSFileSystemDirectoryEntryConstructor::s_info = { "FileSystemDirectoryEntry" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSFileSystemDirectoryEntryConstructor) }; |
138 | |
139 | /* Hash table for prototype */ |
140 | |
141 | static const HashTableValue JSFileSystemDirectoryEntryPrototypeTableValues[] = |
142 | { |
143 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFileSystemDirectoryEntryConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSFileSystemDirectoryEntryConstructor) } }, |
144 | { "createReader" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsFileSystemDirectoryEntryPrototypeFunctionCreateReader), (intptr_t) (0) } }, |
145 | { "getFile" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsFileSystemDirectoryEntryPrototypeFunctionGetFile), (intptr_t) (0) } }, |
146 | { "getDirectory" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsFileSystemDirectoryEntryPrototypeFunctionGetDirectory), (intptr_t) (0) } }, |
147 | }; |
148 | |
149 | const ClassInfo JSFileSystemDirectoryEntryPrototype::s_info = { "FileSystemDirectoryEntryPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSFileSystemDirectoryEntryPrototype) }; |
150 | |
151 | void JSFileSystemDirectoryEntryPrototype::finishCreation(VM& vm) |
152 | { |
153 | Base::finishCreation(vm); |
154 | reifyStaticProperties(vm, JSFileSystemDirectoryEntry::info(), JSFileSystemDirectoryEntryPrototypeTableValues, *this); |
155 | } |
156 | |
157 | const ClassInfo JSFileSystemDirectoryEntry::s_info = { "FileSystemDirectoryEntry" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSFileSystemDirectoryEntry) }; |
158 | |
159 | JSFileSystemDirectoryEntry::JSFileSystemDirectoryEntry(Structure* structure, JSDOMGlobalObject& globalObject, Ref<FileSystemDirectoryEntry>&& impl) |
160 | : JSFileSystemEntry(structure, globalObject, WTFMove(impl)) |
161 | { |
162 | } |
163 | |
164 | void JSFileSystemDirectoryEntry::finishCreation(VM& vm) |
165 | { |
166 | Base::finishCreation(vm); |
167 | ASSERT(inherits(vm, info())); |
168 | |
169 | } |
170 | |
171 | JSObject* JSFileSystemDirectoryEntry::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
172 | { |
173 | return JSFileSystemDirectoryEntryPrototype::create(vm, &globalObject, JSFileSystemDirectoryEntryPrototype::createStructure(vm, &globalObject, JSFileSystemEntry::prototype(vm, globalObject))); |
174 | } |
175 | |
176 | JSObject* JSFileSystemDirectoryEntry::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
177 | { |
178 | return getDOMPrototype<JSFileSystemDirectoryEntry>(vm, globalObject); |
179 | } |
180 | |
181 | JSValue JSFileSystemDirectoryEntry::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
182 | { |
183 | return getDOMConstructor<JSFileSystemDirectoryEntryConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
184 | } |
185 | |
186 | template<> inline JSFileSystemDirectoryEntry* IDLOperation<JSFileSystemDirectoryEntry>::cast(ExecState& state) |
187 | { |
188 | return jsDynamicCast<JSFileSystemDirectoryEntry*>(state.vm(), state.thisValue()); |
189 | } |
190 | |
191 | EncodedJSValue jsFileSystemDirectoryEntryConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
192 | { |
193 | VM& vm = state->vm(); |
194 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
195 | auto* prototype = jsDynamicCast<JSFileSystemDirectoryEntryPrototype*>(vm, JSValue::decode(thisValue)); |
196 | if (UNLIKELY(!prototype)) |
197 | return throwVMTypeError(state, throwScope); |
198 | return JSValue::encode(JSFileSystemDirectoryEntry::getConstructor(state->vm(), prototype->globalObject())); |
199 | } |
200 | |
201 | bool setJSFileSystemDirectoryEntryConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
202 | { |
203 | VM& vm = state->vm(); |
204 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
205 | auto* prototype = jsDynamicCast<JSFileSystemDirectoryEntryPrototype*>(vm, JSValue::decode(thisValue)); |
206 | if (UNLIKELY(!prototype)) { |
207 | throwVMTypeError(state, throwScope); |
208 | return false; |
209 | } |
210 | // Shadowing a built-in constructor |
211 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
212 | } |
213 | |
214 | static inline JSC::EncodedJSValue jsFileSystemDirectoryEntryPrototypeFunctionCreateReaderBody(JSC::ExecState* state, typename IDLOperation<JSFileSystemDirectoryEntry>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
215 | { |
216 | UNUSED_PARAM(state); |
217 | UNUSED_PARAM(throwScope); |
218 | auto& impl = castedThis->wrapped(); |
219 | auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext(); |
220 | if (UNLIKELY(!context)) |
221 | return JSValue::encode(jsUndefined()); |
222 | return JSValue::encode(toJS<IDLInterface<FileSystemDirectoryReader>>(*state, *castedThis->globalObject(), impl.createReader(*context))); |
223 | } |
224 | |
225 | EncodedJSValue JSC_HOST_CALL jsFileSystemDirectoryEntryPrototypeFunctionCreateReader(ExecState* state) |
226 | { |
227 | return IDLOperation<JSFileSystemDirectoryEntry>::call<jsFileSystemDirectoryEntryPrototypeFunctionCreateReaderBody>(*state, "createReader" ); |
228 | } |
229 | |
230 | static inline JSC::EncodedJSValue jsFileSystemDirectoryEntryPrototypeFunctionGetFileBody(JSC::ExecState* state, typename IDLOperation<JSFileSystemDirectoryEntry>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
231 | { |
232 | UNUSED_PARAM(state); |
233 | UNUSED_PARAM(throwScope); |
234 | auto& impl = castedThis->wrapped(); |
235 | auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext(); |
236 | if (UNLIKELY(!context)) |
237 | return JSValue::encode(jsUndefined()); |
238 | auto path = state->argument(0).isUndefined() ? String() : convert<IDLNullable<IDLUSVString>>(*state, state->uncheckedArgument(0)); |
239 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
240 | auto options = convert<IDLDictionary<FileSystemDirectoryEntry::Flags>>(*state, state->argument(1)); |
241 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
242 | auto successCallback = convert<IDLNullable<IDLCallbackFunction<JSFileSystemEntryCallback>>>(*state, state->argument(2), *castedThis->globalObject(), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(state, scope, 2, "successCallback" , "FileSystemDirectoryEntry" , "getFile" ); }); |
243 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
244 | auto errorCallback = convert<IDLNullable<IDLCallbackFunction<JSErrorCallback>>>(*state, state->argument(3), *castedThis->globalObject(), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(state, scope, 3, "errorCallback" , "FileSystemDirectoryEntry" , "getFile" ); }); |
245 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
246 | impl.getFile(*context, WTFMove(path), WTFMove(options), WTFMove(successCallback), WTFMove(errorCallback)); |
247 | return JSValue::encode(jsUndefined()); |
248 | } |
249 | |
250 | EncodedJSValue JSC_HOST_CALL jsFileSystemDirectoryEntryPrototypeFunctionGetFile(ExecState* state) |
251 | { |
252 | return IDLOperation<JSFileSystemDirectoryEntry>::call<jsFileSystemDirectoryEntryPrototypeFunctionGetFileBody>(*state, "getFile" ); |
253 | } |
254 | |
255 | static inline JSC::EncodedJSValue jsFileSystemDirectoryEntryPrototypeFunctionGetDirectoryBody(JSC::ExecState* state, typename IDLOperation<JSFileSystemDirectoryEntry>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
256 | { |
257 | UNUSED_PARAM(state); |
258 | UNUSED_PARAM(throwScope); |
259 | auto& impl = castedThis->wrapped(); |
260 | auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext(); |
261 | if (UNLIKELY(!context)) |
262 | return JSValue::encode(jsUndefined()); |
263 | auto path = state->argument(0).isUndefined() ? String() : convert<IDLNullable<IDLUSVString>>(*state, state->uncheckedArgument(0)); |
264 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
265 | auto options = convert<IDLDictionary<FileSystemDirectoryEntry::Flags>>(*state, state->argument(1)); |
266 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
267 | auto successCallback = convert<IDLNullable<IDLCallbackFunction<JSFileSystemEntryCallback>>>(*state, state->argument(2), *castedThis->globalObject(), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(state, scope, 2, "successCallback" , "FileSystemDirectoryEntry" , "getDirectory" ); }); |
268 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
269 | auto errorCallback = convert<IDLNullable<IDLCallbackFunction<JSErrorCallback>>>(*state, state->argument(3), *castedThis->globalObject(), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(state, scope, 3, "errorCallback" , "FileSystemDirectoryEntry" , "getDirectory" ); }); |
270 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
271 | impl.getDirectory(*context, WTFMove(path), WTFMove(options), WTFMove(successCallback), WTFMove(errorCallback)); |
272 | return JSValue::encode(jsUndefined()); |
273 | } |
274 | |
275 | EncodedJSValue JSC_HOST_CALL jsFileSystemDirectoryEntryPrototypeFunctionGetDirectory(ExecState* state) |
276 | { |
277 | return IDLOperation<JSFileSystemDirectoryEntry>::call<jsFileSystemDirectoryEntryPrototypeFunctionGetDirectoryBody>(*state, "getDirectory" ); |
278 | } |
279 | |
280 | void JSFileSystemDirectoryEntry::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
281 | { |
282 | auto* thisObject = jsCast<JSFileSystemDirectoryEntry*>(cell); |
283 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
284 | if (thisObject->scriptExecutionContext()) |
285 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
286 | Base::heapSnapshot(cell, builder); |
287 | } |
288 | |
289 | |
290 | } |
291 | |