|
|
@@ -319,6 +319,39 @@ var tests = [
|
|
|
return f10.call(this);
|
|
|
}
|
|
|
assert.areEqual(thisObj, f9.call(thisObj)()(), "This object is returned properly from the inner lambda defnied inside a double nested split scoped function");
|
|
|
+
|
|
|
+ function f11(a = this.x * 10, b = () => { a; return this; }) {
|
|
|
+ assert.areEqual(10, a, "this should be accessible in the parameter scope");
|
|
|
+ assert.areEqual(thisObj, this, "Body scope should get the right value for this object");
|
|
|
+ assert.isTrue(eval("thisObj == this"), "Eval should be able to access the this object properly");
|
|
|
+ return b;
|
|
|
+ }
|
|
|
+ assert.areEqual(thisObj, f11.call(thisObj)(), "Lambda defined in the param scope returns the right this object");
|
|
|
+
|
|
|
+ function f12(a = this.x * 10, b = () => { a; return this; }) {
|
|
|
+ var c = 100;
|
|
|
+ assert.areEqual(10, a, "this should be accessible in the parameter scope");
|
|
|
+ assert.areEqual(thisObj, this, "Body scope should get the right value for this object");
|
|
|
+ assert.isTrue(eval("thisObj == this"), "Eval should be able to access the this object properly");
|
|
|
+ assert.areEqual(thisObj, (() => this)(), "Lambda should capture the this object from body properly");
|
|
|
+ assert.areEqual(100, c, "Body variable should be unaffected by the slot allocation of this object");
|
|
|
+ return b;
|
|
|
+ }
|
|
|
+ assert.areEqual(thisObj, f12.call(thisObj)(), "Lambda defined in the param scope returns the right this object");
|
|
|
+
|
|
|
+ function f13(a = 10, b = () => { a; return this; }) {
|
|
|
+ var c = 100;
|
|
|
+ assert.areEqual(thisObj, this, "Body scope should get the right value for this object");
|
|
|
+ var d = () => this;
|
|
|
+ this.x = 5;
|
|
|
+ assert.isTrue(eval("this.x == 5"), "Eval should be able to access the this object properly after the field is updated");
|
|
|
+ assert.isTrue(eval("d().x == 5"), "Lambda should capture the this symbol from the body properly");
|
|
|
+ assert.isTrue(eval("a == 10"), "Eval should be able to access the first parameter properly");
|
|
|
+ assert.isTrue(eval("b().x == 5"), "Lambda from the param scope should capture the this symbol properly");
|
|
|
+ assert.isTrue(eval("d().x == 5"), "Lambda should capture the this symbol from the body properly");
|
|
|
+ return b;
|
|
|
+ }
|
|
|
+ assert.areEqual(5, f13.call(thisObj)().x, "Lambda defined in the param scope returns the same this object as the one in body");
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
@@ -688,6 +721,350 @@ var tests = [
|
|
|
assert.areEqual(1, f6()(), "Symbol capture at the param scope is unaffected by other references in the body and param");
|
|
|
}
|
|
|
},
|
|
|
+ {
|
|
|
+ name : "Split scope and arguments symbol",
|
|
|
+ body : function () {
|
|
|
+ assert.throws(function () { eval("function f(a = arguments, b = () => a) { }"); }, SyntaxError, "Use of arguments symbol is not allowed in non-simple parameter list with split scope", "Use of 'arguments' in non-simple parameter list is not supported when one of the formals is captured");
|
|
|
+ assert.throws(function () { eval("function f1() { function f2(a = arguments, b = () => a) { } }"); }, SyntaxError, "Use of arguments symbol is not allowed in non-simple parameter list with split scope inside another function", "Use of 'arguments' in non-simple parameter list is not supported when one of the formals is captured");
|
|
|
+ assert.throws(function () { eval("function f(a = arguments, b = () => a, c = eval('')) { }"); }, SyntaxError, "Use of arguments symbol is not allowed in non-simple parameter list with eval", "Use of 'arguments' in non-simple parameter list is not supported when one of the formals is captured");
|
|
|
+ assert.throws(function () { eval("function f(a = arguments = [1, 2], b = () => a) { }"); }, SyntaxError, "Use of arguments symbol is not allowed in non-simple parameter list with split scope", "Use of 'arguments' in non-simple parameter list is not supported when one of the formals is captured");
|
|
|
+ assert.throws(function () { eval("function f(a = 10, b = () => a, c = arguments) { }"); }, SyntaxError, "Use of arguments symbol is not allowed in non-simple parameter list with split scope", "Use of 'arguments' in non-simple parameter list is not supported when one of the formals is captured");
|
|
|
+ assert.throws(function () { eval("function f(a = 10, b = () => a, c = a = arguments) { }"); }, SyntaxError, "Use of arguments symbol is not allowed in non-simple parameter list with split scope", "Use of 'arguments' in non-simple parameter list is not supported when one of the formals is captured");
|
|
|
+ assert.throws(function () { eval("function f(a, b = () => { a; arguments}) { }"); }, SyntaxError, "Use of arguments symbol is not allowed in non-simple parameter list when captured in lambda method", "Use of 'arguments' in non-simple parameter list is not supported when one of the formals is captured");
|
|
|
+ assert.throws(function () { eval("function f(a = 10, b = (c = arguments) => a) { }"); }, SyntaxError, "Use of arguments symbol is not allowed in non-simple parameter list when captured in a lambda in split scope", "Use of 'arguments' in non-simple parameter list is not supported when one of the formals is captured");
|
|
|
+ assert.throws(function () { eval("function f(a, b = () => a, c = () => { return arguments; }) { }"); }, SyntaxError, "Use of arguments symbol is not allowed in non-simple parameter list in split scope when captured by a lambda method", "Use of 'arguments' in non-simple parameter list is not supported when one of the formals is captured");
|
|
|
+ assert.throws(function () { eval("function f(a = 10, b = () => a, c = () => () => arguments) { }"); }, SyntaxError, "Use of arguments symbol is not allowed in non-simple parameter list in split scope when captured by nested lambda", "Use of 'arguments' in non-simple parameter list is not supported when one of the formals is captured");
|
|
|
+ assert.throws(function () { eval("function f3(a, arguments = function () { return a; } ) { }"); }, SyntaxError, "Use of arguments as a parameter name is not allowed in non-simple parameter list in split scope when captured by nested lambda", "Use of 'arguments' in non-simple parameter list is not supported when one of the formals is captured");
|
|
|
+ assert.throws(function () { eval("function f3({a, arguments = function () { return a; }}) { }"); }, SyntaxError, "Use of arguments as a parameter name is not allowed in destructuring parameter list in split scope when captured by nested lambda", "Use of 'arguments' in non-simple parameter list is not supported when one of the formals is captured");
|
|
|
+ assert.throws(function () { eval("function f3({a = arguments}, b = function () { return a; } ) { }"); }, SyntaxError, "Use of arguments is not allowed in destructuring parameter list in split scope when captured by nested lambda", "Use of 'arguments' in non-simple parameter list is not supported when one of the formals is captured");
|
|
|
+
|
|
|
+ function f1(a, b = () => a) {
|
|
|
+ eval("");
|
|
|
+ b = () => { return arguments; };
|
|
|
+ assert.areEqual(1, arguments[0], "Arguments object receives the first parameter properly");
|
|
|
+ assert.areEqual(1, b()[0], "First argument receives the right value passed in");
|
|
|
+ assert.areEqual(undefined, b()[1], "Second argument receives the right value passed in");
|
|
|
+ assert.areEqual(2, arguments.length, "Arguments should have only two elements in it");
|
|
|
+ }
|
|
|
+ f1(1, undefined);
|
|
|
+
|
|
|
+ function f2(a, b = () => { return a; }) {
|
|
|
+ a = 10;
|
|
|
+ assert.areEqual(1, arguments[0], "First argument is properly received");
|
|
|
+ assert.areEqual(2, arguments[2], "Third argument is properly received");
|
|
|
+ assert.areEqual(3, arguments.length, "Only three arguments are passed in");
|
|
|
+ (() => { arguments = [3, 4]; a; })();
|
|
|
+ assert.areEqual(3, arguments[0], "Arguments symbol is updated with the new value when the lambda is executed");
|
|
|
+ assert.areEqual(4, arguments[1], "New array is properly assigned to arguments symbol");
|
|
|
+ assert.areEqual(2, arguments.length, "New array has only elements");
|
|
|
+
|
|
|
+ return b;
|
|
|
+ }
|
|
|
+ assert.areEqual(1, f2(1, undefined, 2)(), "Param scope method properly captures the first parameter");
|
|
|
+
|
|
|
+ function f3(a, b = () => { return a; }) {
|
|
|
+ eval("");
|
|
|
+ a = 10;
|
|
|
+ assert.areEqual(1, arguments[0], "First argument is properly received");
|
|
|
+ assert.areEqual(2, arguments[2], "Third argument is properly received");
|
|
|
+ assert.areEqual(3, arguments.length, "Only three arguments are passed in");
|
|
|
+ (() => { arguments = [3, 4]; a; })();
|
|
|
+ assert.areEqual(3, arguments[0], "Arguments symbol is updated with the new value when the lambda is executed");
|
|
|
+ assert.areEqual(4, arguments[1], "New array is properly assigned to arguments symbol");
|
|
|
+ assert.areEqual(2, arguments.length, "New array has only elements");
|
|
|
+
|
|
|
+ return b;
|
|
|
+ }
|
|
|
+ assert.areEqual(1, f3(1, undefined, 2)(), "Param scope method properly captures the first parameter, with eval in the body");
|
|
|
+
|
|
|
+ function f4(a, b = function () { a; } ) {
|
|
|
+ var c = 10;
|
|
|
+ assert.areEqual(1, arguments[0], "Arguments symbol properly receives the passed in values");
|
|
|
+ eval("");
|
|
|
+ }
|
|
|
+ f4(1);
|
|
|
+
|
|
|
+ function f5(a, b = function () { a; } ) {
|
|
|
+ var c = 10;
|
|
|
+ assert.areEqual(1, arguments[0], "Arguments symbol properly receives the passed in values");
|
|
|
+ arguments = 100;
|
|
|
+ assert.areEqual(100, arguments, "Arguments is updated after the assignment");
|
|
|
+ eval("");
|
|
|
+ }
|
|
|
+ f5(1);
|
|
|
+
|
|
|
+ function f6(a, b = function () { a; } ) {
|
|
|
+ assert.areEqual(1, arguments[0], "Arguments symbol properly receives the passed in values");
|
|
|
+ arguments = 100;
|
|
|
+ assert.areEqual(100, arguments, "Arguments is updated after the assignment");
|
|
|
+ }
|
|
|
+ f6(1);
|
|
|
+
|
|
|
+ function f7(a, b = function () { a; } ) {
|
|
|
+ assert.areEqual(5, arguments(), "Function definition is hoisted");
|
|
|
+ function arguments() { return 5; }
|
|
|
+ }
|
|
|
+ f7(1);
|
|
|
+
|
|
|
+ function f8(a, b = function () { a; } ) {
|
|
|
+ assert.areEqual(5, arguments(), "Function definition is hoisted");
|
|
|
+ function arguments() { return 5; }
|
|
|
+ eval("");
|
|
|
+ }
|
|
|
+ f8(1);
|
|
|
+
|
|
|
+ function f9(a, b = function () { a; } ) {
|
|
|
+ assert.areEqual(1, eval("a"), "Eval should be able to access the first argument properly");
|
|
|
+ assert.areEqual(1, eval("arguments[0]"), "Eval should be able to access the first argument properly from arguments object");
|
|
|
+ assert.areEqual(1, arguments[0], "Arguments symbol properly receives the passed in values");
|
|
|
+ arguments = 100;
|
|
|
+ assert.areEqual(100, arguments, "Arguments is updated after the assignment");
|
|
|
+ assert.areEqual(100, eval("arguments"), "Updated value of arguments is visible in eval");
|
|
|
+ assert.areEqual(1, eval("a"), "First argument remains unchanged after the arguments are updated");
|
|
|
+ }
|
|
|
+ f9(1);
|
|
|
+
|
|
|
+ function f10(a, b = function () { a; } ) {
|
|
|
+ assert.areEqual(1, arguments[0], "Arguments symbol properly receives the passed in values");
|
|
|
+ var arguments = 100;
|
|
|
+ assert.areEqual(100, arguments, "Arguments is updated after the assignment");
|
|
|
+ }
|
|
|
+ f10(1);
|
|
|
+
|
|
|
+ function f11(a, b = function () { a; } ) {
|
|
|
+ assert.areEqual(1, arguments[0], "Arguments symbol properly receives the passed in values");
|
|
|
+ var arguments = 100;
|
|
|
+ assert.areEqual(100, arguments, "Arguments is updated after the assignment");
|
|
|
+ eval("");
|
|
|
+ }
|
|
|
+ f11(1);
|
|
|
+
|
|
|
+ function f12(a, b = function () { a; } ) {
|
|
|
+ assert.areEqual(1, arguments[0], "Arguments symbol properly receives the passed in values");
|
|
|
+ b = () => arguments;
|
|
|
+ assert.areEqual(1, b()[0], "Lambda captures the right arguments symbol");
|
|
|
+ var arguments = 100;
|
|
|
+ assert.areEqual(100, arguments, "Arguments is updated after the assignment");
|
|
|
+ assert.areEqual(100, b(), "Lambda now gives the updated value");
|
|
|
+ eval("");
|
|
|
+ }
|
|
|
+ f12(1);
|
|
|
+
|
|
|
+ function f13(a, b = () => { return a; }) {
|
|
|
+ a = 10;
|
|
|
+ assert.areEqual(1, arguments[0], "First argument is properly received");
|
|
|
+ assert.areEqual(2, arguments[2], "Third argument is properly received");
|
|
|
+ assert.areEqual(3, arguments.length, "Only three arguments are passed in");
|
|
|
+ ((c = arguments = [3, 4]) => { a; })();
|
|
|
+ assert.areEqual(3, arguments[0], "Arguments symbol is updated with the new value when the lambda is executed");
|
|
|
+ assert.areEqual(4, arguments[1], "New array is properly assigned to arguments symbol");
|
|
|
+ assert.areEqual(2, arguments.length, "New array has only elements");
|
|
|
+
|
|
|
+ return b;
|
|
|
+ }
|
|
|
+ assert.areEqual(1, f13(1, undefined, 2)(), "Param scope method properly captures the first parameter");
|
|
|
+
|
|
|
+ function f14(a, b = () => { return a; }) {
|
|
|
+ eval("");
|
|
|
+ a = 10;
|
|
|
+ assert.areEqual(1, arguments[0], "First argument is properly received");
|
|
|
+ assert.areEqual(2, arguments[2], "Third argument is properly received");
|
|
|
+ assert.areEqual(3, arguments.length, "Only three arguments are passed in");
|
|
|
+ ((c = arguments = [3, 4]) => { a; })();
|
|
|
+ assert.areEqual(3, arguments[0], "Arguments symbol is updated with the new value when the lambda is executed");
|
|
|
+ assert.areEqual(4, arguments[1], "New array is properly assigned to arguments symbol");
|
|
|
+ assert.areEqual(2, arguments.length, "New array has only elements");
|
|
|
+
|
|
|
+ return b;
|
|
|
+ }
|
|
|
+ assert.areEqual(1, f14(1, undefined, 2)(), "Param scope method properly captures the first parameter, with eval in the body");
|
|
|
+
|
|
|
+ function f15(a, b = function () { a; }, ...c) {
|
|
|
+ assert.areEqual(1, arguments[0], "Checking first argument");
|
|
|
+ assert.areEqual(undefined, arguments[1], "Checking second argument");
|
|
|
+ assert.areEqual(2, arguments[2], "Checking third argument");
|
|
|
+ assert.areEqual(3, arguments[3], "Checking fourth argument");
|
|
|
+ assert.areEqual([2, 3], c, "Rest argument should get the trailing parameters properly");
|
|
|
+ var arguments = 100;
|
|
|
+ assert.areEqual(100, arguments, "Arguments is updated after the assignment");
|
|
|
+ assert.areEqual([2, 3], c, "Rest should remain unaffected when arguments is updated");
|
|
|
+ eval("");
|
|
|
+ }
|
|
|
+ f15(1, undefined, 2, 3);
|
|
|
+
|
|
|
+ var f16 = function f17(a, b = function () { a; }, ...c) {
|
|
|
+ if (a === 1) {
|
|
|
+ assert.areEqual(1, arguments[0], "Checking first argument");
|
|
|
+ assert.areEqual(undefined, arguments[1], "Checking second argument");
|
|
|
+ assert.areEqual(2, arguments[2], "Checking third argument");
|
|
|
+ assert.areEqual(3, arguments[3], "Checking fourth argument");
|
|
|
+ assert.areEqual([2, 3], c, "Rest argument should get the trailing parameters properly");
|
|
|
+ return f17(undefined, undefined, ...c);
|
|
|
+ } else {
|
|
|
+ assert.areEqual(undefined, arguments[0], "Checking first argument on the recursive call");
|
|
|
+ assert.areEqual(undefined, arguments[1], "Checking second argument on the recursive call");
|
|
|
+ assert.areEqual(2, arguments[2], "Checking third argument on the recursive call");
|
|
|
+ assert.areEqual(3, arguments[3], "Checking fourth argument on the recursive call");
|
|
|
+ assert.areEqual([2, 3], c, "Rest argument should get the trailing parameters properly");
|
|
|
+ var arguments = 100;
|
|
|
+ assert.areEqual(100, arguments, "Arguments is updated after the assignment");
|
|
|
+ assert.areEqual([2, 3], c, "Rest should remain unaffected when arguments is updated");
|
|
|
+ return eval("c");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ assert.areEqual([2, 3], f16(1, undefined, 2, 3), "Rest should remain unaffected when arguments is updated");
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "Split scope and super call",
|
|
|
+ body: function () {
|
|
|
+ class c1 {
|
|
|
+ constructor() {
|
|
|
+ return { x : 1 };
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ class c2 extends c1 {
|
|
|
+ constructor(a = 1, b = () => { assert.areEqual(1, super().x, "Super is accessible in the param scope"); return a; }) {
|
|
|
+ var c = 10;
|
|
|
+ a = 20;
|
|
|
+ (() => assert.areEqual(10, c, "Allocation of scope slot for super property shouldn't affect the body variables"))();
|
|
|
+ assert.areEqual(1, b(), "Function defined in the param scope should capture the formal");
|
|
|
+ return {};
|
|
|
+ }
|
|
|
+ }
|
|
|
+ new c2();
|
|
|
+
|
|
|
+ class c3 extends c1 {
|
|
|
+ constructor(a = 1, b = () => { return a; }) {
|
|
|
+ (() => assert.areEqual(1, super().x, "Lambda should be able to access the super method properly in the body"))();
|
|
|
+ a = 10;
|
|
|
+ assert.areEqual(1, b(), "Function defined in the param scope should capture the formal");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ new c3();
|
|
|
+
|
|
|
+ class c4 extends c1 {
|
|
|
+ constructor(a = 1, b = () => { return a; }) {
|
|
|
+ var c = 10;
|
|
|
+ (() => assert.areEqual(10, c, "Allocation of scope slot for super property shouldn't affect the body variables"))();
|
|
|
+ assert.areEqual(1, b(), "Function defined in the param scope should capture the formal");
|
|
|
+ assert.areEqual(1, eval("super().x"), "Eval should be able to access the super property properly");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ new c4();
|
|
|
+
|
|
|
+ class c5 extends c1 {
|
|
|
+ constructor(a = super().x, b = () => { return a; }) {
|
|
|
+ assert.areEqual(1, a, "First formal calls the super from the param scope");
|
|
|
+ var c = 10;
|
|
|
+ (() => assert.areEqual(10, c, "Allocation of scope slot for super property shouldn't affect the body variables"))();
|
|
|
+ assert.areEqual(1, b(), "Function defined in the param scope should capture the formal");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ new c5();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "Split scope and super property",
|
|
|
+ body: function () {
|
|
|
+ class c1 {
|
|
|
+ foo () {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ class c2 extends c1 {
|
|
|
+ foo(a = 1, b = () => { assert.areEqual(1, super.foo(), "Super property access works fine from a lambda defined in the param scope"); return a; }) {
|
|
|
+ a = 20;
|
|
|
+ var c = 10;
|
|
|
+ (() => assert.areEqual(10, c, "Allocation of scope slot for super property shouldn't affect the body variables"))();
|
|
|
+ assert.areEqual(1, b(), "Function defined in the param scope should capture the formal");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ (new c2()).foo();
|
|
|
+
|
|
|
+ class c3 extends c1 {
|
|
|
+ foo(a = 1, b = () => { return a; }) {
|
|
|
+ var c = 10;
|
|
|
+ a = 20;
|
|
|
+ (() => assert.areEqual(1, super.foo(), "Super property access works fine from a lambda defined in the body scope"))();
|
|
|
+ assert.areEqual(1, b(), "Function defined in the param scope should capture the formal");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ (new c3()).foo();
|
|
|
+
|
|
|
+ class c4 extends c1 {
|
|
|
+ foo(a = 1, b = () => { return a; }) {
|
|
|
+ var c = 10;
|
|
|
+ a = 20;
|
|
|
+ (() => assert.areEqual(10, c, "Allocation of scope slot for super property shouldn't affect the body variables"))();
|
|
|
+ assert.areEqual(1, b(), "Function defined in the param scope should capture the formal");
|
|
|
+ assert.areEqual(1, eval("super.foo()"), "Eval should be able to access the super property properly from the body scope");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ (new c4()).foo();
|
|
|
+
|
|
|
+ class c5 extends c1 {
|
|
|
+ foo(a = super.foo(), b = () => { return a; }) {
|
|
|
+ assert.areEqual(1, a, "First formal uses the super property from the param scope");
|
|
|
+ var c = 10;
|
|
|
+ (() => assert.areEqual(10, c, "Allocation of scope slot for super property shouldn't affect the body variables"))();
|
|
|
+ a = 20;
|
|
|
+ assert.areEqual(1, b(), "Function defined in the param scope should capture the formal");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ (new c5()).foo();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "Split scope and new.target",
|
|
|
+ body: function () {
|
|
|
+ class c1 {
|
|
|
+ constructor(newTarget) {
|
|
|
+ assert.isTrue(newTarget == new.target, "Base class should receive the right value for new.target");
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ class c2 extends c1 {
|
|
|
+ constructor(a = 1, b = () => { assert.isTrue(new.target == c2, "new.target should have the derived class value in the param scope"); return a; }) {
|
|
|
+ super(c2);
|
|
|
+ var c = 10;
|
|
|
+ a = 20;
|
|
|
+ (() => assert.areEqual(10, c, "Allocation of scope slot for super property shouldn't affect the body variables"))();
|
|
|
+ assert.areEqual(1, b(), "Function defined in the param scope should capture the formal");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ new c2();
|
|
|
+
|
|
|
+ class c3 extends c1 {
|
|
|
+ constructor(a = 1, b = () => { return a; }) {
|
|
|
+ super(c3);
|
|
|
+ var c = 10;
|
|
|
+ (() => assert.isTrue(new.target == c3, "new.target should be the derived class in the body scope when captured by lambda"))();
|
|
|
+ assert.isTrue(new.target == c3, "new.target should be the derived class in the body scope");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ new c3();
|
|
|
+
|
|
|
+ class c4 extends c1 {
|
|
|
+ constructor(a = 1, b = () => { return a; }) {
|
|
|
+ super(c4);
|
|
|
+ assert.isTrue(eval("new.target == c4"), "new.target should be the derived class inside eval");
|
|
|
+ assert.isTrue(new.target == c4, "new.target should be the derived class in the body scope");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ new c4();
|
|
|
+
|
|
|
+ class c5 extends c1 {
|
|
|
+ constructor(a = new.target, b = () => { return a; }) {
|
|
|
+ super(c5);
|
|
|
+ assert.isTrue(a == c5, "new.target accessed from the param scope should work fine");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ new c5();
|
|
|
+ }
|
|
|
+ },
|
|
|
{
|
|
|
name: "Split parameter scope and eval",
|
|
|
body: function () {
|
|
|
@@ -745,7 +1122,111 @@ var tests = [
|
|
|
};
|
|
|
f4.call(1, 2);
|
|
|
}
|
|
|
- },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "Split scope and with",
|
|
|
+ body: function () {
|
|
|
+ function f1(a, b, c = function () { a; }) {
|
|
|
+ with ({}) {
|
|
|
+ var d = function () {
|
|
|
+ return 10;
|
|
|
+ };
|
|
|
+ assert.areEqual(10, d(), "With inside a split scope function should work fine");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ f1();
|
|
|
+
|
|
|
+ function f2(a, b, c = function () { a; }) {
|
|
|
+ var d = function () {
|
|
|
+ return 10;
|
|
|
+ };
|
|
|
+ with ({}) {
|
|
|
+ assert.areEqual(10, d(), "With inside a split scope function should be able to access the function definition from the body");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ f2();
|
|
|
+
|
|
|
+ function f3(a, b = function () { return 10; }, c = function () { a; }) {
|
|
|
+ with ({}) {
|
|
|
+ assert.areEqual(10, b(), "With inside a split scope function should be able to access the function definition from the param scope");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ f3();
|
|
|
+
|
|
|
+ function f4(a, b = function () { return 10; }, c = function () { a; }) {
|
|
|
+ var d = {
|
|
|
+ e : function () { return 10; }
|
|
|
+ };
|
|
|
+ e = function () { return 100; };
|
|
|
+ with (d) {
|
|
|
+ assert.areEqual(10, e(), "With should use the function definition inside the object not the one from body");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ f4();
|
|
|
+
|
|
|
+ function f5(a, b = { d : function () { return 10; } }, c = function () { a; }) {
|
|
|
+ var d = { };
|
|
|
+ with (b) {
|
|
|
+ assert.areEqual(10, d(), "With should use the function definition inside the object from the param scope not the one from body");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ f5();
|
|
|
+
|
|
|
+ var v6 = 100
|
|
|
+ function f6(a, b, c = function () { a; }, e = function () { with({}) { assert.areEqual(100, v6, "With inside param scope should be able to access var from outside"); } }, f = e()) {
|
|
|
+ var v6 = { };
|
|
|
+ }
|
|
|
+ f6();
|
|
|
+
|
|
|
+ function f7(a, b, c = function () { a; }) {
|
|
|
+ with ({}) {
|
|
|
+ assert.areEqual(100, v6, "With inside body scope should be able to access var from outside");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ f7();
|
|
|
+
|
|
|
+ function f8() {
|
|
|
+ function f9() {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ var v1 = 10;
|
|
|
+ function f10(a = 10, b = function f11() {
|
|
|
+ a;
|
|
|
+ assert.areEqual(10, v1, "Function in the param scope should be able to access the outside variable");
|
|
|
+ with ({}) {
|
|
|
+ assert.areEqual(1, f9(), "With construct inside a param scoped function should be able to execute functions from outside");
|
|
|
+ }
|
|
|
+ }) {
|
|
|
+ b();
|
|
|
+ };
|
|
|
+ f10();
|
|
|
+ }
|
|
|
+ f8();
|
|
|
+ f8();
|
|
|
+
|
|
|
+ function f12() {
|
|
|
+ function f13() {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ var v2 = 100;
|
|
|
+ function f14(a = 10, b = function () {
|
|
|
+ assert.areEqual(10, a, "Function in the param scope should be able to access the formal from parent");
|
|
|
+ return function () {
|
|
|
+ assert.areEqual(10, a, "Function nested in the param scope should be able to access the formal from the split scoped function");
|
|
|
+ assert.areEqual(100, v2, "Function in the param scope should be able to access the outside variable");
|
|
|
+ with ({}) {
|
|
|
+ assert.areEqual(1, f13(), "With construct inside a param scoped function should be able to execute functions from outside");
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }) {
|
|
|
+ b()();
|
|
|
+ };
|
|
|
+ f14();
|
|
|
+ }
|
|
|
+ f12();
|
|
|
+ f12();
|
|
|
+ }
|
|
|
+ },
|
|
|
{
|
|
|
name: "Basic eval in parameter scope",
|
|
|
body: function () {
|