diff --git a/api-reports/2_12.txt b/api-reports/2_12.txt index 9be38550d..fc20a3f5d 100644 --- a/api-reports/2_12.txt +++ b/api-reports/2_12.txt @@ -24057,6 +24057,7 @@ SharedWorker[JC] var onerror: js.Function1[ErrorEvent, _] SharedWorker[JC] def port: MessagePort SharedWorker[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit SharedWorker[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit +SharedWorker[SO] SharedWorkerGlobalScope[JO] def self: SharedWorkerGlobalScope SharedWorkerGlobalScope[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit SharedWorkerGlobalScope[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit @@ -25351,6 +25352,12 @@ WorkerNavigator[JT] def onLine: Boolean WorkerNavigator[JT] def platform: String WorkerNavigator[JT] def sendBeacon(url: String, data: BodyInit?): Boolean (@deprecated in 2.0.0) WorkerNavigator[JT] def userAgent: String +WorkerOptions[JT] var credentials: js.UndefOr[RequestCredentials] +WorkerOptions[JT] var name: js.UndefOr[String] +WorkerOptions[JT] var `type`: js.UndefOr[WorkerType] +WorkerType[JT] +WorkerType[SO] val classic: WorkerType +WorkerType[SO] val module: WorkerType WriteableState[JT] WriteableState[SO] val closed: WriteableState WriteableState[SO] val closing: WriteableState diff --git a/api-reports/2_13.txt b/api-reports/2_13.txt index 9be38550d..fc20a3f5d 100644 --- a/api-reports/2_13.txt +++ b/api-reports/2_13.txt @@ -24057,6 +24057,7 @@ SharedWorker[JC] var onerror: js.Function1[ErrorEvent, _] SharedWorker[JC] def port: MessagePort SharedWorker[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit SharedWorker[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit +SharedWorker[SO] SharedWorkerGlobalScope[JO] def self: SharedWorkerGlobalScope SharedWorkerGlobalScope[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit SharedWorkerGlobalScope[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit @@ -25351,6 +25352,12 @@ WorkerNavigator[JT] def onLine: Boolean WorkerNavigator[JT] def platform: String WorkerNavigator[JT] def sendBeacon(url: String, data: BodyInit?): Boolean (@deprecated in 2.0.0) WorkerNavigator[JT] def userAgent: String +WorkerOptions[JT] var credentials: js.UndefOr[RequestCredentials] +WorkerOptions[JT] var name: js.UndefOr[String] +WorkerOptions[JT] var `type`: js.UndefOr[WorkerType] +WorkerType[JT] +WorkerType[SO] val classic: WorkerType +WorkerType[SO] val module: WorkerType WriteableState[JT] WriteableState[SO] val closed: WriteableState WriteableState[SO] val closing: WriteableState diff --git a/dom/src/main/scala-2/org/scalajs/dom/WorkerType.scala b/dom/src/main/scala-2/org/scalajs/dom/WorkerType.scala new file mode 100644 index 000000000..3fef2275e --- /dev/null +++ b/dom/src/main/scala-2/org/scalajs/dom/WorkerType.scala @@ -0,0 +1,11 @@ +package org.scalajs.dom + +import scala.scalajs.js + +@js.native +sealed trait WorkerType extends js.Any + +object WorkerType { + val classic: WorkerType = "classic".asInstanceOf[WorkerType] + val module: WorkerType = "module".asInstanceOf[WorkerType] +} diff --git a/dom/src/main/scala-3/org/scalajs/dom/WorkerType.scala b/dom/src/main/scala-3/org/scalajs/dom/WorkerType.scala new file mode 100644 index 000000000..8a32bec38 --- /dev/null +++ b/dom/src/main/scala-3/org/scalajs/dom/WorkerType.scala @@ -0,0 +1,10 @@ +package org.scalajs.dom + +import scala.scalajs.js + +opaque type WorkerType <: String = String + +object WorkerType { + val classic: WorkerType = "classic" + val module: WorkerType = "module" +} diff --git a/dom/src/main/scala/org/scalajs/dom/SharedWorker.scala b/dom/src/main/scala/org/scalajs/dom/SharedWorker.scala index 1fd081f51..257252274 100644 --- a/dom/src/main/scala/org/scalajs/dom/SharedWorker.scala +++ b/dom/src/main/scala/org/scalajs/dom/SharedWorker.scala @@ -15,18 +15,24 @@ import scala.scalajs.js.annotation._ * thrown. * @example * {{{var myWorker = new SharedWorker("aURL", name);}}} - * @param stringUrl + * @param scriptURL * A DOMString representing the URL of the script the worker will execute. It must obey the same-origin policy. - * @param name - * An optional argument that specifies an existing SharedWorkerGlobalScope.name — if this is specified then that - * SharedWorkerGlobalScope will be used as the scope for this shared worker. + * @param options + * A DOMString specifying an identifying name for the SharedWorkerGlobalScope representing the scope of the worker, + * which is mainly useful for debugging purposes. Or, an object containing option properties that can set when + * creating the object instance. */ @js.native @JSGlobal -class SharedWorker(stringUrl: String, name: js.UndefOr[String] = js.native) extends AbstractWorker { +class SharedWorker(scriptURL: String) extends AbstractWorker { + def this(scriptURL: String, name: String) = this(scriptURL) + + def this(scriptURL: String, options: WorkerOptions) = this(scriptURL) /** The port property of the SharedWorker interface returns a [[MessagePort]] object used to communicate and control * the shared worker. */ def port: MessagePort = js.native } + +object SharedWorker diff --git a/dom/src/main/scala/org/scalajs/dom/Worker.scala b/dom/src/main/scala/org/scalajs/dom/Worker.scala index 7cb7ee7c3..a38e99eeb 100644 --- a/dom/src/main/scala/org/scalajs/dom/Worker.scala +++ b/dom/src/main/scala/org/scalajs/dom/Worker.scala @@ -10,10 +10,17 @@ import scala.scalajs.js.annotation._ * Of note is the fact that workers may in turn spawn new workers as long as those workers are hosted within the same * origin as the parent page. In addition, workers may use XMLHttpRequest for network I/O, with the exception that the * responseXML and channel attributes on XMLHttpRequest always return null. + * + * @param scriptURL + * A USVString representing the URL of the script the worker will execute. It must obey the same-origin policy. + * @param options + * An object containing option properties that can be set when creating the object instance. */ @js.native @JSGlobal -class Worker(stringUrl: String) extends AbstractWorker { +class Worker(scriptURL: String, options: WorkerOptions) extends AbstractWorker { + + def this(scriptURL: String) = this(scriptURL, js.native) /** The Worker.onmessage property represents an EventHandler, that is a function to be called when the message event * occurs. These events are of type MessageEvent and will be called when the worker calls its own postMessage() diff --git a/dom/src/main/scala/org/scalajs/dom/WorkerOptions.scala b/dom/src/main/scala/org/scalajs/dom/WorkerOptions.scala new file mode 100644 index 000000000..986b3e2b8 --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/WorkerOptions.scala @@ -0,0 +1,9 @@ +package org.scalajs.dom + +import scala.scalajs.js + +trait WorkerOptions extends js.Object { + var credentials: js.UndefOr[RequestCredentials] = js.undefined + var name: js.UndefOr[String] = js.undefined + var `type`: js.UndefOr[WorkerType] = js.undefined +}