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({
name: "worker fetch API",
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);
return numCpus;
},
language: {
configurable: true,
enumerable: true,
get() {
webidl.assertBranded(this, WorkerNavigatorPrototype);
return language;
},
},
userAgent: {
configurable: true,
enumerable: true,
get() {
webidl.assertBranded(this, WorkerNavigatorPrototype);
return userAgent;
},
languages: {
configurable: true,
enumerable: true,
get() {
webidl.assertBranded(this, WorkerNavigatorPrototype);
return [language];
},
},
language: {
configurable: true,
enumerable: true,
get() {
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,
11: target,
12: v8Version,
// 13: userAgent,
13: userAgent,
// 14: inspectFlag,
15: enableTestingFeaturesFlag,
} = runtimeOptions;
@ -633,6 +633,7 @@ function bootstrapWorkerRuntime(
location.setLocationHref(location_);
setNumCpus(cpuCount);
setUserAgent(userAgent);
setLanguage(locale);
globalThis.pollForMessages = pollForMessages;

View file

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