Hopbot log for 2007-09-19 - Helma IRC channel: #helma on irc.freenode.net

2007-09-19:

[10:59] <hypersmil> is it possible to throw an exception and print the stack trace in the catch block?
[11:26] <rjb> looks like not
[11:28] <rjb> Error has no 'stack' property in rhino
[11:28] <rjb> you can throw it, but no stack
[11:29] <rjb> i *think* i found a bug in rhino
[11:29] <rjb> js> list instanceof Array; -> true
[11:30] <rjb> js> list.toSource; -> function toSource() { [native code for Array.toSource, arity=0] }
[11:31] <rjb> js> list.toSource(); -> js: "<stdin>", line 19: uncaught JavaScript runtime exception: TypeError: Method "toSource" called on incompatible object.
[11:33] <rjb> i was trying to cast a java String[] to a js Array, but apparently didn't quite succeed
[11:36] <rjb> actually the problem might be with the array's elements, which are still java StringS at the time of the call
[11:36] <rjb> (and toSource() recurses)
[12:01] <rjb> wow, another weirdness:
[12:02] <rjb> js> ['a','b'].map( String.prototype.concat, '');
[12:02] <rjb> i thought i knew what this was supposed to return
[12:03] <rjb> instead, i get:
[12:03] <rjb> [object global]a0a,b,[object global]b1a,b
[12:05] <rjb> WTF?
[12:13] <rjb> ok, got it - concat() is a varargs function
[12:14] <rjb> which doesn't quite explain the [object globa] though
[12:19] <zumbrunn> concat is a method of the string prototype and expects "this" to be the String instance it's invoked on
[12:19] <zumbrunn> the way you invoke it, "this" is the global object
[12:20] <rjb> yes, and setting the second arg of map() to '' is supposed to set 'this' for invocations of concat() to ''
[12:20] <zumbrunn> and the empty string is false, which makes concat ignore that argument
[12:21] <rjb> aaah right! thanx
[12:24] <rjb> i guess then that (new String('')) will work there
[12:25] <rjb> well except for concat() eating all the arguments provided to it by map()
[12:27] <rjb> so i can get around this only by wrapping concat in a lambda, and that works fine
[12:31] <rjb> but, this still seems wrong:
[12:32] <rjb> http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:map
[12:32] <rjb> under compatibility, that code doesn't test thisp = arguments[1] for being true
[12:33] <rjb> neither does fun.call()
[12:35] <rjb> so the actual behavior of Array.map() diverges from what's described there
[12:43] <rjb> ok i think this nails down a bug, this time
[12:44] <rjb> in Array.map(arg1, arg2) , arg2 is ignored if arg2 == false
[12:45] <zumbrunn> I can't think of a reason why ignoring the empty string there should be considered a "feature", anyway
[12:48] <rjb> there are definitely times where one would want to use an empty string, or an empty array in that position
[12:48] <rjb> ok, i seem to have another:
[12:51] <rjb> or, maybe not
[12:52] <rjb> {}.toSource(); is a syntax error, while neither [].toSource(); nor (new Object()).toSource(); is
[12:53] <rjb> but ({}).toSource(); is OK
[12:53] <rjb> maybe a gotcha, but not really a bug
[12:54] <hypersmil> what should {} mean/return?
[12:56] <zumbrunn> there are several cases where I've seen the need to add () around things for unclear reasons
[12:56] <zumbrunn> I agree {} should be equal to new Object()
[12:57] <zumbrunn> (not undefined)
[12:57] <zumbrunn> it's probably because {} is also used a block delimiter in the syntax of the language
[12:58] <zumbrunn> ...used as a...
[12:58] <hypersmil> you are right: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Literals
[12:59] <hypersmil> until now i didn't know that it is possible to write it without () ... :)
[13:01] <rjb> var foo = {}; is ok, no syntax error
[13:01] <zumbrunn> yeah, I'm often using that
[13:02] <rjb> back to the previous point,
[13:03] <rjb> [77].map(Array.prototype.concat, []); does return the expected result
[13:03] <rjb> even though [] is just as false as ''
[13:05] <rjb> while [77].map(String.prototype.concat, ''); weirds out
[13:09] <rjb> a slightly cleaner test case:
[13:09] <rjb> [0].map( function(){return this.toString();}, '');
[13:11] <rjb> or better - contrast
[13:12] <rjb> [0].map( function(){return this.toSource();}, '');
[13:12] <rjb> with
[13:12] <rjb> [0].map( function(){return this.toSource();}, []);
[13:13] <rjb> [0].map( function(){return this.toSource();}, new String('')); is ok
[13:14] <rjb> ( function(){return this.toSource();} ).call(''); works fine too
[13:25] <rjb> anyone have a minute to verify this on the most recent rhino, before i file a bug?
[13:25] <rjb> i'm working on 1.6 release 7
[13:32] <zumbrunn> I dont' have a more recent version built here either
[13:32] <zumbrunn> did you test the behavior in spidermonkey?
[13:36] <rjb> no i didn't (yet)
[13:56] <rjb> spidermonkey does it correctly
[13:58] <zumbrunn> it's good to point that out when filing the rhino bug

 

 

In the channel now:

Logs by date: