Java Code Examples for org.mozilla.javascript.ScriptRuntime#toObject()

The following examples show how to use org.mozilla.javascript.ScriptRuntime#toObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Require.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
private Scriptable executeModuleScript(Context cx, String id,
        Scriptable exports, ModuleScript moduleScript, boolean isMain)
{
    final 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());
    }
    final 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(cx, nativeScope,
            ScriptableObject.getProperty(moduleObject, "exports"));
}
 
Example 2
Source File: Environment.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Object get(String name, Scriptable start) {
    if (this == thePrototypeInstance)
        return super.get(name, start);

    String result = System.getProperty(name);
    if (result != null)
        return ScriptRuntime.toObject(getParentScope(), result);
    else
        return Scriptable.NOT_FOUND;
}
 
Example 3
Source File: Environment.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object get(String name, Scriptable start) {
    if (this == thePrototypeInstance)
        return super.get(name, start);

    String result = System.getProperty(name);
    if (result != null)
        return ScriptRuntime.toObject(getParentScope(), result);
    else
        return Scriptable.NOT_FOUND;
}
 
Example 4
Source File: Require.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private Scriptable executeModuleScript(Context cx, String id,
        Scriptable exports, ModuleScript moduleScript, boolean isMain)
{
    final 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());
    }
    final 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"));
}