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:
parent
a8a7848c86
commit
f070bc4b9a
5 changed files with 63 additions and 16 deletions
20
cli/tests/testdata/workers/test.ts
vendored
20
cli/tests/testdata/workers/test.ts
vendored
|
@ -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 () {
|
||||||
|
|
11
cli/tests/testdata/workers/worker_navigator.ts
vendored
Normal file
11
cli/tests/testdata/workers/worker_navigator.ts
vendored
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
onmessage = function () {
|
||||||
|
postMessage(
|
||||||
|
[
|
||||||
|
typeof navigator.language,
|
||||||
|
typeof navigator.languages,
|
||||||
|
typeof navigator.userAgent,
|
||||||
|
typeof navigator.hardwareConcurrency,
|
||||||
|
].join(", "),
|
||||||
|
);
|
||||||
|
close();
|
||||||
|
};
|
|
@ -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];
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue