throws Exception
{
Context context = Context.enter();
context.setOptimizationLevel(OPTIMIZATION_LEVEL);
context.setCompileFunctionsWithDynamicScope(true);
Scriptable thrScope = context.newObject(scope);
thrScope.setPrototype(scope);
// We want 'thrScope' to be a new top-level scope, so set its
// parent scope to null. This means that any variables created
// by assignments will be properties of "thrScope".
thrScope.setParentScope(null);
// Put in the thread scope the Cocoon object, which gives access
// to the interpreter object, and some Cocoon objects. See
// JSCocoon for more details.
Object args[] = {};
Scriptable cocoon = context.newObject(scope, "Cocoon", args);
((JSCocoon)cocoon).setInterpreter(this);
((JSCocoon)cocoon).setContext(manager, environment, ctx);
((JSCocoon)cocoon).setContinuationsManager(continuationsMgr);
((JSCocoon)cocoon).setScope(thrScope);
thrScope.put("cocoon", thrScope, cocoon);