private Scriptable ExecuteModuleScript(Context cx, string id, Scriptable exports, ModuleScript moduleScript, bool isMain)
{
ScriptableObject moduleObject = (ScriptableObject)cx.NewObject(nativeScope);
Uri uri = moduleScript.GetUri();
Uri @base = moduleScript.GetBase();
DefineReadOnlyProperty(moduleObject, "id", id);
if (!sandboxed)
{
DefineReadOnlyProperty(moduleObject, "uri", uri.ToString());
}
Scriptable executionScope = new ModuleScope(nativeScope, uri, @base);
// Set this so it can access the global JS environment objects.
// This means we're currently using the "MGN" approach (ModuleScript
// with Global Natives) as specified here:
// <http://wiki.commonjs.org/wiki/Modules/ProposalForNativeExtension>
executionScope.Put("exports", executionScope, exports);
executionScope.Put("module", executionScope, moduleObject);
moduleObject.Put("exports", moduleObject, exports);
Install(executionScope);
if (isMain)
{
DefineReadOnlyProperty(this, "main", moduleObject);
}
ExecuteOptionalScript(preExec, cx, executionScope);
moduleScript.GetScript().Exec(cx, executionScope);
ExecuteOptionalScript(postExec, cx, executionScope);
return ScriptRuntime.ToObject(nativeScope, ScriptableObject.GetProperty(moduleObject, "exports"));
}