diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/jit-test/tests/basic/object-shorthand.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/basic/object-shorthand.js')
-rw-r--r-- | js/src/jit-test/tests/basic/object-shorthand.js | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/basic/object-shorthand.js b/js/src/jit-test/tests/basic/object-shorthand.js new file mode 100644 index 0000000000..934f466800 --- /dev/null +++ b/js/src/jit-test/tests/basic/object-shorthand.js @@ -0,0 +1,90 @@ + +load(libdir + 'asserts.js'); + +// globals: +a = b = get = set = eval = arguments = 10; + +assertEq({arguments}.arguments, 10); + +var o = {a, b: b, get, set: set}; +assertEq(o.a, 10); +assertEq(o.b, 10); +assertEq(o.get, 10); +assertEq(o.set, 10); + +var names = ['a', 'get', 'set', 'eval']; +// global +names.forEach(ident => + assertEq(new Function('return {' + ident + '}.' + ident + ';')(), 10)); +// local +names.forEach(ident => + assertEq(new Function('var ' + ident + ' = 20; return {' + ident + '}.' + ident + ';')(), 20)); +// scope +names.forEach(ident => + assertEq(new Function('var ' + ident + ' = 30; return (function () {return {' + ident + '}.' + ident + ';})();')(), 30)); + +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' +]; + +// non-identifiers should also throw +var nonidents = [ + '"str"', + '0' +]; + +reserved.concat(nonidents).forEach(ident => + assertThrowsInstanceOf(() => new Function('return {' + ident + '}'), SyntaxError)); + +var reservedStrict = [ + 'implements', + 'interface', + 'package', + 'private', + 'protected', + 'public', + 'static', + // XXX: according to 12.1.1, these should only be errors in strict code: + // see https://bugzilla.mozilla.org/show_bug.cgi?id=1032150 + //'let', + //'yield' +]; + +reservedStrict.forEach(ident => + assertEq(new Function('var ' + ident + ' = 10; return {' + ident + '}.' + ident + ';')(), 10)); + +reservedStrict.concat(['let', 'yield']).forEach(ident => + assertThrowsInstanceOf(() => new Function('"use strict"; return {' + ident + '}'), SyntaxError)); + |