diff options
Diffstat (limited to 'js/src/jit-test/tests/basic/destructuring-rest-identifiers.js')
-rw-r--r-- | js/src/jit-test/tests/basic/destructuring-rest-identifiers.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/basic/destructuring-rest-identifiers.js b/js/src/jit-test/tests/basic/destructuring-rest-identifiers.js new file mode 100644 index 000000000..437a66668 --- /dev/null +++ b/js/src/jit-test/tests/basic/destructuring-rest-identifiers.js @@ -0,0 +1,73 @@ + +load(libdir + 'asserts.js'); +load(libdir + 'eqArrayHelper.js'); + +var reserved = [ + 'break', + 'do', + 'in', + 'typeof', + 'case', + 'else', + 'instanceof', + 'var', + 'catch', + 'export', + 'new', + 'void', + 'class', + 'extends', + 'return', + 'while', + 'const', + 'finally', + 'super', + 'with', + 'continue', + 'for', + 'switch', + 'debugger', + 'function', + 'this', + 'delete', + 'import', + 'try', + 'enum', + 'null', + 'true', + 'false' +]; +reserved.forEach(ident => { + assertThrowsInstanceOf(() => new Function('var [...' + ident + '] = []'), SyntaxError); +}); + +var strictIdentifiers = [ + // XXX: see bug 1032150. Once fixed, please uncomment these values and + // remove the assertions below + //'yield', + //'let', + 'eval', + 'arguments', + 'implements', + 'interface', + 'package', + 'private', + 'protected', + 'public', + 'static' +]; +assertThrowsInstanceOf(() => new Function('[...yield] = []'), SyntaxError); +assertThrowsInstanceOf(() => new Function('"use strict"; [...let] = []'), SyntaxError); + +strictIdentifiers.forEach(ident => + assertThrowsInstanceOf(() => + new Function('"use strict"; [...' + ident + '] = []'), SyntaxError)); + +var globalEval = eval; +strictIdentifiers.forEach(ident => { + globalEval(ident + ' = null'); + assertEqArray(new Function('input', '[, ...' + ident + '] = input;' + + 'return ' + ident + )([1, 2, 3]), [2, 3]); +}); + |