[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
| Re: [ease-dev] Could EASE helper modules have only a static public interface? | 
Christian-
Thanks. Yes, I thought it might be something like that, that there were 
some interpreter specific things used by some of the modules. I can see 
the argument that it is better to do it one way (the current way) than 
cause confusion by having two ways to do things, one of which doesn't 
work sometimes. I was surprised myself that the constructor worked 
without "new". Also, I expected I would have to supply some kind of 
arguments like to a script interpreter. I then am curious what specific 
method calls will fail because presumably some default constructor was 
used to make those instances and it may not have the interpreter set 
correctly?
Still, is it possible that there is some way for the Java code to figure 
out what interpreter it was called from? Perhaps by looking up the call 
stack? Or maybe by looking at some thread-specific data? Then maybe 
these could all be static methods and they could just get that minimal 
information by such a lookup process in cases where they need it? 
Another option might be to use Java's "ThreadLocal" storage?
http://java.dzone.com/articles/painless-introduction-javas-threadlocal-storage
Rhino already seems to define such a ThreadLocal variable with the 
interpreter:
http://schierlm.users.sourceforge.net/CVE-2011-3544.html
"The reason for this is simple: Rhino expects every script call to be 
run inside of a Context - basically an object that captures your local 
variables etc. This context is stored in a thread local variable to be 
available all the time when the script is executed. Since we called an 
"internal" method directly, there is no context assigned to the current 
thread any longer, so we get this error."
However, that is just for the Rhino interpreter. Possibly EASE needs its 
own extra information? Again though, maybe that could be done as a 
thread local thing? Although, would that work because EASE support 
multiple threads (like a main interpreter thread and then running stuff 
on the GUI thread)?
Some other related discussion on Rhino and multiple thread:
"Single Rhino Context in MultiThreaded Environment"
https://groups.google.com/forum/?_escaped_fragment_=topic/mozilla.dev.tech.js-engine.rhino/VifR2mwNxko
Is trying to resolve this worth the trouble or the extra complexity 
(including for cleanup of ThreadLocal variables to prevent leaks) 
compared to just making module instances that know what interpreter they 
go with? I don't know because I still don't know for sure if it is 
possible or how complex and brittle the EASE code would become as far as 
maintenance with such a change. However, I suspect though that this may 
not be that hard to do, perhaps with some function like 
getCurrentEaseContext() that would get the ThreadLocal context. If it 
was easy, then perhaps the whole process of writing and importing core 
EASE modules could be simplified down to importing Java classes with 
only static methods.
--Paul Fernhout
On 11/26/14 1:11 AM, Christian Pontesegger wrote:
Hi
On 25.11.2014 19:39, Paul D. Fernhout wrote:
> org.eclipse.ease.modules.platform.UIModule.setClipboard("hello");
    Java class "org.eclipse.ease.modules.platform.UIModule" has no
public instance field or method named "setClipboard".
> org.eclipse.ease.modules.platform.UIModule().setClipboard("hello");
    [null]
First I was not aware that you may skip the "new" keyword in js, thanks
for showing me a new trick :)
For the functions: some methods require access to the running script
engine. Eg resources need it to resolve relative files. Same applies for
UIModule.executeUI(). Does not work for static methods as we need engine
specific information here. As multiple engines might run concurrently,
we cannot use statics here.
Some other methods could be static, so we can think of changing them.
Question is, if this helps, because your first example of accessing
methods would only work for some methods, while the latter would work
for any method.
--
Christian