Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / js / script-tests / string-match.js
blob92a1f6562f1ab3e648ef916352fcaf1924b0b5d1
1 description(
2 "String.match(…) test"
3 );
5 // match with a global regexp should set lastIndex to zero; if read-only this should throw.
6 // If the regexp is not global, lastIndex is not modified.
7 var re;
8 function testMatch(_re, readonly)
10 re = _re;
11 re.lastIndex = 3;
12 if (readonly)
13 re = Object.defineProperty(re, 'lastIndex', {writable:false});
14 return '0x1x2'.match(re);
17 shouldBe("testMatch(/x/g, false)", '["x","x"]');
18 shouldThrow("testMatch(/x/g, true)");
19 shouldBe("testMatch(/x/, false)", '["x"]');
20 shouldBe("testMatch(/x/, true)", '["x"]');
21 shouldBe("testMatch(/x/g, false); re.lastIndex", '0');
22 shouldThrow("testMatch(/x/g, true); re.lastIndex");
23 shouldBe("testMatch(/x/, false); re.lastIndex", '3');
24 shouldBe("testMatch(/x/, true); re.lastIndex", '3');