| 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 | |
| 23 | #if ENABLE(INDEXED_DATABASE) |
| 24 | |
| 25 | #include "JSIDBDatabase.h" |
| 26 | |
| 27 | #include "EventNames.h" |
| 28 | #include "JSDOMAttribute.h" |
| 29 | #include "JSDOMBinding.h" |
| 30 | #include "JSDOMConstructorNotConstructable.h" |
| 31 | #include "JSDOMConvertBoolean.h" |
| 32 | #include "JSDOMConvertEnumeration.h" |
| 33 | #include "JSDOMConvertInterface.h" |
| 34 | #include "JSDOMConvertNullable.h" |
| 35 | #include "JSDOMConvertNumbers.h" |
| 36 | #include "JSDOMConvertSequences.h" |
| 37 | #include "JSDOMConvertStrings.h" |
| 38 | #include "JSDOMConvertUnion.h" |
| 39 | #include "JSDOMExceptionHandling.h" |
| 40 | #include "JSDOMGlobalObject.h" |
| 41 | #include "JSDOMOperation.h" |
| 42 | #include "JSDOMStringList.h" |
| 43 | #include "JSDOMWrapperCache.h" |
| 44 | #include "JSEventListener.h" |
| 45 | #include "JSIDBObjectStore.h" |
| 46 | #include "JSIDBTransaction.h" |
| 47 | #include "JSIDBTransactionMode.h" |
| 48 | #include "ScriptExecutionContext.h" |
| 49 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
| 50 | #include <JavaScriptCore/IteratorOperations.h> |
| 51 | #include <JavaScriptCore/JSArray.h> |
| 52 | #include <JavaScriptCore/JSCInlines.h> |
| 53 | #include <wtf/GetPtr.h> |
| 54 | #include <wtf/PointerPreparations.h> |
| 55 | #include <wtf/URL.h> |
| 56 | #include <wtf/Variant.h> |
| 57 | |
| 58 | |
| 59 | namespace WebCore { |
| 60 | using namespace JSC; |
| 61 | |
| 62 | template<> IDBDatabase::ObjectStoreParameters convertDictionary<IDBDatabase::ObjectStoreParameters>(ExecState& state, JSValue value) |
| 63 | { |
| 64 | VM& vm = state.vm(); |
| 65 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 66 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
| 67 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
| 68 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
| 69 | throwTypeError(&state, throwScope); |
| 70 | return { }; |
| 71 | } |
| 72 | IDBDatabase::ObjectStoreParameters result; |
| 73 | JSValue autoIncrementValue; |
| 74 | if (isNullOrUndefined) |
| 75 | autoIncrementValue = jsUndefined(); |
| 76 | else { |
| 77 | autoIncrementValue = object->get(&state, Identifier::fromString(&state, "autoIncrement" )); |
| 78 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 79 | } |
| 80 | if (!autoIncrementValue.isUndefined()) { |
| 81 | result.autoIncrement = convert<IDLBoolean>(state, autoIncrementValue); |
| 82 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 83 | } else |
| 84 | result.autoIncrement = false; |
| 85 | JSValue keyPathValue; |
| 86 | if (isNullOrUndefined) |
| 87 | keyPathValue = jsUndefined(); |
| 88 | else { |
| 89 | keyPathValue = object->get(&state, Identifier::fromString(&state, "keyPath" )); |
| 90 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 91 | } |
| 92 | if (!keyPathValue.isUndefined()) { |
| 93 | result.keyPath = convert<IDLNullable<IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>>>>(state, keyPathValue); |
| 94 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 95 | } else |
| 96 | result.keyPath = WTF::nullopt; |
| 97 | return result; |
| 98 | } |
| 99 | |
| 100 | // Functions |
| 101 | |
| 102 | JSC::EncodedJSValue JSC_HOST_CALL jsIDBDatabasePrototypeFunctionCreateObjectStore(JSC::ExecState*); |
| 103 | JSC::EncodedJSValue JSC_HOST_CALL jsIDBDatabasePrototypeFunctionDeleteObjectStore(JSC::ExecState*); |
| 104 | JSC::EncodedJSValue JSC_HOST_CALL jsIDBDatabasePrototypeFunctionTransaction(JSC::ExecState*); |
| 105 | JSC::EncodedJSValue JSC_HOST_CALL jsIDBDatabasePrototypeFunctionClose(JSC::ExecState*); |
| 106 | |
| 107 | // Attributes |
| 108 | |
| 109 | JSC::EncodedJSValue jsIDBDatabaseConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 110 | bool setJSIDBDatabaseConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 111 | JSC::EncodedJSValue jsIDBDatabaseName(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 112 | JSC::EncodedJSValue jsIDBDatabaseVersion(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 113 | JSC::EncodedJSValue jsIDBDatabaseObjectStoreNames(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 114 | JSC::EncodedJSValue jsIDBDatabaseOnabort(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 115 | bool setJSIDBDatabaseOnabort(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 116 | JSC::EncodedJSValue jsIDBDatabaseOnclose(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 117 | bool setJSIDBDatabaseOnclose(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 118 | JSC::EncodedJSValue jsIDBDatabaseOnerror(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 119 | bool setJSIDBDatabaseOnerror(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 120 | JSC::EncodedJSValue jsIDBDatabaseOnversionchange(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 121 | bool setJSIDBDatabaseOnversionchange(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 122 | |
| 123 | class JSIDBDatabasePrototype : public JSC::JSNonFinalObject { |
| 124 | public: |
| 125 | using Base = JSC::JSNonFinalObject; |
| 126 | static JSIDBDatabasePrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
| 127 | { |
| 128 | JSIDBDatabasePrototype* ptr = new (NotNull, JSC::allocateCell<JSIDBDatabasePrototype>(vm.heap)) JSIDBDatabasePrototype(vm, globalObject, structure); |
| 129 | ptr->finishCreation(vm); |
| 130 | return ptr; |
| 131 | } |
| 132 | |
| 133 | DECLARE_INFO; |
| 134 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
| 135 | { |
| 136 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
| 137 | } |
| 138 | |
| 139 | private: |
| 140 | JSIDBDatabasePrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
| 141 | : JSC::JSNonFinalObject(vm, structure) |
| 142 | { |
| 143 | } |
| 144 | |
| 145 | void finishCreation(JSC::VM&); |
| 146 | }; |
| 147 | |
| 148 | using JSIDBDatabaseConstructor = JSDOMConstructorNotConstructable<JSIDBDatabase>; |
| 149 | |
| 150 | template<> JSValue JSIDBDatabaseConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| 151 | { |
| 152 | return JSEventTarget::getConstructor(vm, &globalObject); |
| 153 | } |
| 154 | |
| 155 | template<> void JSIDBDatabaseConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
| 156 | { |
| 157 | putDirect(vm, vm.propertyNames->prototype, JSIDBDatabase::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 158 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("IDBDatabase"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 159 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 160 | } |
| 161 | |
| 162 | template<> const ClassInfo JSIDBDatabaseConstructor::s_info = { "IDBDatabase" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSIDBDatabaseConstructor) }; |
| 163 | |
| 164 | /* Hash table for prototype */ |
| 165 | |
| 166 | static const HashTableValue JSIDBDatabasePrototypeTableValues[] = |
| 167 | { |
| 168 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBDatabaseConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSIDBDatabaseConstructor) } }, |
| 169 | { "name" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBDatabaseName), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 170 | { "version" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBDatabaseVersion), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 171 | { "objectStoreNames" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBDatabaseObjectStoreNames), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 172 | { "onabort" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBDatabaseOnabort), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSIDBDatabaseOnabort) } }, |
| 173 | { "onclose" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBDatabaseOnclose), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSIDBDatabaseOnclose) } }, |
| 174 | { "onerror" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBDatabaseOnerror), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSIDBDatabaseOnerror) } }, |
| 175 | { "onversionchange" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBDatabaseOnversionchange), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSIDBDatabaseOnversionchange) } }, |
| 176 | { "createObjectStore" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsIDBDatabasePrototypeFunctionCreateObjectStore), (intptr_t) (1) } }, |
| 177 | { "deleteObjectStore" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsIDBDatabasePrototypeFunctionDeleteObjectStore), (intptr_t) (1) } }, |
| 178 | { "transaction" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsIDBDatabasePrototypeFunctionTransaction), (intptr_t) (1) } }, |
| 179 | { "close" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsIDBDatabasePrototypeFunctionClose), (intptr_t) (0) } }, |
| 180 | }; |
| 181 | |
| 182 | const ClassInfo JSIDBDatabasePrototype::s_info = { "IDBDatabasePrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSIDBDatabasePrototype) }; |
| 183 | |
| 184 | void JSIDBDatabasePrototype::finishCreation(VM& vm) |
| 185 | { |
| 186 | Base::finishCreation(vm); |
| 187 | reifyStaticProperties(vm, JSIDBDatabase::info(), JSIDBDatabasePrototypeTableValues, *this); |
| 188 | } |
| 189 | |
| 190 | const ClassInfo JSIDBDatabase::s_info = { "IDBDatabase" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSIDBDatabase) }; |
| 191 | |
| 192 | JSIDBDatabase::JSIDBDatabase(Structure* structure, JSDOMGlobalObject& globalObject, Ref<IDBDatabase>&& impl) |
| 193 | : JSEventTarget(structure, globalObject, WTFMove(impl)) |
| 194 | { |
| 195 | } |
| 196 | |
| 197 | void JSIDBDatabase::finishCreation(VM& vm) |
| 198 | { |
| 199 | Base::finishCreation(vm); |
| 200 | ASSERT(inherits(vm, info())); |
| 201 | |
| 202 | } |
| 203 | |
| 204 | JSObject* JSIDBDatabase::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 205 | { |
| 206 | return JSIDBDatabasePrototype::create(vm, &globalObject, JSIDBDatabasePrototype::createStructure(vm, &globalObject, JSEventTarget::prototype(vm, globalObject))); |
| 207 | } |
| 208 | |
| 209 | JSObject* JSIDBDatabase::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 210 | { |
| 211 | return getDOMPrototype<JSIDBDatabase>(vm, globalObject); |
| 212 | } |
| 213 | |
| 214 | JSValue JSIDBDatabase::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| 215 | { |
| 216 | return getDOMConstructor<JSIDBDatabaseConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| 217 | } |
| 218 | |
| 219 | template<> inline JSIDBDatabase* IDLAttribute<JSIDBDatabase>::cast(ExecState& state, EncodedJSValue thisValue) |
| 220 | { |
| 221 | return jsDynamicCast<JSIDBDatabase*>(state.vm(), JSValue::decode(thisValue)); |
| 222 | } |
| 223 | |
| 224 | template<> inline JSIDBDatabase* IDLOperation<JSIDBDatabase>::cast(ExecState& state) |
| 225 | { |
| 226 | return jsDynamicCast<JSIDBDatabase*>(state.vm(), state.thisValue()); |
| 227 | } |
| 228 | |
| 229 | EncodedJSValue jsIDBDatabaseConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 230 | { |
| 231 | VM& vm = state->vm(); |
| 232 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 233 | auto* prototype = jsDynamicCast<JSIDBDatabasePrototype*>(vm, JSValue::decode(thisValue)); |
| 234 | if (UNLIKELY(!prototype)) |
| 235 | return throwVMTypeError(state, throwScope); |
| 236 | return JSValue::encode(JSIDBDatabase::getConstructor(state->vm(), prototype->globalObject())); |
| 237 | } |
| 238 | |
| 239 | bool setJSIDBDatabaseConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 240 | { |
| 241 | VM& vm = state->vm(); |
| 242 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 243 | auto* prototype = jsDynamicCast<JSIDBDatabasePrototype*>(vm, JSValue::decode(thisValue)); |
| 244 | if (UNLIKELY(!prototype)) { |
| 245 | throwVMTypeError(state, throwScope); |
| 246 | return false; |
| 247 | } |
| 248 | // Shadowing a built-in constructor |
| 249 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
| 250 | } |
| 251 | |
| 252 | static inline JSValue jsIDBDatabaseNameGetter(ExecState& state, JSIDBDatabase& thisObject, ThrowScope& throwScope) |
| 253 | { |
| 254 | UNUSED_PARAM(throwScope); |
| 255 | UNUSED_PARAM(state); |
| 256 | auto& impl = thisObject.wrapped(); |
| 257 | JSValue result = toJS<IDLDOMString>(state, throwScope, impl.name()); |
| 258 | return result; |
| 259 | } |
| 260 | |
| 261 | EncodedJSValue jsIDBDatabaseName(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 262 | { |
| 263 | return IDLAttribute<JSIDBDatabase>::get<jsIDBDatabaseNameGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "name" ); |
| 264 | } |
| 265 | |
| 266 | static inline JSValue jsIDBDatabaseVersionGetter(ExecState& state, JSIDBDatabase& thisObject, ThrowScope& throwScope) |
| 267 | { |
| 268 | UNUSED_PARAM(throwScope); |
| 269 | UNUSED_PARAM(state); |
| 270 | auto& impl = thisObject.wrapped(); |
| 271 | JSValue result = toJS<IDLUnsignedLongLong>(state, throwScope, impl.version()); |
| 272 | return result; |
| 273 | } |
| 274 | |
| 275 | EncodedJSValue jsIDBDatabaseVersion(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 276 | { |
| 277 | return IDLAttribute<JSIDBDatabase>::get<jsIDBDatabaseVersionGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "version" ); |
| 278 | } |
| 279 | |
| 280 | static inline JSValue jsIDBDatabaseObjectStoreNamesGetter(ExecState& state, JSIDBDatabase& thisObject, ThrowScope& throwScope) |
| 281 | { |
| 282 | UNUSED_PARAM(throwScope); |
| 283 | UNUSED_PARAM(state); |
| 284 | auto& impl = thisObject.wrapped(); |
| 285 | JSValue result = toJS<IDLInterface<DOMStringList>>(state, *thisObject.globalObject(), throwScope, impl.objectStoreNames()); |
| 286 | return result; |
| 287 | } |
| 288 | |
| 289 | EncodedJSValue jsIDBDatabaseObjectStoreNames(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 290 | { |
| 291 | return IDLAttribute<JSIDBDatabase>::get<jsIDBDatabaseObjectStoreNamesGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "objectStoreNames" ); |
| 292 | } |
| 293 | |
| 294 | static inline JSValue jsIDBDatabaseOnabortGetter(ExecState& state, JSIDBDatabase& thisObject, ThrowScope& throwScope) |
| 295 | { |
| 296 | UNUSED_PARAM(throwScope); |
| 297 | UNUSED_PARAM(state); |
| 298 | return eventHandlerAttribute(thisObject.wrapped(), eventNames().abortEvent, worldForDOMObject(thisObject)); |
| 299 | } |
| 300 | |
| 301 | EncodedJSValue jsIDBDatabaseOnabort(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 302 | { |
| 303 | return IDLAttribute<JSIDBDatabase>::get<jsIDBDatabaseOnabortGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onabort" ); |
| 304 | } |
| 305 | |
| 306 | static inline bool setJSIDBDatabaseOnabortSetter(ExecState& state, JSIDBDatabase& thisObject, JSValue value, ThrowScope& throwScope) |
| 307 | { |
| 308 | UNUSED_PARAM(throwScope); |
| 309 | setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().abortEvent, value); |
| 310 | return true; |
| 311 | } |
| 312 | |
| 313 | bool setJSIDBDatabaseOnabort(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 314 | { |
| 315 | return IDLAttribute<JSIDBDatabase>::set<setJSIDBDatabaseOnabortSetter>(*state, thisValue, encodedValue, "onabort" ); |
| 316 | } |
| 317 | |
| 318 | static inline JSValue jsIDBDatabaseOncloseGetter(ExecState& state, JSIDBDatabase& thisObject, ThrowScope& throwScope) |
| 319 | { |
| 320 | UNUSED_PARAM(throwScope); |
| 321 | UNUSED_PARAM(state); |
| 322 | return eventHandlerAttribute(thisObject.wrapped(), eventNames().closeEvent, worldForDOMObject(thisObject)); |
| 323 | } |
| 324 | |
| 325 | EncodedJSValue jsIDBDatabaseOnclose(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 326 | { |
| 327 | return IDLAttribute<JSIDBDatabase>::get<jsIDBDatabaseOncloseGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onclose" ); |
| 328 | } |
| 329 | |
| 330 | static inline bool setJSIDBDatabaseOncloseSetter(ExecState& state, JSIDBDatabase& thisObject, JSValue value, ThrowScope& throwScope) |
| 331 | { |
| 332 | UNUSED_PARAM(throwScope); |
| 333 | setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().closeEvent, value); |
| 334 | return true; |
| 335 | } |
| 336 | |
| 337 | bool setJSIDBDatabaseOnclose(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 338 | { |
| 339 | return IDLAttribute<JSIDBDatabase>::set<setJSIDBDatabaseOncloseSetter>(*state, thisValue, encodedValue, "onclose" ); |
| 340 | } |
| 341 | |
| 342 | static inline JSValue jsIDBDatabaseOnerrorGetter(ExecState& state, JSIDBDatabase& thisObject, ThrowScope& throwScope) |
| 343 | { |
| 344 | UNUSED_PARAM(throwScope); |
| 345 | UNUSED_PARAM(state); |
| 346 | return eventHandlerAttribute(thisObject.wrapped(), eventNames().errorEvent, worldForDOMObject(thisObject)); |
| 347 | } |
| 348 | |
| 349 | EncodedJSValue jsIDBDatabaseOnerror(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 350 | { |
| 351 | return IDLAttribute<JSIDBDatabase>::get<jsIDBDatabaseOnerrorGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onerror" ); |
| 352 | } |
| 353 | |
| 354 | static inline bool setJSIDBDatabaseOnerrorSetter(ExecState& state, JSIDBDatabase& thisObject, JSValue value, ThrowScope& throwScope) |
| 355 | { |
| 356 | UNUSED_PARAM(throwScope); |
| 357 | setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().errorEvent, value); |
| 358 | return true; |
| 359 | } |
| 360 | |
| 361 | bool setJSIDBDatabaseOnerror(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 362 | { |
| 363 | return IDLAttribute<JSIDBDatabase>::set<setJSIDBDatabaseOnerrorSetter>(*state, thisValue, encodedValue, "onerror" ); |
| 364 | } |
| 365 | |
| 366 | static inline JSValue jsIDBDatabaseOnversionchangeGetter(ExecState& state, JSIDBDatabase& thisObject, ThrowScope& throwScope) |
| 367 | { |
| 368 | UNUSED_PARAM(throwScope); |
| 369 | UNUSED_PARAM(state); |
| 370 | return eventHandlerAttribute(thisObject.wrapped(), eventNames().versionchangeEvent, worldForDOMObject(thisObject)); |
| 371 | } |
| 372 | |
| 373 | EncodedJSValue jsIDBDatabaseOnversionchange(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 374 | { |
| 375 | return IDLAttribute<JSIDBDatabase>::get<jsIDBDatabaseOnversionchangeGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onversionchange" ); |
| 376 | } |
| 377 | |
| 378 | static inline bool setJSIDBDatabaseOnversionchangeSetter(ExecState& state, JSIDBDatabase& thisObject, JSValue value, ThrowScope& throwScope) |
| 379 | { |
| 380 | UNUSED_PARAM(throwScope); |
| 381 | setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().versionchangeEvent, value); |
| 382 | return true; |
| 383 | } |
| 384 | |
| 385 | bool setJSIDBDatabaseOnversionchange(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 386 | { |
| 387 | return IDLAttribute<JSIDBDatabase>::set<setJSIDBDatabaseOnversionchangeSetter>(*state, thisValue, encodedValue, "onversionchange" ); |
| 388 | } |
| 389 | |
| 390 | static inline JSC::EncodedJSValue jsIDBDatabasePrototypeFunctionCreateObjectStoreBody(JSC::ExecState* state, typename IDLOperation<JSIDBDatabase>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 391 | { |
| 392 | UNUSED_PARAM(state); |
| 393 | UNUSED_PARAM(throwScope); |
| 394 | auto& impl = castedThis->wrapped(); |
| 395 | if (UNLIKELY(state->argumentCount() < 1)) |
| 396 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| 397 | auto name = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
| 398 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 399 | auto parameters = convert<IDLDictionary<IDBDatabase::ObjectStoreParameters>>(*state, state->argument(1)); |
| 400 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 401 | return JSValue::encode(toJS<IDLInterface<IDBObjectStore>>(*state, *castedThis->globalObject(), throwScope, impl.createObjectStore(WTFMove(name), WTFMove(parameters)))); |
| 402 | } |
| 403 | |
| 404 | EncodedJSValue JSC_HOST_CALL jsIDBDatabasePrototypeFunctionCreateObjectStore(ExecState* state) |
| 405 | { |
| 406 | return IDLOperation<JSIDBDatabase>::call<jsIDBDatabasePrototypeFunctionCreateObjectStoreBody>(*state, "createObjectStore" ); |
| 407 | } |
| 408 | |
| 409 | static inline JSC::EncodedJSValue jsIDBDatabasePrototypeFunctionDeleteObjectStoreBody(JSC::ExecState* state, typename IDLOperation<JSIDBDatabase>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 410 | { |
| 411 | UNUSED_PARAM(state); |
| 412 | UNUSED_PARAM(throwScope); |
| 413 | auto& impl = castedThis->wrapped(); |
| 414 | if (UNLIKELY(state->argumentCount() < 1)) |
| 415 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| 416 | auto name = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
| 417 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 418 | propagateException(*state, throwScope, impl.deleteObjectStore(WTFMove(name))); |
| 419 | return JSValue::encode(jsUndefined()); |
| 420 | } |
| 421 | |
| 422 | EncodedJSValue JSC_HOST_CALL jsIDBDatabasePrototypeFunctionDeleteObjectStore(ExecState* state) |
| 423 | { |
| 424 | return IDLOperation<JSIDBDatabase>::call<jsIDBDatabasePrototypeFunctionDeleteObjectStoreBody>(*state, "deleteObjectStore" ); |
| 425 | } |
| 426 | |
| 427 | static inline JSC::EncodedJSValue jsIDBDatabasePrototypeFunctionTransaction1Body(JSC::ExecState* state, typename IDLOperation<JSIDBDatabase>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 428 | { |
| 429 | UNUSED_PARAM(state); |
| 430 | UNUSED_PARAM(throwScope); |
| 431 | auto& impl = castedThis->wrapped(); |
| 432 | auto storeNames = convert<IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>>>(*state, state->uncheckedArgument(0)); |
| 433 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 434 | auto mode = state->argument(1).isUndefined() ? IDBTransactionMode::Readonly : convert<IDLEnumeration<IDBTransactionMode>>(*state, state->uncheckedArgument(1), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeEnumError(state, scope, 1, "mode" , "IDBDatabase" , "transaction" , expectedEnumerationValues<IDBTransactionMode>()); }); |
| 435 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 436 | return JSValue::encode(toJS<IDLInterface<IDBTransaction>>(*state, *castedThis->globalObject(), throwScope, impl.transaction(WTFMove(storeNames), WTFMove(mode)))); |
| 437 | } |
| 438 | |
| 439 | static inline JSC::EncodedJSValue jsIDBDatabasePrototypeFunctionTransaction2Body(JSC::ExecState* state, typename IDLOperation<JSIDBDatabase>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 440 | { |
| 441 | UNUSED_PARAM(state); |
| 442 | UNUSED_PARAM(throwScope); |
| 443 | auto& impl = castedThis->wrapped(); |
| 444 | auto storeNames = convert<IDLInterface<DOMStringList>>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentTypeError(state, scope, 0, "storeNames" , "IDBDatabase" , "transaction" , "DOMStringList" ); }); |
| 445 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 446 | auto mode = state->argument(1).isUndefined() ? IDBTransactionMode::Readonly : convert<IDLEnumeration<IDBTransactionMode>>(*state, state->uncheckedArgument(1), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeEnumError(state, scope, 1, "mode" , "IDBDatabase" , "transaction" , expectedEnumerationValues<IDBTransactionMode>()); }); |
| 447 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 448 | return JSValue::encode(toJS<IDLInterface<IDBTransaction>>(*state, *castedThis->globalObject(), throwScope, impl.transaction(*storeNames, WTFMove(mode)))); |
| 449 | } |
| 450 | |
| 451 | static inline JSC::EncodedJSValue jsIDBDatabasePrototypeFunctionTransactionOverloadDispatcher(JSC::ExecState* state, typename IDLOperation<JSIDBDatabase>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 452 | { |
| 453 | UNUSED_PARAM(state); |
| 454 | UNUSED_PARAM(throwScope); |
| 455 | VM& vm = state->vm(); |
| 456 | UNUSED_PARAM(vm); |
| 457 | size_t argsCount = std::min<size_t>(2, state->argumentCount()); |
| 458 | if (argsCount == 1) { |
| 459 | JSValue distinguishingArg = state->uncheckedArgument(0); |
| 460 | if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits<JSDOMStringList>(vm)) |
| 461 | return jsIDBDatabasePrototypeFunctionTransaction2Body(state, castedThis, throwScope); |
| 462 | if (hasIteratorMethod(*state, distinguishingArg)) |
| 463 | return jsIDBDatabasePrototypeFunctionTransaction1Body(state, castedThis, throwScope); |
| 464 | return jsIDBDatabasePrototypeFunctionTransaction1Body(state, castedThis, throwScope); |
| 465 | } |
| 466 | if (argsCount == 2) { |
| 467 | JSValue distinguishingArg = state->uncheckedArgument(0); |
| 468 | if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits<JSDOMStringList>(vm)) |
| 469 | return jsIDBDatabasePrototypeFunctionTransaction2Body(state, castedThis, throwScope); |
| 470 | if (hasIteratorMethod(*state, distinguishingArg)) |
| 471 | return jsIDBDatabasePrototypeFunctionTransaction1Body(state, castedThis, throwScope); |
| 472 | return jsIDBDatabasePrototypeFunctionTransaction1Body(state, castedThis, throwScope); |
| 473 | } |
| 474 | return argsCount < 1 ? throwVMError(state, throwScope, createNotEnoughArgumentsError(state)) : throwVMTypeError(state, throwScope); |
| 475 | } |
| 476 | |
| 477 | EncodedJSValue JSC_HOST_CALL jsIDBDatabasePrototypeFunctionTransaction(ExecState* state) |
| 478 | { |
| 479 | return IDLOperation<JSIDBDatabase>::call<jsIDBDatabasePrototypeFunctionTransactionOverloadDispatcher>(*state, "transaction" ); |
| 480 | } |
| 481 | |
| 482 | static inline JSC::EncodedJSValue jsIDBDatabasePrototypeFunctionCloseBody(JSC::ExecState* state, typename IDLOperation<JSIDBDatabase>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 483 | { |
| 484 | UNUSED_PARAM(state); |
| 485 | UNUSED_PARAM(throwScope); |
| 486 | auto& impl = castedThis->wrapped(); |
| 487 | impl.close(); |
| 488 | return JSValue::encode(jsUndefined()); |
| 489 | } |
| 490 | |
| 491 | EncodedJSValue JSC_HOST_CALL jsIDBDatabasePrototypeFunctionClose(ExecState* state) |
| 492 | { |
| 493 | return IDLOperation<JSIDBDatabase>::call<jsIDBDatabasePrototypeFunctionCloseBody>(*state, "close" ); |
| 494 | } |
| 495 | |
| 496 | void JSIDBDatabase::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
| 497 | { |
| 498 | auto* thisObject = jsCast<JSIDBDatabase*>(cell); |
| 499 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
| 500 | if (thisObject->scriptExecutionContext()) |
| 501 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
| 502 | Base::heapSnapshot(cell, builder); |
| 503 | } |
| 504 | |
| 505 | bool JSIDBDatabaseOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
| 506 | { |
| 507 | auto* jsIDBDatabase = jsCast<JSIDBDatabase*>(handle.slot()->asCell()); |
| 508 | if (jsIDBDatabase->wrapped().hasPendingActivity()) { |
| 509 | if (UNLIKELY(reason)) |
| 510 | *reason = "ActiveDOMObject with pending activity" ; |
| 511 | return true; |
| 512 | } |
| 513 | if (jsIDBDatabase->wrapped().isFiringEventListeners()) { |
| 514 | if (UNLIKELY(reason)) |
| 515 | *reason = "EventTarget firing event listeners" ; |
| 516 | return true; |
| 517 | } |
| 518 | UNUSED_PARAM(visitor); |
| 519 | UNUSED_PARAM(reason); |
| 520 | return false; |
| 521 | } |
| 522 | |
| 523 | void JSIDBDatabaseOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
| 524 | { |
| 525 | auto* jsIDBDatabase = static_cast<JSIDBDatabase*>(handle.slot()->asCell()); |
| 526 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
| 527 | uncacheWrapper(world, &jsIDBDatabase->wrapped(), jsIDBDatabase); |
| 528 | } |
| 529 | |
| 530 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<IDBDatabase>&& impl) |
| 531 | { |
| 532 | return createWrapper<IDBDatabase>(globalObject, WTFMove(impl)); |
| 533 | } |
| 534 | |
| 535 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, IDBDatabase& impl) |
| 536 | { |
| 537 | return wrap(state, globalObject, impl); |
| 538 | } |
| 539 | |
| 540 | IDBDatabase* JSIDBDatabase::toWrapped(JSC::VM& vm, JSC::JSValue value) |
| 541 | { |
| 542 | if (auto* wrapper = jsDynamicCast<JSIDBDatabase*>(vm, value)) |
| 543 | return &wrapper->wrapped(); |
| 544 | return nullptr; |
| 545 | } |
| 546 | |
| 547 | } |
| 548 | |
| 549 | #endif // ENABLE(INDEXED_DATABASE) |
| 550 | |