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: c8876485c9e4
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ddd9349fbcb2
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Dec 25, 2013

  1. Copy the full SHA
    23c0212 View commit details
  2. Cleanup some passing specs

    meh committed Dec 25, 2013
    Copy the full SHA
    c29a1a2 View commit details
  3. Style cleanup for Array#pop

    meh committed Dec 25, 2013
    3
    Copy the full SHA
    ddd9349 View commit details
Showing with 30 additions and 20 deletions.
  1. +15 −13 opal/corelib/array.rb
  2. +14 −0 opal/corelib/helpers.rb
  3. +1 −0 spec/opal/filters/bugs/arity_check.rb
  4. +0 −7 spec/opal/filters/bugs/array.rb
28 changes: 15 additions & 13 deletions opal/corelib/array.rb
Original file line number Diff line number Diff line change
@@ -75,8 +75,7 @@ def self.new(size = nil, obj = nil, &block)
end

def self.try_convert(obj)
return nil unless obj.respond_to? :to_ary
obj = Opal.coerce_to obj, Array, :to_ary
Opal.coerce_to? obj, Array, :to_ary
end

def &(other)
@@ -1061,21 +1060,24 @@ def length
alias map! collect!

def pop(count = undefined)
%x{
var length = self.length;
if `count === undefined`
return if `self.length === 0`
return `self.pop()`
end

if (count == null) {
return length === 0 ? nil : self.pop();
}
count = Opal.coerce_to count, Integer, :to_int

count = #{Opal.coerce_to `count`, Integer, :to_int};
if `count < 0`
raise ArgumentError, 'negative array size'
end

if (count < 0) {
#{ raise ArgumentError, "negative count given" };
}
return [] if `self.length === 0`

return count > length ? self.splice(0, self.length) : self.splice(length - count, length);
}
if `count > self.length`
`self.splice(0, self.length)`
else
`self.splice(self.length - count, self.length)`
end
end

def push(*objects)
14 changes: 14 additions & 0 deletions opal/corelib/helpers.rb
Original file line number Diff line number Diff line change
@@ -19,6 +19,20 @@ def self.coerce_to!(object, type, method)
coerced
end

def self.coerce_to?(object, type, method)
return unless object.respond_to? method

coerced = coerce_to(object, type, method)

return if coerced.nil?

unless type === coerced
raise TypeError, "can't convert #{object.class} into #{type} (#{object.class}##{method} gives #{coerced.class}"
end

coerced
end

def self.try_convert(object, type, method)
return object if type === object

1 change: 1 addition & 0 deletions spec/opal/filters/bugs/arity_check.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
opal_filter "Wrong arity check" do
fails "Array#shift passed a number n as an argument raises an ArgumentError if more arguments are passed"
fails "Array#pop passed a number n as an argument raises an ArgumentError if more arguments are passed"
end
7 changes: 0 additions & 7 deletions spec/opal/filters/bugs/array.rb
Original file line number Diff line number Diff line change
@@ -25,11 +25,8 @@

fails "Array#[]= sets elements in the range arguments when passed ranges"

fails "Array#eql? ignores array class differences"
fails "Array#eql? handles well recursive arrays"
fails "Array#eql? returns true if corresponding elements are #eql?"

fails "Array#== compares with an equivalent Array-like object using #to_ary"
fails "Array#== handles well recursive arrays"

fails "Array#flatten does not call flatten on elements"
@@ -109,8 +106,6 @@
fails "Array#permutation returns an Enumerator of permutations of given length when called with an argument but no block"
fails "Array#permutation returns an Enumerator of all permutations when called without a block or arguments"

fails "Array#pop passed a number n as an argument raises an ArgumentError if more arguments are passed"

fails "Array#product when given an empty block returns self"
fails "Array#product when given a block will ignore unreasonable numbers of products and yield anyway"
fails "Array#product when given a block yields all combinations in turn"
@@ -203,8 +198,6 @@
fails "Array#transpose raises a TypeError if the passed Argument does not respond to #to_ary"
fails "Array#transpose tries to convert the passed argument to an Array using #to_ary"

fails "Array.try_convert sends #to_ary to the argument and raises TypeError if it's not a kind of Array"

fails "Array#uniq compares elements based on the value returned from the block"
fails "Array#uniq compares elements with matching hash codes with #eql?"
fails "Array#uniq uses eql? semantics"