Changeset 9172

Show
Ignore:
Timestamp:
08/22/08 14:37:34 (3 months ago)
Author:
hannes
Message:

Execute top level scripts in a dedicated module scope with name set to 'main'

This is identical to what Python does to let scripts know they're being run
as top-level scripts rather than imported as modules:

if (name == 'main') {

// run as script

}

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • helma-ng/trunk/src/org/helma/javascript/RhinoEngine.java

    r9170 r9172  
    175175            } 
    176176            ReloadableScript script = new ReloadableScript(resource, this); 
    177             retval = script.evaluate(topLevelScope, cx); 
     177            Scriptable scope = new ModuleScope("__main__", resource,  
     178                    resource.getRepository(), topLevelScope); 
     179            retval = script.evaluate(scope, cx); 
    178180                if (retval instanceof Wrapper) { 
    179181                        return ((Wrapper) retval).unwrap();