22:22 | <mgaudet> | Hey; I've got a bug which essentially boils down to this little test case
|
22:22 | <mgaudet> | I'm trying to figure out what the spec says and got a little confused |
22:24 | <mgaudet> | https://tc39.es/ecma262/#sec-evaluatenew says that ArgumentListEvaluation happens before the constructor is invoked; but AFAICT it's the constructor that actually allocates the object... |
22:24 | <mgaudet> | does ArgumentListEvaluation not actually... evaluate the arguments? ie, is the processing of the default argument deferred until later? |
22:31 | <bakkot> | ArgumentListEvaluation evaluates the arguments, not the parameters |
22:32 | <bakkot> | it's the thing which would trigger the console.log in f(console.log(0)); , not the thing which would trigger the console.log in function f(x = console.log(0)) {}; f() |
22:32 | <mgaudet> | yeah; I think I've got the latter traced down further into https://tc39.es/ecma262/#sec-functiondeclarationinstantiation |
22:33 | <mgaudet> | (which seems to imply that the answer is that private fields ought to be available in that parameter expression) |
22:33 | <mgaudet> | (I always get bit when coming back to arguments/formals/parameters) |
22:36 | <bakkot> | yeah |
22:37 | <bakkot> | specifically, for base classes, class fields are created/installed by [[construct]] step 6.b: https://tc39.es/ecma262/multipage/ordinary-and-exotic-objects-behaviours.html#sec-ecmascript-function-objects-construct-argumentslist-newtarget |
22:39 | <bakkot> | and parameter defaults (and other expressions) are evaluated later, in [[construct]] step 8, via OrdinaryCallEvaluateBody -> EvaluateBody -> EvaluateFunctionBody -> FunctionDeclarationInstantiation -> IteratorBindingInitialization |
22:40 | <bakkot> | so private fields (and all other fields) are available (for base classes) by the time the parameter list is evaluated |
22:40 | <mgaudet> | Yep :) Was writing that out... less nicely than you in the bug :P |