From e873f751c5895c0b6e6b7f2b548f88e86285f9a5 Mon Sep 17 00:00:00 2001 From: Jason Orendorff Date: Mon, 19 Oct 2015 15:58:19 -0500 Subject: [PATCH] Bug 1217099 - Stop emitting pointless JSOP_GETLOCAL; JSOP_POP bytecode sequence for `var x;`. r=shu. --- .../tests/unit/test_get-executable-lines.js | 2 +- js/src/frontend/BytecodeEmitter.cpp | 3 +++ .../tests/debug/Script-getAllColumnOffsets-02.js | 2 +- js/src/tests/ecma_5/Global/bug-320887.js | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 js/src/tests/ecma_5/Global/bug-320887.js diff --git a/devtools/server/tests/unit/test_get-executable-lines.js b/devtools/server/tests/unit/test_get-executable-lines.js index a593a64f143..2228fa5259f 100644 --- a/devtools/server/tests/unit/test_get-executable-lines.js +++ b/devtools/server/tests/unit/test_get-executable-lines.js @@ -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); }); }); diff --git a/js/src/frontend/BytecodeEmitter.cpp b/js/src/frontend/BytecodeEmitter.cpp index ed2842a99a6..b93d0a1ae97 100644 --- a/js/src/frontend/BytecodeEmitter.cpp +++ b/js/src/frontend/BytecodeEmitter.cpp @@ -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 diff --git a/js/src/jit-test/tests/debug/Script-getAllColumnOffsets-02.js b/js/src/jit-test/tests/debug/Script-getAllColumnOffsets-02.js index 145643d3b63..405b13d629b 100644 --- a/js/src/jit-test/tests/debug/Script-getAllColumnOffsets-02.js +++ b/js/src/jit-test/tests/debug/Script-getAllColumnOffsets-02.js @@ -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 "); diff --git a/js/src/tests/ecma_5/Global/bug-320887.js b/js/src/tests/ecma_5/Global/bug-320887.js new file mode 100644 index 00000000000..5e8d3445abd --- /dev/null +++ b/js/src/tests/ecma_5/Global/bug-320887.js @@ -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);