From e0b580ab4bae8c79a8c7a8cd72602dd729b41fe2 Mon Sep 17 00:00:00 2001 From: Tooru Fujisawa Date: Tue, 27 Sep 2016 13:57:00 +0900 Subject: [PATCH] Bug 1184922 - Part 3: Add a test for array destructuring with complicated default values. r=shu --- .../destructuring-array-default-call.js | 10 + .../destructuring-array-default-class.js | 72 +++++++ .../destructuring-array-default-function.js | 11 ++ .../destructuring-array-default-simple.js | 16 ++ .../destructuring-array-default-yield.js | 22 +++ js/src/tests/ecma_6/Expressions/shell.js | 186 ++++++++++++++++++ 6 files changed, 317 insertions(+) create mode 100644 js/src/tests/ecma_6/Expressions/destructuring-array-default-call.js create mode 100644 js/src/tests/ecma_6/Expressions/destructuring-array-default-class.js create mode 100644 js/src/tests/ecma_6/Expressions/destructuring-array-default-function.js create mode 100644 js/src/tests/ecma_6/Expressions/destructuring-array-default-simple.js create mode 100644 js/src/tests/ecma_6/Expressions/destructuring-array-default-yield.js diff --git a/js/src/tests/ecma_6/Expressions/destructuring-array-default-call.js b/js/src/tests/ecma_6/Expressions/destructuring-array-default-call.js new file mode 100644 index 000000000000..a3a3622054dc --- /dev/null +++ b/js/src/tests/ecma_6/Expressions/destructuring-array-default-call.js @@ -0,0 +1,10 @@ +var BUGNUMBER = 1184922; +var summary = "Array destructuring with various default values in various context - call/new expression"; + +print(BUGNUMBER + ": " + summary); + +testDestructuringArrayDefault("func()"); +testDestructuringArrayDefault("new func()"); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/ecma_6/Expressions/destructuring-array-default-class.js b/js/src/tests/ecma_6/Expressions/destructuring-array-default-class.js new file mode 100644 index 000000000000..80830892865a --- /dev/null +++ b/js/src/tests/ecma_6/Expressions/destructuring-array-default-class.js @@ -0,0 +1,72 @@ +var BUGNUMBER = 1184922; +var summary = "Array destructuring with various default values in various context - class expression and super/new.target"; + +print(BUGNUMBER + ": " + summary); + +testDestructuringArrayDefault(`class E { + constructor() {} + method() {} + get v() {} + set v(_) {} + static method() {} + static get v() {} + static set v(_) {} +}`); + +testDestructuringArrayDefault(`class E extends C { + constructor() {} + method() {} + get v() {} + set v(_) {} + static method() {} + static get v() {} + static set v(_) {} +}`); + +var opt = { + no_plain: true, + no_func: true, + no_func_arg: true, + no_gen: true, + no_gen_arg: true, + no_ctor: true, + no_method: true, + no_pre_super: true, + no_comp: true, + + no_derived_ctor: false, +}; +testDestructuringArrayDefault("super()", opt); + +opt = { + no_plain: true, + no_func: true, + no_func_arg: true, + no_gen: true, + no_gen_arg: true, + no_ctor: true, + no_comp: true, + + no_derived_ctor: false, + no_method: false, + no_pre_super: false, +}; +testDestructuringArrayDefault("super.foo()", opt); + +opt = { + no_plain: true, + + no_func: false, + no_func_arg: false, + no_gen: false, + no_gen_arg: false, + no_ctor: false, + no_derived_ctor: false, + no_method: false, + no_pre_super: false, + no_comp: false, +}; +testDestructuringArrayDefault("new.target", opt); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/ecma_6/Expressions/destructuring-array-default-function.js b/js/src/tests/ecma_6/Expressions/destructuring-array-default-function.js new file mode 100644 index 000000000000..5d2ffef1885e --- /dev/null +++ b/js/src/tests/ecma_6/Expressions/destructuring-array-default-function.js @@ -0,0 +1,11 @@ +var BUGNUMBER = 1184922; +var summary = "Array destructuring with various default values in various context - function expression"; + +print(BUGNUMBER + ": " + summary); + +testDestructuringArrayDefault("function f() {}"); +testDestructuringArrayDefault("function* g() {}"); +testDestructuringArrayDefault("() => {}"); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/ecma_6/Expressions/destructuring-array-default-simple.js b/js/src/tests/ecma_6/Expressions/destructuring-array-default-simple.js new file mode 100644 index 000000000000..50c6c37f3dc6 --- /dev/null +++ b/js/src/tests/ecma_6/Expressions/destructuring-array-default-simple.js @@ -0,0 +1,16 @@ +var BUGNUMBER = 1184922; +var summary = "Array destructuring with various default values in various context - simple literal"; + +print(BUGNUMBER + ": " + summary); + +testDestructuringArrayDefault("'foo'"); +testDestructuringArrayDefault("`foo`"); +testDestructuringArrayDefault("func`foo`"); + +testDestructuringArrayDefault("/foo/"); + +testDestructuringArrayDefault("{}"); +testDestructuringArrayDefault("[]"); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/ecma_6/Expressions/destructuring-array-default-yield.js b/js/src/tests/ecma_6/Expressions/destructuring-array-default-yield.js new file mode 100644 index 000000000000..57ff9e94729a --- /dev/null +++ b/js/src/tests/ecma_6/Expressions/destructuring-array-default-yield.js @@ -0,0 +1,22 @@ +var BUGNUMBER = 1184922; +var summary = "Array destructuring with various default values in various context - yield expression"; + +print(BUGNUMBER + ": " + summary); + +var opt = { + no_plain: true, + no_func: true, + no_func_arg: true, + no_gen_arg: true, + no_ctor: true, + no_derived_ctor: true, + no_method: true, + no_pre_super: true, + no_comp: true, + + no_gen: false, +}; +testDestructuringArrayDefault("yield 1", opt); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/ecma_6/Expressions/shell.js b/js/src/tests/ecma_6/Expressions/shell.js index e69de29bb2d1..0a0a24656bbf 100644 --- a/js/src/tests/ecma_6/Expressions/shell.js +++ b/js/src/tests/ecma_6/Expressions/shell.js @@ -0,0 +1,186 @@ +(function(global) { + function func() { + } + class C { + foo() { + } + static foo() { + } + } + + function test_one(pattern, val, opt) { + var stmts = []; + var i = 0; + var c; + + stmts.push(`var ${pattern} = ${val};`); + if (!opt.no_comp) { + stmts.push(`[for (x of [1]) ${pattern} = ${val}];`); + stmts.push(`[...(for (x of [1]) ${pattern} = ${val})];`); + } + + for (var stmt of stmts) { + if (!opt.no_plain) { + eval(` +${stmt} +`); + } + + if (!opt.no_func) { + eval(` +function f${i}() { + ${stmt} +} +f${i}(); +`); + i++; + + eval(` +var f${i} = function foo() { + ${stmt} +}; +f${i}(); +`); + i++; + + eval(` +var f${i} = () => { + ${stmt} +}; +f${i}(); +`); + i++; + } + + if (!opt.no_gen) { + eval(` +function* g${i}() { + ${stmt} +} +[...g${i}()]; +`); + i++; + + eval(` +var g${i} = function* foo() { + ${stmt} +}; +[...g${i}()]; +`); + i++; + } + + if (!opt.no_ctor) { + eval(` +class D${i} { + constructor() { + ${stmt} + } +} +new D${i}(); +`); + i++; + } + + if (!opt.no_derived_ctor) { + if (opt.no_pre_super) { + eval(` +class D${i} extends C { + constructor() { + ${stmt} + try { super(); } catch (e) {} + } +} +new D${i}(); +`); + i++; + } else { + eval(` +class D${i} extends C { + constructor() { + super(); + ${stmt} + } +} +new D${i}(); +`); + i++; + } + } + + if (!opt.no_method) { + eval(` +class D${i} extends C { + method() { + ${stmt} + } + static staticMethod() { + ${stmt} + } +} +new D${i}().method(); +D${i}.staticMethod(); +`); + i++; + } + } + + if (!opt.no_func_arg) { + eval(` +function f${i}(${pattern}) {} +f${i}(${val}); +`); + i++; + + eval(` +var f${i} = function foo(${pattern}) {}; +f${i}(${val}); +`); + i++; + + eval(` +var f${i} = (${pattern}) => {}; +f${i}(${val}); +`); + i++; + } + + if (!opt.no_gen_arg) { + eval(` +function* g${i}(${pattern}) {} +[...g${i}(${val})]; +`); + i++; + + eval(` +var g${i} = function* foo(${pattern}) {}; +[...g${i}(${val})]; +`); + i++; + } + } + + function test(expr, opt={}) { + var pattern = `[a=${expr}, ...c]`; + test_one(pattern, "[]", opt); + test_one(pattern, "[1]", opt); + + pattern = `[,a=${expr}]`; + test_one(pattern, "[]", opt); + test_one(pattern, "[1]", opt); + test_one(pattern, "[1, 2]", opt); + + pattern = `[{x: [a=${expr}]}]`; + test_one(pattern, "[{x: [1]}]", opt); + + pattern = `[x=[a=${expr}]=[]]`; + test_one(pattern, "[]", opt); + test_one(pattern, "[1]", opt); + + pattern = `[x=[a=${expr}]=[1]]`; + test_one(pattern, "[]", opt); + test_one(pattern, "[1]", opt); + } + + global.testDestructuringArrayDefault = test; +})(this);