Skip to content

Add WindowOrWorkerGlobalScope #430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 149 additions & 24 deletions api-reports/2_12.txt

Large diffs are not rendered by default.

173 changes: 149 additions & 24 deletions api-reports/2_13.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,43 @@ class GenerateApiReport extends SemanticRule("GenerateApiReport") {

if (enabled)
doc.tree.traverse {
case a: Defn.Class => process(a.symbol, a.templ, ScopeType.Class)
case a: Defn.Object => process(a.symbol, a.templ, ScopeType.Object)
case a: Defn.Trait => process(a.symbol, a.templ, ScopeType.Trait)
case a: Pkg.Object => process(a.symbol, a.templ, ScopeType.Object)
case a: Defn.Class => process(a.mods, a.symbol, a.templ, ScopeType.Class)
case a: Defn.Object => process(a.mods, a.symbol, a.templ, ScopeType.Object)
case a: Defn.Trait => process(a.mods, a.symbol, a.templ, ScopeType.Trait)
case a: Pkg.Object => process(a.mods, a.symbol, a.templ, ScopeType.Object)
case _ =>
}

Patch.empty
}

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

def inspectAnnotationsFn(set: String => Unit): List[Mod] => List[Mod] =
_.filter {
case Mod.Annot(Init(tpe, _, List(List(_, ver)))) if tpe.toString == "deprecated" =>
set(
ver match {
case Lit.String(s) => s
case term => term.toString
}
)
false
case _ => true
}

// Inspect scope's annotations
var scopeDeprecatedVer = Option.empty[String]
inspectAnnotationsFn(v => scopeDeprecatedVer = Some(v))(parentMods)

val parents = Util.parents(sym).iterator.map(Util.typeSymbol).toList
val domParents = parents.iterator.filter(isScalaJsDom).toSet
val isJsType = parents.exists(isScalaJs)
val s = state.register(sym, isJsType, typ, domParents)
val s = state.register(sym, isJsType, typ, domParents, scopeDeprecatedVer)

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

// Inspect annotations
var deprecatedVer = Option.empty[String]

def inspectAnnotations(mods: List[Mod]): List[Mod] =
mods.filter {
case Mod.Annot(Init(tpe, _, List(List(_, ver)))) if tpe.toString == "deprecated" =>
deprecatedVer = Some {
ver match {
case Lit.String(s) => s
case term => term.toString
}
}
false
case _ => true
}

