Bug 1455179: Support destructuring with default values in undefined property detection checks. r?nbp
MozReview-Commit-ID: O5sCGmjJxA
--- 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