Skip to content

Commit 2227462

Browse files
authored
Merge pull request #430 from japgolly/WindowOrWorkerGlobalScope
Add WindowOrWorkerGlobalScope
2 parents e9c79fa + ffd1916 commit 2227462

File tree

12 files changed

+675
-182
lines changed

12 files changed

+675
-182
lines changed

api-reports/2_12.txt

+149-24
Large diffs are not rendered by default.

api-reports/2_13.txt

+149-24
Large diffs are not rendered by default.

scalafix/src/main/scala/org/scalajs/dom/scalafix/GenerateApiReport.scala

+25-20
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,43 @@ class GenerateApiReport extends SemanticRule("GenerateApiReport") {
2121

2222
if (enabled)
2323
doc.tree.traverse {
24-
case a: Defn.Class => process(a.symbol, a.templ, ScopeType.Class)
25-
case a: Defn.Object => process(a.symbol, a.templ, ScopeType.Object)
26-
case a: Defn.Trait => process(a.symbol, a.templ, ScopeType.Trait)
27-
case a: Pkg.Object => process(a.symbol, a.templ, ScopeType.Object)
24+
case a: Defn.Class => process(a.mods, a.symbol, a.templ, ScopeType.Class)
25+
case a: Defn.Object => process(a.mods, a.symbol, a.templ, ScopeType.Object)
26+
case a: Defn.Trait => process(a.mods, a.symbol, a.templ, ScopeType.Trait)
27+
case a: Pkg.Object => process(a.mods, a.symbol, a.templ, ScopeType.Object)
2828
case _ =>
2929
}
3030

3131
Patch.empty
3232
}
3333

