js/src/jit-test/tests/basic/bug576837-regexp.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Check that builtin character classes within ranges produce syntax
michael@0 3 * errors.
michael@0 4 *
michael@0 5 * Note that, per the extension in bug 351463, SpiderMonkey permits hyphens
michael@0 6 * adjacent to character class escapes in character classes, treating them as a
michael@0 7 * hyphen pattern character. Therefore /[\d-\s]/ is okay
michael@0 8 *
michael@0 9 * Note: /\b/ is the backspace escape, which is a single pattern character,
michael@0 10 * though it looks deceptively like a character class.
michael@0 11 */
michael@0 12
michael@0 13 function isRegExpSyntaxError(pattern) {
michael@0 14 try {
michael@0 15 var re = new RegExp(pattern);
michael@0 16 } catch (e) {
michael@0 17 if (e instanceof SyntaxError)
michael@0 18 return true;
michael@0 19 }
michael@0 20 return false;
michael@0 21 }
michael@0 22
michael@0 23 assertEq(isRegExpSyntaxError('[C-\\s]'), true);
michael@0 24 assertEq(isRegExpSyntaxError('[C-\\d]'), true);
michael@0 25 assertEq(isRegExpSyntaxError('[C-\\W]'), true);
michael@0 26 assertEq(isRegExpSyntaxError('[C-]'), false);
michael@0 27 assertEq(isRegExpSyntaxError('[-C]'), false);
michael@0 28 assertEq(isRegExpSyntaxError('[C-C]'), false);
michael@0 29 assertEq(isRegExpSyntaxError('[C-C]'), false);
michael@0 30 assertEq(isRegExpSyntaxError('[\\b-\\b]'), false);
michael@0 31 assertEq(isRegExpSyntaxError('[\\B-\\B]'), false);
michael@0 32 assertEq(isRegExpSyntaxError('[\\b-\\B]'), false);
michael@0 33 assertEq(isRegExpSyntaxError('[\\B-\\b]'), true);
michael@0 34 assertEq(isRegExpSyntaxError('[\\b-\\w]'), true);
michael@0 35 assertEq(isRegExpSyntaxError('[\\B-\\w]'), true);
michael@0 36
michael@0 37 /* Extension. */
michael@0 38 assertEq(isRegExpSyntaxError('[\\s-\\s]'), false);
michael@0 39 assertEq(isRegExpSyntaxError('[\\W-\\s]'), false);
michael@0 40 assertEq(isRegExpSyntaxError('[\\s-\\W]'), false);
michael@0 41 assertEq(isRegExpSyntaxError('[\\W-C]'), false);
michael@0 42 assertEq(isRegExpSyntaxError('[\\d-C]'), false);
michael@0 43 assertEq(isRegExpSyntaxError('[\\s-C]'), false);
michael@0 44 assertEq(isRegExpSyntaxError('[\\w-\\b]'), false);
michael@0 45 assertEq(isRegExpSyntaxError('[\\w-\\B]'), false);

mercurial