top_scope = cx.initStandardObjects( null, false );
...
loading some shared JS variables/functions
...
top_scope.sealObject();
Then I am creating multiple scopes like this
scope = (ScriptableObject)cx.newObject( top_scope );
scope.setPrototype( top_scope );
scope.setParentScope( null );
>From this point on, I can load/execute any JS using scope object,
unless these scripts are using RegExp. If I am trying to create RegExp
variable ( for example something like this : 'var re1 = new RegExp(
"/>(?:\s+)</g" );' ) I am getting following exception:
org.mozilla.javascript.EvaluatorException: Cannot modify a property of
a sealed object: RegExp. (filter::removeSpacesFilter#1)
at
org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:95)
at org.mozilla.javascript.Context.reportRuntimeError(Context.java:966)
at
org.mozilla.javascript.Context.reportRuntimeError(Context.java:1022)
at
org.mozilla.javascript.Context.reportRuntimeError1(Context.java:985)
at
org.mozilla.javascript.ScriptableObject.put(ScriptableObject.java:231)
at
org.mozilla.javascript.IdScriptableObject.put(IdScriptableObject.java:415)
at
org.mozilla.javascript.ScriptableObject.defineProperty(ScriptableObject.java:1000)
at
org.mozilla.javascript.ScriptableObject.defineProperty(ScriptableObject.java:1019)
at
org.mozilla.javascript.regexp.NativeRegExp.init(NativeRegExp.java:153)
...
Could some one please shed some light to this problem? Why RegExp
(function/class?) needs to have one of its properties modified each
time you are creating new instance of it?
I guess the question is, does this approach ( Lazily Loading ) save so
much time/memory/cpu that it really worth the efforts? I guess if you
create many "top" scopes, it could become expensive, but "shared" top
scope solves this problem rather nicely.
Attila.
--
home: http://www.szegedi.org
weblog: http://www.jroller.com/page/aszegedi