val inspectAnnotations = inspectAnnotationsFn(v => deprecatedVer = Some(v))
t2 match {
case Decl.Def(mods, name, tparams, paramss, tpe) => t2 = Decl.Def(inspectAnnotations(mods), name, tparams, paramss, tpe)
case Decl.Val(mods, pats, tpe) => t2 = Decl.Val(inspectAnnotations(mods), pats, tpe)
case Decl.Var(mods, pats, tpe) => t2 = Decl.Var(inspectAnnotations(mods), pats, tpe)
case Defn.Type(mods, names, params, tpe) => t2 = Defn.Type(inspectAnnotations(mods), names, params, tpe)
case _ =>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ final class MutableState {

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

def register(sym: Symbol, isJsType: Boolean, scopeType: ScopeType, parents: Set[Symbol]): Scope = synchronized {
def register(sym : Symbol,
isJsType : Boolean,
scopeType : ScopeType,
parents : Set[Symbol],
deprecatedVer: Option[String]): Scope = synchronized {
scopes.get(sym) match {
case None =>
val s = Scope(sym)(scopeType, parents)
scopes.update(sym, s)
s.isJsType = isJsType
s.deprecatedVer = deprecatedVer
s
case Some(s) =>
s
Expand Down Expand Up @@ -47,10 +52,20 @@ final class MutableState {

val b = SortedSet.newBuilder[Result]

def deprecationSuffix(ver: Option[String]): String =
ver match {
case None => ""
case Some(v) => s" (@deprecated in $v)"
}

// Pass 1
for (root <- scopes.valuesIterator) {
if (!root.isJsType && scopeParents(root).exists(_.isJsType))
val parents = scopeParents(root)
if (!root.isJsType && parents.exists(_.isJsType))
root.isJsType = true
if (root.deprecatedVer.isEmpty)
for (p <- parents.find(_.deprecatedVer.isDefined))
root.deprecatedVer = p.deprecatedVer
}

// Pass 2
Expand All @@ -65,19 +80,18 @@ final class MutableState {
var membersFound = false
for {
s <- root :: scopeParents(root)
v <- s.directMembers
m <- s.directMembers
} {
membersFound = true
val key = (scopeKey, v.name, v.desc)
var result = prefix + v.desc
for (ver <- v.deprecatedVer)
result = s"$result (@deprecated in $ver)"
val key = (scopeKey, m.name, m.desc)
val result = prefix + m.desc + deprecationSuffix(m.deprecatedVer.orElse(root.deprecatedVer))
b += Result(key, result)
}

if (!membersFound && !scopeName.endsWith("/package")) {
val key = (scopeKey, " ", "")
b += Result(key, prefix.trim)
val result = prefix.trim + deprecationSuffix(root.deprecatedVer)
b += Result(key, result)
}
}

Expand All @@ -101,6 +115,7 @@ object MutableState {

private[MutableState] val directMembers = mutable.Set.empty[Member]
private[MutableState] var isJsType = false
private[MutableState] var deprecatedVer = Option.empty[String]

def add(v: Member): Unit =
synchronized(directMembers += v)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package org.scalajs.dom.experimental.cachestorage

import scala.scalajs.js
import scala.scalajs.js.annotation._
import org.scalajs.dom.experimental._

/**
* See [[https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/#cache ¶5.4 cache]]
* of ServiceWorker whatwg spec.
*/
@js.native
trait CacheQueryOptions extends js.Object {
var ignoreSearch: Boolean = js.native // false

var ignoreMethod: Boolean = js.native // false

var ignoreVary: Boolean = js.native //false

var cacheName: String = js.native
}

/**
* See [[https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/#cache-storage ¶5.5 cache]]
* of ServiceWorker whatwg spec.
*/
@js.native
trait CacheStorage extends js.Object {
def `match`(request: RequestInfo,
options: CacheQueryOptions = js.native): js.Promise[js.Any] = js.native

def has(cacheName: String): js.Promise[Boolean] = js.native

def open(cacheName: String): js.Promise[Cache] = js.native

def delete(cacheName: String): js.Promise[Boolean] = js.native

def keys(): js.Promise[js.Array[String]] = js.native
}

/**
* See [[https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/#cache ¶5.4 cache]]
* of ServiceWorker whatwg spec.
*/
@js.native
@JSGlobal
abstract class Cache extends js.Object {
def `match`(request: RequestInfo,
options: js.UndefOr[
CacheQueryOptions] = js.native): js.Promise[js.UndefOr[Response]] = js.native

def matchAll(request: RequestInfo = js.native,
options: js.UndefOr[
CacheQueryOptions] = js.native): js.Promise[js.Array[Response]] = js.native

def add(request: RequestInfo): js.Promise[Unit] = js.native

def addAll(requests: js.Array[RequestInfo]): js.Promise[Unit] = js.native

def put(request: RequestInfo,
response: Response): js.Promise[Unit] = js.native

def delete(request: RequestInfo,
options: js.UndefOr[
CacheQueryOptions] = js.native): js.Promise[Boolean] = js.native

def keys(request: js.UndefOr[RequestInfo] = js.native,
options: js.UndefOr[
CacheQueryOptions] = js.native): js.Promise[js.Array[Request]]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import scala.scalajs.js.|
import org.scalajs.dom.experimental.{
Notification, NotificationOptions, Request, RequestInfo, Response, Sequence
}
import org.scalajs.dom.raw.{WorkerGlobalScope, ErrorEvent}
import org.scalajs.dom.experimental.cachestorage._
import org.scalajs.dom.raw.{ErrorEvent, EventInit, WorkerGlobalScope}
import org.scalajs.dom.webgl.RenderingContext
import org.scalajs.dom.{Event, EventTarget, MessageEvent, MessagePort}
import org.scalajs.dom.raw.EventInit

@js.native
sealed trait FrameType extends js.Any
Expand Down Expand Up @@ -608,70 +608,6 @@ trait Clients extends js.Object {
def claim(): js.Promise[Unit] = js.native
}

/**
* See [[https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/#cache ¶5.4 cache]]
* of ServiceWorker whatwg spec.
*/
@js.native
@JSGlobal
abstract class Cache extends js.Object {
def `match`(request: RequestInfo,
options: js.UndefOr[
CacheQueryOptions] = js.native): js.Promise[js.UndefOr[Response]] = js.native

def matchAll(request: RequestInfo = js.native,
options: js.UndefOr[
CacheQueryOptions] = js.native): js.Promise[js.Array[Response]] = js.native

def add(request: RequestInfo): js.Promise[Unit] = js.native

def addAll(requests: js.Array[RequestInfo]): js.Promise[Unit] = js.native

def put(request: RequestInfo,
response: Response): js.Promise[Unit] = js.native

def delete(request: RequestInfo,
options: js.UndefOr[
CacheQueryOptions] = js.native): js.Promise[Boolean] = js.native

def keys(request: js.UndefOr[RequestInfo] = js.native,
options: js.UndefOr[
CacheQueryOptions] = js.native): js.Promise[js.Array[Request]]
}

/**
* See [[https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/#cache ¶5.4 cache]]
* of ServiceWorker whatwg spec.
*/
@js.native
trait CacheQueryOptions extends js.Object {
var ignoreSearch: Boolean = js.native // false

var ignoreMethod: Boolean = js.native // false

var ignoreVary: Boolean = js.native //false

var cacheName: String = js.native
}

/**
* See [[https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/#cache-storage ¶5.5 cache]]
* of ServiceWorker whatwg spec.
*/
@js.native
trait CacheStorage extends js.Object {
def `match`(request: RequestInfo,
options: CacheQueryOptions = js.native): js.Promise[js.Any] = js.native

def has(cacheName: String): js.Promise[Boolean] = js.native

def open(cacheName: String): js.Promise[Cache] = js.native

def delete(cacheName: String): js.Promise[Boolean] = js.native

def keys(): js.Promise[js.Array[String]] = js.native
}

/**
* The ServiceWorkerGlobalScope interface of the ServiceWorker API represents
* the global execution context of a service worker.
Expand All @@ -694,13 +630,6 @@ trait CacheStorage extends js.Object {
@js.native
trait ServiceWorkerGlobalScope extends WorkerGlobalScope {

/**
* Returns the CacheStorage object associated with the service worker.
*
* MDN
*/
override def caches: CacheStorage = js.native

/**
* Returns the Clients object associated with the service worker.
*
Expand Down Expand Up @@ -769,3 +698,32 @@ trait ServiceWorkerGlobalScope extends WorkerGlobalScope {
object ServiceWorkerGlobalScope extends js.Object {
def self: ServiceWorkerGlobalScope = js.native
}

/**
* See [[https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/#cache ¶5.4 cache]]
* of ServiceWorker whatwg spec.
*/
@deprecated("Use org.scalajs.dom.experimental.cachestorage.Cache", "1.2.0")
@js.native
@JSGlobal
abstract class Cache extends org.scalajs.dom.experimental.cachestorage.Cache

/**
* See [[https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/#cache ¶5.4 cache]]
* of ServiceWorker whatwg spec.
*/
@deprecated("Use org.scalajs.dom.experimental.cachestorage.CacheQueryOptions",
"1.2.0")
@js.native
trait CacheQueryOptions
extends org.scalajs.dom.experimental.cachestorage.CacheQueryOptions

/**
* See [[https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/#cache-storage ¶5.5 cache]]
* of ServiceWorker whatwg spec.
*/
@deprecated("Use org.scalajs.dom.experimental.cachestorage.CacheStorage",
"1.2.0")
@js.native
trait CacheStorage
extends org.scalajs.dom.experimental.cachestorage.CacheStorage
5 changes: 4 additions & 1 deletion src/main/scala/org/scalajs/dom/idb.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ object idb {
@inline def Cursor = raw.IDBCursor
type CursorWithValue = raw.IDBCursorWithValue
type Database = raw.IDBDatabase
type Environment = raw.IDBEnvironment
type Factory = raw.IDBFactory
type Index = raw.IDBIndex
type KeyRange = raw.IDBKeyRange
Expand All @@ -19,4 +18,8 @@ object idb {
type Transaction = raw.IDBTransaction
@inline def Transaction = raw.IDBTransaction
type VersionChangeEvent = raw.IDBVersionChangeEvent
@deprecated(
"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",
"1.2.0")
type Environment = raw.IDBEnvironment
}
Loading