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

Commits on Nov 29, 2013

  1. Cleanup some Native helpers

    meh committed Nov 29, 2013

    Verified

    This commit was signed with the committer’s verified signature.
    makenowjust Hiroya Fujinami
    Copy the full SHA
    88e43fb View commit details
  2. Add Native::Object#respond_to?

    meh committed Nov 29, 2013
    2
    Copy the full SHA
    a0ff614 View commit details
Showing with 18 additions and 21 deletions.
  1. +18 −21 stdlib/native.rb
39 changes: 18 additions & 21 deletions stdlib/native.rb
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ module Native
def self.is_a?(object, klass)
%x{
try {
return #{object} instanceof #{Native.try_convert(klass)};
return #{object} instanceof #{try_convert(klass)};
}
catch (e) {
return false;
@@ -42,31 +42,24 @@ def self.call(obj, key, *args, &block)
%x{
var prop = #{obj}[#{key}];
if (prop == null) {
return nil;
}
else if (prop instanceof Function) {
if (block !== nil) {
args.push(block);
}
if (prop instanceof Function) {
var converted = new Array(args.length);
args = #{args.map {|value|
native = try_convert(value)
for (var i = 0, length = args.length; i < length; i++) {
var item = args[i],
conv = #{try_convert(`item`)};
if nil === native
value
else
native
end
}};
converted[i] = conv === nil ? item : conv;
}
return #{Native(`prop.apply(#{obj}, #{args})`)};
}
else if (#{native?(`prop`)}) {
return #{Native(`prop`)};
if (block !== nil) {
converted.push(block);
}
return #{Native(`prop.apply(#{obj}, converted)`)};
}
else {
return prop;
return #{Native(`prop`)};
}
}
end
@@ -200,6 +193,10 @@ def []=(key, value)
end
end

def respond_to?(name, *)
`typeof(self["$" + name]) === "function" || #@native.hasOwnProperty(#{name})`
end

def method_missing(mid, *args, &block)
%x{
if (mid.charAt(mid.length - 1) === '=') {