ctorExpr-isCtor-after-args-eval.js (982B)
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 info: | 9 NewExpression : new NewExpression 10 1. Return ? EvaluateNew(NewExpression, empty). 11 MemberExpression : new MemberExpression Arguments 12 1. Return ? EvaluateNew(MemberExpression, Arguments). 13 14 Runtime Semantics: EvaluateNew 15 16 3. Let ref be the result of evaluating constructExpr. 17 4. Let constructor be ? GetValue(ref). 18 5. If arguments is empty, let argList be a new empty List. 19 6. Else, 20 a. Let argList be ? ArgumentListEvaluation of arguments. 21 7. If IsConstructor(constructor) is false, throw a TypeError exception. 22 8. Return ? Construct(constructor, argList). 23 ---*/ 24 25 var x = {}; 26 assert.throws(TypeError, function() { 27 new x(x = Array); 28 }); 29 30 assert.sameValue(x, Array); 31 32 reportCompare(0, 0);