Closed
Bug 201896
Opened 22 years ago
Closed 22 years ago
Convenient way to implement functions in Java without using reflection
Categories
(Rhino Graveyard :: Core, enhancement)
Rhino Graveyard
Core
Tracking
(Not tracked)
VERIFIED
FIXED
1.5R5
People
(Reporter: igor, Assigned: norrisboyd)
Details
Attachments
(1 file, 2 obsolete files)
Currently any usage of IdFunction requires to implement at least 2 methods in
IdFunctionMaster, execMethod and methodArity in addition to code to create
IdFunction instances. If methodArity is replaced by passing the arity value
directly to IdFunction constructor, the usage would be simpler.
Reporter | ||
Comment 1•22 years ago
|
||
The patch did not touch IdScriptable ands its subclasses besides changing
methodArity in IdScriptable from public to protected since IdScriptable needs
to get an arity value form its subclasses which brings patrch minuses:
1. Additional method invocation per each IdFunction instance initialization in
IdScriptable subclasses.
2. Additional field in IdScriptable.
Perhaps for code that wants to add a function or two without using reflection
it would be better to define something like JavaFunction or SimpleFunction that
should be extended to override the call method?
Reporter | ||
Comment 2•22 years ago
|
||
I renamed title since it seems a separated class to provide IdFunction
functionality without a requirement to implement an additional interface would
be a good option to have.
Summary: More convenient way to use IdFunction → Convenient way to implement functions in Java without using reflection
Reporter | ||
Comment 3•22 years ago
|
||
The patch adds new JIFunction class which stands for Java Implemented Function
(NativeFunction is already taken and I like to have a short name) which is a
simplified version of IdFunction. The function has to be subclassed to
implement call method. I changed NativeJavaPackage to use it instead of using
reflection to export getClass functionality. The core of changes is
replacement:
- Method[] methods = FunctionObject.getMethodList(
- NativeJavaPackage.class);
- Method m = FunctionObject.findSingleMethod(methods,
- "jsFunction_getClass");
- FunctionObject f = new FunctionObject("getClass", m, scope);
+ JIFunction getClass = new JIFunction("getClass", 1) {
+ public Object call(Context fcx, Scriptable fscope,
+ Scriptable thisObj, Object[] args)
+ {
+ return js_getClass(fcx, fscope, packages, args);
+ }
+ };
...
- global.defineProperty("getClass", f, ScriptableObject.DONTENUM);
+ getClass.define(global, ScriptableObject.DONTENUM);
which defines new function and does not increase amount of code lines
noticeably.
It also allows to make NativeJavaPackage.js_getClass package private thus
providing less room for erroneous code calling js_getClass from Java.
Attachment #120402 -
Attachment is obsolete: true
Reporter | ||
Comment 4•22 years ago
|
||
Attachment #122199 -
Attachment is obsolete: true
Reporter | ||
Comment 5•22 years ago
|
||
I committed the patch.
Status: NEW → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•