Created
December 23, 2011 03:14
-
-
Save hideo55/1512988 to your computer and use it in GitHub Desktop.
V8 Engine cached target string of pattern match.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var assert = function(expr, msg){ | |
var message = 'Assertion failed'; | |
if(msg) message += ': ' + msg; | |
if(!expr) throw new Error(message); | |
}; | |
var matchResultA; | |
(function(){ | |
var A = RegExp('.'); | |
matchResultA = A.exec('foo')[0]; | |
})(); | |
(function(){ | |
var B = new RegExp('.'); | |
var C = new RegExp('.'); | |
assert( B !== C, 'B and C are diffent object' ); | |
var matchResultB = B.exec()[0]; | |
var matchResultC = C.exec()[0]; | |
assert( matchResultA === matchResultB, 'Pattern match result of B equals result of A' ); | |
assert( matchResultB === matchResultC, 'Pattern match result of C equals result of B' ); | |
assert( matchResultA === /./.exec()[0] ); | |
assert( /.../.exec()[0] == 'foo' ); | |
// String 'foo' cached by V8? | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment