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

Commits on Nov 14, 2013

  1. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    06a0db7 View commit details
  2. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    af2082d View commit details
  3. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    81b5d5f View commit details
Showing with 21 additions and 16 deletions.
  1. +21 −16 stdlib/native.rb
37 changes: 21 additions & 16 deletions stdlib/native.rb
Original file line number Diff line number Diff line change
@@ -61,13 +61,17 @@ def self.try_convert(value)
end

def self.convert(value)
native = try_convert(value)

if `#{native} === nil`
raise ArgumentError, "the passed value isn't a native"
end

native
%x{
if (#{native?(value)}) {
return #{value};
}
else if (#{value.respond_to? :to_n}) {
return #{value.to_n};
}
else {
#{raise ArgumentError, "the passed value isn't a native"};
}
}
end

def self.call(obj, key, *args, &block)
@@ -258,14 +262,15 @@ def initialize(native, options = {}, &block)
def each(&block)
return enum_for :each unless block

index = 0
length = self.length

while index < length
block.call(self[index])
%x{
for (var i = 0, length = #{length}; i < length; i++) {
var value = $opal.$yield1(block, #{self[`i`]});
index += 1
end
if (value === $breaker) {
return $breaker.$v;
}
}
}

self
end
@@ -290,9 +295,9 @@ def [](index)

def []=(index, value)
if @set
`#@native[#@set](#{index}, #{value})`
`#@native[#@set](#{index}, #{Native.convert(value)})`
else
`#@native[#{index}] = #{value}`
`#@native[#{index}] = #{Native.convert(value)}`
end
end