Bug 1639591 - Part 1: Assign name to anonymous function for short-circuit assignment. r=yulia
authorAndré Bargull <andre.bargull@gmail.com>
Tue, 02 Jun 2020 15:50:22 +0000
changeset 533678 f15d364b3feca665e6ddc1a0c2d1b53ca68cad04
parent 533677 7d431fe9ab856da58908979ec04bfa4997b99162
child 533679 c7e9155860a9873991d57fe7d3e3bb50403f1f25
push id37475
push userbtara@mozilla.com
push dateWed, 03 Jun 2020 16:12:12 +0000
treeherdermozilla-central@ea34fd156c89 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyulia
bugs1639591
milestone79.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1639591 - Part 1: Assign name to anonymous function for short-circuit assignment. r=yulia Differential Revision: https://phabricator.services.mozilla.com/D77822
js/src/frontend/BytecodeEmitter.cpp
js/src/frontend/FullParseHandler.h
js/src/tests/non262/expressions/short-circuit-compound-assignment-anon-fns.js
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -4453,19 +4453,17 @@ bool BytecodeEmitter::emitShortCircuitAs
 
   // The short-circuit condition wasn't fulfilled, pop the left-hand side value
   // which was kept on the stack.
   if (!emit1(JSOp::Pop)) {
     //              [stack] ...
     return false;
   }
 
-  // TODO: Open spec issue about setting inferred function names.
-  // <https://github.com/tc39/proposal-logical-assignment/issues/23>
-  if (!emitTree(rhs)) {
+  if (!emitAssignmentRhs(rhs, name)) {
     //              [stack] ... RHS
     return false;
   }
 
   // Perform the actual assignment.
   switch (lhs->getKind()) {
     case ParseNodeKind::Name: {
       if (!noe->emitAssignment()) {
--- a/js/src/frontend/FullParseHandler.h
+++ b/js/src/frontend/FullParseHandler.h
@@ -867,16 +867,19 @@ class FullParseHandler {
                                 bool isSpread) {
     return new_<CallNode>(ParseNodeKind::NewExpr,
                           isSpread ? JSOp::SpreadNew : JSOp::New,
                           TokenPos(begin, args->pn_pos.end), ctor, args);
   }
 
   AssignmentNodeType newAssignment(ParseNodeKind kind, Node lhs, Node rhs) {
     if ((kind == ParseNodeKind::AssignExpr ||
+         kind == ParseNodeKind::CoalesceAssignExpr ||
+         kind == ParseNodeKind::OrAssignExpr ||
+         kind == ParseNodeKind::AndAssignExpr ||
          kind == ParseNodeKind::InitExpr) &&
         lhs->isKind(ParseNodeKind::Name) && !lhs->isInParens()) {
       checkAndSetIsDirectRHSAnonFunction(rhs);
     }
 
     return new_<AssignmentNode>(kind, lhs, rhs);
   }
 
new file mode 100644
--- /dev/null
+++ b/js/src/tests/non262/expressions/short-circuit-compound-assignment-anon-fns.js
@@ -0,0 +1,44 @@
+// |reftest| skip-if(release_or_beta)
+
+// NamedEvaluation applies to short-circuit assignment.
+
+{
+  let a;
+  a ??= function(){};
+  assertEq(a.name, "a");
+}
+
+{
+  let a = false;
+  a ||= function(){};
+  assertEq(a.name, "a");
+}
+
+{
+  let a = true;
+  a &&= function(){};
+  assertEq(a.name, "a");
+}
+
+// No name assignments for parenthesised left-hand sides.
+
+{
+  let a;
+  (a) ??= function(){};
+  assertEq(a.name, "");
+}
+
+{
+  let a = false;
+  (a) ||= function(){};
+  assertEq(a.name, "");
+}
+
+{
+  let a = true;
+  (a) &&= function(){};
+  assertEq(a.name, "");
+}
+
+if (typeof reportCompare === "function")
+  reportCompare(0, 0);