| /* |
| This file is part of the WebKit open source project. |
| This file has been generated by generate-bindings.pl. DO NOT MODIFY! |
| |
| This library is free software; you can redistribute it and/or |
| modify it under the terms of the GNU Library General Public |
| License as published by the Free Software Foundation; either |
| version 2 of the License, or (at your option) any later version. |
| |
| This library is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| Library General Public License for more details. |
| |
| You should have received a copy of the GNU Library General Public License |
| along with this library; see the file COPYING.LIB. If not, write to |
| the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| Boston, MA 02110-1301, USA. |
| */ |
| |
| #include "config.h" |
| |
| #if ENABLE(INDEXED_DATABASE) |
| |
| #include "JSIDBObjectStore.h" |
| |
| #include "ExceptionCode.h" |
| #include "IDBBindingUtilities.h" |
| #include "IDBIndex.h" |
| #include "IDBRequest.h" |
| #include "JSDOMBinding.h" |
| #include "JSDOMConstructor.h" |
| #include "JSDOMConvert.h" |
| #include "JSDOMStringList.h" |
| #include "JSIDBIndex.h" |
| #include "JSIDBKeyRange.h" |
| #include "JSIDBRequest.h" |
| #include "JSIDBTransaction.h" |
| #include "URL.h" |
| #include <runtime/Error.h> |
| #include <runtime/FunctionPrototype.h> |
| #include <wtf/GetPtr.h> |
| |
| using namespace JSC; |
| |
| namespace WebCore { |
| |
| template<> Optional<IDBObjectStore::IndexParameters> convertDictionary<IDBObjectStore::IndexParameters>(ExecState& state, JSValue value) |
| { |
| VM& vm = state.vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| if (value.isUndefinedOrNull()) |
| return IDBObjectStore::IndexParameters { false, false }; |
| auto* object = value.getObject(); |
| if (UNLIKELY(!object || object->type() == RegExpObjectType)) { |
| throwTypeError(&state, throwScope); |
| return Nullopt; |
| } |
| auto unique = convertOptional<bool>(state, object->get(&state, Identifier::fromString(&state, "unique")), false); |
| RETURN_IF_EXCEPTION(throwScope, Nullopt); |
| auto multiEntry = convertOptional<bool>(state, object->get(&state, Identifier::fromString(&state, "multiEntry")), false); |
| return IDBObjectStore::IndexParameters { WTFMove(unique), WTFMove(multiEntry) }; |
| } |
| |
| // Functions |
| |
| JSC::EncodedJSValue JSC_HOST_CALL jsIDBObjectStorePrototypeFunctionPut(JSC::ExecState*); |
| JSC::EncodedJSValue JSC_HOST_CALL jsIDBObjectStorePrototypeFunctionAdd(JSC::ExecState*); |
| JSC::EncodedJSValue JSC_HOST_CALL jsIDBObjectStorePrototypeFunctionDelete(JSC::ExecState*); |
| JSC::EncodedJSValue JSC_HOST_CALL jsIDBObjectStorePrototypeFunctionGet(JSC::ExecState*); |
| JSC::EncodedJSValue JSC_HOST_CALL jsIDBObjectStorePrototypeFunctionClear(JSC::ExecState*); |
| JSC::EncodedJSValue JSC_HOST_CALL jsIDBObjectStorePrototypeFunctionOpenCursor(JSC::ExecState*); |
| JSC::EncodedJSValue JSC_HOST_CALL jsIDBObjectStorePrototypeFunctionCreateIndex(JSC::ExecState*); |
| JSC::EncodedJSValue JSC_HOST_CALL jsIDBObjectStorePrototypeFunctionIndex(JSC::ExecState*); |
| JSC::EncodedJSValue JSC_HOST_CALL jsIDBObjectStorePrototypeFunctionDeleteIndex(JSC::ExecState*); |
| JSC::EncodedJSValue JSC_HOST_CALL jsIDBObjectStorePrototypeFunctionCount(JSC::ExecState*); |
| |
| // Attributes |
| |
| JSC::EncodedJSValue jsIDBObjectStoreName(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsIDBObjectStoreKeyPath(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsIDBObjectStoreIndexNames(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsIDBObjectStoreTransaction(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsIDBObjectStoreAutoIncrement(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| JSC::EncodedJSValue jsIDBObjectStoreConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| bool setJSIDBObjectStoreConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| |
| class JSIDBObjectStorePrototype : public JSC::JSNonFinalObject { |
| public: |
| typedef JSC::JSNonFinalObject Base; |
| static JSIDBObjectStorePrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure) |
| { |
| JSIDBObjectStorePrototype* ptr = new (NotNull, JSC::allocateCell<JSIDBObjectStorePrototype>(vm.heap)) JSIDBObjectStorePrototype(vm, globalObject, structure); |
| ptr->finishCreation(vm); |
| return ptr; |
| } |
| |
| DECLARE_INFO; |
| static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
| { |
| return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
| } |
| |
| private: |
| JSIDBObjectStorePrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
| : JSC::JSNonFinalObject(vm, structure) |
| { |
| } |
| |
| void finishCreation(JSC::VM&); |
| }; |
| |
| typedef JSDOMConstructorNotConstructable<JSIDBObjectStore> JSIDBObjectStoreConstructor; |
| |
| template<> JSValue JSIDBObjectStoreConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| { |
| UNUSED_PARAM(vm); |
| return globalObject.functionPrototype(); |
| } |
| |
| template<> void JSIDBObjectStoreConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
| { |
| putDirect(vm, vm.propertyNames->prototype, JSIDBObjectStore::prototype(vm, &globalObject), DontDelete | ReadOnly | DontEnum); |
| putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("IDBObjectStore"))), ReadOnly | DontEnum); |
| putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontEnum); |
| } |
| |
| template<> const ClassInfo JSIDBObjectStoreConstructor::s_info = { "IDBObjectStore", &Base::s_info, 0, CREATE_METHOD_TABLE(JSIDBObjectStoreConstructor) }; |
| |
| /* Hash table for prototype */ |
| |
| static const HashTableValue JSIDBObjectStorePrototypeTableValues[] = |
| { |
| { "constructor", DontEnum, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBObjectStoreConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSIDBObjectStoreConstructor) } }, |
| { "name", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBObjectStoreName), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "keyPath", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBObjectStoreKeyPath), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "indexNames", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBObjectStoreIndexNames), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "transaction", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBObjectStoreTransaction), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "autoIncrement", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBObjectStoreAutoIncrement), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| { "put", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsIDBObjectStorePrototypeFunctionPut), (intptr_t) (1) } }, |
| { "add", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsIDBObjectStorePrototypeFunctionAdd), (intptr_t) (1) } }, |
| { "delete", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsIDBObjectStorePrototypeFunctionDelete), (intptr_t) (1) } }, |
| { "get", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsIDBObjectStorePrototypeFunctionGet), (intptr_t) (1) } }, |
| { "clear", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsIDBObjectStorePrototypeFunctionClear), (intptr_t) (0) } }, |
| { "openCursor", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsIDBObjectStorePrototypeFunctionOpenCursor), (intptr_t) (0) } }, |
| { "createIndex", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsIDBObjectStorePrototypeFunctionCreateIndex), (intptr_t) (2) } }, |
| { "index", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsIDBObjectStorePrototypeFunctionIndex), (intptr_t) (1) } }, |
| { "deleteIndex", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsIDBObjectStorePrototypeFunctionDeleteIndex), (intptr_t) (1) } }, |
| { "count", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsIDBObjectStorePrototypeFunctionCount), (intptr_t) (0) } }, |
| }; |
| |
| const ClassInfo JSIDBObjectStorePrototype::s_info = { "IDBObjectStorePrototype", &Base::s_info, 0, CREATE_METHOD_TABLE(JSIDBObjectStorePrototype) }; |
| |
| void JSIDBObjectStorePrototype::finishCreation(VM& vm) |
| { |
| Base::finishCreation(vm); |
| reifyStaticProperties(vm, JSIDBObjectStorePrototypeTableValues, *this); |
| } |
| |
| const ClassInfo JSIDBObjectStore::s_info = { "IDBObjectStore", &Base::s_info, 0, CREATE_METHOD_TABLE(JSIDBObjectStore) }; |
| |
| JSIDBObjectStore::JSIDBObjectStore(Structure* structure, JSDOMGlobalObject& globalObject, Ref<IDBObjectStore>&& impl) |
| : JSDOMWrapper<IDBObjectStore>(structure, globalObject, WTFMove(impl)) |
| { |
| } |
| |
| JSObject* JSIDBObjectStore::createPrototype(VM& vm, JSGlobalObject* globalObject) |
| { |
| return JSIDBObjectStorePrototype::create(vm, globalObject, JSIDBObjectStorePrototype::createStructure(vm, globalObject, globalObject->objectPrototype())); |
| } |
| |
| JSObject* JSIDBObjectStore::prototype(VM& vm, JSGlobalObject* globalObject) |
| { |
| return getDOMPrototype<JSIDBObjectStore>(vm, globalObject); |
| } |
| |
| void JSIDBObjectStore::destroy(JSC::JSCell* cell) |
| { |
| JSIDBObjectStore* thisObject = static_cast<JSIDBObjectStore*>(cell); |
| thisObject->JSIDBObjectStore::~JSIDBObjectStore(); |
| } |
| |
| EncodedJSValue jsIDBObjectStoreName(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSIDBObjectStore*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "IDBObjectStore", "name"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsStringOrNull(state, impl.name()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsIDBObjectStoreKeyPath(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSIDBObjectStore*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "IDBObjectStore", "keyPath"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = toJS(*state, *castedThis->globalObject(), impl.keyPath()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsIDBObjectStoreIndexNames(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSIDBObjectStore*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "IDBObjectStore", "indexNames"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = toJS(state, castedThis->globalObject(), impl.indexNames()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsIDBObjectStoreTransaction(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSIDBObjectStore*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "IDBObjectStore", "transaction"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = toJS(state, castedThis->globalObject(), impl.transaction()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsIDBObjectStoreAutoIncrement(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| UNUSED_PARAM(thisValue); |
| JSValue decodedThisValue = JSValue::decode(thisValue); |
| auto* castedThis = jsDynamicCast<JSIDBObjectStore*>(decodedThisValue); |
| if (UNLIKELY(!castedThis)) { |
| return throwGetterTypeError(*state, throwScope, "IDBObjectStore", "autoIncrement"); |
| } |
| auto& impl = castedThis->wrapped(); |
| JSValue result = jsBoolean(impl.autoIncrement()); |
| return JSValue::encode(result); |
| } |
| |
| |
| EncodedJSValue jsIDBObjectStoreConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| JSIDBObjectStorePrototype* domObject = jsDynamicCast<JSIDBObjectStorePrototype*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!domObject)) |
| return throwVMTypeError(state, throwScope); |
| return JSValue::encode(JSIDBObjectStore::getConstructor(state->vm(), domObject->globalObject())); |
| } |
| |
| bool setJSIDBObjectStoreConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| JSValue value = JSValue::decode(encodedValue); |
| JSIDBObjectStorePrototype* domObject = jsDynamicCast<JSIDBObjectStorePrototype*>(JSValue::decode(thisValue)); |
| if (UNLIKELY(!domObject)) { |
| throwVMTypeError(state, throwScope); |
| return false; |
| } |
| // Shadowing a built-in constructor |
| return domObject->putDirect(state->vm(), state->propertyNames().constructor, value); |
| } |
| |
| JSValue JSIDBObjectStore::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| { |
| return getDOMConstructor<JSIDBObjectStoreConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsIDBObjectStorePrototypeFunctionPut(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSIDBObjectStore*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "IDBObjectStore", "put"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSIDBObjectStore::info()); |
| auto& impl = castedThis->wrapped(); |
| if (UNLIKELY(state->argumentCount() < 1)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| ExceptionCodeWithMessage ec; |
| auto value = state->uncheckedArgument(0); |
| auto key = state->argument(1); |
| JSValue result = toJS(state, castedThis->globalObject(), impl.put(*state, WTFMove(value), WTFMove(key), ec)); |
| |
| setDOMException(state, throwScope, ec); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| return JSValue::encode(result); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsIDBObjectStorePrototypeFunctionAdd(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSIDBObjectStore*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "IDBObjectStore", "add"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSIDBObjectStore::info()); |
| auto& impl = castedThis->wrapped(); |
| if (UNLIKELY(state->argumentCount() < 1)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| ExceptionCodeWithMessage ec; |
| auto value = state->uncheckedArgument(0); |
| auto key = state->argument(1); |
| JSValue result = toJS(state, castedThis->globalObject(), impl.add(*state, WTFMove(value), WTFMove(key), ec)); |
| |
| setDOMException(state, throwScope, ec); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| return JSValue::encode(result); |
| } |
| |
| static inline EncodedJSValue jsIDBObjectStorePrototypeFunctionDelete1(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSIDBObjectStore*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "IDBObjectStore", "delete"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSIDBObjectStore::info()); |
| auto& impl = castedThis->wrapped(); |
| if (UNLIKELY(state->argumentCount() < 1)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| ExceptionCodeWithMessage ec; |
| IDBKeyRange* keyRange = nullptr; |
| if (!state->uncheckedArgument(0).isUndefinedOrNull()) { |
| keyRange = JSIDBKeyRange::toWrapped(state->uncheckedArgument(0)); |
| if (UNLIKELY(!keyRange)) |
| return throwArgumentTypeError(*state, throwScope, 0, "keyRange", "IDBObjectStore", "delete", "IDBKeyRange"); |
| } |
| JSValue result = toJS(state, castedThis->globalObject(), impl.deleteFunction(*state, WTFMove(keyRange), ec)); |
| |
| setDOMException(state, throwScope, ec); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| return JSValue::encode(result); |
| } |
| |
| static inline EncodedJSValue jsIDBObjectStorePrototypeFunctionDelete2(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSIDBObjectStore*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "IDBObjectStore", "delete"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSIDBObjectStore::info()); |
| auto& impl = castedThis->wrapped(); |
| if (UNLIKELY(state->argumentCount() < 1)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| ExceptionCodeWithMessage ec; |
| auto key = state->uncheckedArgument(0); |
| JSValue result = toJS(state, castedThis->globalObject(), impl.deleteFunction(*state, WTFMove(key), ec)); |
| |
| setDOMException(state, throwScope, ec); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| return JSValue::encode(result); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsIDBObjectStorePrototypeFunctionDelete(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| size_t argsCount = std::min<size_t>(1, state->argumentCount()); |
| if (argsCount == 1) { |
| JSValue distinguishingArg = state->uncheckedArgument(0); |
| if (distinguishingArg.isUndefinedOrNull()) |
| return jsIDBObjectStorePrototypeFunctionDelete1(state); |
| if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits(JSIDBKeyRange::info())) |
| return jsIDBObjectStorePrototypeFunctionDelete1(state); |
| return jsIDBObjectStorePrototypeFunctionDelete2(state); |
| } |
| return argsCount < 1 ? throwVMError(state, throwScope, createNotEnoughArgumentsError(state)) : throwVMTypeError(state, throwScope); |
| } |
| |
| static inline EncodedJSValue jsIDBObjectStorePrototypeFunctionGet1(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSIDBObjectStore*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "IDBObjectStore", "get"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSIDBObjectStore::info()); |
| auto& impl = castedThis->wrapped(); |
| if (UNLIKELY(state->argumentCount() < 1)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| ExceptionCodeWithMessage ec; |
| IDBKeyRange* key = nullptr; |
| if (!state->uncheckedArgument(0).isUndefinedOrNull()) { |
| key = JSIDBKeyRange::toWrapped(state->uncheckedArgument(0)); |
| if (UNLIKELY(!key)) |
| return throwArgumentTypeError(*state, throwScope, 0, "key", "IDBObjectStore", "get", "IDBKeyRange"); |
| } |
| JSValue result = toJS(state, castedThis->globalObject(), impl.get(*state, WTFMove(key), ec)); |
| |
| setDOMException(state, throwScope, ec); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| return JSValue::encode(result); |
| } |
| |
| static inline EncodedJSValue jsIDBObjectStorePrototypeFunctionGet2(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSIDBObjectStore*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "IDBObjectStore", "get"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSIDBObjectStore::info()); |
| auto& impl = castedThis->wrapped(); |
| if (UNLIKELY(state->argumentCount() < 1)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| ExceptionCodeWithMessage ec; |
| auto key = state->uncheckedArgument(0); |
| JSValue result = toJS(state, castedThis->globalObject(), impl.get(*state, WTFMove(key), ec)); |
| |
| setDOMException(state, throwScope, ec); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| return JSValue::encode(result); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsIDBObjectStorePrototypeFunctionGet(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| size_t argsCount = std::min<size_t>(1, state->argumentCount()); |
| if (argsCount == 1) { |
| JSValue distinguishingArg = state->uncheckedArgument(0); |
| if (distinguishingArg.isUndefinedOrNull()) |
| return jsIDBObjectStorePrototypeFunctionGet1(state); |
| if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits(JSIDBKeyRange::info())) |
| return jsIDBObjectStorePrototypeFunctionGet1(state); |
| return jsIDBObjectStorePrototypeFunctionGet2(state); |
| } |
| return argsCount < 1 ? throwVMError(state, throwScope, createNotEnoughArgumentsError(state)) : throwVMTypeError(state, throwScope); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsIDBObjectStorePrototypeFunctionClear(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSIDBObjectStore*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "IDBObjectStore", "clear"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSIDBObjectStore::info()); |
| auto& impl = castedThis->wrapped(); |
| ExceptionCodeWithMessage ec; |
| JSValue result = toJS(state, castedThis->globalObject(), impl.clear(*state, ec)); |
| |
| setDOMException(state, throwScope, ec); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| return JSValue::encode(result); |
| } |
| |
| static inline EncodedJSValue jsIDBObjectStorePrototypeFunctionOpenCursor1(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSIDBObjectStore*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "IDBObjectStore", "openCursor"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSIDBObjectStore::info()); |
| auto& impl = castedThis->wrapped(); |
| ExceptionCodeWithMessage ec; |
| IDBKeyRange* range = nullptr; |
| if (!state->argument(0).isUndefinedOrNull()) { |
| range = JSIDBKeyRange::toWrapped(state->uncheckedArgument(0)); |
| if (UNLIKELY(!range)) |
| return throwArgumentTypeError(*state, throwScope, 0, "range", "IDBObjectStore", "openCursor", "IDBKeyRange"); |
| } |
| auto direction = state->argument(1).isUndefined() ? ASCIILiteral("next") : state->uncheckedArgument(1).toWTFString(state); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| JSValue result = toJS(state, castedThis->globalObject(), impl.openCursor(*state, WTFMove(range), WTFMove(direction), ec)); |
| |
| setDOMException(state, throwScope, ec); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| return JSValue::encode(result); |
| } |
| |
| static inline EncodedJSValue jsIDBObjectStorePrototypeFunctionOpenCursor2(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSIDBObjectStore*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "IDBObjectStore", "openCursor"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSIDBObjectStore::info()); |
| auto& impl = castedThis->wrapped(); |
| if (UNLIKELY(state->argumentCount() < 1)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| ExceptionCodeWithMessage ec; |
| auto key = state->uncheckedArgument(0); |
| auto direction = state->argument(1).isUndefined() ? ASCIILiteral("next") : state->uncheckedArgument(1).toWTFString(state); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| JSValue result = toJS(state, castedThis->globalObject(), impl.openCursor(*state, WTFMove(key), WTFMove(direction), ec)); |
| |
| setDOMException(state, throwScope, ec); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| return JSValue::encode(result); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsIDBObjectStorePrototypeFunctionOpenCursor(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| size_t argsCount = std::min<size_t>(2, state->argumentCount()); |
| if (argsCount == 0) { |
| return jsIDBObjectStorePrototypeFunctionOpenCursor1(state); |
| } |
| if (argsCount == 1) { |
| JSValue distinguishingArg = state->uncheckedArgument(0); |
| if (distinguishingArg.isUndefined()) |
| return jsIDBObjectStorePrototypeFunctionOpenCursor1(state); |
| if (distinguishingArg.isUndefinedOrNull()) |
| return jsIDBObjectStorePrototypeFunctionOpenCursor1(state); |
| if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits(JSIDBKeyRange::info())) |
| return jsIDBObjectStorePrototypeFunctionOpenCursor1(state); |
| return jsIDBObjectStorePrototypeFunctionOpenCursor2(state); |
| } |
| if (argsCount == 2) { |
| JSValue distinguishingArg = state->uncheckedArgument(0); |
| if (distinguishingArg.isUndefined()) |
| return jsIDBObjectStorePrototypeFunctionOpenCursor1(state); |
| if (distinguishingArg.isUndefinedOrNull()) |
| return jsIDBObjectStorePrototypeFunctionOpenCursor1(state); |
| if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits(JSIDBKeyRange::info())) |
| return jsIDBObjectStorePrototypeFunctionOpenCursor1(state); |
| return jsIDBObjectStorePrototypeFunctionOpenCursor2(state); |
| } |
| return throwVMTypeError(state, throwScope); |
| } |
| |
| static inline EncodedJSValue jsIDBObjectStorePrototypeFunctionCreateIndex1(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSIDBObjectStore*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "IDBObjectStore", "createIndex"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSIDBObjectStore::info()); |
| auto& impl = castedThis->wrapped(); |
| if (UNLIKELY(state->argumentCount() < 2)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| ExceptionCodeWithMessage ec; |
| auto name = state->uncheckedArgument(0).toWTFString(state); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| auto keyPath = toNativeArray<String>(*state, state->uncheckedArgument(1)); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| auto options = state->argument(2).isUndefined() ? IDBObjectStore::IndexParameters() : convertDictionary<IDBObjectStore::IndexParameters>(*state, state->uncheckedArgument(2)); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| JSValue result = toJS(state, castedThis->globalObject(), impl.createIndex(*state, WTFMove(name), WTFMove(keyPath), options.value(), ec)); |
| |
| setDOMException(state, throwScope, ec); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| return JSValue::encode(result); |
| } |
| |
| static inline EncodedJSValue jsIDBObjectStorePrototypeFunctionCreateIndex2(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSIDBObjectStore*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "IDBObjectStore", "createIndex"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSIDBObjectStore::info()); |
| auto& impl = castedThis->wrapped(); |
| if (UNLIKELY(state->argumentCount() < 2)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| ExceptionCodeWithMessage ec; |
| auto name = state->uncheckedArgument(0).toWTFString(state); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| auto keyPath = state->uncheckedArgument(1).toWTFString(state); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| auto options = state->argument(2).isUndefined() ? IDBObjectStore::IndexParameters() : convertDictionary<IDBObjectStore::IndexParameters>(*state, state->uncheckedArgument(2)); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| JSValue result = toJS(state, castedThis->globalObject(), impl.createIndex(*state, WTFMove(name), WTFMove(keyPath), options.value(), ec)); |
| |
| setDOMException(state, throwScope, ec); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| return JSValue::encode(result); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsIDBObjectStorePrototypeFunctionCreateIndex(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| size_t argsCount = std::min<size_t>(3, state->argumentCount()); |
| if (argsCount == 2) { |
| JSValue distinguishingArg = state->uncheckedArgument(1); |
| if (hasIteratorMethod(*state, distinguishingArg)) |
| return jsIDBObjectStorePrototypeFunctionCreateIndex1(state); |
| return jsIDBObjectStorePrototypeFunctionCreateIndex2(state); |
| } |
| if (argsCount == 3) { |
| JSValue distinguishingArg = state->uncheckedArgument(1); |
| if (hasIteratorMethod(*state, distinguishingArg)) |
| return jsIDBObjectStorePrototypeFunctionCreateIndex1(state); |
| return jsIDBObjectStorePrototypeFunctionCreateIndex2(state); |
| } |
| return argsCount < 2 ? throwVMError(state, throwScope, createNotEnoughArgumentsError(state)) : throwVMTypeError(state, throwScope); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsIDBObjectStorePrototypeFunctionIndex(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSIDBObjectStore*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "IDBObjectStore", "index"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSIDBObjectStore::info()); |
| auto& impl = castedThis->wrapped(); |
| if (UNLIKELY(state->argumentCount() < 1)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| ExceptionCodeWithMessage ec; |
| auto name = state->uncheckedArgument(0).toWTFString(state); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| JSValue result = toJS(state, castedThis->globalObject(), impl.index(WTFMove(name), ec)); |
| |
| setDOMException(state, throwScope, ec); |
| return JSValue::encode(result); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsIDBObjectStorePrototypeFunctionDeleteIndex(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSIDBObjectStore*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "IDBObjectStore", "deleteIndex"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSIDBObjectStore::info()); |
| auto& impl = castedThis->wrapped(); |
| if (UNLIKELY(state->argumentCount() < 1)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| ExceptionCodeWithMessage ec; |
| auto name = state->uncheckedArgument(0).toWTFString(state); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| impl.deleteIndex(WTFMove(name), ec); |
| setDOMException(state, throwScope, ec); |
| return JSValue::encode(jsUndefined()); |
| } |
| |
| static inline EncodedJSValue jsIDBObjectStorePrototypeFunctionCount1(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSIDBObjectStore*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "IDBObjectStore", "count"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSIDBObjectStore::info()); |
| auto& impl = castedThis->wrapped(); |
| ExceptionCodeWithMessage ec; |
| IDBKeyRange* range = nullptr; |
| if (!state->argument(0).isUndefinedOrNull()) { |
| range = JSIDBKeyRange::toWrapped(state->uncheckedArgument(0)); |
| if (UNLIKELY(!range)) |
| return throwArgumentTypeError(*state, throwScope, 0, "range", "IDBObjectStore", "count", "IDBKeyRange"); |
| } |
| JSValue result = toJS(state, castedThis->globalObject(), impl.count(*state, WTFMove(range), ec)); |
| |
| setDOMException(state, throwScope, ec); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| return JSValue::encode(result); |
| } |
| |
| static inline EncodedJSValue jsIDBObjectStorePrototypeFunctionCount2(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| JSValue thisValue = state->thisValue(); |
| auto castedThis = jsDynamicCast<JSIDBObjectStore*>(thisValue); |
| if (UNLIKELY(!castedThis)) |
| return throwThisTypeError(*state, throwScope, "IDBObjectStore", "count"); |
| ASSERT_GC_OBJECT_INHERITS(castedThis, JSIDBObjectStore::info()); |
| auto& impl = castedThis->wrapped(); |
| if (UNLIKELY(state->argumentCount() < 1)) |
| return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| ExceptionCodeWithMessage ec; |
| auto key = state->uncheckedArgument(0); |
| JSValue result = toJS(state, castedThis->globalObject(), impl.count(*state, WTFMove(key), ec)); |
| |
| setDOMException(state, throwScope, ec); |
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| return JSValue::encode(result); |
| } |
| |
| EncodedJSValue JSC_HOST_CALL jsIDBObjectStorePrototypeFunctionCount(ExecState* state) |
| { |
| VM& vm = state->vm(); |
| auto throwScope = DECLARE_THROW_SCOPE(vm); |
| UNUSED_PARAM(throwScope); |
| size_t argsCount = std::min<size_t>(1, state->argumentCount()); |
| if (argsCount == 0) { |
| return jsIDBObjectStorePrototypeFunctionCount1(state); |
| } |
| if (argsCount == 1) { |
| JSValue distinguishingArg = state->uncheckedArgument(0); |
| if (distinguishingArg.isUndefined()) |
| return jsIDBObjectStorePrototypeFunctionCount1(state); |
| if (distinguishingArg.isUndefinedOrNull()) |
| return jsIDBObjectStorePrototypeFunctionCount1(state); |
| if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits(JSIDBKeyRange::info())) |
| return jsIDBObjectStorePrototypeFunctionCount1(state); |
| return jsIDBObjectStorePrototypeFunctionCount2(state); |
| } |
| return throwVMTypeError(state, throwScope); |
| } |
| |
| void JSIDBObjectStore::visitChildren(JSCell* cell, SlotVisitor& visitor) |
| { |
| auto* thisObject = jsCast<JSIDBObjectStore*>(cell); |
| ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
| Base::visitChildren(thisObject, visitor); |
| thisObject->visitAdditionalChildren(visitor); |
| } |
| |
| bool JSIDBObjectStoreOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor) |
| { |
| auto* jsIDBObjectStore = jsCast<JSIDBObjectStore*>(handle.slot()->asCell()); |
| IDBObjectStore* root = &jsIDBObjectStore->wrapped(); |
| return visitor.containsOpaqueRoot(root); |
| } |
| |
| void JSIDBObjectStoreOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
| { |
| auto* jsIDBObjectStore = jsCast<JSIDBObjectStore*>(handle.slot()->asCell()); |
| auto& world = *static_cast<DOMWrapperWorld*>(context); |
| uncacheWrapper(world, &jsIDBObjectStore->wrapped(), jsIDBObjectStore); |
| } |
| |
| JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<IDBObjectStore>&& impl) |
| { |
| return createWrapper<IDBObjectStore>(globalObject, WTFMove(impl)); |
| } |
| |
| JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, IDBObjectStore& impl) |
| { |
| return wrap(state, globalObject, impl); |
| } |
| |
| IDBObjectStore* JSIDBObjectStore::toWrapped(JSC::JSValue value) |
| { |
| if (auto* wrapper = jsDynamicCast<JSIDBObjectStore*>(value)) |
| return &wrapper->wrapped(); |
| return nullptr; |
| } |
| |
| } |
| |
| #endif // ENABLE(INDEXED_DATABASE) |