Bug 1455179: Support destructuring with default values in undefined property detection checks. r?nbp draft
authorKris Maglione <maglione.k@gmail.com>
Wed, 18 Apr 2018 18:36:57 -0700
changeset 784796 44db05eecaee0f463fd7c876e66c2fdb69887ba9
parent 784795 84e73c51c90f199f4abf5b6dc9b6523b75647559
push id107034
push usermaglione.k@gmail.com
push dateThu, 19 Apr 2018 01:37:56 +0000
reviewersnbp
bugs1455179
milestone61.0a1
Bug 1455179: Support destructuring with default values in undefined property detection checks. r?nbp MozReview-Commit-ID: O5sCGmjJxA
js/src/vm/NativeObject.cpp
--- a/js/src/vm/NativeObject.cpp
+++ b/js/src/vm/NativeObject.cpp
@@ -2246,18 +2246,19 @@ js::NativeGetExistingProperty(JSContext*
  * access is "property-detecting" -- that is, if we shouldn't warn about it
  * even if no such property is found and strict warnings are enabled.
  */
 static bool
 Detecting(JSContext* cx, JSScript* script, jsbytecode* pc)
 {
     MOZ_ASSERT(script->containsPC(pc));
 
-    // Skip jump target opcodes.
-    while (pc < script->codeEnd() && BytecodeIsJumpTarget(JSOp(*pc)))
+    // Skip jump target and dup opcodes.
+    while (pc < script->codeEnd() && (BytecodeIsJumpTarget(JSOp(*pc)) ||
+                                      JSOp(*pc) == JSOP_DUP))
         pc = GetNextPc(pc);
 
     MOZ_ASSERT(script->containsPC(pc));
     if (pc >= script->codeEnd())
         return false;
 
     // General case: a branch or equality op follows the access.
     JSOp op = JSOp(*pc);
@@ -2270,25 +2271,31 @@ Detecting(JSContext* cx, JSScript* scrip
         // Special case #1: don't warn about (obj.prop == null).
         if (++pc < endpc) {
             op = JSOp(*pc);
             return op == JSOP_EQ || op == JSOP_NE;
         }
         return false;
     }
 
+    // Special case #2: don't warn about (obj.prop == undefined).
     if (op == JSOP_GETGNAME || op == JSOP_GETNAME) {
-        // Special case #2: don't warn about (obj.prop == undefined).
         JSAtom* atom = script->getAtom(GET_UINT32_INDEX(pc));
         if (atom == cx->names().undefined &&
             (pc += CodeSpec[op].length) < endpc) {
             op = JSOp(*pc);
             return op == JSOP_EQ || op == JSOP_NE || op == JSOP_STRICTEQ || op == JSOP_STRICTNE;
         }
     }
+    if (op == JSOP_UNDEFINED) {
+        if ((pc += CodeSpec[op].length) < endpc) {
+            op = JSOp(*pc);
+            return op == JSOP_EQ || op == JSOP_NE || op == JSOP_STRICTEQ || op == JSOP_STRICTNE;
+        }
+    }
 
     return false;
 }
 
 enum IsNameLookup { NotNameLookup = false, NameLookup = true };
 
 /*
  * Finish getting the property `receiver[id]` after looking at every object on