mirror of
https://github.com/daijro/camoufox.git
synced 2026-11-19 00:07:28 +00:00
The last bit of these differs between glibc (or fdlibm) and the Windows CRT, so one call told a page that a build claiming Windows ran on Linux: against stock 152.0.4 on Windows, sin differed on 22, cos on 26 and tan on 30 of 1,670 inputs, pow on 45 of 1,410. windows-crt-math.patch adds javascript.options.use_ucrt_math, which routes them to ports of ucrtbase.dll's FMA3 code path (browser/additions/js/src/builtin/UcrtMath*.c), keeping SpiderMonkey's own pow fast paths. On 156 the pow hook sits in pow_libm_or_fdlibm, the one place both callers already reach the platform pow. It is built only for 64-bit non-Windows targets, without FP contraction. The launcher turns it on for Windows identities on a non-Windows host, where upstream did nothing; the TypeScript launcher does the same. browser/tests/ucrt-math checks the C alone against ucrtbase.dll on ~127,000 results in the static job. The windows-crt-math guard checks the browser against stock Windows Firefox cold, JIT-hot and constant folded, with a pref-off control that must differ; a missing result counts as a difference. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
59 lines
2.1 KiB
Python
59 lines
2.1 KiB
Python
"""A Windows identity on another host behaves as stock Windows Firefox does.
|
|
|
|
Each value the launcher sets here was measured on stock Firefox on Windows
|
|
against this build on a Linux host claiming Windows. On a Windows host the
|
|
build already behaves that way, and a macOS or Linux identity is left as it is.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from camoufox import utils
|
|
|
|
from test_launch_environment import isolated_launch_dependencies # noqa: F401
|
|
|
|
WIN_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:156.0) Gecko/20100101 Firefox/156.0"
|
|
MAC_UA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:156.0) Gecko/20100101 Firefox/156.0"
|
|
LIN_UA = "Mozilla/5.0 (X11; Linux x86_64; rv:156.0) Gecko/20100101 Firefox/156.0"
|
|
|
|
|
|
@pytest.fixture
|
|
def launch(monkeypatch, isolated_launch_dependencies): # noqa: F811
|
|
"""launch_options on a Linux host; returns (config, prefs)."""
|
|
monkeypatch.setattr(utils, "_host_os_key", lambda: "lin")
|
|
seen = {}
|
|
|
|
def capture(config, *args, **kwargs):
|
|
seen["config"] = dict(config)
|
|
return {}
|
|
|
|
monkeypatch.setattr(utils, "get_env_vars", capture)
|
|
|
|
def run(ua, **kwargs):
|
|
config = {"navigator.userAgent": ua, **kwargs.pop("config", {})}
|
|
prefs = utils.launch_options(config=config, i_know_what_im_doing=True, **kwargs)["firefox_user_prefs"]
|
|
return seen["config"], prefs
|
|
|
|
return run
|
|
|
|
|
|
def test_windows_identity_gets_windows_crt_math(launch):
|
|
_, prefs = launch(WIN_UA)
|
|
assert prefs["javascript.options.use_ucrt_math"] is True
|
|
|
|
|
|
@pytest.mark.parametrize("ua", [MAC_UA, LIN_UA])
|
|
def test_other_identities_keep_host_math(launch, ua):
|
|
_, prefs = launch(ua)
|
|
assert "javascript.options.use_ucrt_math" not in prefs
|
|
|
|
|
|
def test_windows_identity_on_windows_host_is_left_alone(launch, monkeypatch):
|
|
monkeypatch.setattr(utils, "_host_os_key", lambda: "win")
|
|
_, prefs = launch(WIN_UA)
|
|
assert "javascript.options.use_ucrt_math" not in prefs
|
|
|
|
|
|
def test_caller_values_win(launch):
|
|
_, prefs = launch(WIN_UA, firefox_user_prefs={"javascript.options.use_ucrt_math": False})
|
|
assert prefs["javascript.options.use_ucrt_math"] is False
|