Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 } | 127 } | 
| 128 | 128 | 
| 129 // String.prototype.replace must interleave matching and replacing when a | 129 // String.prototype.replace must interleave matching and replacing when a | 
| 130 // global regexp is matched and replaced with the result of a function, in | 130 // global regexp is matched and replaced with the result of a function, in | 
| 131 // case the function uses the static properties of the regexp constructor. | 131 // case the function uses the static properties of the regexp constructor. | 
| 132 re = /(.)/g; | 132 re = /(.)/g; | 
| 133 function f() { return RegExp.$1; }; | 133 function f() { return RegExp.$1; }; | 
| 134 assertEquals('abcd', 'abcd'.replace(re, f)); | 134 assertEquals('abcd', 'abcd'.replace(re, f)); | 
| 135 | 135 | 
| 136 // lastParen where the last parenthesis didn't match. | 136 // lastParen where the last parenthesis didn't match. | 
| 137 assertEquals("foo,", /foo(?:a(x))?/.exec("foobx"), "lastParen setup"); | 137 assertEquals(["foo",undefined], /foo(?:a(x))?/.exec("foobx"), | 
| 
 
Søren Thygesen Gjesse
2011/04/15 10:20:51
void 0 instead of undefined?
 
Lasse Reichstein
2011/04/15 11:33:54
Not necessary, and not more readable.
 
 | |
| 138 "lastParen setup"); | |
| 138 assertEquals("", RegExp.lastParen, "lastParen"); | 139 assertEquals("", RegExp.lastParen, "lastParen"); | 
| 139 | 140 | 
| 140 // The same test for $1 to $9. | 141 // The same test for $1 to $9. | 
| 141 for (var i = 1; i <= 9; i++) { | 142 for (var i = 1; i <= 9; i++) { | 
| 142 var haystack = "foo"; | 143 var haystack = "foo"; | 
| 143 var re_text = "^foo"; | 144 var re_text = "^foo"; | 
| 144 for (var j = 0; j < i - 1; j++) { | 145 for (var j = 0; j < i - 1; j++) { | 
| 145 haystack += "x"; | 146 haystack += "x"; | 
| 146 re_text += "(x)"; | 147 re_text += "(x)"; | 
| 147 } | 148 } | 
| (...skipping 10 matching lines...) Expand all Loading... | |
| 158 RegExp.multiline = "foo"; | 159 RegExp.multiline = "foo"; | 
| 159 assertTrue(typeof RegExp.multiline == typeof Boolean(), "RegExp.multiline coerce s values to booleans"); | 160 assertTrue(typeof RegExp.multiline == typeof Boolean(), "RegExp.multiline coerce s values to booleans"); | 
| 160 RegExp.input = Number(); | 161 RegExp.input = Number(); | 
| 161 assertTrue(typeof RegExp.input == typeof String(), "RegExp.input coerces values to booleans"); | 162 assertTrue(typeof RegExp.input == typeof String(), "RegExp.input coerces values to booleans"); | 
| 162 | 163 | 
| 163 // Ensure that we save the correct string as the last subject when | 164 // Ensure that we save the correct string as the last subject when | 
| 164 // we do a match on a sliced string (the top one not the underlying). | 165 // we do a match on a sliced string (the top one not the underlying). | 
| 165 var foo = "lsdfj sldkfj sdklfj læsdfjl sdkfjlsdk fjsdl fjsdljskdj flsj flsdkj fl skd regexp: /foobar/\nldkfj sdlkfj sdkl"; | 166 var foo = "lsdfj sldkfj sdklfj læsdfjl sdkfjlsdk fjsdl fjsdljskdj flsj flsdkj fl skd regexp: /foobar/\nldkfj sdlkfj sdkl"; | 
| 166 assertTrue(/^([a-z]+): (.*)/.test(foo.substring(foo.indexOf("regexp:"))), "regex p: setup"); | 167 assertTrue(/^([a-z]+): (.*)/.test(foo.substring(foo.indexOf("regexp:"))), "regex p: setup"); | 
| 167 assertEquals("regexp", RegExp.$1, "RegExp.$1"); | 168 assertEquals("regexp", RegExp.$1, "RegExp.$1"); | 
| OLD | NEW |