Bug 1217099 - Stop emitting pointless JSOP_GETLOCAL; JSOP_POP bytecode sequence for var x;. r=shu.

This commit is contained in:
Jason Orendorff 2015-10-19 15:58:19 -05:00
parent e4610df25d
commit e873f751c5
4 changed files with 20 additions and 2 deletions

View File

@ -38,7 +38,7 @@ function test_executable_lines() {
do_check_true(!error);
let source = gThreadClient.source(sources[0]);
source.getExecutableLines(function(lines){
do_check_true(arrays_equal([2, 3, 5, 6, 7, 8, 12, 14, 16], lines));
do_check_true(arrays_equal([2, 5, 7, 8, 12, 14, 16], lines));
finishClient(gClient);
});
});

View File

@ -4355,6 +4355,9 @@ BytecodeEmitter::emitSingleVariable(ParseNode* pn, ParseNode* binding, ParseNode
MOZ_ASSERT(emitOption != DefineVars);
if (!emit1(JSOP_UNDEFINED))
return false;
} else {
// The declaration is like `var x;`. Nothing to do.
return true;
}
// If we are not initializing, nothing to pop. If we are initializing

View File

@ -18,4 +18,4 @@ global.eval("function f(n){var w0,x1=3,y2=4,z3=9} debugger;");
global.f(3);
// Should have hit each variable declared.
assertEq(global.log, "18 21 26 31 35 ");
assertEq(global.log, "21 26 31 35 ");

View File

@ -0,0 +1,15 @@
// `var x` should not call the getter of an existing global property.
var hit = 0;
Object.defineProperty(this, "x", {
get: function () { return ++hit; },
configurable: true
});
eval("var x;");
assertEq(hit, 0);
// The declaration should not have redefined the global x, either.
assertEq(x, 1);
assertEq(x, 2);
reportCompare(0, 0);