summaryrefslogtreecommitdiff
path: root/runtime/js
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2021-03-08 12:27:49 +0000
committerGitHub <noreply@github.com>2021-03-08 13:27:49 +0100
commit0bc488c85c4bbc5b900cf5ff7b09227345b87763 (patch)
tree315a6bded05a4ab5d9946f837e4ec98162420089 /runtime/js
parentceeebe46eeb548ab3048f244a942973d9e8a2f41 (diff)
fix(runtime/js): add navigator interface objects (#9685)
Diffstat (limited to 'runtime/js')
-rw-r--r--runtime/js/99_main.js69
1 files changed, 59 insertions, 10 deletions
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js
index 811412049..2c4decd32 100644
--- a/runtime/js/99_main.js
+++ b/runtime/js/99_main.js
@@ -35,6 +35,7 @@ delete Object.prototype.__proto__;
const denoNs = window.__bootstrap.denoNs;
const denoNsUnstable = window.__bootstrap.denoNsUnstable;
const errors = window.__bootstrap.errors.errors;
+ const webidl = window.__bootstrap.webidl;
const { defineEventHandler } = window.__bootstrap.webUtil;
let windowIsClosing = false;
@@ -203,6 +204,52 @@ delete Object.prototype.__proto__;
);
}
+ class Navigator {
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${inspect({})}`;
+ }
+ }
+
+ const navigator = webidl.createBranded(Navigator);
+
+ Object.defineProperties(Navigator.prototype, {
+ gpu: {
+ configurable: true,
+ enumerable: true,
+ get() {
+ webidl.assertBranded(this, Navigator);
+ return webgpu.gpu;
+ },
+ },
+ });
+
+ class WorkerNavigator {
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${inspect({})}`;
+ }
+ }
+
+ const workerNavigator = webidl.createBranded(WorkerNavigator);
+
+ Object.defineProperties(WorkerNavigator.prototype, {
+ gpu: {
+ configurable: true,
+ enumerable: true,
+ get() {
+ webidl.assertBranded(this, WorkerNavigator);
+ return webgpu.gpu;
+ },
+ },
+ });
+
// https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope
const windowOrWorkerGlobalScope = {
Blob: util.nonEnumerable(file.Blob),
@@ -293,17 +340,18 @@ delete Object.prototype.__proto__;
// structure, it might be worth it to define a helper in `util`
windowOrWorkerGlobalScope.console.enumerable = false;
- const windowNavigatorProperties = {
- gpu: webgpu.gpu,
- };
-
const mainRuntimeGlobalProperties = {
Location: location.locationConstructorDescriptor,
location: location.locationDescriptor,
Window: globalInterfaces.windowConstructorDescriptor,
window: util.readOnly(globalThis),
self: util.readOnly(globalThis),
- navigator: util.readOnly(windowNavigatorProperties),
+ Navigator: util.nonEnumerable(Navigator),
+ navigator: {
+ configurable: true,
+ enumerable: true,
+ get: () => navigator,
+ },
// TODO(bartlomieju): from MDN docs (https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope)
// it seems those two properties should be available to workers as well
onload: util.writable(null),
@@ -315,17 +363,18 @@ delete Object.prototype.__proto__;
prompt: util.writable(prompt.prompt),
};
- const workerNavigatorProperties = {
- gpu: webgpu.gpu,
- };
-
const workerRuntimeGlobalProperties = {
WorkerLocation: location.workerLocationConstructorDescriptor,
location: location.workerLocationDescriptor,
WorkerGlobalScope: globalInterfaces.workerGlobalScopeConstructorDescriptor,
DedicatedWorkerGlobalScope:
globalInterfaces.dedicatedWorkerGlobalScopeConstructorDescriptor,
- navigator: util.readOnly(workerNavigatorProperties),
+ WorkerNavigator: util.nonEnumerable(WorkerNavigator),
+ navigator: {
+ configurable: true,
+ enumerable: true,
+ get: () => workerNavigator,
+ },
self: util.readOnly(globalThis),
onmessage: util.writable(onmessage),
onerror: util.writable(onerror),