I haven't had the time to look at this today. However, I can quickly
explain why
var sortedWords = words.sort(coll.compare);
does not work as you expect. You are extracting the compare function and
passing
it to the sort function on arrays (I assume that words is a normal array
here?).
That function is then called to compare the elements. However, it is not
called
with the coll object as its receiver, it is called with the global object
as the
receiver. The global object cannot be transformed to a Collator object
because
it is not.
Standalone JS example showing that this is the correct JS behavior:
$ ./shell
V8 version 3.2.0 (candidate)
var ints = [2, 3, 4];
function f() { if (!this.hasOwnProperty('x')) throw "NOPE!"; }
var o = new Object();
o.f = f
function f() { if (!this.hasOwnProperty('x')) throw "NOPE!"; }
o.f()
(shell):1: NOPE!
function f() { if (!this.hasOwnProperty('x')) throw "NOPE!"; }
^
o.x = 42
42
o.f()
ints.sort(o.f)
(shell):1: NOPE!
function f() { if (!this.hasOwnProperty('x')) throw "NOPE!"; }
http://codereview.chromium.org/6673011/
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev