Skip to content

Commit a306825

Browse files
committed
Add WindowOrWorkerGlobalScope
Additionally, this fixes the following: * IDBEnvironment removed because it's officially obsolete and "although it may still work in some browsers, its use is discouraged since it could be removed at any time". * indexedDB now wrapped in js.UndefOr because it's not always available * indexedDB added to WorkerGlobalScope * caches return type changed from js.Any to js.UndefOr[CacheStorage] * caches added to Window * CacheStorage moved into experiment.cachestorage as it's available from Window too * Add missing methods to window and web-worker scopes: * crossOriginIsolated * isSecureContext * origin Ref: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope
1 parent 5a502ad commit a306825

File tree

7 files changed

+130
-105
lines changed

7 files changed

+130
-105
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package org.scalajs.dom.experimental.cachestorage
2+
3+
import scala.scalajs.js
4+
import scala.scalajs.js.annotation._
5+
import org.scalajs.dom.experimental._
6+
7+
/**
8+
* See [[https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/#cache ¶5.4 cache]]
9+
* of ServiceWorker whatwg spec.
10+
*/
11+
@js.native
12+
trait CacheQueryOptions extends js.Object {
13+
var ignoreSearch: Boolean = js.native // false
14+
15+
var ignoreMethod: Boolean = js.native // false
16+
17+
var ignoreVary: Boolean = js.native //false
18+
19+
var cacheName: String = js.native
20+
}
21+
22+
/**
23+
* See [[https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/#cache-storage ¶5.5 cache]]
24+
* of ServiceWorker whatwg spec.
25+
*/
26+
@js.native
27+
trait CacheStorage extends js.Object {
28+
def `match`(request: RequestInfo,
29+
options: CacheQueryOptions = js.native): js.Promise[js.Any] = js.native
30+
31+
def has(cacheName: String): js.Promise[Boolean] = js.native
32+
33+
def open(cacheName: String): js.Promise[Cache] = js.native
34+
35+
def delete(cacheName: String): js.Promise[Boolean] = js.native
36+
37+
def keys(): js.Promise[js.Array[String]] = js.native
38+
}
39+
40+
/**
41+
* See [[https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/#cache ¶5.4 cache]]
42+
* of ServiceWorker whatwg spec.
43+
*/
44+
@js.native
45+
@JSGlobal
46+
abstract class Cache extends js.Object {
47+
def `match`(request: RequestInfo,
48+
options: js.UndefOr[
49+
CacheQueryOptions] = js.native): js.Promise[js.UndefOr[Response]] = js.native
50+
51+
def matchAll(request: RequestInfo = js.native,
52+
options: js.UndefOr[
53+
CacheQueryOptions] = js.native): js.Promise[js.Array[Response]] = js.native
54+
55+
def add(request: RequestInfo): js.Promise[Unit] = js.native
56+
57+
def addAll(requests: js.Array[RequestInfo]): js.Promise[Unit] = js.native
58+
59+
def put(request: RequestInfo,
60+
response: Response): js.Promise[Unit] = js.native
61+
62+
def delete(request: RequestInfo,
63+
options: js.UndefOr[
64+
CacheQueryOptions] = js.native): js.Promise[Boolean] = js.native
65+
66+
def keys(request: js.UndefOr[RequestInfo] = js.native,
67+
options: js.UndefOr[
68+
CacheQueryOptions] = js.native): js.Promise[js.Array[Request]]
69+
}

src/main/scala/org/scalajs/dom/experimental/serviceworkers/ServiceWorkers.scala

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import scala.scalajs.js.|
77
import org.scalajs.dom.experimental.{
88
Notification, NotificationOptions, Request, RequestInfo, Response, Sequence
99
}
10-
import org.scalajs.dom.raw.{WorkerGlobalScope, ErrorEvent}
10+
import org.scalajs.dom.experimental.cachestorage._
11+
import org.scalajs.dom.raw.{ErrorEvent, EventInit, WorkerGlobalScope}
1112
import org.scalajs.dom.webgl.RenderingContext
1213
import org.scalajs.dom.{Event, EventTarget, MessageEvent, MessagePort}
13-
import org.scalajs.dom.raw.EventInit
1414

1515
@js.native
1616
sealed trait FrameType extends js.Any
@@ -608,70 +608,6 @@ trait Clients extends js.Object {
608608
def claim(): js.Promise[Unit] = js.native
609609
}
610610

611-
/**
612-
* See [[https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/#cache ¶5.4 cache]]
613-
* of ServiceWorker whatwg spec.
614-
*/
615-
@js.native
616-
@JSGlobal
617-
abstract class Cache extends js.Object {
618-
def `match`(request: RequestInfo,
619-
options: js.UndefOr[
620-
CacheQueryOptions] = js.native): js.Promise[js.UndefOr[Response]] = js.native
621-
622-
def matchAll(request: RequestInfo = js.native,
623-
options: js.UndefOr[
624-
CacheQueryOptions] = js.native): js.Promise[js.Array[Response]] = js.native
625-
626-
def add(request: RequestInfo): js.Promise[Unit] = js.native
627-
628-
def addAll(requests: js.Array[RequestInfo]): js.Promise[Unit] = js.native
629-
630-
def put(request: RequestInfo,
631-
response: Response): js.Promise[Unit] = js.native
632-
633-
def delete(request: RequestInfo,
634-
options: js.UndefOr[
635-
CacheQueryOptions] = js.native): js.Promise[Boolean] = js.native
636-
637-
def keys(request: js.UndefOr[RequestInfo] = js.native,
638-
options: js.UndefOr[
639-
CacheQueryOptions] = js.native): js.Promise[js.Array[Request]]
640-
}
641-
642-
/**
643-
* See [[https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/#cache ¶5.4 cache]]
644-
* of ServiceWorker whatwg spec.
645-
*/
646-
@js.native
647-
trait CacheQueryOptions extends js.Object {
648-
var ignoreSearch: Boolean = js.native // false
649-
650-
var ignoreMethod: Boolean = js.native // false
651-
652-
var ignoreVary: Boolean = js.native //false
653-
654-
var cacheName: String = js.native
655-
}
656-
657-
/**
658-
* See [[https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/#cache-storage ¶5.5 cache]]
659-
* of ServiceWorker whatwg spec.
660-
*/
661-
@js.native
662-
trait CacheStorage extends js.Object {
663-
def `match`(request: RequestInfo,
664-
options: CacheQueryOptions = js.native): js.Promise[js.Any] = js.native
665-
666-
def has(cacheName: String): js.Promise[Boolean] = js.native
667-
668-
def open(cacheName: String): js.Promise[Cache] = js.native
669-
670-
def delete(cacheName: String): js.Promise[Boolean] = js.native
671-
672-
def keys(): js.Promise[js.Array[String]] = js.native
673-
}
674-
675611
/**
676612
* The ServiceWorkerGlobalScope interface of the ServiceWorker API represents
677613
* the global execution context of a service worker.
@@ -694,13 +630,6 @@ trait CacheStorage extends js.Object {
694630
@js.native
695631
trait ServiceWorkerGlobalScope extends WorkerGlobalScope {
696632

697-
/**
698-
* Returns the CacheStorage object associated with the service worker.
699-
*
700-
* MDN
701-
*/
702-
override def caches: CacheStorage = js.native
703-
704633
/**
705634
* Returns the Clients object associated with the service worker.
706635
*

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ object idb {
88
@inline def Cursor = raw.IDBCursor
99
type CursorWithValue = raw.IDBCursorWithValue
1010
type Database = raw.IDBDatabase
11-
type Environment = raw.IDBEnvironment
1211
type Factory = raw.IDBFactory
1312
type Index = raw.IDBIndex
1413
type KeyRange = raw.IDBKeyRange

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -354,25 +354,6 @@ class IDBCursorWithValue extends IDBCursor {
354354
def value: js.Any = js.native
355355
}
356356

357-
/**
358-
* The IDBEvironment interface of the IndexedDB API provides asynchronous access
359-
* to a client-side database. It is implemented by window and Worker objects.
360-
*
361-
* MDN
362-
*/
363-
@js.native
364-
trait IDBEnvironment extends js.Object {
365-
366-
/**
367-
* an IDBRequest object that communicates back to the requesting application
368-
* through events. This design means that any number of requests can be active on any
369-
* database at a time.
370-
*
371-
* MDN
372-
*/
373-
def indexedDB: IDBFactory = js.native
374-
}
375-
376357
/**
377358
* The IDBKeyRange interface of the IndexedDB API represents a continuous interval
378359
* over some data type that is used for keys. Records can be retrieved from object

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,7 @@ class Worker(stringUrl: String) extends AbstractWorker {
107107
* MDN
108108
*/
109109
@js.native
110-
trait WorkerGlobalScope extends EventTarget {
111-
112-
/**
113-
* The caches read-only property of the WorkerGlobalScope interface returns
114-
* the CacheStorage object associated with the current worker context.
115-
* This object enables service worker functionality such as storing assets
116-
* for offline use, and generating custom responses to requests.
117-
*
118-
* MDN
119-
*/
120-
def caches: js.Any = js.native
110+
trait WorkerGlobalScope extends EventTarget with WindowOrWorkerGlobalScope {
121111

122112
/**
123113
* The self read-only property of the WorkerGlobalScope interface returns a
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.scalajs.dom.raw
2+
3+
import scala.scalajs.js
4+
import scala.scalajs.js.annotation._
5+
import org.scalajs.dom.experimental.cachestorage.CacheStorage
6+
7+
/**
8+
* The WindowOrWorkerGlobalScope mixin describes several features common to the
9+
* Window and WorkerGlobalScope interfaces.
10+
*
11+
* Note: WindowOrWorkerGlobalScope is a mixin and not an interface; you can't
12+
* actually create an object of type WindowOrWorkerGlobalScope.
13+
*
14+
* MDN
15+
*/
16+
@js.native
17+
trait WindowOrWorkerGlobalScope extends js.Object {
18+
19+
/**
20+
* Returns the CacheStorage object associated with the current context.
21+
* This object enables functionality such as storing assets for offline use,
22+
* and generating custom responses to requests.
23+
*
24+
* MDN
25+
*/
26+
def caches: js.UndefOr[CacheStorage] = js.native
27+
28+
/**
29+
* Returns a boolean value that indicates whether a SharedArrayBuffer can be
30+
* sent via a Window.postMessage() call.
31+
*
32+
* MDN
33+
*/
34+
def crossOriginIsolated: Boolean = js.native
35+
36+
/**
37+
* Provides a mechanism for applications to asynchronously access
38+
* capabilities of indexed databases.
39+
*
40+
* MDN
41+
*/
42+
def indexedDB: js.UndefOr[IDBFactory] = js.native
43+
44+
/**
45+
* Returns a boolean indicating whether the current context is secure or not.
46+
*
47+
* MDN
48+
*/
49+
def isSecureContext: Boolean = js.native
50+
51+
/**
52+
* Returns the origin of the global scope, serialized as a string.
53+
*
54+
* MDN
55+
*/
56+
def origin: String = js.native //should be USVString
57+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2057,7 +2057,7 @@ trait WindowSessionStorage extends js.Object {
20572057
@JSGlobal
20582058
class Window
20592059
extends EventTarget with WindowLocalStorage with WindowSessionStorage
2060-
with WindowTimers with WindowBase64 with IDBEnvironment
2060+
with WindowTimers with WindowBase64 with WindowOrWorkerGlobalScope
20612061
with WindowConsole {
20622062
var ondragend: js.Function1[DragEvent, _] = js.native
20632063

0 commit comments

Comments
 (0)