From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../jit-test/tests/resist-fingerprinting/locale.js | 19 +++++ .../math-fdlibm-sincostan-asm.js | 56 ++++++++++++++ .../resist-fingerprinting/math-fdlibm-sincostan.js | 88 ++++++++++++++++++++++ .../tests/resist-fingerprinting/timezone.js | 33 ++++++++ 4 files changed, 196 insertions(+) create mode 100644 js/src/jit-test/tests/resist-fingerprinting/locale.js create mode 100644 js/src/jit-test/tests/resist-fingerprinting/math-fdlibm-sincostan-asm.js create mode 100644 js/src/jit-test/tests/resist-fingerprinting/math-fdlibm-sincostan.js create mode 100644 js/src/jit-test/tests/resist-fingerprinting/timezone.js (limited to 'js/src/jit-test/tests/resist-fingerprinting') diff --git a/js/src/jit-test/tests/resist-fingerprinting/locale.js b/js/src/jit-test/tests/resist-fingerprinting/locale.js new file mode 100644 index 0000000000..6c15ca88ae --- /dev/null +++ b/js/src/jit-test/tests/resist-fingerprinting/locale.js @@ -0,0 +1,19 @@ +// |jit-test| skip-if: typeof Intl === 'undefined' + +function test(locale, timeZone) { + let global = newGlobal({locale, forceUTC: true}); + + const constructors = ["Collator", "DateTimeFormat", "ListFormat", + "NumberFormat", "PluralRules", "RelativeTimeFormat"]; + for (const constructor of constructors) { + let intl = new global.Intl[constructor]; + assertEq(intl.resolvedOptions().locale, locale); + } + + const date = new global.Date(2012, 0, 10); + let tzRE = /\(([^\)]+)\)/; + assertEq(tzRE.exec(date)[1], timeZone) +} + +test("de-CH", "Koordinierte Weltzeit"); +test("en", "Coordinated Universal Time"); diff --git a/js/src/jit-test/tests/resist-fingerprinting/math-fdlibm-sincostan-asm.js b/js/src/jit-test/tests/resist-fingerprinting/math-fdlibm-sincostan-asm.js new file mode 100644 index 0000000000..e95b807117 --- /dev/null +++ b/js/src/jit-test/tests/resist-fingerprinting/math-fdlibm-sincostan-asm.js @@ -0,0 +1,56 @@ +// |jit-test| skip-if: !isAsmJSCompilationAvailable() + +load(libdir + "asm.js"); + +var g = newGlobal({alwaysUseFdlibm: true}) + +var code = (fun) => { + return `(function asm(glob) { + "use asm"; + var sq=glob.Math.${fun}; function f(d) { d=+d; return +sq(d) } return f; + })`; +} + +// Linking RFP asm.js with non-RFP Math.sin. +let asmSin = g.eval(code("sin")); +assertAsmLinkFail(asmSin, {Math: {sin: Math.sin}}); + +// Linking RFP asm.js with RFP Math.sin +const sin = asmLink(asmSin, {Math: {sin: g.Math.sin}}); +assertEq(sin(35*Math.LN2 ), -0.765996413898051); +assertEq(sin(110*Math.LOG2E), 0.9989410140273757); +assertEq(sin(7*Math.LOG10E ), 0.10135692924965616); + +// Linking non-RFP asm.js with RFP Math.sin +asmSin = eval(code("sin")) +assertAsmLinkFail(asmSin, {Math: {sin: g.Math.sin}}); + +// Linking non-RFP asm.js with non-RFP Math.sin (the "normal case") +asmLink(asmSin, {Math: {sin: Math.sin}}); + +// Testing cos +let asmCos = g.eval(code("cos")); +assertAsmLinkFail(asmCos, {Math: {cos: Math.cos}}); +const cos = asmLink(asmCos, {Math: {cos: g.Math.cos}}); +assertEq(cos(1e130 ), -0.767224894221913); +assertEq(cos(1e272 ), -0.7415825695514536); +assertEq(cos(1e284 ), 0.7086865671674247); +assertEq(cos(1e75 ), -0.7482651726250321); +assertEq(cos(57*Math.E ), -0.536911695749024); +assertEq(cos(21*Math.LN2 ), -0.4067775970251724); +assertEq(cos(51*Math.LN2 ), -0.7017203400855446); +assertEq(cos(21*Math.SQRT1_2), -0.6534063185820198); +assertEq(cos(17*Math.LOG10E ), 0.4537557425982784); +assertEq(cos(2*Math.LOG10E ), 0.6459044007438142); + +// Testing tan +let asmTan = g.eval(code("tan")); +assertAsmLinkFail(asmTan, {Math: {tan: Math.tan}}); +const tan = asmLink(asmTan, {Math: {tan: g.Math.tan}}); +assertEq(tan(1e140 ), 0.7879079967710036); +assertEq(tan(6*Math.E ), 0.6866761546452431); +assertEq(tan(6*Math.LN2 ), 1.6182817135715877); +assertEq(tan(10*Math.LOG2E ), -3.3537128705376014); +assertEq(tan(17*Math.SQRT2 ), -1.9222955461799982); +assertEq(tan(34*Math.SQRT1_2), -1.9222955461799982); +assertEq(tan(10*Math.LOG10E ), 2.5824856130712432); diff --git a/js/src/jit-test/tests/resist-fingerprinting/math-fdlibm-sincostan.js b/js/src/jit-test/tests/resist-fingerprinting/math-fdlibm-sincostan.js new file mode 100644 index 0000000000..0fe5445e79 --- /dev/null +++ b/js/src/jit-test/tests/resist-fingerprinting/math-fdlibm-sincostan.js @@ -0,0 +1,88 @@ +let g = newGlobal({alwaysUseFdlibm: true}); + +// Adapted from https://github.com/arkenfox/TZP/blob/master/tests/math.html +// Tests all values that differed from libm for me on Linux and Windows. + +function test() { + for (var i = 0; i < 100; i++) { + assertEq(g.Math.cos(1e130 ), -0.767224894221913); + assertEq(g.Math.cos(1e272 ), -0.7415825695514536); + assertEq(g.Math.cos(1e284 ), 0.7086865671674247); + assertEq(g.Math.cos(1e75 ), -0.7482651726250321); + assertEq(g.Math.cos(57*Math.E ), -0.536911695749024); + assertEq(g.Math.cos(21*Math.LN2 ), -0.4067775970251724); + assertEq(g.Math.cos(51*Math.LN2 ), -0.7017203400855446); + assertEq(g.Math.cos(21*Math.SQRT1_2), -0.6534063185820198); + assertEq(g.Math.cos(17*Math.LOG10E ), 0.4537557425982784); + assertEq(g.Math.cos(2*Math.LOG10E ), 0.6459044007438142); + + assertEq(g.Math.sin(35*Math.LN2 ), -0.765996413898051); + assertEq(g.Math.sin(110*Math.LOG2E ), 0.9989410140273757); + assertEq(g.Math.sin(7*Math.LOG10E ), 0.10135692924965616); + + assertEq(g.Math.tan(1e140 ), 0.7879079967710036); + assertEq(g.Math.tan(6*Math.E ), 0.6866761546452431); + assertEq(g.Math.tan(6*Math.LN2 ), 1.6182817135715877); + assertEq(g.Math.tan(10*Math.LOG2E ), -3.3537128705376014); + assertEq(g.Math.tan(17*Math.SQRT2 ), -1.9222955461799982); + assertEq(g.Math.tan(34*Math.SQRT1_2), -1.9222955461799982); + assertEq(g.Math.tan(10*Math.LOG10E ), 2.5824856130712432); + } +} + +/* +cos + 3: 1e130 : -0.767224894221913 , + 4: 1e272 : -0.7415825695514536, + 6: 1e284 : 0.7086865671674247, + 7: 1e75 : -0.7482651726250321, + 13: 57*Math.E : -0.536911695749024, + 14: 21*Math.LN2 : -0.4067775970251724, + 15: 51*Math.LN2 : -0.7017203400855446, + 19: 21*Math.SQRT1_2 : -0.6534063185820198, + 20: 17*Math.LOG10E : 0.4537557425982784, + 21: 2*Math.LOG10E : 0.6459044007438142, + + +sin + 11: : -0.765996413898051, + 12: : 0.9989410140273757, + 13: : 0.10135692924965616, + +tan + 1: 1e140 : 0.7879079967710036, + 10: 6*Math.E : 0.6866761546452431, + 11: 6*Math.LN2 : 1.6182817135715877, + 12: 10*Math.LOG2E : -3.3537128705376014, + 13: 17*Math.SQRT2 : -1.9222955461799982, + 14: 34*Math.SQRT1_2 : -1.9222955461799982, + 15: 10*Math.LOG10E : 2.5824856130712432, +*/ + +test(); + +// Test if the test is still useful, or if all results match without +// fingerprinting resistance as well. +if (!getBuildConfiguration("android") && + Math.cos(1e130 ) == -0.767224894221913 && + Math.cos(1e272 ) == -0.7415825695514536 && + Math.cos(1e284 ) == 0.7086865671674247 && + Math.cos(1e75 ) == -0.7482651726250321 && + Math.cos(57*Math.E ) == -0.536911695749024 && + Math.cos(21*Math.LN2 ) == -0.4067775970251724 && + Math.cos(51*Math.LN2 ) == -0.7017203400855446 && + Math.cos(21*Math.SQRT1_2) == -0.6534063185820198 && + Math.cos(17*Math.LOG10E ) == 0.4537557425982784 && + Math.cos(2*Math.LOG10E ) == 0.6459044007438142 && + Math.sin(35*Math.LN2 ) == -0.765996413898051 && + Math.sin(110*Math.LOG2E ) == 0.9989410140273757 && + Math.sin(7*Math.LOG10E ) == 0.10135692924965616 && + Math.tan(1e140 ) == 0.7879079967710036 && + Math.tan(6*Math.E ) == 0.6866761546452431 && + Math.tan(6*Math.LN2 ) == 1.6182817135715877 && + Math.tan(10*Math.LOG2E ) == -3.3537128705376014 && + Math.tan(17*Math.SQRT2 ) == -1.9222955461799982 && + Math.tan(34*Math.SQRT1_2) == -1.9222955461799982 && + Math.tan(10*Math.LOG10E ) == 2.5824856130712432) { + assertEq(false, true); +} diff --git a/js/src/jit-test/tests/resist-fingerprinting/timezone.js b/js/src/jit-test/tests/resist-fingerprinting/timezone.js new file mode 100644 index 0000000000..06aa089965 --- /dev/null +++ b/js/src/jit-test/tests/resist-fingerprinting/timezone.js @@ -0,0 +1,33 @@ +// |jit-test| tz-pacific; skip-if: typeof Intl === 'undefined' + +let tzRE = /\(([^\)]+)\)/; + +// Make sure we aren't already running with UTC +let original = new Date(0); +assertEq(tzRE.exec(original.toString())[1], "Pacific Standard Time"); + +let originalDT = Intl.DateTimeFormat("en-US", { + dateStyle: "full", + timeStyle: "full", +}); +assertEq(originalDT.format(original).endsWith("Pacific Standard Time"), true); +assertEq(originalDT.resolvedOptions().timeZone, "PST8PDT"); + +let global = newGlobal({forceUTC: true}); + +let date = new global.Date(); +assertEq(tzRE.exec(date.toString())[1], "Coordinated Universal Time"); +assertEq(tzRE.exec(date.toTimeString())[1], "Coordinated Universal Time"); +assertEq(date.getFullYear(), date.getUTCFullYear()); +assertEq(date.getMonth(), date.getUTCMonth()); +assertEq(date.getDate(), date.getUTCDate()); +assertEq(date.getDay(), date.getUTCDay()); +assertEq(date.getHours(),date.getUTCHours()); +assertEq(date.getTimezoneOffset(), 0); + +let dt = global.Intl.DateTimeFormat("en-US", { + dateStyle: "full", + timeStyle: "full", +}); +assertEq(dt.format(date).endsWith("Coordinated Universal Time"), true); +assertEq(dt.resolvedOptions().timeZone, "UTC"); -- cgit v1.2.3