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

Commits on Nov 12, 2013

  1. Copy the full SHA
    b242465 View commit details
  2. Cleanup Array#[]

    meh committed Nov 12, 2013
    Copy the full SHA
    20abdae View commit details
  3. Use new helpers in Array#fill

    meh committed Nov 12, 2013
    Copy the full SHA
    9f2a5fc View commit details
Showing with 42 additions and 31 deletions.
  1. +28 −31 opal/core/array.rb
  2. +14 −0 opal/opal.rb
59 changes: 28 additions & 31 deletions opal/core/array.rb
Original file line number Diff line number Diff line change
@@ -229,36 +229,40 @@ def ==(other)
def [](index, length = undefined)
if Range === index
%x{
var exclude = index.exclude,
length = #{Opal.coerce_to `index.end`, Integer, :to_int},
index = #{Opal.coerce_to `index.begin`, Integer, :to_int},
size = self.length;
var size = self.length,
exclude = index.exclude,
from = #{Opal.coerce_to `index.begin`, Integer, :to_int},
to = #{Opal.coerce_to `index.end`, Integer, :to_int};
if (index < 0) {
index += size;
}
if (from < 0) {
from += size;
if (index > 2147483648) {
#{raise RangeError, "bignum too big to convert into `long'"};
if (from < 0) {
return nil;
}
}
if (index > size || index < 0) {
#{Opal.fits_fixnum!(`from`)};
if (from > size) {
return nil;
}
if (length < 0) {
length += size;
}
if (to < 0) {
to += size;
if (length > 2147483648) {
#{raise RangeError, "bignum too big to convert into `long'"};
if (to < 0) {
return [];
}
}
#{Opal.fits_fixnum!(`to`)};
if (!exclude) {
length += 1;
to += 1;
}
return self.slice(index, length);
return self.slice(from, to);
}
else
index = Opal.coerce_to index, Integer, :to_int
@@ -268,15 +272,13 @@ def [](index, length = undefined)
if (index < 0) {
index += size;
}
if (index > 2147483648) {
#{raise RangeError, "bignum too big to convert into `long'"};
if (index < 0) {
return nil;
}
}
if (index < 0) {
return nil;
}
#{Opal.fits_fixnum!(`index`)};
if (length === undefined) {
if (index >= size || index < 0) {
@@ -288,9 +290,7 @@ def [](index, length = undefined)
else {
length = #{Opal.coerce_to length, Integer, :to_int};
if (length > 2147483648) {
#{raise RangeError, "bignum too big to convert into `long'"};
}
#{Opal.fits_fixnum!(`length`)};
if (length < 0 || index > size || index < 0) {
return nil;
@@ -740,11 +740,8 @@ def fill(*args, &block)
right = @length
end

if `right > 2147483648`
raise RangeError, "bignum too big to convert into `long'"
elsif `right >= 536870910`
raise ArgumentError, "argument too big"
end
Opal.fits_fixnum!(right)
Opal.fits_array!(right)

if `left > #@length`
%x{
14 changes: 14 additions & 0 deletions opal/opal.rb
Original file line number Diff line number Diff line change
@@ -88,6 +88,20 @@ def self.compare(a, b)
compare
end

def self.fits_fixnum!(value)
# since we have Fixnum#size as 32 bit, this is based on the int limits
if `value > 2147483648`
raise RangeError, "bignum too big to convert into `long'"
end
end

def self.fits_array!(value)
# this is the computed ARY_MAX_SIZE for 32 bit
if `value >= 536870910`
raise ArgumentError, "argument too big"
end
end

def self.truthy?(value)
if value
true