Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / js / regexp-caching.html
blob06ada7011020ceb28bedfffd46e8aa8115635804
1 <html>
2 <head>
3 <script>
4 function print(message)
6 var block = document.createElement("div");
7 block.appendChild(document.createTextNode(message));
8 block.appendChild(document.createElement("br"));
9 document.getElementById("console").appendChild(block);
12 function isReadOnly(object, property)
14 var oldValue = object[property];
15 object[property] = !object[property];
16 var result = (object[property] == oldValue);
17 object[property] = oldValue;
18 return result;
21 function printPropertiesWithReadOnly(object)
23 var array = new Array;
24 for (var property in object) {
25 array.push(property);
27 array.sort();
28 for (var i = 0; i < array.length; i++) {
29 var property = array[i];
30 print(property + ": {" + object[property] + "} " + (isReadOnly(object, property) ? "(read-only)" : "(read-write)"));
34 function printProperties(object)
36 var array = new Array;
37 for (var property in object) {
38 array.push(property);
40 array.sort();
41 for (var i = 0; i < array.length; i++) {
42 var property = array[i];
43 print(property + ": {" + object[property] + "}");
47 function test() {
48 if (window.testRunner)
49 testRunner.dumpAsText();
51 print("Properties of RegExp at startup:");
52 printPropertiesWithReadOnly(RegExp);
54 var r = /(1)(2)(3)(4)(5)(6)(7)(8)(9)(0)/;
55 var matchingString = "<1234567890>";
56 var unmatchingString = "XXX";
58 var dummyRegExp = new RegExp();
59 var dummyString = "";
61 print("");
62 r.exec(matchingString);
63 print("Properties of RegExp after " + r + ".exec(" + matchingString + "):");
64 printProperties(RegExp);
66 print("");
67 print("RegExp.$0 " + (RegExp.$0 ? "exists" : "does not exist"));
68 print("RegExp.$10 " + (RegExp.$10 ? "exists" : "does not exist"));
69 print("RegExp " + (r.test() ? "uses" : "doesn't use") + " RegExp.input");
71 RegExp.multiline = "foo";
72 print("RegExp.multiline " + (typeof RegExp.multiline == typeof Boolean() ? "coerces" : "doesn't coerce") + " values to booleans");
73 RegExp.input = Number();
74 print("RegExp.input " + (typeof RegExp.input == typeof String() ? "coerces" : "doesn't coerce") + " values to strings");
76 print("");
77 r.exec(unmatchingString);
78 print("Properties of RegExp after " + r + ".exec(" + unmatchingString + "):");
79 printProperties(RegExp);
81 print("");
82 print("---------- [Cleared RegExp values] ----------");
83 dummyRegExp.exec(dummyString);
84 if (RegExp.lastMatch != "")
85 print("Clear failed");
87 matchingString.search(r);
88 print("Properties of RegExp after " + matchingString + ".search(" + r + "):");
89 printProperties(RegExp);
91 print("");
92 print("---------- [Cleared RegExp values] ----------");
93 dummyRegExp.exec(dummyString);
95 matchingString.replace(r);
96 print("Properties of RegExp after " + matchingString + ".replace(" + r + "):");
97 printProperties(RegExp);
99 </script>
100 </head>
101 <body onload="test();">
103 This test checks our implementation of the special RegExp member variables.
104 </p>
105 <hr>
106 <div id='console'/ style="font-family: courier; font-size: 12">
107 </body>
108 </html>