Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1a6fc9c

Browse files
committedSep 6, 2021
Improve precision of IDB API and add tests
1 parent 23aef73 commit 1a6fc9c

File tree

10 files changed

+414
-156
lines changed

10 files changed

+414
-156
lines changed
 

‎api-reports/2_12.txt

Lines changed: 81 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13530,32 +13530,43 @@ HttpMethod[SO] val PATCH: HttpMethod
1353013530
HttpMethod[SO] val POST: HttpMethod
1353113531
HttpMethod[SO] val PUT: HttpMethod
1353213532
HttpMethod[SO] val QUERY: HttpMethod
13533+
IDBCreateIndexOptions[JT] val locale: js.UndefOr[String]
13534+
IDBCreateIndexOptions[JT] val multiEntry: js.UndefOr[Boolean]
13535+
IDBCreateIndexOptions[JT] val unique: js.UndefOr[Boolean]
13536+
IDBCreateObjectStoreOptions[JT] val autoIncrement: js.UndefOr[Boolean]
13537+
IDBCreateObjectStoreOptions[JT] val keyPath: Any
1353313538
IDBCursor[JC] def advance(count: Int): Unit
13534-
IDBCursor[JC] def continue(key: js.Any?): Unit
13535-
IDBCursor[JC] def delete(): IDBRequest
13539+
IDBCursor[JC] def continue(key: Any?): Unit
13540+
IDBCursor[JC] def delete(): IDBRequest[Unit]
1353613541
IDBCursor[JC] def direction: IDBCursorDirection
13537-
IDBCursor[JC] def key: js.Any
13542+
IDBCursor[JC] def key: Any
1353813543
IDBCursor[JC] def primaryKey: js.Any
1353913544
IDBCursor[JC] def source: js.Any
13540-
IDBCursor[JC] def update(value: js.Any): IDBRequest
13545+
IDBCursor[JC] def update(value: js.Any): IDBRequest[Any]
1354113546
IDBCursorDirection[JT]
1354213547
IDBCursorDirection[SO] val NEXT: IDBCursorDirection
1354313548
IDBCursorDirection[SO] val NEXT_UNIQUE: IDBCursorDirection
1354413549
IDBCursorDirection[SO] val PREV: IDBCursorDirection
1354513550
IDBCursorDirection[SO] val PREV_UNIQUE: IDBCursorDirection
13551+
IDBCursorReadOnly[JC] def advance(count: Int): Unit
13552+
IDBCursorReadOnly[JC] def continue(key: Any?): Unit
13553+
IDBCursorReadOnly[JC] def direction: IDBCursorDirection
13554+
IDBCursorReadOnly[JC] def key: Any
13555+
IDBCursorReadOnly[JC] def primaryKey: js.Any
13556+
IDBCursorReadOnly[JC] def source: js.Any
1354613557
IDBCursorWithValue[JC] def advance(count: Int): Unit
13547-
IDBCursorWithValue[JC] def continue(key: js.Any?): Unit
13548-
IDBCursorWithValue[JC] def delete(): IDBRequest
13558+
IDBCursorWithValue[JC] def continue(key: Any?): Unit
13559+
IDBCursorWithValue[JC] def delete(): IDBRequest[Unit]
1354913560
IDBCursorWithValue[JC] def direction: IDBCursorDirection
13550-
IDBCursorWithValue[JC] def key: js.Any
13561+
IDBCursorWithValue[JC] def key: Any
1355113562
IDBCursorWithValue[JC] def primaryKey: js.Any
1355213563
IDBCursorWithValue[JC] def source: js.Any
13553-
IDBCursorWithValue[JC] def update(value: js.Any): IDBRequest
13564+
IDBCursorWithValue[JC] def update(value: js.Any): IDBRequest[Any]
1355413565
IDBCursorWithValue[JC] def value: js.Any
1355513566
IDBDatabase[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
1355613567
IDBDatabase[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
1355713568
IDBDatabase[JC] def close(): Unit
13558-
IDBDatabase[JC] def createObjectStore(name: String, optionalParameters: js.Any?): IDBObjectStore
13569+
IDBDatabase[JC] def createObjectStore(name: String, optionalParameters: js.UndefOr[IDBCreateObjectStoreOptions]?): IDBObjectStore
1355913570
IDBDatabase[JC] def deleteObjectStore(name: String): Unit
1356013571
IDBDatabase[JC] def dispatchEvent(evt: Event): Boolean
1356113572
IDBDatabase[JC] def name: String
@@ -13567,20 +13578,42 @@ IDBDatabase[JC] def removeEventListener[T <: Event](`type`: String, listener: js
1356713578
IDBDatabase[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
1356813579
IDBDatabase[JC] def transaction(storeNames: js.Any, mode: IDBTransactionMode?): IDBTransaction
1356913580
IDBDatabase[JC] def version: Int
13581+
IDBDatabaseInfo[JT] val name: String
13582+
IDBDatabaseInfo[JT] val version: Int
1357013583
IDBEnvironment[JT] def indexedDB: IDBFactory (@deprecated in 1.2.0)
13584+
IDBEvent[JC] def bubbles: Boolean
13585+
IDBEvent[JC] def cancelBubble: Boolean
13586+
IDBEvent[JC] def cancelable: Boolean
13587+
IDBEvent[JC] def currentTarget: EventTarget
13588+
IDBEvent[JC] def defaultPrevented: Boolean
13589+
IDBEvent[JC] def eventPhase: Int
13590+
IDBEvent[JC] def isTrusted: Boolean
13591+
IDBEvent[JC] def preventDefault(): Unit
13592+
IDBEvent[JC] def stopImmediatePropagation(): Unit
13593+
IDBEvent[JC] def stopPropagation(): Unit
13594+
IDBEvent[JC] def target: EventTarget
13595+
IDBEvent[JC] override def target: IDBEventTarget[A]
13596+
IDBEvent[JC] def timeStamp: Double
13597+
IDBEvent[JC] def `type`: String
13598+
IDBEventTarget[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
13599+
IDBEventTarget[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
13600+
IDBEventTarget[JC] def dispatchEvent(evt: Event): Boolean
13601+
IDBEventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
13602+
IDBEventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
13603+
IDBEventTarget[JC] def result: A
1357113604
IDBFactory[JC] def cmp(first: js.Any, second: js.Any): Int
13572-
IDBFactory[JC] def deleteDatabase(name: String): IDBOpenDBRequest
13573-
IDBFactory[JC] def open(name: String): IDBOpenDBRequest
13574-
IDBFactory[JC] def open(name: String, version: Int): IDBOpenDBRequest
13575-
IDBIndex[JC] def count(): IDBRequest
13576-
IDBIndex[JC] def count(key: js.Any): IDBRequest
13577-
IDBIndex[JC] def get(key: js.Any): IDBRequest
13578-
IDBIndex[JC] def getKey(key: js.Any): IDBRequest
13605+
IDBFactory[JC] def databases(): js.Promise[js.Array[IDBDatabaseInfo]]
13606+
IDBFactory[JC] def deleteDatabase(name: String): IDBOpenDBRequest[Unit]
13607+
IDBFactory[JC] def open(name: String, version: Int?): IDBOpenDBRequest[IDBDatabase]
13608+
IDBIndex[JC] def count(): IDBRequest[Double]
13609+
IDBIndex[JC] def count(key: Any): IDBRequest[Double]
13610+
IDBIndex[JC] def get(key: Any): IDBRequest[js.Any]
13611+
IDBIndex[JC] def getKey(key: Any): IDBRequest[js.UndefOr[js.Any]]
1357913612
IDBIndex[JC] def keyPath: String
1358013613
IDBIndex[JC] def name: String
1358113614
IDBIndex[JC] def objectStore: IDBObjectStore
13582-
IDBIndex[JC] def openCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest
13583-
IDBIndex[JC] def openKeyCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest
13615+
IDBIndex[JC] def openCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest[IDBCursor]
13616+
IDBIndex[JC] def openKeyCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest[IDBCursorReadOnly]
1358413617
IDBIndex[JC] def unique: Boolean
1358513618
IDBKeyRange[JC] def lower: js.Any
1358613619
IDBKeyRange[JC] def lowerOpen: Boolean
@@ -13590,48 +13623,48 @@ IDBKeyRange[JO] def bound(lower: js.Any, upper: js.Any, lowerOpen: Boolean?, upp
1359013623
IDBKeyRange[JO] def lowerBound(bound: js.Any, open: Boolean?): IDBKeyRange
1359113624
IDBKeyRange[JO] def only(value: js.Any): IDBKeyRange
1359213625
IDBKeyRange[JO] def upperBound(bound: js.Any, open: Boolean?): IDBKeyRange
13593-
IDBObjectStore[JC] def add(value: js.Any, key: js.Any?): IDBRequest
13594-
IDBObjectStore[JC] def clear(): IDBRequest
13595-
IDBObjectStore[JC] def count(key: js.Any?): IDBRequest
13596-
IDBObjectStore[JC] def createIndex(name: String, keyPath: String, optionalParameters: js.Any?): IDBIndex
13597-
IDBObjectStore[JC] def delete(key: js.Any): IDBRequest
13626+
IDBObjectStore[JC] def add(value: js.Any, key: Any?): IDBRequest[Any]
13627+
IDBObjectStore[JC] def clear(): IDBRequest[Unit]
13628+
IDBObjectStore[JC] def count(key: Any?): IDBRequest[Double]
13629+
IDBObjectStore[JC] def createIndex(name: String, keyPath: Any, optionalParameters: IDBCreateIndexOptions?): IDBIndex
13630+
IDBObjectStore[JC] def delete(key: Any): IDBRequest[Unit]
1359813631
IDBObjectStore[JC] def deleteIndex(indexName: String): Unit
13599-
IDBObjectStore[JC] def get(key: js.Any): IDBRequest
13600-
IDBObjectStore[JC] def getAll(query: js.UndefOr[IDBKeyRange | js.Any]?, count: js.UndefOr[Int]?): IDBRequest
13601-
IDBObjectStore[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | js.Any]?, count: js.UndefOr[Int]?): IDBRequest
13602-
IDBObjectStore[JC] def getKey(key: js.Any): IDBRequest
13632+
IDBObjectStore[JC] def get(key: Any): IDBRequest[js.Any]
13633+
IDBObjectStore[JC] def getAll(query: js.UndefOr[IDBKeyRange | Any]?, count: js.UndefOr[Int]?): IDBRequest[js.Array[js.Any]]
13634+
IDBObjectStore[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | Any]?, count: js.UndefOr[Int]?): IDBRequest[js.Array[Any]]
13635+
IDBObjectStore[JC] def getKey(key: Any): IDBRequest[js.UndefOr[Any]]
1360313636
IDBObjectStore[JC] def index(name: String): IDBIndex
1360413637
IDBObjectStore[JC] def indexNames: DOMStringList
1360513638
IDBObjectStore[JC] def keyPath: String
1360613639
IDBObjectStore[JC] def name: String
13607-
IDBObjectStore[JC] def openCursor(range: js.UndefOr[IDBKeyRange | js.Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest
13608-
IDBObjectStore[JC] def openKeyCursor(range: js.UndefOr[IDBKeyRange | js.Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest
13609-
IDBObjectStore[JC] def put(value: js.Any, key: js.Any?): IDBRequest
13640+
IDBObjectStore[JC] def openCursor(range: js.UndefOr[IDBKeyRange | Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[IDBCursor]
13641+
IDBObjectStore[JC] def openKeyCursor(range: js.UndefOr[IDBKeyRange | Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[IDBCursorReadOnly]
13642+
IDBObjectStore[JC] def put(value: js.Any, key: Any?): IDBRequest[Any]
1361013643
IDBObjectStore[JC] def transaction: IDBTransaction
1361113644
IDBOpenDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
1361213645
IDBOpenDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
1361313646
IDBOpenDBRequest[JC] def dispatchEvent(evt: Event): Boolean
1361413647
IDBOpenDBRequest[JC] def error: DOMException
1361513648
IDBOpenDBRequest[JC] var onblocked: js.Function1[IDBVersionChangeEvent, _]
1361613649
IDBOpenDBRequest[JC] var onerror: js.Function1[Event, _]
13617-
IDBOpenDBRequest[JC] var onsuccess: js.Function1[Event, _]
13650+
IDBOpenDBRequest[JC] var onsuccess: js.Function1[IDBEvent[A], _]
1361813651
IDBOpenDBRequest[JC] var onupgradeneeded: js.Function1[IDBVersionChangeEvent, _]
1361913652
IDBOpenDBRequest[JC] def readyState: String
1362013653
IDBOpenDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
1362113654
IDBOpenDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
13622-
IDBOpenDBRequest[JC] def result: js.Any
13655+
IDBOpenDBRequest[JC] def result: A
1362313656
IDBOpenDBRequest[JC] def source: js.Any
1362413657
IDBOpenDBRequest[JC] def transaction: IDBTransaction
1362513658
IDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
1362613659
IDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
1362713660
IDBRequest[JC] def dispatchEvent(evt: Event): Boolean
1362813661
IDBRequest[JC] def error: DOMException
1362913662
IDBRequest[JC] var onerror: js.Function1[Event, _]
13630-
IDBRequest[JC] var onsuccess: js.Function1[Event, _]
13663+
IDBRequest[JC] var onsuccess: js.Function1[IDBEvent[A], _]
1363113664
IDBRequest[JC] def readyState: String
1363213665
IDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
1363313666
IDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
13634-
IDBRequest[JC] def result: js.Any
13667+
IDBRequest[JC] def result: A
1363513668
IDBRequest[JC] def source: js.Any
1363613669
IDBRequest[JC] def transaction: IDBTransaction
1363713670
IDBTransaction[JC] def abort(): Unit
@@ -13648,9 +13681,9 @@ IDBTransaction[JC] var onerror: js.Function1[Event, _]
1364813681
IDBTransaction[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
1364913682
IDBTransaction[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
1365013683
IDBTransactionMode[JT]
13651-
IDBTransactionMode[SO] val READ_ONLY: IDBTransactionMode
13652-
IDBTransactionMode[SO] val READ_WRITE: IDBTransactionMode
13653-
IDBTransactionMode[SO] val VERSION_CHANGE: IDBTransactionMode
13684+
IDBTransactionMode[SO] val readonly: IDBTransactionMode
13685+
IDBTransactionMode[SO] val readwrite: IDBTransactionMode
13686+
IDBTransactionMode[SO] val versionchange: IDBTransactionMode
1365413687
IDBVersionChangeEvent[JC] def bubbles: Boolean
1365513688
IDBVersionChangeEvent[JC] def cancelBubble: Boolean
1365613689
IDBVersionChangeEvent[JC] def cancelable: Boolean
@@ -13664,6 +13697,7 @@ IDBVersionChangeEvent[JC] def preventDefault(): Unit
1366413697
IDBVersionChangeEvent[JC] def stopImmediatePropagation(): Unit
1366513698
IDBVersionChangeEvent[JC] def stopPropagation(): Unit
1366613699
IDBVersionChangeEvent[JC] def target: EventTarget
13700+
IDBVersionChangeEvent[JC] override def target: IDBEventTarget[A]
1366713701
IDBVersionChangeEvent[JC] def timeStamp: Double
1366813702
IDBVersionChangeEvent[JC] def `type`: String
1366913703
IDBVersionChangeEventInit[JT] var bubbles: js.UndefOr[Boolean]
@@ -25561,16 +25595,22 @@ html[SO] type UList = HTMLUListElement
2556125595
html[SO] type Unknown = HTMLUnknownElement
2556225596
html[SO] type Video = HTMLVideoElement
2556325597
html[SO] def Media = HTMLMediaElement
25598+
idb[SO] type CreateIndexOptions = IDBCreateIndexOptions
25599+
idb[SO] type CreateObjectStoreOptions = IDBCreateObjectStoreOptions
2556425600
idb[SO] type Cursor = IDBCursor
25601+
idb[SO] type CursorReadOnly = IDBCursorReadOnly
2556525602
idb[SO] type CursorWithValue = IDBCursorWithValue
2556625603
idb[SO] type Database = IDBDatabase
25604+
idb[SO] type DatabaseInfo = IDBDatabaseInfo
2556725605
idb[SO] type Environment = IDBEnvironment (@deprecated in 1.2.0)
25606+
idb[SO] type EventTarget[+A] = IDBEventTarget[A]
25607+
idb[SO] type Event[+A] = IDBEvent[A]
2556825608
idb[SO] type Factory = IDBFactory
2556925609
idb[SO] type Index = IDBIndex
2557025610
idb[SO] type KeyRange = IDBKeyRange
2557125611
idb[SO] type ObjectStore = IDBObjectStore
25572-
idb[SO] type OpenDBRequest = IDBOpenDBRequest
25573-
idb[SO] type Request = IDBRequest
25612+
idb[SO] type OpenDBRequest[A] = IDBOpenDBRequest[A]
25613+
idb[SO] type Request[A] = IDBRequest[A]
2557425614
idb[SO] type Transaction = IDBTransaction
2557525615
idb[SO] type VersionChangeEvent = IDBVersionChangeEvent
2557625616
idb[SO] def CursorDirection = IDBCursorDirection
@@ -25744,8 +25784,8 @@ raw[SO] type IDBFactory = dom.IDBFactory (@deprecated in 2.0.0)
2574425784
raw[SO] type IDBIndex = dom.IDBIndex (@deprecated in 2.0.0)
2574525785
raw[SO] type IDBKeyRange = dom.IDBKeyRange (@deprecated in 2.0.0)
2574625786
raw[SO] type IDBObjectStore = dom.IDBObjectStore (@deprecated in 2.0.0)
25747-
raw[SO] type IDBOpenDBRequest = dom.IDBOpenDBRequest (@deprecated in 2.0.0)
25748-
raw[SO] type IDBRequest = dom.IDBRequest (@deprecated in 2.0.0)
25787+
raw[SO] type IDBOpenDBRequest = dom.IDBOpenDBRequest[js.Any] (@deprecated in 2.0.0)
25788+
raw[SO] type IDBRequest = dom.IDBRequest[js.Any] (@deprecated in 2.0.0)
2574925789
raw[SO] type IDBTransaction = dom.IDBTransaction (@deprecated in 2.0.0)
2575025790
raw[SO] type IDBVersionChangeEvent = dom.IDBVersionChangeEvent (@deprecated in 2.0.0)
2575125791
raw[SO] type ImageBitmap = dom.ImageBitmap (@deprecated in 2.0.0)

‎api-reports/2_13.txt

Lines changed: 81 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13530,32 +13530,43 @@ HttpMethod[SO] val PATCH: HttpMethod
1353013530
HttpMethod[SO] val POST: HttpMethod
1353113531
HttpMethod[SO] val PUT: HttpMethod
1353213532
HttpMethod[SO] val QUERY: HttpMethod
13533+
IDBCreateIndexOptions[JT] val locale: js.UndefOr[String]
13534+
IDBCreateIndexOptions[JT] val multiEntry: js.UndefOr[Boolean]
13535+
IDBCreateIndexOptions[JT] val unique: js.UndefOr[Boolean]
13536+
IDBCreateObjectStoreOptions[JT] val autoIncrement: js.UndefOr[Boolean]
13537+
IDBCreateObjectStoreOptions[JT] val keyPath: Any
1353313538
IDBCursor[JC] def advance(count: Int): Unit
13534-
IDBCursor[JC] def continue(key: js.Any?): Unit
13535-
IDBCursor[JC] def delete(): IDBRequest
13539+
IDBCursor[JC] def continue(key: Any?): Unit
13540+
IDBCursor[JC] def delete(): IDBRequest[Unit]
1353613541
IDBCursor[JC] def direction: IDBCursorDirection
13537-
IDBCursor[JC] def key: js.Any
13542+
IDBCursor[JC] def key: Any
1353813543
IDBCursor[JC] def primaryKey: js.Any
1353913544
IDBCursor[JC] def source: js.Any
13540-
IDBCursor[JC] def update(value: js.Any): IDBRequest
13545+
IDBCursor[JC] def update(value: js.Any): IDBRequest[Any]
1354113546
IDBCursorDirection[JT]
1354213547
IDBCursorDirection[SO] val NEXT: IDBCursorDirection
1354313548
IDBCursorDirection[SO] val NEXT_UNIQUE: IDBCursorDirection
1354413549
IDBCursorDirection[SO] val PREV: IDBCursorDirection
1354513550
IDBCursorDirection[SO] val PREV_UNIQUE: IDBCursorDirection
13551+
IDBCursorReadOnly[JC] def advance(count: Int): Unit
13552+
IDBCursorReadOnly[JC] def continue(key: Any?): Unit
13553+
IDBCursorReadOnly[JC] def direction: IDBCursorDirection
13554+
IDBCursorReadOnly[JC] def key: Any
13555+
IDBCursorReadOnly[JC] def primaryKey: js.Any
13556+
IDBCursorReadOnly[JC] def source: js.Any
1354613557
IDBCursorWithValue[JC] def advance(count: Int): Unit
13547-
IDBCursorWithValue[JC] def continue(key: js.Any?): Unit
13548-
IDBCursorWithValue[JC] def delete(): IDBRequest
13558+
IDBCursorWithValue[JC] def continue(key: Any?): Unit
13559+
IDBCursorWithValue[JC] def delete(): IDBRequest[Unit]
1354913560
IDBCursorWithValue[JC] def direction: IDBCursorDirection
13550-
IDBCursorWithValue[JC] def key: js.Any
13561+
IDBCursorWithValue[JC] def key: Any
1355113562
IDBCursorWithValue[JC] def primaryKey: js.Any
1355213563
IDBCursorWithValue[JC] def source: js.Any
13553-
IDBCursorWithValue[JC] def update(value: js.Any): IDBRequest
13564+
IDBCursorWithValue[JC] def update(value: js.Any): IDBRequest[Any]
1355413565
IDBCursorWithValue[JC] def value: js.Any
1355513566
IDBDatabase[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
1355613567
IDBDatabase[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
1355713568
IDBDatabase[JC] def close(): Unit
13558-
IDBDatabase[JC] def createObjectStore(name: String, optionalParameters: js.Any?): IDBObjectStore
13569+
IDBDatabase[JC] def createObjectStore(name: String, optionalParameters: js.UndefOr[IDBCreateObjectStoreOptions]?): IDBObjectStore
1355913570
IDBDatabase[JC] def deleteObjectStore(name: String): Unit
1356013571
IDBDatabase[JC] def dispatchEvent(evt: Event): Boolean
1356113572
IDBDatabase[JC] def name: String
@@ -13567,20 +13578,42 @@ IDBDatabase[JC] def removeEventListener[T <: Event](`type`: String, listener: js
1356713578
IDBDatabase[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
1356813579
IDBDatabase[JC] def transaction(storeNames: js.Any, mode: IDBTransactionMode?): IDBTransaction
1356913580
IDBDatabase[JC] def version: Int
13581+
IDBDatabaseInfo[JT] val name: String
13582+
IDBDatabaseInfo[JT] val version: Int
1357013583
IDBEnvironment[JT] def indexedDB: IDBFactory (@deprecated in 1.2.0)
13584+
IDBEvent[JC] def bubbles: Boolean
13585+
IDBEvent[JC] def cancelBubble: Boolean
13586+
IDBEvent[JC] def cancelable: Boolean
13587+
IDBEvent[JC] def currentTarget: EventTarget
13588+
IDBEvent[JC] def defaultPrevented: Boolean
13589+
IDBEvent[JC] def eventPhase: Int
13590+
IDBEvent[JC] def isTrusted: Boolean
13591+
IDBEvent[JC] def preventDefault(): Unit
13592+
IDBEvent[JC] def stopImmediatePropagation(): Unit
13593+
IDBEvent[JC] def stopPropagation(): Unit
13594+
IDBEvent[JC] def target: EventTarget
13595+
IDBEvent[JC] override def target: IDBEventTarget[A]
13596+
IDBEvent[JC] def timeStamp: Double
13597+
IDBEvent[JC] def `type`: String
13598+
IDBEventTarget[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
13599+
IDBEventTarget[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
13600+
IDBEventTarget[JC] def dispatchEvent(evt: Event): Boolean
13601+
IDBEventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
13602+
IDBEventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
13603+
IDBEventTarget[JC] def result: A
1357113604
IDBFactory[JC] def cmp(first: js.Any, second: js.Any): Int
13572-
IDBFactory[JC] def deleteDatabase(name: String): IDBOpenDBRequest
13573-
IDBFactory[JC] def open(name: String): IDBOpenDBRequest
13574-
IDBFactory[JC] def open(name: String, version: Int): IDBOpenDBRequest
13575-
IDBIndex[JC] def count(): IDBRequest
13576-
IDBIndex[JC] def count(key: js.Any): IDBRequest
13577-
IDBIndex[JC] def get(key: js.Any): IDBRequest
13578-
IDBIndex[JC] def getKey(key: js.Any): IDBRequest
13605+
IDBFactory[JC] def databases(): js.Promise[js.Array[IDBDatabaseInfo]]
13606+
IDBFactory[JC] def deleteDatabase(name: String): IDBOpenDBRequest[Unit]
13607+
IDBFactory[JC] def open(name: String, version: Int?): IDBOpenDBRequest[IDBDatabase]
13608+
IDBIndex[JC] def count(): IDBRequest[Double]
13609+
IDBIndex[JC] def count(key: Any): IDBRequest[Double]
13610+
IDBIndex[JC] def get(key: Any): IDBRequest[js.Any]
13611+
IDBIndex[JC] def getKey(key: Any): IDBRequest[js.UndefOr[js.Any]]
1357913612
IDBIndex[JC] def keyPath: String
1358013613
IDBIndex[JC] def name: String
1358113614
IDBIndex[JC] def objectStore: IDBObjectStore
13582-
IDBIndex[JC] def openCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest
13583-
IDBIndex[JC] def openKeyCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest
13615+
IDBIndex[JC] def openCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest[IDBCursor]
13616+
IDBIndex[JC] def openKeyCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest[IDBCursorReadOnly]
1358413617
IDBIndex[JC] def unique: Boolean
1358513618
IDBKeyRange[JC] def lower: js.Any
1358613619
IDBKeyRange[JC] def lowerOpen: Boolean
@@ -13590,48 +13623,48 @@ IDBKeyRange[JO] def bound(lower: js.Any, upper: js.Any, lowerOpen: Boolean?, upp
1359013623
IDBKeyRange[JO] def lowerBound(bound: js.Any, open: Boolean?): IDBKeyRange
1359113624
IDBKeyRange[JO] def only(value: js.Any): IDBKeyRange
1359213625
IDBKeyRange[JO] def upperBound(bound: js.Any, open: Boolean?): IDBKeyRange
13593-
IDBObjectStore[JC] def add(value: js.Any, key: js.Any?): IDBRequest
13594-
IDBObjectStore[JC] def clear(): IDBRequest
13595-
IDBObjectStore[JC] def count(key: js.Any?): IDBRequest
13596-
IDBObjectStore[JC] def createIndex(name: String, keyPath: String, optionalParameters: js.Any?): IDBIndex
13597-
IDBObjectStore[JC] def delete(key: js.Any): IDBRequest
13626+
IDBObjectStore[JC] def add(value: js.Any, key: Any?): IDBRequest[Any]
13627+
IDBObjectStore[JC] def clear(): IDBRequest[Unit]
13628+
IDBObjectStore[JC] def count(key: Any?): IDBRequest[Double]
13629+
IDBObjectStore[JC] def createIndex(name: String, keyPath: Any, optionalParameters: IDBCreateIndexOptions?): IDBIndex
13630+
IDBObjectStore[JC] def delete(key: Any): IDBRequest[Unit]
1359813631
IDBObjectStore[JC] def deleteIndex(indexName: String): Unit
13599-
IDBObjectStore[JC] def get(key: js.Any): IDBRequest
13600-
IDBObjectStore[JC] def getAll(query: js.UndefOr[IDBKeyRange | js.Any]?, count: js.UndefOr[Int]?): IDBRequest
13601-
IDBObjectStore[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | js.Any]?, count: js.UndefOr[Int]?): IDBRequest
13602-
IDBObjectStore[JC] def getKey(key: js.Any): IDBRequest
13632+
IDBObjectStore[JC] def get(key: Any): IDBRequest[js.Any]
13633+
IDBObjectStore[JC] def getAll(query: js.UndefOr[IDBKeyRange | Any]?, count: js.UndefOr[Int]?): IDBRequest[js.Array[js.Any]]
13634+
IDBObjectStore[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | Any]?, count: js.UndefOr[Int]?): IDBRequest[js.Array[Any]]
13635+
IDBObjectStore[JC] def getKey(key: Any): IDBRequest[js.UndefOr[Any]]
1360313636
IDBObjectStore[JC] def index(name: String): IDBIndex
1360413637
IDBObjectStore[JC] def indexNames: DOMStringList
1360513638
IDBObjectStore[JC] def keyPath: String
1360613639
IDBObjectStore[JC] def name: String
13607-
IDBObjectStore[JC] def openCursor(range: js.UndefOr[IDBKeyRange | js.Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest
13608-
IDBObjectStore[JC] def openKeyCursor(range: js.UndefOr[IDBKeyRange | js.Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest
13609-
IDBObjectStore[JC] def put(value: js.Any, key: js.Any?): IDBRequest
13640+
IDBObjectStore[JC] def openCursor(range: js.UndefOr[IDBKeyRange | Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[IDBCursor]
13641+
IDBObjectStore[JC] def openKeyCursor(range: js.UndefOr[IDBKeyRange | Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[IDBCursorReadOnly]
13642+
IDBObjectStore[JC] def put(value: js.Any, key: Any?): IDBRequest[Any]
1361013643
IDBObjectStore[JC] def transaction: IDBTransaction
1361113644
IDBOpenDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
1361213645
IDBOpenDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
1361313646
IDBOpenDBRequest[JC] def dispatchEvent(evt: Event): Boolean
1361413647
IDBOpenDBRequest[JC] def error: DOMException
1361513648
IDBOpenDBRequest[JC] var onblocked: js.Function1[IDBVersionChangeEvent, _]
1361613649
IDBOpenDBRequest[JC] var onerror: js.Function1[Event, _]
13617-
IDBOpenDBRequest[JC] var onsuccess: js.Function1[Event, _]
13650+
IDBOpenDBRequest[JC] var onsuccess: js.Function1[IDBEvent[A], _]
1361813651
IDBOpenDBRequest[JC] var onupgradeneeded: js.Function1[IDBVersionChangeEvent, _]
1361913652
IDBOpenDBRequest[JC] def readyState: String
1362013653
IDBOpenDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
1362113654
IDBOpenDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
13622-
IDBOpenDBRequest[JC] def result: js.Any
13655+
IDBOpenDBRequest[JC] def result: A
1362313656
IDBOpenDBRequest[JC] def source: js.Any
1362413657
IDBOpenDBRequest[JC] def transaction: IDBTransaction
1362513658
IDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
1362613659
IDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
1362713660
IDBRequest[JC] def dispatchEvent(evt: Event): Boolean
1362813661
IDBRequest[JC] def error: DOMException
1362913662
IDBRequest[JC] var onerror: js.Function1[Event, _]
13630-
IDBRequest[JC] var onsuccess: js.Function1[Event, _]
13663+
IDBRequest[JC] var onsuccess: js.Function1[IDBEvent[A], _]
1363113664
IDBRequest[JC] def readyState: String
1363213665
IDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
1363313666
IDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
13634-
IDBRequest[JC] def result: js.Any
13667+
IDBRequest[JC] def result: A
1363513668
IDBRequest[JC] def source: js.Any
1363613669
IDBRequest[JC] def transaction: IDBTransaction
1363713670
IDBTransaction[JC] def abort(): Unit
@@ -13648,9 +13681,9 @@ IDBTransaction[JC] var onerror: js.Function1[Event, _]
1364813681
IDBTransaction[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
1364913682
IDBTransaction[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
1365013683
IDBTransactionMode[JT]
13651-
IDBTransactionMode[SO] val READ_ONLY: IDBTransactionMode
13652-
IDBTransactionMode[SO] val READ_WRITE: IDBTransactionMode
13653-
IDBTransactionMode[SO] val VERSION_CHANGE: IDBTransactionMode
13684+
IDBTransactionMode[SO] val readonly: IDBTransactionMode
13685+
IDBTransactionMode[SO] val readwrite: IDBTransactionMode
13686+
IDBTransactionMode[SO] val versionchange: IDBTransactionMode
1365413687
IDBVersionChangeEvent[JC] def bubbles: Boolean
1365513688
IDBVersionChangeEvent[JC] def cancelBubble: Boolean
1365613689
IDBVersionChangeEvent[JC] def cancelable: Boolean
@@ -13664,6 +13697,7 @@ IDBVersionChangeEvent[JC] def preventDefault(): Unit
1366413697
IDBVersionChangeEvent[JC] def stopImmediatePropagation(): Unit
1366513698
IDBVersionChangeEvent[JC] def stopPropagation(): Unit
1366613699
IDBVersionChangeEvent[JC] def target: EventTarget
13700+
IDBVersionChangeEvent[JC] override def target: IDBEventTarget[A]
1366713701
IDBVersionChangeEvent[JC] def timeStamp: Double
1366813702
IDBVersionChangeEvent[JC] def `type`: String
1366913703
IDBVersionChangeEventInit[JT] var bubbles: js.UndefOr[Boolean]
@@ -25561,16 +25595,22 @@ html[SO] type UList = HTMLUListElement
2556125595
html[SO] type Unknown = HTMLUnknownElement
2556225596
html[SO] type Video = HTMLVideoElement
2556325597
html[SO] def Media = HTMLMediaElement
25598+
idb[SO] type CreateIndexOptions = IDBCreateIndexOptions
25599+
idb[SO] type CreateObjectStoreOptions = IDBCreateObjectStoreOptions
2556425600
idb[SO] type Cursor = IDBCursor
25601+
idb[SO] type CursorReadOnly = IDBCursorReadOnly
2556525602
idb[SO] type CursorWithValue = IDBCursorWithValue
2556625603
idb[SO] type Database = IDBDatabase
25604+
idb[SO] type DatabaseInfo = IDBDatabaseInfo
2556725605
idb[SO] type Environment = IDBEnvironment (@deprecated in 1.2.0)
25606+
idb[SO] type EventTarget[+A] = IDBEventTarget[A]
25607+
idb[SO] type Event[+A] = IDBEvent[A]
2556825608
idb[SO] type Factory = IDBFactory
2556925609
idb[SO] type Index = IDBIndex
2557025610
idb[SO] type KeyRange = IDBKeyRange
2557125611
idb[SO] type ObjectStore = IDBObjectStore
25572-
idb[SO] type OpenDBRequest = IDBOpenDBRequest
25573-
idb[SO] type Request = IDBRequest
25612+
idb[SO] type OpenDBRequest[A] = IDBOpenDBRequest[A]
25613+
idb[SO] type Request[A] = IDBRequest[A]
2557425614
idb[SO] type Transaction = IDBTransaction
2557525615
idb[SO] type VersionChangeEvent = IDBVersionChangeEvent
2557625616
idb[SO] def CursorDirection = IDBCursorDirection
@@ -25744,8 +25784,8 @@ raw[SO] type IDBFactory = dom.IDBFactory (@deprecated in 2.0.0)
2574425784
raw[SO] type IDBIndex = dom.IDBIndex (@deprecated in 2.0.0)
2574525785
raw[SO] type IDBKeyRange = dom.IDBKeyRange (@deprecated in 2.0.0)
2574625786
raw[SO] type IDBObjectStore = dom.IDBObjectStore (@deprecated in 2.0.0)
25747-
raw[SO] type IDBOpenDBRequest = dom.IDBOpenDBRequest (@deprecated in 2.0.0)
25748-
raw[SO] type IDBRequest = dom.IDBRequest (@deprecated in 2.0.0)
25787+
raw[SO] type IDBOpenDBRequest = dom.IDBOpenDBRequest[js.Any] (@deprecated in 2.0.0)
25788+
raw[SO] type IDBRequest = dom.IDBRequest[js.Any] (@deprecated in 2.0.0)
2574925789
raw[SO] type IDBTransaction = dom.IDBTransaction (@deprecated in 2.0.0)
2575025790
raw[SO] type IDBVersionChangeEvent = dom.IDBVersionChangeEvent (@deprecated in 2.0.0)
2575125791
raw[SO] type ImageBitmap = dom.ImageBitmap (@deprecated in 2.0.0)

‎src/main/scala/org/scalajs/dom/IDBTypes.scala

Lines changed: 123 additions & 47 deletions
Large diffs are not rendered by default.

‎src/main/scala/org/scalajs/dom/idb.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@ package org.scalajs.dom
22

33
/** Short aliases of all the dom.IDBThing classes */
44
object idb {
5+
type CreateIndexOptions = IDBCreateIndexOptions
6+
type CreateObjectStoreOptions = IDBCreateObjectStoreOptions
57
type Cursor = IDBCursor
68
@inline def CursorDirection = IDBCursorDirection
9+
type CursorReadOnly = IDBCursorReadOnly
710
type CursorWithValue = IDBCursorWithValue
811
type Database = IDBDatabase
12+
type DatabaseInfo = IDBDatabaseInfo
13+
type Event[+A] = IDBEvent[A]
14+
type EventTarget[+A] = IDBEventTarget[A]
915
type Factory = IDBFactory
1016
type Index = IDBIndex
1117
type KeyRange = IDBKeyRange
1218
@inline def KeyRange = IDBKeyRange
1319
type ObjectStore = IDBObjectStore
14-
type OpenDBRequest = IDBOpenDBRequest
15-
type Request = IDBRequest
20+
type OpenDBRequest[A] = IDBOpenDBRequest[A]
21+
type Request[A] = IDBRequest[A]
1622
type Transaction = IDBTransaction
1723
@inline def TransactionMode = IDBTransactionMode
1824
type VersionChangeEvent = IDBVersionChangeEvent

‎src/main/scala/org/scalajs/dom/raw.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,10 @@ object raw {
506506
type IDBObjectStore = dom.IDBObjectStore
507507

508508
@deprecated("use dom.IDBOpenDBRequest instead", "2.0.0")
509-
type IDBOpenDBRequest = dom.IDBOpenDBRequest
509+
type IDBOpenDBRequest = dom.IDBOpenDBRequest[js.Any]
510510

511511
@deprecated("use dom.IDBRequest instead", "2.0.0")
512-
type IDBRequest = dom.IDBRequest
512+
type IDBRequest = dom.IDBRequest[js.Any]
513513

514514
@deprecated("use dom.IDBTransaction instead", "2.0.0")
515515
type IDBTransaction = dom.IDBTransaction

‎tests-shared/src/main/scala/org/scalajs/dom/tests/shared/AsyncTesting.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.scalajs.dom.tests.shared
33
import org.junit.Assert
44
import scala.concurrent._
55
import scala.util._
6+
import scala.scalajs.js
67
import scala.scalajs.js.timers._
78

89
object AsyncTesting {
@@ -12,6 +13,12 @@ object AsyncTesting {
1213
implicit def global: ExecutionContext =
1314
ExecutionContext.global
1415

16+
def asyncPass: AsyncResult =
17+
Future.successful(Success(()))
18+
19+
def asyncWhenDefined[A](o: js.UndefOr[A])(f: A => AsyncResult): AsyncResult =
20+
o.fold(asyncPass)(f)
21+
1522
def async(run: => Future[Any]): AsyncResult = {
1623
val p = Promise[Try[Unit]]()
1724
val timeout = setTimeout(1200) {
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package org.scalajs.dom.tests.shared
2+
3+
import java.util.UUID
4+
import org.junit.Assert._
5+
import org.scalajs.dom._
6+
import org.scalajs.dom.tests.shared.AsyncTesting._
7+
import scala.concurrent._
8+
import scala.scalajs.js
9+
import scala.util.Try
10+
11+
/** Scala.js version of https://gist.github.com/JamesMessinger/a0d6389a5d0e3a24814b */
12+
object IdbTest {
13+
14+
def apply(idb: js.UndefOr[IDBFactory]): AsyncResult =
15+
asyncWhenDefined(idb)(apply(_))
16+
17+
def apply(idb: IDBFactory): AsyncResult = async {
18+
open(idb).flatMap(use)
19+
}
20+
21+
private def open(idb: IDBFactory): Future[IDBDatabase] = {
22+
val p = Promise[IDBDatabase]()
23+
val r = idb.open(UUID.randomUUID().toString)
24+
25+
r.onerror = (e: Event) => fail(p, "idb.open failed: " + r.error)
26+
27+
r.onupgradeneeded = (e: IDBEvent[IDBDatabase]) => {
28+
val db = e.target.result
29+
val opts = new IDBCreateObjectStoreOptions { override val keyPath = "id" }
30+
val store = db.createObjectStore("MyObjectStore", opts)
31+
store.createIndex("NameIndex", js.Array("name.last", "name.first"))
32+
}
33+
34+
r.onsuccess = (e: IDBEvent[IDBDatabase]) => {
35+
assertSame(r.result, e.target.result)
36+
p.success(r.result)
37+
}
38+
39+
p.future
40+
}
41+
42+
private def fail(p: Promise[_], why: Any): Unit =
43+
p.failure(new RuntimeException("" + why))
44+
45+
private def use(db: IDBDatabase): Future[Unit] = {
46+
import js.Dynamic.{literal => obj}
47+
48+
val tx = db.transaction("MyObjectStore", IDBTransactionMode.readwrite)
49+
val store = tx.objectStore("MyObjectStore")
50+
val index = store.index("NameIndex")
51+
52+
// Add some data
53+
store.put(obj(id = 12345, name = obj(first = "John", last = "Doe"), age = 42))
54+
store.put(obj(id = 67890, name = obj(first = "Bob", last = "Smith"), age = 35))
55+
56+
// Query the data
57+
val getJohn = store.get(12345)
58+
val getBob = index.get(js.Array("Smith", "Bob"))
59+
60+
// Close the db when the transaction is done
61+
tx.oncomplete = (e: Event) => {
62+
db.close()
63+
}
64+
65+
def getFirstName(r: IDBRequest[js.Any]): Future[String] = {
66+
val p = Promise[String]()
67+
r.onerror = (e: Event) => fail(p, e)
68+
r.onsuccess = (e: IDBEvent[js.Any]) => {
69+
p.complete(Try(e.target.result.asInstanceOf[js.Dynamic].name.first.asInstanceOf[String]))
70+
}
71+
p.future
72+
}
73+
74+
for {
75+
john <- getFirstName(getJohn)
76+
bob <- getFirstName(getBob)
77+
} yield {
78+
assertEquals("John", john)
79+
assertEquals("Bob", bob)
80+
}
81+
}
82+
}
Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package org.scalajs.dom.tests.shared
22

3-
import java.util.UUID
3+
import org.scalajs.dom.tests.shared.AsyncTesting._
44
import org.junit.Test
55

66
trait SharedTests {
7-
import SharedTests._
7+
8+
// ===================================================================================================================
9+
// Tests WITHOUT org.scalajs.dom._ in scope
810

911
// This tests that ops are always implicitly available, no imports required
1012
@Test final def NodeListOpsTest(): Unit =
@@ -18,7 +20,8 @@ trait SharedTests {
1820
.map(_.classList.mkString)
1921
}
2022

21-
// Don't move up
23+
// ===================================================================================================================
24+
// Tests WITH org.scalajs.dom._ in scope
2225
import org.scalajs.dom._
2326

2427
// https://github.com/scala-js/scala-js-dom/issues/411 - console doesn't work in web workers
@@ -30,17 +33,6 @@ trait SharedTests {
3033
val _ = crypto.HashAlgorithm
3134
}
3235

33-
@Test final def WindowIdbTest(): Unit =
34-
window.indexedDB.foreach(testIdb)
35-
36-
}
37-
38-
object SharedTests {
39-
import org.scalajs.dom._
40-
41-
def testIdb(idb: IDBFactory): Unit = {
42-
val open = idb.open(UUID.randomUUID().toString())
43-
open.onerror = (e: Event) => sys.error("idb open failed: " + e)
44-
// TODO: Test properly in a different PR
45-
}
36+
@Test final def WindowIdbTest(): AsyncResult =
37+
IdbTest(window.indexedDB)
4638
}

‎tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/Server.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.scalajs.dom.tests.webworker
22

33
import org.scalajs.dom._
4+
import scala.concurrent.ExecutionContext.Implicits.global
45

56
object Server extends ServerResponses {
67
import Protocol._
@@ -13,9 +14,11 @@ object Server extends ServerResponses {
1314
val id = msgIn._1
1415
val cmdId = msgIn._2
1516
val cmd = WebWorkerCmd.byId(cmdId)
16-
val output = respond(cmd)
17-
val msgOut = Message(id, output)
18-
ww.postMessage(msgOut)
17+
respond(cmd).onComplete { t =>
18+
val output = t.getOrElse(t.failed.get.toString)
19+
val msgOut = Message(id, output)
20+
ww.postMessage(msgOut)
21+
}
1922
}
2023

2124
ww.postMessage(Message(ServerStarted, ""))

‎tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/WebWorkerTests.scala

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.scalajs.dom.tests.webworker
22

3+
import scala.language.implicitConversions
4+
import scala.concurrent.Future
35
import org.junit.Assert._
46
import org.junit.Test
57
import org.scalajs.dom.tests.shared.AsyncTesting._
@@ -46,10 +48,21 @@ trait WebWorkerTests {
4648
// =====================================================================================================================
4749
trait ServerResponses {
4850
import org.scalajs.dom._
49-
import org.scalajs.dom.tests.shared.SharedTests._
51+
import org.scalajs.dom.tests.shared._
5052
import org.scalajs.dom.DedicatedWorkerGlobalScope.self
5153

52-
final val respond: WebWorkerCmd => String = {
54+
private implicit def autoLift(s: => String): Future[String] =
55+
Future(s)
56+
57+
private implicit class AsyncOps(r: AsyncResult) {
58+
def andReturn(s: String): Future[String] =
59+
r.map { t =>
60+
t.get
61+
s
62+
}
63+
}
64+
65+
final val respond: WebWorkerCmd => Future[String] = {
5366

5467
case SayHello =>
5568
"hello"
@@ -60,7 +73,6 @@ trait ServerResponses {
6073

6174
case TestIdb =>
6275
assertTrue(self.indexedDB.isDefined)
63-
testIdb(self.indexedDB.get)
64-
"ok"
76+
IdbTest(self.indexedDB.get).andReturn("ok")
6577
}
6678
}

0 commit comments

Comments
 (0)
Please sign in to comment.