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.

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

mercurial