diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/jit-test/tests/basic/external-strings.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/basic/external-strings.js')
-rw-r--r-- | js/src/jit-test/tests/basic/external-strings.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/basic/external-strings.js b/js/src/jit-test/tests/basic/external-strings.js new file mode 100644 index 0000000000..fd5faa27ef --- /dev/null +++ b/js/src/jit-test/tests/basic/external-strings.js @@ -0,0 +1,48 @@ +assertEq(newString("", {external: true}), ""); +assertEq(newString("abc", {external: true}), "abc"); +assertEq(newString("abc\0def\u1234", {external: true}), "abc\0def\u1234"); + +var o = {foo: 2, "foo\0": 4}; +var ext = newString("foo", {external: true}); +assertEq(o[ext], 2); +var ext2 = newString("foo\0", {external: true}); +assertEq(o[ext2], 4); + +eval(newString("assertEq(1, 1)", {external: true})); + +// Make sure ensureLinearString does the right thing for external strings. +ext = newString("abc\0defg\0", {external: true}); +assertEq(ensureLinearString(ext), "abc\0defg\0"); +assertEq(ensureLinearString(ext), "abc\0defg\0"); + +for (var s of representativeStringArray()) + assertEq(ensureLinearString(s), s); + +for (var s of representativeStringArray()) + assertEq(newString(s, {external: true}), s); + +function testQuote() { + for (var data of [["abc", "abc"], + ["abc\t", "abc\\t"], + ["abc\t\t\0", "abc\\t\\t\\x00"], + ["abc\\def", "abc\\\\def"]]) { + try { + assertEq(newString(data[0], {external: true}), false); + } catch(e) { + assertEq(e.toString().includes('got "' + data[1] + '",'), true) + } + } +} +testQuote(); + +function testMaybeExternal() { + for (var i=0; i<10; i++) { + var s = "abcdef4321" + i; + assertEq(newString(s, {maybeExternal: true}), s); + if ((i % 2) === 0) + assertEq(ensureLinearString(newString(s, {maybeExternal: true})), s); + } +} +testMaybeExternal(); +gc(); +testMaybeExternal(); |