diff options
author | 2023-09-10 20:40:46 -0800 | |
---|---|---|
committer | 2023-09-10 21:40:46 -0700 | |
commit | edea4f095a3bebf54f986c0fa038482316f4cde8 (patch) | |
tree | 922c4d1fb2b2abf1831a181b7e9571847aa654dc | |
parent | 07c88435e0aede1d58bf462ef56270ca43d4e961 (diff) | |
download | bun-edea4f095a3bebf54f986c0fa038482316f4cde8.tar.gz bun-edea4f095a3bebf54f986c0fa038482316f4cde8.tar.zst bun-edea4f095a3bebf54f986c0fa038482316f4cde8.zip |
Fixes #4588 (#4804)
* Fixes #4588
* typo
* fixup
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
-rw-r--r-- | src/bun.js/bindings/ZigGlobalObject.cpp | 12 | ||||
-rw-r--r-- | test/js/web/web-globals.test.js | 7 |
2 files changed, 18 insertions, 1 deletions
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index 6398fb7a0..cdc4adb1b 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -3075,11 +3075,21 @@ void GlobalObject::finishCreation(VM& vm) JSC::Identifier userAgentIdentifier = JSC::Identifier::fromString(init.vm, "userAgent"_s); JSC::Identifier hardwareConcurrencyIdentifier = JSC::Identifier::fromString(init.vm, "hardwareConcurrency"_s); - JSC::JSObject* obj = JSC::constructEmptyObject(init.owner, init.owner->objectPrototype(), 3); + JSC::JSObject* obj = JSC::constructEmptyObject(init.owner, init.owner->objectPrototype(), 4); obj->putDirect(init.vm, userAgentIdentifier, JSC::jsString(init.vm, str)); obj->putDirect(init.vm, init.vm.propertyNames->toStringTagSymbol, jsNontrivialString(init.vm, "Navigator"_s), JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::ReadOnly); +// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform +// https://github.com/oven-sh/bun/issues/4588 +#if OS(DARWIN) + obj->putDirect(init.vm, JSC::Identifier::fromString(init.vm, "platform"_s), JSC::jsString(init.vm, String("MacIntel"_s))); +#elif OS(WINDOWS) + obj->putDirect(init.vm, JSC::Identifier::fromString(init.vm, "platform"_s), JSC::jsString(init.vm, String("Win32"_s))); +#elif OS(LINUX) + obj->putDirect(init.vm, JSC::Identifier::fromString(init.vm, "platform"_s), JSC::jsString(init.vm, String("Linux x86_64"_s))); +#endif + obj->putDirect(init.vm, hardwareConcurrencyIdentifier, JSC::jsNumber(cpuCount)); init.set( obj); diff --git a/test/js/web/web-globals.test.js b/test/js/web/web-globals.test.js index 9b4c86006..1a4d7b1d1 100644 --- a/test/js/web/web-globals.test.js +++ b/test/js/web/web-globals.test.js @@ -224,4 +224,11 @@ test("navigator", () => { const userAgent = `Bun/${version}`; expect(navigator.hardwareConcurrency > 0).toBe(true); expect(navigator.userAgent).toBe(userAgent); + if (process.platform === "darwin") { + expect(navigator.platform).toBe("MacIntel"); + } else if (process.platform === "win32") { + expect(navigator.platform).toBe("Win32"); + } else if (process.platform === "linux") { + expect(navigator.platform).toBe("Linux x86_64"); + } }); |