| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 17 matching lines...) Expand all Loading... |
| 28 function testSideEffects(subject, re) { | 28 function testSideEffects(subject, re) { |
| 29 var counter = 0; | 29 var counter = 0; |
| 30 var side_effect_object = { valueOf: function() { return counter++; } }; | 30 var side_effect_object = { valueOf: function() { return counter++; } }; |
| 31 re.lastIndex = side_effect_object; | 31 re.lastIndex = side_effect_object; |
| 32 re.exec(subject); | 32 re.exec(subject); |
| 33 assertEquals(1, counter); | 33 assertEquals(1, counter); |
| 34 | 34 |
| 35 re.lastIndex = side_effect_object; | 35 re.lastIndex = side_effect_object; |
| 36 re.test(subject); | 36 re.test(subject); |
| 37 assertEquals(2, counter); | 37 assertEquals(2, counter); |
| 38 | |
| 39 re.lastIndex = side_effect_object; | |
| 40 subject.match(re); | |
| 41 assertEquals(3, counter); | |
| 42 | |
| 43 re.lastIndex = side_effect_object; | |
| 44 subject.replace(re, ""); | |
| 45 assertEquals(4, counter); | |
| 46 } | 38 } |
| 47 | 39 |
| 48 testSideEffects("zzzz", /a/); | 40 testSideEffects("zzzz", /a/); |
| 49 testSideEffects("zzzz", /a/g); | 41 testSideEffects("zzzz", /a/g); |
| 50 testSideEffects("xaxa", /a/); | 42 testSideEffects("xaxa", /a/); |
| 51 testSideEffects("xaxa", /a/g); | 43 testSideEffects("xaxa", /a/g); |
| OLD | NEW |