34-
private def process(sym: Symbol, body: Template, typ: ScopeType)(implicit doc: SemanticDocument): Unit = {
34+
private def process(parentMods: List[Mod], sym: Symbol, body: Template, typ: ScopeType)(implicit doc: SemanticDocument): Unit = {
3535
// Skip non-public scopes
3636
val info = sym.info.get
3737
if (!info.isPublic && !info.isPackageObject)
3838
return
3939

40+
def inspectAnnotationsFn(set: String => Unit): List[Mod] => List[Mod] =
41+
_.filter {
42+
case Mod.Annot(Init(tpe, _, List(List(_, ver)))) if tpe.toString == "deprecated" =>
43+
set(
44+
ver match {
45+
case Lit.String(s) => s
46+
case term => term.toString
47+
}
48+
)
49+
false
50+
case _ => true
51+
}
52+
53+
// Inspect scope's annotations
54+
var scopeDeprecatedVer = Option.empty[String]
55+
inspectAnnotationsFn(v => scopeDeprecatedVer = Some(v))(parentMods)
56+
4057
val parents = Util.parents(sym).iterator.map(Util.typeSymbol).toList
4158
val domParents = parents.iterator.filter(isScalaJsDom).toSet
4259
val isJsType = parents.exists(isScalaJs)
43-
val s = state.register(sym, isJsType, typ, domParents)
60+
val s = state.register(sym, isJsType, typ, domParents, scopeDeprecatedVer)
4461

4562
def letsSeeHowLazyWeCanBeLol(t: Tree): Unit = {
4663
// Skip non-public members
@@ -58,24 +75,12 @@ class GenerateApiReport extends SemanticRule("GenerateApiReport") {
5875

5976
// Inspect annotations
6077
var deprecatedVer = Option.empty[String]
61-
62-
def inspectAnnotations(mods: List[Mod]): List[Mod] =
63-
mods.filter {
64-
case Mod.Annot(Init(tpe, _, List(List(_, ver)))) if tpe.toString == "deprecated" =>
65-
deprecatedVer = Some {
66-
ver match {
67-
case Lit.String(s) => s
68-
case term => term.toString
69-
}
70-
}
71-
false
72-
case _ => true
73-
}
74-
78+
val inspectAnnotations = inspectAnnotationsFn(v => deprecatedVer = Some(v))
7579
t2 match {
7680
case Decl.Def(mods, name, tparams, paramss, tpe) => t2 = Decl.Def(inspectAnnotations(mods), name, tparams, paramss, tpe)
7781
case Decl.Val(mods, pats, tpe) => t2 = Decl.Val(inspectAnnotations(mods), pats, tpe)
7882
case Decl.Var(mods, pats, tpe) => t2 = Decl.Var(inspectAnnotations(mods), pats, tpe)
83+
case Defn.Type(mods, names, params, tpe) => t2 = Defn.Type(inspectAnnotations(mods), names, params, tpe)
7984
case _ =>
8085
}
8186

scalafix/src/main/scala/org/scalajs/dom/scalafix/MutableState.scala

+23-8
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ final class MutableState {
1111

1212
private[this] val scopes = mutable.Map.empty[Symbol, Scope]
1313

14-
def register(sym: Symbol, isJsType: Boolean, scopeType: ScopeType, parents: Set[Symbol]): Scope = synchronized {
14+
def register(sym : Symbol,
15+
isJsType : Boolean,
16+
scopeType : ScopeType,
17+
parents : Set[Symbol],
18+
deprecatedVer: Option[String]): Scope = synchronized {
1519
scopes.get(sym) match {
1620
case None =>
1721
val s = Scope(sym)(scopeType, parents)
1822
scopes.update(sym, s)
1923
s.isJsType = isJsType
24+
s.deprecatedVer = deprecatedVer
2025
s
2126
case Some(s) =>
2227
s
@@ -47,10 +52,20 @@ final class MutableState {
4752

4853
val b = SortedSet.newBuilder[Result]
4954

55+
def deprecationSuffix(ver: Option[String]): String =
56+
ver match {
57+
case None => ""
58+
case Some(v) => s" (@deprecated in $v)"
59+
}
60+
5061
// Pass 1
5162
for (root <- scopes.valuesIterator) {
52-
if (!root.isJsType && scopeParents(root).exists(_.isJsType))
63+
val parents = scopeParents(root)
64+
if (!root.isJsType && parents.exists(_.isJsType))
5365
root.isJsType = true
66+
if (root.deprecatedVer.isEmpty)
67+
for (p <- parents.find(_.deprecatedVer.isDefined))
68+
root.deprecatedVer = p.deprecatedVer
5469
}
5570

5671
// Pass 2
@@ -65,19 +80,18 @@ final class MutableState {
6580
var membersFound = false
6681
for {
6782
s <- root :: scopeParents(root)
68-
v <- s.directMembers
83+
m <- s.directMembers
6984
} {
7085
membersFound = true
71-
val key = (scopeKey, v.name, v.desc)
72-
var result = prefix + v.desc
73-
for (ver <- v.deprecatedVer)
74-
result = s"$result (@deprecated in $ver)"
86+
val key = (scopeKey, m.name, m.desc)
87+
val result = prefix + m.desc + deprecationSuffix(m.deprecatedVer.orElse(root.deprecatedVer))
7588
b += Result(key, result)
7689
}
7790

7891
if (!membersFound && !scopeName.endsWith("/package")) {
7992
val key = (scopeKey, " ", "")
80-
b += Result(key, prefix.trim)
93+
val result = prefix.trim + deprecationSuffix(root.deprecatedVer)
94+
b += Result(key, result)
8195
}
8296
}
8397

@@ -101,6 +115,7 @@ object MutableState {
101115

102116
private[MutableState] val directMembers = mutable.Set.empty[Member]
103117
private[MutableState] var isJsType = false
118+
private[MutableState] var deprecatedVer = Option.empty[String]
104119

105120
def add(v: Member): Unit =
106121
synchronized(directMembers += v)
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

+31-73
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
*
@@ -769,3 +698,32 @@ trait ServiceWorkerGlobalScope extends WorkerGlobalScope {
769698
object ServiceWorkerGlobalScope extends js.Object {
770699
def self: ServiceWorkerGlobalScope = js.native
771700
}
701+
702+
/**
703+
* See [[https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/#cache ¶5.4 cache]]
704+
* of ServiceWorker whatwg spec.
705+
*/
706+
@deprecated("Use org.scalajs.dom.experimental.cachestorage.Cache", "1.2.0")
707+
@js.native
708+
@JSGlobal
709+
abstract class Cache extends org.scalajs.dom.experimental.cachestorage.Cache
710+
711+
/**
712+
* See [[https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/#cache ¶5.4 cache]]
713+
* of ServiceWorker whatwg spec.
714+
*/
715+
@deprecated("Use org.scalajs.dom.experimental.cachestorage.CacheQueryOptions",
716+
"1.2.0")
717+
@js.native
718+
trait CacheQueryOptions
719+
extends org.scalajs.dom.experimental.cachestorage.CacheQueryOptions
720+
721+
/**
722+
* See [[https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/#cache-storage ¶5.5 cache]]
723+
* of ServiceWorker whatwg spec.
724+
*/
725+
@deprecated("Use org.scalajs.dom.experimental.cachestorage.CacheStorage",
726+
"1.2.0")
727+
@js.native
728+
trait CacheStorage
729+
extends org.scalajs.dom.experimental.cachestorage.CacheStorage

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

+4-1
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
@@ -19,4 +18,8 @@ object idb {
1918
type Transaction = raw.IDBTransaction
2019
@inline def Transaction = raw.IDBTransaction
2120
type VersionChangeEvent = raw.IDBVersionChangeEvent
21+
@deprecated(
22+
"Removed. This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible. See https://developer.mozilla.org/en-US/docs/Web/API/IDBEnvironment",
23+
"1.2.0")
24+
type Environment = raw.IDBEnvironment
2225
}

0 commit comments

Comments
 (0)