Java Code Examples for org.mozilla.javascript.ScriptableObject#setParentScope()

The following examples show how to use org.mozilla.javascript.ScriptableObject#setParentScope() . 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: ScriptNodeTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private ScriptableObject getScope() 
{
    // Create a scope for the value conversion. This scope will be an empty scope exposing basic Object and Function, sufficient for value-conversion.
    // In case no context is active for the current thread, we can safely enter end exit one to get hold of a scope
    ScriptableObject scope;
    Context ctx = Context.getCurrentContext();
    boolean closeContext = false;
    if (ctx == null) 
    {
        ctx = Context.enter();
        closeContext = true;
    }
    scope = ctx.initStandardObjects();
    scope.setParentScope(null);

    if (closeContext) 
    {
        Context.exit();
    }
    return scope;
}
 
Example 2
Source File: SharedScope.java    From manifold with Apache License 2.0 5 votes vote down vote up
/**
 * Static scope applies to a program or class and is analogous to Java's Class scope.  An instance scope is created
 * when an object is constructed via Context.newObject(), which is called from the manifold generated constructor for
 * a js class.
 */
static ScriptableObject newStaticScope()
{
  ScriptableObject sharedGlobalScope = SharedScope.get();
  ScriptableObject programScope = (ScriptableObject)Context.getCurrentContext().newObject( sharedGlobalScope );
  programScope.setPrototype( sharedGlobalScope );
  programScope.setParentScope( null );
  return programScope;
}