Google Groups không còn hỗ trợ đăng ký sử dụng hoặc đăng nội dung mới trên Usenet. Bạn vẫn có thể xem nội dung cũ.

Can not use RegExp with sealed shared top scope

0 lượt xem
Chuyển tới thư đầu tiên chưa đọc

andrei....@gmail.com

chưa đọc,
20:13:16 6 thg 7, 20056/7/05
đến
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

chưa đọc,
20:44:09 6 thg 7, 20056/7/05
đến
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

chưa đọc,
03:31:40 10 thg 7, 200510/7/05
đến
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 tin nhắn mới