summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/html-extensions.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /js/src/jit-test/tests/basic/html-extensions.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/basic/html-extensions.js')
-rw-r--r--js/src/jit-test/tests/basic/html-extensions.js87
1 files changed, 87 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/basic/html-extensions.js b/js/src/jit-test/tests/basic/html-extensions.js
new file mode 100644
index 0000000000..5cf52aefd1
--- /dev/null
+++ b/js/src/jit-test/tests/basic/html-extensions.js
@@ -0,0 +1,87 @@
+var noParamFuns = ["".bold, "".italics, "".fixed, "".strike, "".small, "".big,
+ "".blink, "".sup, "".sub];
+var noParamTags = ["b", "i", "tt", "strike", "small", "big",
+ "blink", "sup", "sub"];
+
+function testNoParam(s) {
+ for (var i=0; i<noParamFuns.length; i++) {
+ var fun = noParamFuns[i];
+ assertEq(fun.length, 0);
+ var res = fun.call(s);
+ var tag = noParamTags[i];
+ assertEq(res, "<" + tag + ">" + String(s) + "</" + tag + ">");
+ }
+}
+testNoParam("Foo");
+testNoParam('aaa"bbb\'c<>123');
+testNoParam(123);
+
+// toString should be called, not valueOf
+testNoParam({toString: () => 1, valueOf: () => { throw "fail"; } });
+
+assertEq("".anchor.length, 1);
+assertEq("".link.length, 1);
+assertEq("".fontsize.length, 1);
+assertEq("".fontcolor.length, 1);
+
+// Ensure @@replace on String.prototype isn't called.
+String.prototype[Symbol.replace] = function() {
+ throw "Shouldn't call @@replace";
+};
+
+// " in the attribute value is escaped (&quot;)
+assertEq("bla\"<>'".anchor("foo'<>\"\"123\"/\\"),
+ "<a name=\"foo'<>&quot;&quot;123&quot;/\\\">bla\"<>'</a>");
+assertEq("bla\"<>'".link("foo'<>\"\"123\"/\\"),
+ "<a href=\"foo'<>&quot;&quot;123&quot;/\\\">bla\"<>'</a>");
+assertEq("bla\"<>'".fontsize("foo'<>\"\"123\"/\\"),
+ "<font size=\"foo'<>&quot;&quot;123&quot;/\\\">bla\"<>'</font>");
+assertEq("bla\"<>'".fontcolor("foo'<>\"\"123\"/\\"),
+ "<font color=\"foo'<>&quot;&quot;123&quot;/\\\">bla\"<>'</font>");
+
+assertEq("".anchor('"'), '<a name="&quot;"></a>');
+assertEq("".link('"'), '<a href="&quot;"></a>');
+assertEq("".fontcolor('"'), '<font color="&quot;"></font>');
+assertEq("".fontsize('"'), '<font size="&quot;"></font>');
+
+assertEq("".anchor('"1'), '<a name="&quot;1"></a>');
+assertEq("".link('"1'), '<a href="&quot;1"></a>');
+assertEq("".fontcolor('"1'), '<font color="&quot;1"></font>');
+assertEq("".fontsize('"1'), '<font size="&quot;1"></font>');
+
+assertEq("".anchor('"""a"'), '<a name="&quot;&quot;&quot;a&quot;"></a>');
+assertEq("".link('"""a"'), '<a href="&quot;&quot;&quot;a&quot;"></a>');
+assertEq("".fontcolor('"""a"'), '<font color="&quot;&quot;&quot;a&quot;"></font>');
+assertEq("".fontsize('"""a"'), '<font size="&quot;&quot;&quot;a&quot;"></font>');
+
+assertEq("".anchor(""), '<a name=""></a>');
+assertEq("".link(""), '<a href=""></a>');
+assertEq("".fontcolor(""), '<font color=""></font>');
+assertEq("".fontsize(""), '<font size=""></font>');
+
+assertEq("foo".anchor(), "<a name=\"undefined\">foo</a>");
+assertEq("foo".link(), "<a href=\"undefined\">foo</a>");
+assertEq("foo".fontcolor(), "<font color=\"undefined\">foo</font>");
+assertEq("foo".fontsize(), "<font size=\"undefined\">foo</font>");
+
+assertEq("foo".anchor(3.14), '<a name="3.14">foo</a>');
+assertEq("foo".link(3.14), '<a href="3.14">foo</a>');
+assertEq("foo".fontcolor(3.14), '<font color="3.14">foo</font>');
+assertEq("foo".fontsize(3.14), '<font size="3.14">foo</font>');
+
+assertEq("foo".anchor({}), '<a name="[object Object]">foo</a>');
+assertEq("foo".link(Math), '<a href="[object Math]">foo</a>');
+assertEq("foo".fontcolor([1,2]), '<font color="1,2">foo</font>');
+assertEq("foo".fontsize({}), '<font size="[object Object]">foo</font>');
+
+// toString should be called, not valueOf, and toString must be called on |this|
+// before it's called on the argument. Also makes sure toString is called only
+// once.
+var count = 0;
+var o1 = {toString: () => { return count += 1; }, valueOf: () => { throw "fail"; } };
+var o2 = {toString: () => { return count += 5; }, valueOf: () => { throw "fail"; } };
+assertEq("".anchor.call(o1, o2), '<a name="6">1</a>');
+assertEq("".link.call(o1, o2), '<a href="12">7</a>');
+assertEq("".fontcolor.call(o1, o2), '<font color="18">13</font>');
+assertEq("".fontsize.call(o1, o2), '<font size="24">19</font>');
+assertEq(count, 24);