ctorExpr-isCtor-after-args-eval-fn-wrapup.js (1174B)
1 // Copyright (C) 2020 Leo Balter. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-new-operator 6 description: > 7 The IsConstructor(ctor) happens after evaluating the arguments, use the correct ctor. 8 Function wrap-up to use the same function level binding ref 9 info: | 10 NewExpression : new NewExpression 11 1. Return ? EvaluateNew(NewExpression, empty). 12 MemberExpression : new MemberExpression Arguments 13 1. Return ? EvaluateNew(MemberExpression, Arguments). 14 15 Runtime Semantics: EvaluateNew 16 17 3. Let ref be the result of evaluating constructExpr. 18 4. Let constructor be ? GetValue(ref). 19 5. If arguments is empty, let argList be a new empty List. 20 6. Else, 21 a. Let argList be ? ArgumentListEvaluation of arguments. 22 7. If IsConstructor(constructor) is false, throw a TypeError exception. 23 8. Return ? Construct(constructor, argList). 24 ---*/ 25 26 var ref; 27 var argz; 28 29 assert.throws(TypeError, function() { 30 var x = 42; 31 ref = x; 32 new x(x = function() {}, argz = 39); 33 }); 34 35 assert.sameValue(ref, 42); 36 assert.sameValue(argz, 39, 'arguments evaluated before checking valid ctor'); 37 38 reportCompare(0, 0);