diff --git a/rescript.json b/rescript.json index c803cd98..70551bf0 100644 --- a/rescript.json +++ b/rescript.json @@ -33,6 +33,7 @@ "Canvas" ], "WebAPI.Storage": ["WebAPI.Fetch", "Storage"], + "WebAPI.Workers": ["WebAPI.Messaging", "WebAPI.Storage", "Workers"], "WebAPI.File": ["WebAPI.Event", "File"], "WebAPI.URL": ["WebAPI.DOM", "URL"], "WebAPI.Fetch": ["WebAPI.Event", "WebAPI.File", "WebAPI.URL", "Fetch"], @@ -442,16 +443,20 @@ ] }, { - "dir": "src/ServiceWorker", + "dir": "src/workers", "subdirs": true, - "feature": "WebAPI.ServiceWorker", + "feature": "Workers", "public": [ "Clients", "NavigationPreloadManager", "ServiceWorker", "ServiceWorkerContainer", "ServiceWorkerRegistration", - "ServiceWorkerScope" + "ServiceWorkerScope", + "SharedWorker", + "SharedWorkerScope", + "Worker", + "WorkerLocation" ] }, { @@ -547,16 +552,6 @@ "SubtleCrypto" ] }, - { - "dir": "src/WebWorkers", - "subdirs": true, - "feature": "WebAPI.WebWorkers", - "public": [ - "SharedWorker", - "SharedWorkerScope", - "Worker" - ] - }, { "dir": "tests", "subdirs": true, diff --git a/src/ServiceWorker/Clients.res b/src/workers/Clients.res similarity index 100% rename from src/ServiceWorker/Clients.res rename to src/workers/Clients.res diff --git a/src/ServiceWorker/NavigationPreloadManager.res b/src/workers/NavigationPreloadManager.res similarity index 100% rename from src/ServiceWorker/NavigationPreloadManager.res rename to src/workers/NavigationPreloadManager.res diff --git a/src/ServiceWorker/ServiceWorker.res b/src/workers/ServiceWorker.res similarity index 100% rename from src/ServiceWorker/ServiceWorker.res rename to src/workers/ServiceWorker.res diff --git a/src/ServiceWorker/ServiceWorkerContainer.res b/src/workers/ServiceWorkerContainer.res similarity index 100% rename from src/ServiceWorker/ServiceWorkerContainer.res rename to src/workers/ServiceWorkerContainer.res diff --git a/src/ServiceWorker/ServiceWorkerRegistration.res b/src/workers/ServiceWorkerRegistration.res similarity index 100% rename from src/ServiceWorker/ServiceWorkerRegistration.res rename to src/workers/ServiceWorkerRegistration.res diff --git a/src/ServiceWorker/ServiceWorkerScope.res b/src/workers/ServiceWorkerScope.res similarity index 100% rename from src/ServiceWorker/ServiceWorkerScope.res rename to src/workers/ServiceWorkerScope.res diff --git a/src/ServiceWorker/ServiceWorkerTypes.res b/src/workers/ServiceWorkerTypes.res similarity index 100% rename from src/ServiceWorker/ServiceWorkerTypes.res rename to src/workers/ServiceWorkerTypes.res diff --git a/src/WebWorkers/SharedWorker.res b/src/workers/SharedWorker.res similarity index 100% rename from src/WebWorkers/SharedWorker.res rename to src/workers/SharedWorker.res diff --git a/src/WebWorkers/SharedWorkerScope.res b/src/workers/SharedWorkerScope.res similarity index 100% rename from src/WebWorkers/SharedWorkerScope.res rename to src/workers/SharedWorkerScope.res diff --git a/src/WebWorkers/Worker.res b/src/workers/Worker.res similarity index 83% rename from src/WebWorkers/Worker.res rename to src/workers/Worker.res index 2e78d370..32bc9941 100644 --- a/src/WebWorkers/Worker.res +++ b/src/workers/Worker.res @@ -7,6 +7,13 @@ module Impl = ( external current: T.t = "self" + /** + The absolute URL of the script executed by this worker. + [See WorkerGlobalScope.location on MDN](https://developer.mozilla.org/docs/Web/API/WorkerGlobalScope/location) + */ + @get + external location: T.t => WorkerLocation.t = "location" + /** `fetch(workerGlobalScope, string, init)` diff --git a/src/workers/WorkerLocation.res b/src/workers/WorkerLocation.res new file mode 100644 index 00000000..1393468c --- /dev/null +++ b/src/workers/WorkerLocation.res @@ -0,0 +1,18 @@ +/** +The absolute URL of the script executed by a worker. +[See WorkerLocation on MDN](https://developer.mozilla.org/docs/Web/API/WorkerLocation) +*/ +type t = private { + href: string, + origin: string, + protocol: string, + host: string, + hostname: string, + port: string, + pathname: string, + search: string, + hash: string, +} + +@send +external toString: t => string = "toString" diff --git a/tests/WebWorkersAPI/SharedWorkerScope__test.res b/tests/WebWorkersAPI/SharedWorkerScope__test.res index 52961533..4230e5c6 100644 --- a/tests/WebWorkersAPI/SharedWorkerScope__test.res +++ b/tests/WebWorkersAPI/SharedWorkerScope__test.res @@ -1,3 +1,9 @@ let self = SharedWorkerScope.current self->SharedWorkerScope.close + +let workerLocation = Worker.current->Worker.location +let workerHref: string = workerLocation.href + +let sharedWorkerLocation = self->SharedWorkerScope.location +let sharedWorkerHref: string = sharedWorkerLocation.href