First, you need to figure out what toString() means. Is it a function
you created, or is it bubbling up to the global scope and thus
global.toString()?
Fortunately, JavaScript is a fantastically versatile language, so
there is hope that you can make a change without too much fuss.
For example, consider this implementation:
function toString() {
// check whether any arguments were passed in
if (arguments.length) {
// iterate over all the arguments
var buf = [];
for (var i=0, l=arguments.length; i<l; i++) {
// add each to the buffer
var arg = arguments[i];
buf[i] = arg ? arg.toString() : "";
}
// return the buffer, cast as a string
return buf + "";
// otherwise, of no arguments were passed
} else {
// assume method call and do the default action
return this.toString();
}
}
I inferred based on your code sample what you expected the toString()
function to do, and attempted to implement it above. Disclaimer: I
have not tested the above, and provide it as an example only.
If you can load an alternative toString() function like the one above
early in your program, it will have an effect on all other JavaScript
code running in the JVM.
Hope this helps!
-- Jim
On Fri, Apr 16, 2010 at 10:06 AM, Arvind Dhariwal <[email protected]> wrote:
> Hi Jim,
>
> Thanks for reply.
>
> actually we can't change the code . becuase this type of code is
> written in several files of Existing product. which is aleady in
> market.
> Rhino1.6R5 is supporting this type of code and In this 1.6R5 we are
> getting expected output .
>
> Actually Our plan is to upgrade existing product with Rhino1.7R2.
> which is working fine with Rhino1.6R5.
>
> can we get our below code as workable in next release of Rhino1.7R?
>
> function f() {
> java.lang.System.out.println(toString(arguments));
> }
> f (1, 2, 3);
>
>
>
> On Fri, Apr 16, 2010 at 7:22 PM, Jim R. Wilson <[email protected]> wrote:
>> Thanks!
>>
>> Looks like the problem is in the use of the toString function in your
>> original example:
>>
>>>> function f() {
>>>> java.lang.System.out.println(toString(arguments));
>>>> }
>>>> f (1, 2, 3);
>>
>> In that code fragment, toString() is being called as a standalone
>> function, not as a method on an object.
>>
>> For operating on arguments, I generally make local references to the
>> Array.prototype methods, then call them on the arguments object.
>>
>> For example:
>>
>> var slice = Array.prototype.slice;
>>
>> function foo( /* ... */ ) {
>>
>> // make a copy of arguments, except that it's a true Array instance
>> var args = slice.call( arguments, 0 );
>>
>> args instanceof Array; // true
>>
>> print( args + '' ); // cast args as a string and print
>>
>> }
>>
>> Hope this helps!
>>
>> -- Jim
>>
>> On Fri, Apr 16, 2010 at 12:19 AM, Ravi Tanuku <[email protected]> wrote:
>>> This printed 1,2,3
>>>
>>> Regards,
>>> Ravi Tanuku
>>>
>>>
>>> -----Original Message-----
>>> From: Jim R. Wilson [mailto:[email protected]]
>>> Sent: Wednesday, April 14, 2010 8:28 PM
>>> To: Ravi Tanuku
>>> Cc: arvind; [email protected]
>>> Subject: Re: default argument object issue with Rhino1.7R2
>>>
>>> Hi Ravi,
>>>
>>> Could you run the following? I'm curious to see if it works, thanks!
>>>
>>> function f() {
>>> java.lang.System.out.println(
>>> Array.prototype.slice.call(arguments, 0).toString()
>>> );
>>> }
>>> f (1, 2, 3);
>>>
>>> -- Jim
>>>
>>>
>>> On Wed, Apr 14, 2010 at 1:03 AM, Ravi Tanuku <[email protected]> wrote:
>>>> Hi Jim,
>>>>
>>>> Thank you very much for the prompt reply.
>>>>
>>>> Here print() function is defined. To avoid this dependency, I modified the
>>>> function as follows.
>>>>
>>>> function f() {
>>>> java.lang.System.out.println(toString(arguments));
>>>> }
>>>> f (1, 2, 3);
>>>>
>>>> When I execute above script using rhino 1.6R5 API, it prints [1,2,3]
>>>> With 1.7R2 API, it prints {}.
>>>>
>>>> Can you please explain if there are any changes made to arguments object
>>>> or toString() method in 1.7R2?
>>>>
>>>>
>>>> Thanks,
>>>> Ravi Tanuku
>>>>
>>>> -----Original Message-----
>>>> From: Jim R. Wilson [mailto:[email protected]]
>>>> Sent: Tuesday, April 13, 2010 9:29 PM
>>>> To: arvind
>>>> Cc: [email protected]; Ravi Tanuku
>>>> Subject: Re: default argument object issue with Rhino1.7R2
>>>>
>>>> I recommend trying a simpler test: print("hi");
>>>>
>>>> If that doesn't work, maybe the print function isn't defined?
>>>>
>>>> java.lang.System.out.println( typeof print );
>>>>
>>>> Hope this helps!
>>>>
>>>> -- Jim R. Wilson (jimbojw)
>>>>
>>>> On Tue, Apr 13, 2010 at 6:38 AM, arvind <[email protected]> wrote:
>>>>> Hi ,
>>>>>
>>>>> function f() {
>>>>> print(arguments);
>>>>> }
>>>>> f (1, 2, 3);
>>>>>
>>>>> I am executing above program with different version of rhino library.
>>>>> then i found.
>>>>> it is not printing any thing else with Rhino 1.7R2 but it is printing
>>>>> correct value with Rhino 1.6R5 library.
>>>>> _______________________________________________
>>>>> dev-tech-js-engine-rhino mailing list
>>>>> [email protected]
>>>>> https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
>>>>>
>>>>
>>>> This message and the information contained herein is proprietary and
>>>> confidential and subject to the Amdocs policy statement,
>>>> you may review at http://www.amdocs.com/email_disclaimer.asp
>>>>
>>>>
>>>
>>>
>>
>
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino