From 2c432e35b261a2474f122631b02eff3e031de383 Mon Sep 17 00:00:00 2001 From: Leo Balter Date: Tue, 17 Mar 2020 14:51:05 -0700 Subject: [PATCH] Add coverage for EvaluateNew Fix #2527 --- ...rExpr-fn-ref-before-args-eval-fn-wrapup.js | 37 +++++++++++++++++++ .../new/ctorExpr-fn-ref-before-args-eval.js | 32 ++++++++++++++++ ...orExpr-isCtor-after-args-eval-fn-wrapup.js | 36 ++++++++++++++++++ .../new/ctorExpr-isCtor-after-args-eval.js | 30 +++++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 test/language/expressions/new/ctorExpr-fn-ref-before-args-eval-fn-wrapup.js create mode 100644 test/language/expressions/new/ctorExpr-fn-ref-before-args-eval.js create mode 100644 test/language/expressions/new/ctorExpr-isCtor-after-args-eval-fn-wrapup.js create mode 100644 test/language/expressions/new/ctorExpr-isCtor-after-args-eval.js diff --git a/test/language/expressions/new/ctorExpr-fn-ref-before-args-eval-fn-wrapup.js b/test/language/expressions/new/ctorExpr-fn-ref-before-args-eval-fn-wrapup.js new file mode 100644 index 0000000000..84252195e2 --- /dev/null +++ b/test/language/expressions/new/ctorExpr-fn-ref-before-args-eval-fn-wrapup.js @@ -0,0 +1,37 @@ +// Copyright (C) 2020 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-new-operator +description: > + The constructExpr is referenced before arguments in the same EvaluateNew evaluation. + Function wrap-up to use the same function level binding ref. +info: | + NewExpression : new NewExpression + 1. Return ? EvaluateNew(NewExpression, empty). + MemberExpression : new MemberExpression Arguments + 1. Return ? EvaluateNew(MemberExpression, Arguments). + + Runtime Semantics: EvaluateNew + + 3. Let ref be the result of evaluating constructExpr. + 4. Let constructor be ? GetValue(ref). + 5. If arguments is empty, let argList be a new empty List. + 6. Else, + a. Let argList be ? ArgumentListEvaluation of arguments. + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + 8. Return ? Construct(constructor, argList). +---*/ + +function fn() { + var x = function() { + this.foo = 42; + }; + + var result = new x(x = 1); + + assert.sameValue(x, 1); + assert.sameValue(result.foo, 42); +} + +fn(); diff --git a/test/language/expressions/new/ctorExpr-fn-ref-before-args-eval.js b/test/language/expressions/new/ctorExpr-fn-ref-before-args-eval.js new file mode 100644 index 0000000000..9ad8ad3f42 --- /dev/null +++ b/test/language/expressions/new/ctorExpr-fn-ref-before-args-eval.js @@ -0,0 +1,32 @@ +// Copyright (C) 2020 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-new-operator +description: > + The constructExpr is referenced before arguments in the same EvaluateNew evaluation. +info: | + NewExpression : new NewExpression + 1. Return ? EvaluateNew(NewExpression, empty). + MemberExpression : new MemberExpression Arguments + 1. Return ? EvaluateNew(MemberExpression, Arguments). + + Runtime Semantics: EvaluateNew + + 3. Let ref be the result of evaluating constructExpr. + 4. Let constructor be ? GetValue(ref). + 5. If arguments is empty, let argList be a new empty List. + 6. Else, + a. Let argList be ? ArgumentListEvaluation of arguments. + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + 8. Return ? Construct(constructor, argList). +---*/ + +var x = function() { + this.foo = 42; +}; + +var result = new x(x = 1); + +assert.sameValue(x, 1); +assert.sameValue(result.foo, 42); diff --git a/test/language/expressions/new/ctorExpr-isCtor-after-args-eval-fn-wrapup.js b/test/language/expressions/new/ctorExpr-isCtor-after-args-eval-fn-wrapup.js new file mode 100644 index 0000000000..d9de3f7d75 --- /dev/null +++ b/test/language/expressions/new/ctorExpr-isCtor-after-args-eval-fn-wrapup.js @@ -0,0 +1,36 @@ +// Copyright (C) 2020 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-new-operator +description: > + The IsConstructor(ctor) happens after evaluating the arguments, use the correct ctor. + Function wrap-up to use the same function level binding ref +info: | + NewExpression : new NewExpression + 1. Return ? EvaluateNew(NewExpression, empty). + MemberExpression : new MemberExpression Arguments + 1. Return ? EvaluateNew(MemberExpression, Arguments). + + Runtime Semantics: EvaluateNew + + 3. Let ref be the result of evaluating constructExpr. + 4. Let constructor be ? GetValue(ref). + 5. If arguments is empty, let argList be a new empty List. + 6. Else, + a. Let argList be ? ArgumentListEvaluation of arguments. + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + 8. Return ? Construct(constructor, argList). +---*/ + +var ref; +var argz; + +assert.throws(TypeError, function() { + var x = 42; + ref = x; + new x(x = function() {}, argz = 39); +}); + +assert.sameValue(ref, 42); +assert.sameValue(argz, 39, 'arguments evaluated before checking valid ctor'); diff --git a/test/language/expressions/new/ctorExpr-isCtor-after-args-eval.js b/test/language/expressions/new/ctorExpr-isCtor-after-args-eval.js new file mode 100644 index 0000000000..248a3800dc --- /dev/null +++ b/test/language/expressions/new/ctorExpr-isCtor-after-args-eval.js @@ -0,0 +1,30 @@ +// Copyright (C) 2020 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-new-operator +description: > + The IsConstructor(ctor) happens after evaluating the arguments, use the correct ctor +info: | + NewExpression : new NewExpression + 1. Return ? EvaluateNew(NewExpression, empty). + MemberExpression : new MemberExpression Arguments + 1. Return ? EvaluateNew(MemberExpression, Arguments). + + Runtime Semantics: EvaluateNew + + 3. Let ref be the result of evaluating constructExpr. + 4. Let constructor be ? GetValue(ref). + 5. If arguments is empty, let argList be a new empty List. + 6. Else, + a. Let argList be ? ArgumentListEvaluation of arguments. + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + 8. Return ? Construct(constructor, argList). +---*/ + +var x = {}; +assert.throws(TypeError, function() { + new x(x = Array); +}); + +assert.sameValue(x, Array);