Closed Bug 243057 Opened 21 years ago Closed 20 years ago

enhancement - ability to assign to Java function result and default properties

Categories

(Rhino Graveyard :: Compiler, enhancement)

x86
Windows 2000
enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: mcbp223, Assigned: igor)

Details

User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; T312461; YComp 5.0.0.0; .NET CLR 1.1.4322) Build Identifier: This report is a follow up of the newsgroup discussion http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF- 8&safe=off&frame=right&th=b21c4e09e133d24c&seekm=409C9F5A.2070208% 40fastmail.fm#link8 and is a new feature request. In MS JScript you can assign to a construction that looks like a function call, for example in ASP: Session.Value("foo") = "bar"; which at runtime could be translated by Rhino to Session.jsSet_Value("foo", "bar"); The rule is that a property will have n arguments for the getter, and n+1 arguments for the setter; for the setter, the last argument is rhs. Also in JScript you can write Session("foo") = "bar"; which translates to the same thing, because Value is marked as default property. A solution to mark getters/setters as default could be to implement a new prefix, so the Java class to be scripted will have Session.jsGetDefault_Value(String key) and Session.jsSetDefault_Value(String key, Object val) When encountering a construct like var str = Session("foo") the runtime could check first if Session is instanceof Callable. If it is not, it can continue the introspection with checking whether Session has a default getter matching the number of arguments. Reproducible: Always Steps to Reproduce: 1. compile Session.Value("foo") = "bar"; Actual Results: jsc reports: Invalid assignment left-hand side. Expected Results: Check if the Session object, a Java class provided by the programmer, has a setter named jsSet_Value(String key, Object rhs); Things can get more complicated, for example consider a call to ADODB.Recordset var str = rs("field"); that should translate in var str = rs.jsGetDefault_Fields().jsGetDefault_Item ("field").jsGetDefault_Value();
With the introduction of RefCallable interface Rhino allows to define native functions that can be used as rvalue so one can define a native function foo so foo() = bar or even foo() += q works. As regarding the default option it is already doable throw overriding Scriptable.get method so I close the bug as fixed.
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.