This code is also duplicated with xpcshell-common.mk, that would be really great to factorize it.
Then regarding your comment https://github.com/mozilla-b2g/gaia/pull/16604/files#r10515827 it would be easier to expose STAGE_APP_DIR to the js code...
For example, but feel free to do something else,
```
// xpcshell-common.mk
const { env } = require('sdk/system/environment');

var { Loader } = Components.utils.import(loaderURI, {});

var paths = {
  'toolkit/': 'resource://gre/modules/commonjs/toolkit/',
  'sdk/': 'resource://gre/modules/commonjs/sdk/',
  '': env.get("GAIA_BUILD_DIR") // Fetch from env to simplify the makefile
};

// Same thing, fetch from env to simplify the makefile
if (env.get("APP_BUILD_DIR")) {
  paths['app/'] = env.get("APP_BUILD_DIR");
}

var loader = Loader.Loader({
  paths: paths,
  modules: {
    'toolkit/loader': Loader
  }
});

function run(module) {
  // Move this code here, to simplify the Makefile...
  try {
    let options = env.get("BUILD_CONFIG");
    // ...and to allow doing easily such thing \o/
    if (env.get("STAGE_APP_DIR"))
      options.STAGE_APP_DIR = env.get("STAGE_APP_DIR");

    require(module).execute(options);

    // When an xpcshell module throws exception which is already captured by
    // JavaScript module, some exceptions will make xpcshell returns error code.
    // We put quit(0); to override the return code when all exceptions are handled
    // in JavaScript module.
    quit(0);
  } catch(e) {
    dump('Exception: ' + e + '\n' + e.stack + '\n');
    throw(e);
  }
}
```

Then, in the shared mk file,
```
// xpcshell-common.mk
define run-js-command
  export BUILD_CONFIG
  export GAIA_BUILD_DIR
  export APP_BUILD_DIR
  $(XULRUNNERSDK) $(XPCSHELLSDK) \
				  -f ./build/xpcshell-commonjs.js \
				  -e "run('$(strip $1)')"
```
And right here, you would only have to do (and ensure loading the shared mk file from the root makefile):
```
// Makefile
 APP_BUILD_DIR="file://$(2)/build/"
 @$(call run-js-command, "app/build")
```
And later in this makefile, you can remove the last third copy of this code. (the define run-js-command)