Hi,

I played quite a bit with shared, dynamic scopes to reuse a script
loaded from a file in multiple contexts (basically a controller
'class' in a Java webapp framework). It works OK, but there are still
some issues and it is kinda of a hack anyways.
So I would like to avoid dynamic scopes.

Which makes me wonder why I do not simply clone a scope :-) Something
like this:
1. sharedScope = new ImporterTopLevel()
2. script.exec(sharedScope) // imports Java packages, defines
functions & variables, etc
then
3. instanceScope1 = sharedScope.clone()
4. instanceScope2 = sharedScope.clone()
etc

Questions:
Is this going to be problematic? Or stupid for some other reason?
Does clone() work at all? Or is it preferable to iterate over the
props manually?
Do the functions in the shared scope somehow keep strong references to
the shared scope or will they 'migrate' properly?

Doing a shallow copy sounds like a good idea to me, it should be cheap
(~10 slots per controller?) and avoids all the dynamic scoping tricks.
Of course it would only work if the functions work in the cloned
context (but are not cloned themselves).

Thanks,
  Helge
--
http://www.helgehess.eu/
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to