Grupos de Google ya no admite nuevas publicaciones ni suscripciones de Usenet. El contenido anterior sigue siendo visible.

Can not use RegExp with sealed shared top scope

Visto 0 veces
Saltar al primer mensaje no leído

andrei....@gmail.com

no leída,
6 jul 2005, 20:13:166/7/05
a
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

no leída,
6 jul 2005, 20:44:096/7/05
a
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

no leída,
10 jul 2005, 3:31:4010/7/05
a
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 mensajes nuevos