Skip to content

Commit

Permalink
Showing 3 changed files with 15 additions and 4 deletions.
12 changes: 12 additions & 0 deletions opal/corelib/comparable.rb
Original file line number Diff line number Diff line change
@@ -10,6 +10,18 @@ def self.normalize(what)
def ==(other)
return true if equal?(other)

%x{
if (self["$<=>"] == Opal.Kernel["$<=>"]) {
return false;
}
// check for infinite recursion
if (self.$$comparable) {
delete self.$$comparable;
return false;
}
}

return false unless cmp = (self <=> other)

return `#{Comparable.normalize(cmp)} == 0`
3 changes: 3 additions & 0 deletions opal/corelib/kernel.rb
Original file line number Diff line number Diff line change
@@ -13,6 +13,9 @@ def ===(other)

def <=>(other)
%x{
// set guard for infinite recursion
self.$$comparable = true;
var x = #{self == other};
if (x && x !== nil) {
4 changes: 0 additions & 4 deletions spec/filters/bugs/comparable.rb

This file was deleted.

0 comments on commit ec8f400

Please sign in to comment.