// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

// This function should never work (no x in lexical scope)
function getX() { return x; }

global = this;
(function() {
  var x = 12345;
  (function() {

    // indirect call, not direct-call-optimized,
    // uses this scope's parent instead of getX's parent
    try {
        global["getX"]();
    } catch (e) {
        if (!(e instanceof ReferenceError))
            throw("Expected ReferenceError from getX(), got " + e);
        return;
    }
    throw("Indirect call of getX() did not throw");

  })();
})();

// call site triggers direct-call optimization of getX;
// remove this line and the bug doesn't manifest!
function neverCalled() { getX(); }

"success"
