OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 msg: "Number 1234.34", val: 1234.34 | 70 msg: "Number 1234.34", val: 1234.34 |
71 }, { | 71 }, { |
72 msg: "Integer number 0", val: 0 | 72 msg: "Integer number 0", val: 0 |
73 }, { | 73 }, { |
74 msg: "Negative number -1", val: -1 | 74 msg: "Negative number -1", val: -1 |
75 }, { | 75 }, { |
76 msg: "Boolean true", val: true | 76 msg: "Boolean true", val: true |
77 }, { | 77 }, { |
78 msg: "Boolean false", val: false | 78 msg: "Boolean false", val: false |
79 }, { | 79 }, { |
80 msg: "Regular expression /\d+/", val: /\d+/ | |
81 }, { | |
82 msg: "Empty array []", val: [] | 80 msg: "Empty array []", val: [] |
83 }, { | 81 }, { |
84 msg: "Empty object {}", val: {} | 82 msg: "Empty object {}", val: {} |
85 }, { | 83 }, { |
86 msg: "Array of size 3", val: new Array(3) | 84 msg: "Array of size 3", val: new Array(3) |
87 }]; | 85 }]; |
88 | 86 |
89 var i = 0; | 87 var i = 0; |
90 var l = TEST_INPUT.length; | 88 var l = TEST_INPUT.length; |
91 | 89 |
(...skipping 27 matching lines...) Expand all Loading... |
119 assertFalse("abc".contains("a", 42)); | 117 assertFalse("abc".contains("a", 42)); |
120 assertFalse("abc".contains("a", Infinity)); | 118 assertFalse("abc".contains("a", Infinity)); |
121 assertTrue("abc".contains("ab", -43)); | 119 assertTrue("abc".contains("ab", -43)); |
122 assertFalse("abc".contains("cd", -42)); | 120 assertFalse("abc".contains("cd", -42)); |
123 assertTrue("abc".contains("ab", -Infinity)); | 121 assertTrue("abc".contains("ab", -Infinity)); |
124 assertFalse("abc".contains("cd", -Infinity)); | 122 assertFalse("abc".contains("cd", -Infinity)); |
125 assertTrue("abc".contains("ab", NaN)); | 123 assertTrue("abc".contains("ab", NaN)); |
126 assertFalse("abc".contains("cd", NaN)); | 124 assertFalse("abc".contains("cd", NaN)); |
127 assertFalse("xyzzy".contains("zy\0", 2)); | 125 assertFalse("xyzzy".contains("zy\0", 2)); |
128 | 126 |
129 var dots = Array(10000).join('.'); | 127 var dots = Array(10000).join("."); |
130 assertFalse(dots.contains("\x01", 10000)); | 128 assertFalse(dots.contains("\x01", 10000)); |
131 assertFalse(dots.contains("\0", 10000)); | 129 assertFalse(dots.contains("\0", 10000)); |
132 | 130 |
133 var myobj = { | 131 var myobj = { |
134 toString: function () { | 132 toString: function () { |
135 return "abc"; | 133 return "abc"; |
136 }, | 134 }, |
137 contains: String.prototype.contains | 135 contains: String.prototype.contains |
138 }; | 136 }; |
139 assertTrue(myobj.contains("abc")); | 137 assertTrue(myobj.contains("abc")); |
140 assertFalse(myobj.contains("cd")); | 138 assertFalse(myobj.contains("cd")); |
141 | 139 |
142 var gotStr = false; | 140 var gotStr = false; |
143 var gotPos = false; | 141 var gotPos = false; |
144 myobj = { | 142 myobj = { |
145 toString: function () { | 143 toString: function () { |
146 assertFalse(gotPos); | 144 assertFalse(gotPos); |
147 gotStr = true; | 145 gotStr = true; |
148 return "xyz"; | 146 return "xyz"; |
149 }, | 147 }, |
150 contains: String.prototype.contains | 148 contains: String.prototype.contains |
151 }; | 149 }; |
| 150 |
| 151 assertEquals("foo[a-z]+(bar)?".contains("[a-z]+"), true); |
| 152 assertThrows("'foo[a-z]+(bar)?'.contains(/[a-z]+/)", TypeError); |
| 153 assertThrows("'foo/[a-z]+/(bar)?'.contains(/[a-z]+/)", TypeError); |
| 154 assertEquals("foo[a-z]+(bar)?".contains("(bar)?"), true); |
| 155 assertThrows("'foo[a-z]+(bar)?'.contains(/(bar)?/)", TypeError); |
| 156 assertThrows("'foo[a-z]+/(bar)?/'.contains(/(bar)?/)", TypeError); |
| 157 |
| 158 assertThrows("String.prototype.contains.call({ 'toString': function() { " + |
| 159 "throw RangeError(); } }, /./)", RangeError); |
| 160 assertThrows("String.prototype.contains.call({ 'toString': function() { " + |
| 161 "return 'abc'; } }, /./)", TypeError); |
| 162 |
| 163 assertThrows("String.prototype.contains.apply({ 'toString': function() { " + |
| 164 "throw RangeError(); } }, [/./])", RangeError); |
| 165 assertThrows("String.prototype.contains.apply({ 'toString': function() { " + |
| 166 "return 'abc'; } }, [/./])", TypeError); |
OLD | NEW |