1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

fix(runtime): navigator.userAgent in web worker (#20129)

Fixes https://github.com/denoland/deno/issues/20079

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
await-ovo 2023-08-15 23:04:36 +08:00 committed by Divy Srivastava
parent a8a7848c86
commit f070bc4b9a
5 changed files with 63 additions and 16 deletions

View file

@ -119,6 +119,26 @@ Deno.test({
}, },
}); });
Deno.test({
name: "worker navigator",
fn: async function () {
const workerOptions: WorkerOptions = { type: "module" };
const w = new Worker(
import.meta.resolve("./worker_navigator.ts"),
workerOptions,
);
const promise = deferred();
w.onmessage = (e) => {
promise.resolve(e.data);
};
w.postMessage("Hello, world!");
assertEquals(await promise, "string, object, string, number");
w.terminate();
},
});
Deno.test({ Deno.test({
name: "worker fetch API", name: "worker fetch API",
fn: async function () { fn: async function () {

View file

@ -0,0 +1,11 @@
onmessage = function () {
postMessage(
[
typeof navigator.language,
typeof navigator.languages,
typeof navigator.userAgent,
typeof navigator.hardwareConcurrency,
].join(", "),
);
close();
};

View file

@ -225,21 +225,29 @@ ObjectDefineProperties(WorkerNavigator.prototype, {
webidl.assertBranded(this, WorkerNavigatorPrototype); webidl.assertBranded(this, WorkerNavigatorPrototype);
return numCpus; return numCpus;
}, },
language: { },
configurable: true, userAgent: {
enumerable: true, configurable: true,
get() { enumerable: true,
webidl.assertBranded(this, WorkerNavigatorPrototype); get() {
return language; webidl.assertBranded(this, WorkerNavigatorPrototype);
}, return userAgent;
}, },
languages: { },
configurable: true, language: {
enumerable: true, configurable: true,
get() { enumerable: true,
webidl.assertBranded(this, WorkerNavigatorPrototype); get() {
return [language]; webidl.assertBranded(this, WorkerNavigatorPrototype);
}, return language;
},
},
languages: {
configurable: true,
enumerable: true,
get() {
webidl.assertBranded(this, WorkerNavigatorPrototype);
return [language];
}, },
}, },
}); });

View file

@ -567,7 +567,7 @@ function bootstrapWorkerRuntime(
10: pid, 10: pid,
11: target, 11: target,
12: v8Version, 12: v8Version,
// 13: userAgent, 13: userAgent,
// 14: inspectFlag, // 14: inspectFlag,
15: enableTestingFeaturesFlag, 15: enableTestingFeaturesFlag,
} = runtimeOptions; } = runtimeOptions;
@ -633,6 +633,7 @@ function bootstrapWorkerRuntime(
location.setLocationHref(location_); location.setLocationHref(location_);
setNumCpus(cpuCount); setNumCpus(cpuCount);
setUserAgent(userAgent);
setLanguage(locale); setLanguage(locale);
globalThis.pollForMessages = pollForMessages; globalThis.pollForMessages = pollForMessages;

View file

@ -6177,7 +6177,14 @@
"taintEnabled", "taintEnabled",
"oscpu" "oscpu"
], ],
"navigator.any.worker.html": false, "navigator.any.worker.html": [
"appCodeName",
"appName",
"appVersion",
"platform",
"product",
"userAgent value"
],
"per-global.window.html": false "per-global.window.html": false
} }
} }