Class Overview
JSAdapter is java.lang.reflect.Proxy equivalent for JavaScript. JSAdapter
calls specially named JavaScript methods on an adaptee object when property
access is attempted on it.
Example:
var y = {
__get__ : function (name) { ... }
__has__ : function (name) { ... }
__put__ : function (name, value) {...}
__delete__ : function (name) { ... }
__getIds__ : function () { ... }
};
var x = new JSAdapter(y);
x.i; // calls y.__get__
i in x; // calls y.__has__
x.p = 10; // calls y.__put__
delete x.p; // calls y.__delete__
for (i in x) { print(i); } // calls y.__getIds__
If a special JavaScript method is not found in the adaptee, then JSAdapter
forwards the property access to the adaptee itself.
JavaScript caller of adapter object is isolated from the fact that
the property access/mutation/deletion are really calls to
JavaScript methods on adaptee. Use cases include 'smart'
properties, property access tracing/debugging, encaptulation with
easy client access - in short JavaScript becomes more "Self" like.
Note that Rhino already supports special properties like __proto__
(to set, get prototype), __parent__ (to set, get parent scope). We
follow the same double underscore nameing convention here. Similarly
the name JSAdapter is derived from JavaAdapter -- which is a facility
to extend, implement Java classes/interfaces by JavaScript.
Summary
[Expand]
Inherited Fields |
From interface
sun.org.mozilla.javascript.internal.Scriptable
public
static
final
Object |
NOT_FOUND |
|
|
Public Methods |
Object
|
call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args)
|
Scriptable
|
construct(Context cx, Scriptable scope, Object[] args)
|
void
|
delete(int index)
|
void
|
delete(String name)
|
Object
|
get(String name, Scriptable start)
|
Object
|
get(int index, Scriptable start)
|
Scriptable
|
getAdaptee()
|
String
|
getClassName()
|
Object
|
getDefaultValue(Class hint)
|
Object[]
|
getIds()
|
Scriptable
|
getParentScope()
|
Scriptable
|
getPrototype()
|
boolean
|
has(String name, Scriptable start)
|
boolean
|
has(int index, Scriptable start)
|
boolean
|
hasInstance(Scriptable scriptable)
|
static
void
|
init(Context cx, Scriptable scope, boolean sealed)
|
void
|
put(String name, Scriptable start, Object value)
|
void
|
put(int index, Scriptable start, Object value)
|
void
|
setAdaptee(Scriptable adaptee)
|
void
|
setParentScope(Scriptable parent)
|
void
|
setPrototype(Scriptable prototype)
|
[Expand]
Inherited Methods |
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this object.
|
boolean
|
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
void
|
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
final
Class<?>
|
getClass()
Returns the runtime class of this Object .
|
int
|
hashCode()
Returns a hash code value for the object.
|
final
void
|
notify()
Wakes up a single thread that is waiting on this object's
monitor.
|
final
void
|
notifyAll()
Wakes up all threads that are waiting on this object's monitor.
|
String
|
toString()
Returns a string representation of the object.
|
final
void
|
wait()
Causes the current thread to wait until another thread invokes the
notify() method or the
notifyAll() method for this object.
|
final
void
|
wait(long timeout, int nanos)
Causes the current thread to wait until another thread invokes the
notify() method or the
notifyAll() method for this object, or
some other thread interrupts the current thread, or a certain
amount of real time has elapsed.
|
final
void
|
wait(long timeout)
Causes the current thread to wait until either another thread invokes the
notify() method or the
notifyAll() method for this object, or a
specified amount of time has elapsed.
|
|
From interface
sun.org.mozilla.javascript.internal.Callable
abstract
Object
|
call(Context arg0, Scriptable arg1, Scriptable arg2, Object[] arg3)
|
|
From interface
sun.org.mozilla.javascript.internal.Function
abstract
Object
|
call(Context arg0, Scriptable arg1, Scriptable arg2, Object[] arg3)
|
abstract
Scriptable
|
construct(Context arg0, Scriptable arg1, Object[] arg2)
|
|
From interface
sun.org.mozilla.javascript.internal.Scriptable
abstract
void
|
delete(int arg0)
|
abstract
void
|
delete(String arg0)
|
abstract
Object
|
get(String arg0, Scriptable arg1)
|
abstract
Object
|
get(int arg0, Scriptable arg1)
|
abstract
String
|
getClassName()
|
abstract
Object
|
getDefaultValue(Class arg0)
|
abstract
Object[]
|
getIds()
|
abstract
Scriptable
|
getParentScope()
|
abstract
Scriptable
|
getPrototype()
|
abstract
boolean
|
has(String arg0, Scriptable arg1)
|
abstract
boolean
|
has(int arg0, Scriptable arg1)
|
abstract
boolean
|
hasInstance(Scriptable arg0)
|
abstract
void
|
put(String arg0, Scriptable arg1, Object arg2)
|
abstract
void
|
put(int arg0, Scriptable arg1, Object arg2)
|
abstract
void
|
setParentScope(Scriptable arg0)
|
abstract
void
|
setPrototype(Scriptable arg0)
|
|
Public Methods
public
Object
call
(Context cx, Scriptable scope, Scriptable thisObj, Object[] args)
public
Scriptable
construct
(Context cx, Scriptable scope, Object[] args)
public
void
delete
(int index)
public
void
delete
(String name)
public
Object
get
(int index, Scriptable start)
public
Scriptable
getAdaptee
()
public
Scriptable
getParentScope
()
public
Scriptable
getPrototype
()
public
boolean
has
(String name, Scriptable start)
public
boolean
has
(int index, Scriptable start)
public
boolean
hasInstance
(Scriptable scriptable)
public
static
void
init
(Context cx, Scriptable scope, boolean sealed)
public
void
put
(String name, Scriptable start, Object value)
public
void
put
(int index, Scriptable start, Object value)
public
void
setAdaptee
(Scriptable adaptee)
public
void
setParentScope
(Scriptable parent)
public
void
setPrototype
(Scriptable prototype)