Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 14d6cdfe75a0
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ac4df73bd176
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Oct 23, 2014

  1. Copy the full SHA
    f4be208 View commit details
  2. Copy the full SHA
    b5b8db4 View commit details
  3. Copy the full SHA
    ac4df73 View commit details
Showing with 33 additions and 21 deletions.
  1. +32 −4 opal/corelib/hash.rb
  2. +1 −1 spec/corelib
  3. +0 −16 spec/filters/bugs/hash.rb
36 changes: 32 additions & 4 deletions opal/corelib/hash.rb
Original file line number Diff line number Diff line change
@@ -346,7 +346,20 @@ def flatten(level=undefined)
end

def has_key?(key)
`$opal.hasOwnProperty.call(self.map, key.$hash())`
%x{
var map = self.map,
keys = self.keys,
khash = key.$hash();
if ($opal.hasOwnProperty.call(self.map, khash)) {
for (var i = 0, length = keys.length; i < length; i++) {
if (!#{not(key.eql?(`keys[i]`))}) {
return true;
}
}
}
return false;
}
end

def has_value?(value)
@@ -411,19 +424,34 @@ def indexes(*keys)

alias indices indexes

`var inspect_ids = {}`
def inspect
%x{
var inspect = [], keys = self.keys, map = self.map;
var inspect = [],
keys = self.keys,
map = self.map,
top = !!inspect_ids,
id = #{object_id},
seen_string = '{...}';
if (inspect_ids.hasOwnProperty(id)) {
return seen_string;
}
inspect_ids[id] = true;
for (var i = 0, length = keys.length; i < length; i++) {
var key = keys[i], val = map[key.$hash()];
val = (val === self) ? '{...}' : val.$inspect()
key = (key === self) ? '{...}' : key.$inspect()
val = val.$inspect();
key = key.$inspect();
inspect.push(key + '=>' + val);
}
return '{' + inspect.join(', ') + '}';
}
ensure
`if (top) {
inspect_ids = {}
}`
end

def invert
2 changes: 1 addition & 1 deletion spec/corelib
16 changes: 0 additions & 16 deletions spec/filters/bugs/hash.rb
Original file line number Diff line number Diff line change
@@ -55,32 +55,18 @@
fails "Hash#flatten recursively flattens Array values to the given depth"
fails "Hash#flatten raises a TypeError if given a non-Integer argument"

fails "Hash#has_key? compares keys with the same #hash value via #eql?"
fails "Hash#has_key? returns true if argument is a key"

fails "Hash#hash returns the same hash for recursive hashes through arrays"
fails "Hash#hash returns the same hash for recursive hashes"
fails "Hash#hash generates a hash for recursive hash structures"
fails "Hash#hash returns a value which doesn't depend on the hash order"

fails "Hash#include? compares keys with the same #hash value via #eql?"
fails "Hash#include? returns true if argument is a key"

fails "Hash#invert compares new keys with eql? semantics"

fails "Hash#initialize_copy does not transfer default values"
fails "Hash#initialize_copy calls to_hash on hash subclasses"
fails "Hash#initialize_copy tries to convert the passed argument to a hash using #to_hash"
fails "Hash#initialize_copy replaces the contents of self with other"

fails "Hash#inspect handles hashes with recursive values"

fails "Hash#key? compares keys with the same #hash value via #eql?"
fails "Hash#key? returns true if argument is a key"

fails "Hash#member? compares keys with the same #hash value via #eql?"
fails "Hash#member? returns true if argument is a key"

fails "Hash#merge returns subclass instance for subclasses"

fails "Hash.new raises an ArgumentError if more than one argument is passed"
@@ -115,8 +101,6 @@

fails "Hash#to_h returns self for Hash instances"

fails "Hash#to_s handles hashes with recursive values"

fails "Hash.try_convert does not rescue exceptions raised by #to_hash"
fails "Hash.try_convert sends #to_hash to the argument and raises TypeError if it's not a kind of Hash"
fails "Hash.try_convert sends #to_hash to the argument and returns the result if it's a kind of Hash"