Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can not use RegExp with sealed shared top scope

0 views
Skip to first unread message

andrei....@gmail.com

unread,
Jul 6, 2005, 8:13:16 PM7/6/05
to
I am trying to use shared top scope in the way suggested
http://www.mozilla.org/rhino/scopes.html

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?

andrei....@gmail.com

unread,
Jul 6, 2005, 8:44:09 PM7/6/05
to
The second I post my initial message, I figure out what is going on.
It is all due to the LazilyLoadedCtor. Unless I "use/mention" RegExp (
or any other things from ScriptRuntime.lazilyNames ) before I seal
top_scope, I can not use any of these functions. They are not "loaded"
as part of Context.initStandardObject(), but only on a first use.

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 Szegedi

unread,
Jul 10, 2005, 3:31:40 AM7/10/05
to
Well, that's exactly what I do with shared top scopes -- force resolving
of the lazy objects prior to sealing the scope. I guess that's something
that you just learn to live with.

Attila.

--
home: http://www.szegedi.org
weblog: http://www.jroller.com/page/aszegedi

0 new messages