简体   繁体   中英

How can I wipe the JS environment in Rhino within the interperter?

I have a problem wherein I am loading a number of JS files and then executing a function in JavaScript, then I want to wipe the global namespace of the loaded objects, and load a different set of JS files before executing the next JavaScript Function.

Does anyone here know of a good way of doing this without exiting the Rhino JavaScript interpreter.

How exactly you're executing scripts? Some code sample would help.

Some time ago I used it this way:

Object obj = ScriptableObject.getProperty (scope, methodName);
Callable fun = (Callable) obj;
Scriptable thisObj = scope;
scope = ScriptableObject.getTopLevelScope (scope);
Object result = fun.call(cx, scope, thisObj, args);

where scope contains all loaded objects created before and cx is an instance of Context.

So you don't exactly need to wipe anything - just use new scope.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM