Closed Bug 255595 Opened 20 years ago Closed 19 years ago

Factory class for Context creation

Categories

(Rhino Graveyard :: Core, enhancement)

head
enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: igor, Assigned: igor)

Details

Attachments

(2 files)

Problem: 

To setup instruction counting or to override Context.FEATURE_* Rhino embedding
should subclass Context and then pass it explicitly to Context.enter to
associate it with the current thread. Unfortunately it does not work with
JavaAdapter which calls Context.enter() in response to Java calls. If there is
no Context instance associated with current thread, that would trigger use of
default Context ignoring application wish for customization.

Solution: 

A factory class that can be provided to Rhino runtime which will be used for
Context creation.
The initial implementation of factory API in the form of
http://lxr.mozilla.org/mozilla/source/js/rhino/src/org/mozilla/javascript/ContextFactory.java
was committed during spring 2004. The implementation not only allows for full
customization of Context instances but also provide a way to run several
independent Rhino run times in one JVM. 
The current implementation of ContextFactory introduced a couple of
compatibility problems:

1. It started to require that when calling ScriptableObject.callMethod() a
Context instance should be associated with the current thread. This is was done
not to worry about picking up proper ClassFactory.

2. JavaAdapter also started to require to have active context during adapter
creation. This was done to select proper ContextFactory during calls to script
methods. This does not matter for ordinary adapter case since it is always
called from a running script, but automatic function to Java interface can be
called without it.

To solve this compatibility issues patch stores ContextFactory in the top scope
when Context.initStandardObjects is called. In this way the factory is always
reachable from function scope without the need to have active Context instance.
I committed the fix but I will keep the bug assigned if more compatibility
issues will pop up.
Status: NEW → ASSIGNED
Target Milestone: --- → 1.5R6
The previous patch introduces nasty regression reported by Merten.Schumann:

> This simple stuff
> 
>  public static void main(String args[]) throws Exception
>  {
>   Context cx=Context.enter();
>   cx.initStandardObjects(null);
>  }
> 
> worked in former releases IMHO, now it throws
> 
> java.lang.IllegalArgumentException
> at
> org.mozilla.javascript.ScriptableObject.associateValue(ScriptableObject.
> java:1574)
> at
> org.mozilla.javascript.ScriptRuntime.initStandardObjects(ScriptRuntime.j
> ava:127)
> at org.mozilla.javascript.Context.initStandardObjects(Context.java:1108)
> at org.mozilla.javascript.Context.initStandardObjects(Context.java:1075)
> at de.rochade.srap.test.Snippet.main(Snippet.java:14) Exception in
> thread "main" 

The fix fixes that.
The last fix is in CVS. The bug realy should stay open for some time.
Done
Status: ASSIGNED → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: