From 458f1fc31cf46a9c97b397c0ef6ff9ea0379b1f4 Mon Sep 17 00:00:00 2001 From: Jan de Mooij Date: Tue, 22 Jul 2014 14:52:14 +0200 Subject: [PATCH] Bug 1041469 part 3 - Remove toLatin1 shell function, update tests. r=luke --- js/src/jit-test/tests/latin1/asm.js | 1 - js/src/jit-test/tests/latin1/assorted.js | 4 +-- js/src/jit-test/tests/latin1/basic.js | 15 ++++----- js/src/jit-test/tests/latin1/compare.js | 6 ++-- js/src/jit-test/tests/latin1/date.js | 4 +-- js/src/jit-test/tests/latin1/decompiler.js | 2 -- js/src/jit-test/tests/latin1/dependent.js | 9 +++--- js/src/jit-test/tests/latin1/encode-decode.js | 32 ++++++++++++++----- .../jit-test/tests/latin1/escape-unescape.js | 18 +++++++---- js/src/jit-test/tests/latin1/eval.js | 2 +- js/src/jit-test/tests/latin1/function.js | 4 +-- js/src/jit-test/tests/latin1/index.js | 8 ++--- js/src/jit-test/tests/latin1/indexOf.js | 4 +++ js/src/jit-test/tests/latin1/indexing.js | 10 +++--- js/src/jit-test/tests/latin1/join.js | 14 ++++++-- js/src/jit-test/tests/latin1/json.js | 16 ++++++---- js/src/jit-test/tests/latin1/latin1.js | 3 -- js/src/jit-test/tests/latin1/other.js | 7 ++-- .../tests/latin1/parseInt-parseFloat.js | 4 +++ js/src/jit-test/tests/latin1/quote.js | 8 +++-- js/src/jit-test/tests/latin1/regexp.js | 5 +++ js/src/jit-test/tests/latin1/replace.js | 31 ++++++++++++++---- js/src/jit-test/tests/latin1/search.js | 4 +++ js/src/jit-test/tests/latin1/split.js | 9 ++++-- .../tests/latin1/startsWith-endsWith.js | 4 +++ .../jit-test/tests/latin1/structured-clone.js | 4 +-- .../tests/latin1/toLowerCase-toUpperCase.js | 8 +++-- js/src/jit-test/tests/latin1/toNumber.js | 4 +++ js/src/jit-test/tests/latin1/trim.js | 5 +-- js/src/shell/js.cpp | 24 -------------- js/src/tests/lib/tests.py | 2 +- js/src/vm/String.cpp | 21 ------------ js/src/vm/String.h | 3 -- 33 files changed, 167 insertions(+), 128 deletions(-) diff --git a/js/src/jit-test/tests/latin1/asm.js b/js/src/jit-test/tests/latin1/asm.js index 10ef015da45c..0026d3a865bc 100644 --- a/js/src/jit-test/tests/latin1/asm.js +++ b/js/src/jit-test/tests/latin1/asm.js @@ -6,7 +6,6 @@ if (!isAsmJSCompilationAvailable() || !isCachingEnabled()) // Test Latin1 and TwoByte PropertyName serialization. // Latin1 -toLatin1("funName"); // Latin1 atom. var body1 = "'use asm'; function funName() { return 42 } return funName"; var m = new Function(body1); assertEq(isAsmJSModule(m), true); diff --git a/js/src/jit-test/tests/latin1/assorted.js b/js/src/jit-test/tests/latin1/assorted.js index 38e94fdc7c81..cef79cb96fed 100644 --- a/js/src/jit-test/tests/latin1/assorted.js +++ b/js/src/jit-test/tests/latin1/assorted.js @@ -1,6 +1,7 @@ // Reflect.parse Latin1 -var ast = Reflect.parse(toLatin1("function f() { return 3; }")); +var ast = Reflect.parse("function f() { return 3; }"); assertEq(ast.body[0].id.name, "f"); +assertEq(isLatin1(ast.body[0].id.name), true); // Reflect.parse TwoByte var ast = Reflect.parse("function f\u1200() { return 3; }"); @@ -28,7 +29,6 @@ assertEq(o.toSource(), "({prop:((11)), prop:((11))})"); load(libdir + 'bytecode-cache.js'); // Latin1 string constant -toLatin1("string123"); test = "'string123';"; evalWithCache(test, { assertEqBytecode: true, assertEqResult : true }); diff --git a/js/src/jit-test/tests/latin1/basic.js b/js/src/jit-test/tests/latin1/basic.js index f649bb81ee2f..a11a6cf65dd2 100644 --- a/js/src/jit-test/tests/latin1/basic.js +++ b/js/src/jit-test/tests/latin1/basic.js @@ -1,6 +1,6 @@ assertEq(isLatin1("Foo123\u1200"), false); -s = toLatin1("Foo123"); +s = "Foo123"; assertEq(isLatin1(s), true); function testEq(s) { @@ -23,7 +23,6 @@ function testEq(s) { } s = "foo01\u00c7"; -s = toLatin1(s); testEq(s); testEq(s); @@ -34,8 +33,8 @@ function testConcat() { // Following tests create fat inline strings. assertEq(concat("abc", "def"), "abcdef"); - var s1 = toLatin1("ABC"); - var s2 = toLatin1("DEF"); + var s1 = "ABC"; + var s2 = "DEF"; assertEq(concat(s1, s2), "ABCDEF"); assertEq(concat(s1, "GHI\u0580"), "ABCGHI\u0580"); assertEq(concat("GHI\u0580", s2), "GHI\u0580DEF"); @@ -44,7 +43,7 @@ function testConcat() { assertEq(isLatin1(s2), true); // Create a Latin1 rope. - var s3 = toLatin1("0123456789012345678901234567890123456789"); + var s3 = "0123456789012345678901234567890123456789"; var rope = concat(s1, s3); assertEq(isLatin1(rope), true); assertEq(rope, "ABC0123456789012345678901234567890123456789"); @@ -64,7 +63,7 @@ function testConcat() { assertEq(isLatin1(rope), false); // Build a Latin1 rope with left-most string an extensible string. - var s4 = toLatin1("adsfasdfjkasdfkjasdfasasdfasdf"); + var s4 = "adsfasdfjkasdfkjasdfasasdfasdf"; for (var i=0; i<5; i++) { s4 = concat(s4, s1); assertEq(s4 === ".".repeat(s4.length), false); // Flatten rope. @@ -84,8 +83,8 @@ function testFlattenDependent() { } // Create some latin1 strings. - var s1 = toLatin1("Foo0123456789bar012345---"); - var s2 = toLatin1("Foo0123456789bar012345+++"); + var s1 = "Foo0123456789bar012345---"; + var s2 = "Foo0123456789bar012345+++"; assertEq(isLatin1(s1), true); assertEq(isLatin1(s2), true); diff --git a/js/src/jit-test/tests/latin1/compare.js b/js/src/jit-test/tests/latin1/compare.js index c0203d037508..636802b16ca5 100644 --- a/js/src/jit-test/tests/latin1/compare.js +++ b/js/src/jit-test/tests/latin1/compare.js @@ -1,8 +1,8 @@ function test() { var arr = [ - toLatin1("abc"), - toLatin1("abcd"), - toLatin1("123\u00ff") + "abc", + "abcd", + "123\u00ff" ]; for (var i = 0; i < arr.length; i++) { for (var j = 0; j < arr.length; j++) { diff --git a/js/src/jit-test/tests/latin1/date.js b/js/src/jit-test/tests/latin1/date.js index 5b0d86e32f9b..edf0221f9395 100644 --- a/js/src/jit-test/tests/latin1/date.js +++ b/js/src/jit-test/tests/latin1/date.js @@ -1,5 +1,5 @@ -function test(s) { - var lat1 = toLatin1(s); +function test(lat1) { + assertEq(isLatin1(lat1), true); var twoByte = "\u1200" + lat1; twoByte.indexOf("X"); // Flatten. diff --git a/js/src/jit-test/tests/latin1/decompiler.js b/js/src/jit-test/tests/latin1/decompiler.js index 5f94b1824622..7c49026c8b21 100644 --- a/js/src/jit-test/tests/latin1/decompiler.js +++ b/js/src/jit-test/tests/latin1/decompiler.js @@ -1,5 +1,3 @@ -var s = toLatin1("someName"); - // Latin1 function f(someName) { someName(); diff --git a/js/src/jit-test/tests/latin1/dependent.js b/js/src/jit-test/tests/latin1/dependent.js index 7ee73f472889..f92bc9dc1cf2 100644 --- a/js/src/jit-test/tests/latin1/dependent.js +++ b/js/src/jit-test/tests/latin1/dependent.js @@ -1,5 +1,5 @@ function testSubstrLatin1() { - var s1 = toLatin1("abcdefghijklmnopqrstuvwxyz12345678900000a"); + var s1 = "abcdefghijklmnopqrstuvwxyz12345678900000a"; // Static strings. assertEq(s1.substr(s1.length - 1), "a"); @@ -51,7 +51,7 @@ function testSubstrTwoByte() { testSubstrTwoByte(); function testSubstring() { - var s1 = toLatin1("abcdefghijklmnopqrstuvwxyz123456789000ab"); + var s1 = "abcdefghijklmnopqrstuvwxyz123456789000ab"; var s2 = s1.substring(1, 8); assertEq(isLatin1(s2), true); assertEq(s2, "bcdefgh"); @@ -62,7 +62,7 @@ function testSubstring() { testSubstring(); function testSlice() { - var s1 = toLatin1("abcdefghijklmnopqrstuvwxyz123456789000ABC"); + var s1 = "abcdefghijklmnopqrstuvwxyz123456789000ABC"; var s2 = s1.slice(1, 8); assertEq(isLatin1(s2), true); assertEq(s2, "bcdefgh"); @@ -76,7 +76,8 @@ function testUndepend() { // Latin1 var s = "abcdefg".repeat(7); s.indexOf("def"); // flatten - s = toLatin1(s); + assertEq(isLatin1(s), true); + var dep = s.substr(7); var res = dep.replace(/abcdef/g, ""); // StrReplaceRegexpRemove undepends. assertEq(res, "gggggg"); diff --git a/js/src/jit-test/tests/latin1/encode-decode.js b/js/src/jit-test/tests/latin1/encode-decode.js index a6df78338693..cb6869654f3b 100644 --- a/js/src/jit-test/tests/latin1/encode-decode.js +++ b/js/src/jit-test/tests/latin1/encode-decode.js @@ -1,7 +1,13 @@ // Latin1 -s = toLatin1("a%2b%20def%00A0"); -assertEq(decodeURI(s), "a%2b def\x00A0"); -assertEq(decodeURIComponent(s), "a+ def\x00A0"); +s = "a%2b%20def%00A0"; + +res = decodeURI(s); +assertEq(res, "a%2b def\x00A0"); +assertEq(isLatin1(res), true); + +res = decodeURIComponent(s); +assertEq(res, "a+ def\x00A0"); +assertEq(isLatin1(res), true); // TwoByte s += "\u1200"; @@ -10,7 +16,7 @@ assertEq(decodeURIComponent(s), "a+ def\x00A0\u1200"); // Latin1 malformed try { - decodeURI(toLatin1("abc%80")); + decodeURI("abc%80"); assertEq(0, 1); } catch(e) { assertEq(e instanceof URIError, true); @@ -25,12 +31,22 @@ try { } // Latin1 -assertEq(encodeURI(toLatin1("a%2b def\x00A0")), "a%252b%20def%00A0"); -assertEq(encodeURIComponent(toLatin1("a+ def\x00A0")), "a%2B%20def%00A0"); +res = encodeURI("a%2b def\x00A0"); +assertEq(res, "a%252b%20def%00A0"); +assertEq(isLatin1(res), true); + +res = encodeURIComponent("a+ def\x00A0"); +assertEq(res, "a%2B%20def%00A0"); +assertEq(isLatin1(res), true); // TwoByte -assertEq(encodeURI("a%2b def\x00A0\u1200"), "a%252b%20def%00A0%E1%88%80"); -assertEq(encodeURIComponent("a+ def\x00A0\u1200"), "a%2B%20def%00A0%E1%88%80"); +res = encodeURI("a%2b def\x00A0\u1200"); +assertEq(res, "a%252b%20def%00A0%E1%88%80"); +assertEq(isLatin1(res), true); + +res = encodeURIComponent("a+ def\x00A0\u1200"); +assertEq(res, "a%2B%20def%00A0%E1%88%80"); +assertEq(isLatin1(res), true); // TwoByte malformed try { diff --git a/js/src/jit-test/tests/latin1/escape-unescape.js b/js/src/jit-test/tests/latin1/escape-unescape.js index 85e3d5b0a481..9cab2ddbbb5e 100644 --- a/js/src/jit-test/tests/latin1/escape-unescape.js +++ b/js/src/jit-test/tests/latin1/escape-unescape.js @@ -1,8 +1,10 @@ // Latin1 -s = toLatin1("a%2b%20def%00A0"); -assertEq(unescape(s), "a+ def\x00A0"); +s = "a%2b%20def%00A0"; +res = unescape(s); +assertEq(res, "a+ def\x00A0"); +assertEq(isLatin1(res), true); -s = toLatin1("a%2b%20def%00A0%u1200"); +s = "a%2b%20def%00A0%u1200"; assertEq(unescape(s), "a+ def\x00A0\u1200"); // TwoByte @@ -10,9 +12,13 @@ s += "\u1200"; assertEq(unescape(s), "a+ def\x00A0\u1200\u1200"); // Latin1 -s = toLatin1("abc \u00ff"); -assertEq(escape(s), "abc%20%FF"); +s = "abc \u00ff"; +res = escape(s); +assertEq(res, "abc%20%FF"); +assertEq(isLatin1(res), true); // TwoByte s += "\u1200"; -assertEq(escape(s), "abc%20%FF%u1200"); +res = escape(s); +assertEq(res, "abc%20%FF%u1200"); +assertEq(isLatin1(res), true); diff --git a/js/src/jit-test/tests/latin1/eval.js b/js/src/jit-test/tests/latin1/eval.js index 43be304cd1ae..8b13018d07b0 100644 --- a/js/src/jit-test/tests/latin1/eval.js +++ b/js/src/jit-test/tests/latin1/eval.js @@ -3,7 +3,7 @@ function f(s) { var z = eval(s); assertEq(z, 8); } -var s = toLatin1("x + y"); +var s = "x + y"; f(s); // Latin1 f(s); f("x + y;/*\u1200*/"); // TwoByte diff --git a/js/src/jit-test/tests/latin1/function.js b/js/src/jit-test/tests/latin1/function.js index 54012ef7456d..bf248f3ab4bd 100644 --- a/js/src/jit-test/tests/latin1/function.js +++ b/js/src/jit-test/tests/latin1/function.js @@ -1,8 +1,8 @@ function test() { var arg1TwoByte = "arg1\u1200"; - var arg2Latin1 = toLatin1("arg2"); + var arg2Latin1 = "arg2"; - var bodyLatin1 = toLatin1("return arg2 * 3"); + var bodyLatin1 = "return arg2 * 3"; var f = Function(arg1TwoByte, arg2Latin1, bodyLatin1); assertEq(f(10, 20), 60); diff --git a/js/src/jit-test/tests/latin1/index.js b/js/src/jit-test/tests/latin1/index.js index 5ee4fba6e996..4a8a930280a4 100644 --- a/js/src/jit-test/tests/latin1/index.js +++ b/js/src/jit-test/tests/latin1/index.js @@ -1,21 +1,21 @@ function test() { var arr = new Int8Array(400); - var idx = toLatin1("384"); + var idx = "384"; arr[idx] = 9; assertEq(arr[idx], 9); arr[idx] = 10; assertEq(arr[384], 10); - idx = toLatin1("512"); + idx = "512"; assertEq(arr[idx], undefined); - assertEq(arr[toLatin1("byteLength")], 400); + assertEq(arr[(() => "byteLength")()], 400); var o = {}; Object.defineProperty(o, idx, {value: 123}); assertEq(o[512], 123); - var propLatin1 = toLatin1("foobar"); + var propLatin1 = "foobar"; o[propLatin1] = 3; assertEq(o.foobar, 3); diff --git a/js/src/jit-test/tests/latin1/indexOf.js b/js/src/jit-test/tests/latin1/indexOf.js index 44ec60b0a57f..b0816118253a 100644 --- a/js/src/jit-test/tests/latin1/indexOf.js +++ b/js/src/jit-test/tests/latin1/indexOf.js @@ -1,3 +1,7 @@ +function toLatin1(s) { + assertEq(isLatin1(s), true); + return s; +} function testLastIndexOf() { var s1 = toLatin1("abcdefgh123456\u0081defg"); var s2 = toLatin1("456\u0081de"); diff --git a/js/src/jit-test/tests/latin1/indexing.js b/js/src/jit-test/tests/latin1/indexing.js index 298efcfa3ed9..c37ed52be9b9 100644 --- a/js/src/jit-test/tests/latin1/indexing.js +++ b/js/src/jit-test/tests/latin1/indexing.js @@ -1,9 +1,9 @@ function testCharCodeAt() { - var s = toLatin1("abcdefghijklm1234567891000"); + var s = "abcdefghijklm1234567891000"; for (var i=0; i<10; i++) assertEq(s.charCodeAt(i), 97 + i); - var rope = s + toLatin1("blah"); + var rope = s + "blah"; assertEq(rope.charCodeAt(s.length + 3), 104); rope = s + "Foo987"; @@ -16,12 +16,12 @@ function testCharCodeAt() { testCharCodeAt(); function testCharAt() { - var s = toLatin1("abcdefghijklm100000002345"); + var s = "abcdefghijklm100000002345"; assertEq(s.charAt(0), "a"); assertEq(s.charAt(s.length-1), "5"); assertEq(s.charAt(s.length), ""); - var rope = s + toLatin1("abcZYX"); + var rope = s + "abcZYX"; assertEq(rope.charAt(s.length + 3), "Z"); rope = s + "Foo987"; @@ -41,7 +41,7 @@ function testIndex(s) { assertEq(rope[7], "\u0512"); } -var s = toLatin1("abcdefghijklm123456"); +var s = "abcdefghijklm123456"; testIndex(s); testIndex(s); testIndex(s); diff --git a/js/src/jit-test/tests/latin1/join.js b/js/src/jit-test/tests/latin1/join.js index 624f6313899f..ab27a4376b86 100644 --- a/js/src/jit-test/tests/latin1/join.js +++ b/js/src/jit-test/tests/latin1/join.js @@ -1,10 +1,20 @@ +function toLatin1(s) { + assertEq(isLatin1(s), true); + return s; +} + var arrLatin1 = [toLatin1("abc1"), toLatin1("abc\u00A0")]; -assertEq(arrLatin1.join(toLatin1("sep\u00ff")), "abc1sep\xFFabc\xA0"); +var res = arrLatin1.join(toLatin1("sep\u00ff")); +assertEq(res, "abc1sep\xFFabc\xA0"); +assertEq(isLatin1(res), true); var arrTwoByte = [toLatin1("abc2"), "def\u1200"]; assertEq(arrTwoByte.join(toLatin1("sep\u00fe")), "abc2sep\xFEdef\u1200"); -assertEq(arrLatin1.join(toLatin1("-")), "abc1-abc\xA0"); +res = arrLatin1.join(toLatin1("-")); +assertEq(res, "abc1-abc\xA0"); +assertEq(isLatin1(res), true); + assertEq(arrTwoByte.join(toLatin1("7")), "abc27def\u1200"); assertEq(arrLatin1.join("\u1200"), "abc1\u1200abc\xA0"); diff --git a/js/src/jit-test/tests/latin1/json.js b/js/src/jit-test/tests/latin1/json.js index 7bcccc34e335..24a45cdaaa55 100644 --- a/js/src/jit-test/tests/latin1/json.js +++ b/js/src/jit-test/tests/latin1/json.js @@ -1,6 +1,7 @@ function testBasic() { // Latin1 - var s = toLatin1('[1, 2, "foo", "bar\\r\\n", {"xyz": 3}, [1, 2, 3]]'); + var s = '[1, 2, "foo", "bar\\r\\n", {"xyz": 3}, [1, 2, 3]]'; + assertEq(isLatin1(s), true); assertEq(JSON.stringify(JSON.parse(s)), '[1,2,"foo","bar\\r\\n",{"xyz":3},[1,2,3]]'); // TwoByte @@ -13,7 +14,7 @@ function testErrorPos() { // Make sure the error location is calculated correctly. // Latin1 - var s = toLatin1('[1, \n2,'); + var s = '[1, \n2,'; try { JSON.parse(s); assertEq(0, 1); @@ -35,8 +36,9 @@ testErrorPos(); function testEvalHack() { // Latin1 - var arr = eval(toLatin1("[1, 2, 3, \"abc\"]")); + var arr = eval("[1, 2, 3, \"abc\"]"); assertEq(JSON.stringify(arr), '[1,2,3,"abc"]'); + assertEq(isLatin1(JSON.stringify(arr)), true); // TwoByte arr = eval("[1, 2, 3, \"abc\u1200\"]"); @@ -46,7 +48,7 @@ testEvalHack(); function testEvalHackNotJSON() { // Latin1 - var arr = eval(toLatin1("[]; var q; [1, 2, 3, \"abc\"]")); + var arr = eval("[]; var q; [1, 2, 3, \"abc\"]"); assertEq(JSON.stringify(arr), '[1,2,3,"abc"]'); // TwoByte @@ -65,8 +67,10 @@ testEvalHackNotJSON(); function testQuote() { // Latin1 - var s = toLatin1("abc--\x05-'\"-\n-\u00ff++"); - assertEq(JSON.stringify(s), '"abc--\\u0005-\'\\"-\\n-\xFF++"'); + var s = "abc--\x05-'\"-\n-\u00ff++"; + var res = JSON.stringify(s); + assertEq(res, '"abc--\\u0005-\'\\"-\\n-\xFF++"'); + assertEq(isLatin1(res), true); // TwoByte s += "\uAAAA"; diff --git a/js/src/jit-test/tests/latin1/latin1.js b/js/src/jit-test/tests/latin1/latin1.js index 394a49de4a24..f0af0062cf36 100644 --- a/js/src/jit-test/tests/latin1/latin1.js +++ b/js/src/jit-test/tests/latin1/latin1.js @@ -1,6 +1,3 @@ -if (!isLatin1("foo")) //TODO: remove this when removing latin1 flag - quit(); - function assertLatin1(s) { assertEq(isLatin1(s), true, "String: " + s); } diff --git a/js/src/jit-test/tests/latin1/other.js b/js/src/jit-test/tests/latin1/other.js index 3756cfa9472c..6713794ec82e 100644 --- a/js/src/jit-test/tests/latin1/other.js +++ b/js/src/jit-test/tests/latin1/other.js @@ -1,5 +1,8 @@ -var s1 = toLatin1("abcdefg12345"); -var s2 = toLatin1('foo"bar'); +var s1 = "abcdefg12345"; +var s2 = 'foo"bar'; + +assertEq(isLatin1(s1), true); +assertEq(isLatin1(s2), true); function test() { assertEq(s1.valueOf(), s1); diff --git a/js/src/jit-test/tests/latin1/parseInt-parseFloat.js b/js/src/jit-test/tests/latin1/parseInt-parseFloat.js index f07c6bdfcaff..7240224d120a 100644 --- a/js/src/jit-test/tests/latin1/parseInt-parseFloat.js +++ b/js/src/jit-test/tests/latin1/parseInt-parseFloat.js @@ -1,3 +1,7 @@ +function toLatin1(s) { + assertEq(isLatin1(s), true); + return s; +} function testParseInt() { // Latin1 assertEq(parseInt(toLatin1("12345abc")), 12345); diff --git a/js/src/jit-test/tests/latin1/quote.js b/js/src/jit-test/tests/latin1/quote.js index 34bac640cdea..b2bd27d5bf47 100644 --- a/js/src/jit-test/tests/latin1/quote.js +++ b/js/src/jit-test/tests/latin1/quote.js @@ -1,7 +1,11 @@ -var s = toLatin1('Abc1234"\'\t987\u00ff'); +var s = 'Abc1234"\'\t987\u00ff'; +assertEq(isLatin1(s), true); assertEq(s.toSource(), '(new String("Abc1234\\"\'\\t987\\xFF"))'); -assertEq(s.quote(), '"Abc1234\\"\'\\t987\\xFF"'); +var res = s.quote(); +assertEq(res, '"Abc1234\\"\'\\t987\\xFF"'); +assertEq(isLatin1(res), true); s = 'Abc1234"\'\t\u1200987\u00ff'; +assertEq(isLatin1(s), false); assertEq(s.toSource(), '(new String("Abc1234\\"\'\\t\\u1200987\\xFF"))'); assertEq(s.quote(), '"Abc1234\\"\'\\t\\u1200987\\xFF"'); diff --git a/js/src/jit-test/tests/latin1/regexp.js b/js/src/jit-test/tests/latin1/regexp.js index 0efda10c844c..809c3817db49 100644 --- a/js/src/jit-test/tests/latin1/regexp.js +++ b/js/src/jit-test/tests/latin1/regexp.js @@ -1,3 +1,8 @@ +function toLatin1(s) { + assertEq(isLatin1(s), true); + return s; +} + // Latin1 var re = new RegExp(toLatin1("foo[bB]a\\r"), toLatin1("im")); assertEq(isLatin1(re.source), true); diff --git a/js/src/jit-test/tests/latin1/replace.js b/js/src/jit-test/tests/latin1/replace.js index d50aab42511e..fecd958d192c 100644 --- a/js/src/jit-test/tests/latin1/replace.js +++ b/js/src/jit-test/tests/latin1/replace.js @@ -1,3 +1,7 @@ +function toLatin1(s) { + assertEq(isLatin1(s), true); + return s; +} function testDollarReplacement() { // Latin1 input, pat and replacement var s = toLatin1("Foobarbaz123"); @@ -7,6 +11,7 @@ function testDollarReplacement() { assertEq(s.replace(pat, toLatin1("A$`A")), "FooAFooAbaz123"); assertEq(s.replace(pat, toLatin1("A$&A")), "FooAbarAbaz123"); assertEq(s.replace(pat, toLatin1("A$'A")), "FooAbaz123Abaz123"); + assertEq(isLatin1(s.replace(pat, "A$'A")), true); // Latin1 input and pat, TwoByte replacement assertEq(s.replace(pat, "A\u1200"), "FooA\u1200baz123"); @@ -43,13 +48,20 @@ testDollarReplacement(); function testRegExp() { var s = toLatin1("Foobar123bar234"); - assertEq(s.replace(/bar\d\d/, "456"), "Foo4563bar234"); + var res = s.replace(/bar\d\d/, "456"); + assertEq(res, "Foo4563bar234"); + assertEq(isLatin1(res), true); // Latin1 input and replacement var re1 = /bar\d\d/; + res = s.replace(re1, toLatin1("789")); + assertEq(res, "Foo7893bar234"); + assertEq(isLatin1(res), true); + var re2 = /bar\d\d/g; - assertEq(s.replace(re1, toLatin1("789")), "Foo7893bar234"); - assertEq(s.replace(re2, toLatin1("789\u00ff")), "Foo789\u00ff3789\u00ff4"); + res = s.replace(re2, toLatin1("789\u00ff")); + assertEq(res, "Foo789\u00ff3789\u00ff4"); + assertEq(isLatin1(res), true); // Latin1 input, TwoByte replacement assertEq(s.replace(re1, "789\u1200"), "Foo789\u12003bar234"); @@ -75,6 +87,7 @@ function testRegExpDollar() { assertEq(s.replace(re1, toLatin1("--$&--")), "Foo--bar12--3bar2345"); assertEq(s.replace(re2, toLatin1("--$'\u00ff--")), "Foo--3bar2345\xFF--3--45\xFF--45"); assertEq(s.replace(re2, toLatin1("--$`--")), "Foo--Foo--3--Foobar123--45"); + assertEq(isLatin1(s.replace(re2, toLatin1("--$`--"))), true); // Latin1 input, TwoByte replacement assertEq(s.replace(re1, "\u1200$$"), "Foo\u1200$3bar2345"); @@ -100,7 +113,9 @@ function testFlattenPattern() { var s = "abcdef[g]abc"; // Latin1 pattern - assertEq(s.replace(toLatin1("def[g]"), "--$&--", "gi"), "abc--def[g]--abc"); + var res = s.replace(toLatin1("def[g]"), "--$&--", "gi"); + assertEq(res, "abc--def[g]--abc"); + assertEq(isLatin1(res), true); // TwoByte pattern s = "abcdef[g]\u1200abc"; @@ -111,10 +126,14 @@ testFlattenPattern(); function testReplaceEmpty() { // Latin1 var s = toLatin1("--abcdefghijkl--abcdefghijkl--abcdefghijkl--abcdefghijkl"); - assertEq(s.replace(/abcd[eE]/g, ""), "--fghijkl--fghijkl--fghijkl--fghijkl"); + var res = s.replace(/abcd[eE]/g, ""); + assertEq(res, "--fghijkl--fghijkl--fghijkl--fghijkl"); + assertEq(isLatin1(res), true); s = "--abcdEf--"; - assertEq(s.replace(/abcd[eE]/g, ""), "--f--"); + res = s.replace(/abcd[eE]/g, ""); + assertEq(res, "--f--"); + assertEq(isLatin1(res), true); // TwoByte s = "--abcdefghijkl--abcdefghijkl--abcdefghijkl--abcdefghijkl\u1200"; diff --git a/js/src/jit-test/tests/latin1/search.js b/js/src/jit-test/tests/latin1/search.js index 4db8c4e8c4a0..a26c632f2768 100644 --- a/js/src/jit-test/tests/latin1/search.js +++ b/js/src/jit-test/tests/latin1/search.js @@ -1,3 +1,7 @@ +function toLatin1(s) { + assertEq(isLatin1(s), true); + return s; +} function testSearchFlat() { var s1 = toLatin1("fooBar12345"); var s2 = toLatin1("Bar1"); diff --git a/js/src/jit-test/tests/latin1/split.js b/js/src/jit-test/tests/latin1/split.js index 3aa82565821c..d07576e1035f 100644 --- a/js/src/jit-test/tests/latin1/split.js +++ b/js/src/jit-test/tests/latin1/split.js @@ -1,19 +1,22 @@ // Latin1 -var s = toLatin1("abcdef,g,,"); -var res = s.split(toLatin1(",")); +var s = "abcdef,g,,"; +var res = s.split(","); assertEq(res[0], "abcdef"); +assertEq(isLatin1(res[0]), true); assertEq(res[1], "g"); assertEq(res[2], ""); assertEq(res[3], ""); -s = toLatin1("abcdef,gh,,"); +s = "abcdef,gh,,"; res = s.split("\u1200"); assertEq(res[0], "abcdef,gh,,"); +assertEq(isLatin1(res[0]), true); // TwoByte s = "abcdef\u1200\u1200,g,,"; res = s.split(","); assertEq(res[0], "abcdef\u1200\u1200"); +assertEq(isLatin1(res[0]), false); assertEq(res[1], "g"); assertEq(res[2], ""); assertEq(res[3], ""); diff --git a/js/src/jit-test/tests/latin1/startsWith-endsWith.js b/js/src/jit-test/tests/latin1/startsWith-endsWith.js index 913b20250256..eb49bea16530 100644 --- a/js/src/jit-test/tests/latin1/startsWith-endsWith.js +++ b/js/src/jit-test/tests/latin1/startsWith-endsWith.js @@ -1,3 +1,7 @@ +function toLatin1(s) { + assertEq(isLatin1(s), true); + return s; +} function testStartsWith() { var s1 = toLatin1("abc\u0099def"); var s2 = toLatin1("abc\u0099d"); diff --git a/js/src/jit-test/tests/latin1/structured-clone.js b/js/src/jit-test/tests/latin1/structured-clone.js index a6769a1f29f6..d7ad815a57bd 100644 --- a/js/src/jit-test/tests/latin1/structured-clone.js +++ b/js/src/jit-test/tests/latin1/structured-clone.js @@ -1,9 +1,9 @@ // Latin1 -var s = deserialize(serialize(toLatin1("foo123\u00EE"))); +var s = deserialize(serialize("foo123\u00EE")); assertEq(s, "foo123\u00EE"); assertEq(isLatin1(s), true); -var o = deserialize(serialize(new String(toLatin1("foo\u00EE")))); +var o = deserialize(serialize(new String("foo\u00EE"))); assertEq(typeof o, "object"); assertEq(o.valueOf(), "foo\u00EE"); assertEq(isLatin1(o.valueOf()), true); diff --git a/js/src/jit-test/tests/latin1/toLowerCase-toUpperCase.js b/js/src/jit-test/tests/latin1/toLowerCase-toUpperCase.js index 8125d6c88161..412bd3e5260e 100644 --- a/js/src/jit-test/tests/latin1/toLowerCase-toUpperCase.js +++ b/js/src/jit-test/tests/latin1/toLowerCase-toUpperCase.js @@ -1,5 +1,6 @@ function testToLowerCase() { - var s1 = toLatin1("abcdefgABCDEFGH 123456"); + var s1 = "abcdefgABCDEFGH 123456"; + assertEq(isLatin1(s1), true); // Latin1 var s2 = s1.toLowerCase(); @@ -26,7 +27,8 @@ function testToLowerCase() { testToLowerCase(); function testToUpperCase() { - var s1 = toLatin1("abcdefgABCDEFGH 12345"); + var s1 = "abcdefgABCDEFGH 12345"; + assertEq(isLatin1(s1), true); // Latin1 var s2 = s1.toUpperCase(); @@ -44,7 +46,7 @@ function testToUpperCase() { // Tricky case: Latin1 character \u00FF maps to \u0178, a // non-Latin1 character. - s1 = toLatin1("ABC\u00FF"); + s1 = "ABC\u00FF"; assertEq(isLatin1(s1), true); s2 = s1.toUpperCase(); assertEq(isLatin1(s2), false); diff --git a/js/src/jit-test/tests/latin1/toNumber.js b/js/src/jit-test/tests/latin1/toNumber.js index 5cfa444ba52e..ab70342739aa 100644 --- a/js/src/jit-test/tests/latin1/toNumber.js +++ b/js/src/jit-test/tests/latin1/toNumber.js @@ -1,3 +1,7 @@ +function toLatin1(s) { + assertEq(isLatin1(s), true); + return s; +} function testToNumber() { // Latin1 assertEq(+toLatin1("12345.6"), 12345.6); diff --git a/js/src/jit-test/tests/latin1/trim.js b/js/src/jit-test/tests/latin1/trim.js index 0680e82efef5..79e0830126be 100644 --- a/js/src/jit-test/tests/latin1/trim.js +++ b/js/src/jit-test/tests/latin1/trim.js @@ -1,6 +1,7 @@ function test() { // Latin1 - var s = toLatin1(" \r\t\n\u00A0foo 123\t \r\n\u00A0"); + var s = " \r\t\n\u00A0foo 123\t \r\n\u00A0"; + assertEq(isLatin1(s), true); var res = s.trim(); assertEq(isLatin1(res), true); @@ -14,7 +15,7 @@ function test() { assertEq(isLatin1(res), true); assertEq(res, " \r\t\n\u00A0foo 123"); - res = toLatin1("foo 1234").trim(); + res = "foo 1234".trim(); assertEq(isLatin1(res), true); assertEq(res, "foo 1234"); diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 845697bbda5a..b192ac8f7f9b 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -4515,26 +4515,6 @@ IsLatin1(JSContext *cx, unsigned argc, Value *vp) return true; } -static bool -ToLatin1(JSContext *cx, unsigned argc, Value *vp) -{ - CallArgs args = CallArgsFromVp(argc, vp); - if (!args.get(0).isString() || !args[0].toString()->isLinear()) { - args.rval().setUndefined(); - return true; - } - - if (args[0].toString()->hasLatin1Chars()) { - args.rval().set(args[0]); - return true; - } - - JSLinearString *s = &args[0].toString()->asLinear(); - s->debugUnsafeConvertToLatin1(); - args.rval().setString(s); - return true; -} - static const JSFunctionSpecWithHelp shell_functions[] = { JS_FN_HELP("version", Version, 0, 0, "version([number])", @@ -4970,10 +4950,6 @@ static const JSFunctionSpecWithHelp fuzzing_unsafe_functions[] = { "untrap(fun[, pc])", " Remove a trap."), - JS_FN_HELP("toLatin1", ToLatin1, 1, 0, -"toLatin1(s)", -" Convert the string's characters to Latin1."), - JS_FN_HELP("withSourceHook", WithSourceHook, 1, 0, "withSourceHook(hook, fun)", " Set this JS runtime's lazy source retrieval hook (that is, the hook\n" diff --git a/js/src/tests/lib/tests.py b/js/src/tests/lib/tests.py index ad2b96e56e28..a9e35d5a1d45 100644 --- a/js/src/tests/lib/tests.py +++ b/js/src/tests/lib/tests.py @@ -14,7 +14,7 @@ TBPL_FLAGS = [ [], # no flags, normal baseline and ion ['--ion-eager', '--ion-offthread-compile=off'], # implies --baseline-eager ['--ion-eager', '--ion-offthread-compile=off', '--ion-check-range-analysis', '--no-sse3'], - ['--baseline-eager', '--latin1-strings'], + ['--baseline-eager'], ['--baseline-eager', '--no-fpu'], ['--no-baseline', '--no-ion'], ] diff --git a/js/src/vm/String.cpp b/js/src/vm/String.cpp index 4b3d5ac5a94e..40ff79908ca8 100644 --- a/js/src/vm/String.cpp +++ b/js/src/vm/String.cpp @@ -150,27 +150,6 @@ JSString::equals(const char *s) } #endif /* DEBUG */ -void -JSLinearString::debugUnsafeConvertToLatin1() -{ - // Temporary helper function to test changes for bug 998392. - - MOZ_ASSERT(hasTwoByteChars()); - MOZ_ASSERT(!hasBase()); - - size_t len = length(); - const jschar *twoByteChars = rawTwoByteChars(); - Latin1Char *latin1Chars = (Latin1Char *)twoByteChars; - - for (size_t i = 0; i < len; i++) { - MOZ_ASSERT((twoByteChars[i] & 0xff00) == 0); - latin1Chars[i] = Latin1Char(twoByteChars[i]); - } - - latin1Chars[len] = '\0'; - d.u1.flags |= LATIN1_CHARS_BIT; -} - template static MOZ_ALWAYS_INLINE bool AllocChars(ThreadSafeContext *maybecx, size_t length, CharT **chars, size_t *capacity) diff --git a/js/src/vm/String.h b/js/src/vm/String.h index 56a4fedfa953..73794cc25eea 100644 --- a/js/src/vm/String.h +++ b/js/src/vm/String.h @@ -649,9 +649,6 @@ class JSLinearString : public JSString JS::AutoCheckCannotGC nogc; return hasLatin1Chars() ? latin1Chars(nogc)[index] : twoByteChars(nogc)[index]; } - - /* Temporary, unsafe helper function for bug 998392. Don't use for anything else. */ - void debugUnsafeConvertToLatin1(); }; JS_STATIC_ASSERT(sizeof(JSLinearString) == sizeof(JSString));