Fix issue invoking functions with JS scripting extension

The JS scripting extension only allows functions to be called once currently.  This is because the engine scope is reinitialized in the `invokeFunction` and `invokeMethod` calls.  The alternative is to put the global scope in the function's scope chain.