Skip to content

Commit 59b5b89

Browse files
authored
Merge pull request #691 from scala-js/feature/workeroptions
Add `WorkerOptions` to [Shared]Worker constructors
2 parents 3fbde00 + 101ea96 commit 59b5b89

File tree

7 files changed

+63
-6
lines changed

7 files changed

+63
-6
lines changed

api-reports/2_12.txt

+7
Original file line numberDiff line numberDiff line change
@@ -24057,6 +24057,7 @@ SharedWorker[JC] var onerror: js.Function1[ErrorEvent, _]
2405724057
SharedWorker[JC] def port: MessagePort
2405824058
SharedWorker[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
2405924059
SharedWorker[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
24060+
SharedWorker[SO]
2406024061
SharedWorkerGlobalScope[JO] def self: SharedWorkerGlobalScope
2406124062
SharedWorkerGlobalScope[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
2406224063
SharedWorkerGlobalScope[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
@@ -25351,6 +25352,12 @@ WorkerNavigator[JT] def onLine: Boolean
2535125352
WorkerNavigator[JT] def platform: String
2535225353
WorkerNavigator[JT] def sendBeacon(url: String, data: BodyInit?): Boolean (@deprecated in 2.0.0)
2535325354
WorkerNavigator[JT] def userAgent: String
25355+
WorkerOptions[JT] var credentials: js.UndefOr[RequestCredentials]
25356+
WorkerOptions[JT] var name: js.UndefOr[String]
25357+
WorkerOptions[JT] var `type`: js.UndefOr[WorkerType]
25358+
WorkerType[JT]
25359+
WorkerType[SO] val classic: WorkerType
25360+
WorkerType[SO] val module: WorkerType
2535425361
WriteableState[JT]
2535525362
WriteableState[SO] val closed: WriteableState
2535625363
WriteableState[SO] val closing: WriteableState

api-reports/2_13.txt

+7
Original file line numberDiff line numberDiff line change
@@ -24057,6 +24057,7 @@ SharedWorker[JC] var onerror: js.Function1[ErrorEvent, _]
2405724057
SharedWorker[JC] def port: MessagePort
2405824058
SharedWorker[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
2405924059
SharedWorker[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
24060+
SharedWorker[SO]
2406024061
SharedWorkerGlobalScope[JO] def self: SharedWorkerGlobalScope
2406124062
SharedWorkerGlobalScope[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
2406224063
SharedWorkerGlobalScope[JT] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
@@ -25351,6 +25352,12 @@ WorkerNavigator[JT] def onLine: Boolean
2535125352
WorkerNavigator[JT] def platform: String
2535225353
WorkerNavigator[JT] def sendBeacon(url: String, data: BodyInit?): Boolean (@deprecated in 2.0.0)
2535325354
WorkerNavigator[JT] def userAgent: String
25355+
WorkerOptions[JT] var credentials: js.UndefOr[RequestCredentials]
25356+
WorkerOptions[JT] var name: js.UndefOr[String]
25357+
WorkerOptions[JT] var `type`: js.UndefOr[WorkerType]
25358+
WorkerType[JT]
25359+
WorkerType[SO] val classic: WorkerType
25360+
WorkerType[SO] val module: WorkerType
2535425361
WriteableState[JT]
2535525362
WriteableState[SO] val closed: WriteableState
2535625363
WriteableState[SO] val closing: WriteableState
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
@js.native
6+
sealed trait WorkerType extends js.Any
7+
8+
object WorkerType {
9+
val classic: WorkerType = "classic".asInstanceOf[WorkerType]
10+
val module: WorkerType = "module".asInstanceOf[WorkerType]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
opaque type WorkerType <: String = String
6+
7+
object WorkerType {
8+
val classic: WorkerType = "classic"
9+
val module: WorkerType = "module"
10+
}

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

+11-5
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,24 @@ import scala.scalajs.js.annotation._
1515
* thrown.
1616
* @example
1717
* {{{var myWorker = new SharedWorker("aURL", name);}}}
18-
* @param stringUrl
18+
* @param scriptURL
1919
* A DOMString representing the URL of the script the worker will execute. It must obey the same-origin policy.
20-
* @param name
21-
* An optional argument that specifies an existing SharedWorkerGlobalScope.name — if this is specified then that
22-
* SharedWorkerGlobalScope will be used as the scope for this shared worker.
20+
* @param options
21+
* A DOMString specifying an identifying name for the SharedWorkerGlobalScope representing the scope of the worker,
22+
* which is mainly useful for debugging purposes. Or, an object containing option properties that can set when
23+
* creating the object instance.
2324
*/
2425
@js.native
2526
@JSGlobal
26-
class SharedWorker(stringUrl: String, name: js.UndefOr[String] = js.native) extends AbstractWorker {
27+
class SharedWorker(scriptURL: String) extends AbstractWorker {
28+
def this(scriptURL: String, name: String) = this(scriptURL)
29+
30+
def this(scriptURL: String, options: WorkerOptions) = this(scriptURL)
2731

2832
/** The port property of the SharedWorker interface returns a [[MessagePort]] object used to communicate and control
2933
* the shared worker.
3034
*/
3135
def port: MessagePort = js.native
3236
}
37+
38+
object SharedWorker

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@ import scala.scalajs.js.annotation._
1010
* Of note is the fact that workers may in turn spawn new workers as long as those workers are hosted within the same
1111
* origin as the parent page. In addition, workers may use XMLHttpRequest for network I/O, with the exception that the
1212
* responseXML and channel attributes on XMLHttpRequest always return null.
13+
*
14+
* @param scriptURL
15+
* A USVString representing the URL of the script the worker will execute. It must obey the same-origin policy.
16+
* @param options
17+
* An object containing option properties that can be set when creating the object instance.
1318
*/
1419
@js.native
1520
@JSGlobal
16-
class Worker(stringUrl: String) extends AbstractWorker {
21+
class Worker(scriptURL: String, options: WorkerOptions) extends AbstractWorker {
22+
23+
def this(scriptURL: String) = this(scriptURL, js.native)
1724

1825
/** The Worker.onmessage property represents an EventHandler, that is a function to be called when the message event
1926
* occurs. These events are of type MessageEvent and will be called when the worker calls its own postMessage()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
trait WorkerOptions extends js.Object {
6+
var credentials: js.UndefOr[RequestCredentials] = js.undefined
7+
var name: js.UndefOr[String] = js.undefined
8+
var `type`: js.UndefOr[WorkerType] = js.undefined
9+
}

0 commit comments

Comments
 (0)