Skip to content

Commit

Permalink
Showing 5 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions lib/opal/nodes/arglist.rb
Original file line number Diff line number Diff line change
@@ -16,9 +16,9 @@ def compile
if splat
if work.empty?
if code.empty?
code << fragment("Opal.splat(") << arg << fragment(")")
code << fragment("Opal.to_a(") << arg << fragment(")")
else
code << fragment(".concat(Opal.splat(") << arg << fragment("))")
code << fragment(".concat(Opal.to_a(") << arg << fragment("))")
end
else
if code.empty?
@@ -27,7 +27,7 @@ def compile
code << fragment(".concat([") << work << fragment("])")
end

code << fragment(".concat(Opal.splat(") << arg << fragment("))")
code << fragment(".concat(Opal.to_a(") << arg << fragment("))")
end

work = []
@@ -43,7 +43,7 @@ def compile
if code.empty?
code = join
else
code << fragment(".concat(Opal.splat(") << join << fragment("))")
code << fragment(".concat(Opal.to_a(") << join << fragment("))")
end
end

2 changes: 1 addition & 1 deletion lib/opal/nodes/logic.rb
Original file line number Diff line number Diff line change
@@ -96,7 +96,7 @@ def compile
elsif value.type == :sym
push '[', expr(value), ']'
else
push recv(value)
push "Opal.to_a(", recv(value), ")"
end
end
end
3 changes: 1 addition & 2 deletions lib/opal/nodes/masgn.rb
Original file line number Diff line number Diff line change
@@ -17,8 +17,7 @@ def compile
elsif rhs.type == :to_ary
push "#{tmp} = Opal.to_ary(", expr(rhs[1]), ")"
elsif rhs.type == :splat
push "(#{tmp} = ", expr(rhs[1]), ")['$to_a'] && !#{tmp}['$to_a'].$$stub ? (#{tmp} = #{tmp}['$to_a']())"
push " : (#{tmp}).$$is_array ? #{tmp} : (#{tmp} = [#{tmp}])"
push "#{tmp} = Opal.to_a(", expr(rhs[1]), ")"
else
raise "unsupported mlhs type"
end
4 changes: 2 additions & 2 deletions lib/opal/nodes/variables.rb
Original file line number Diff line number Diff line change
@@ -33,14 +33,14 @@ def using_irb?
def compile
if using_irb?
push "Opal.irb_vars#{property var_name.to_s} = "
push expr(value)
else
add_local variable(var_name.to_s)

push "#{variable(var_name.to_s)} = "
push expr(value)
end

push expr(value)

wrap '(', ')' if recv?
end
end
27 changes: 14 additions & 13 deletions opal/corelib/runtime.js
Original file line number Diff line number Diff line change
@@ -907,8 +907,21 @@
else if (value.$to_ary && !value.$to_ary.$$stub) {
return value.$to_ary();
}
else {
return [value];
}
};

return [value];
Opal.to_a = function(value) {
if (value == null || value == nil) {
return [];
}
else if (value.$to_a && !value.$to_a.$$stub) {
return value.$to_a();
}
else {
return [value];
}
};

/**
@@ -1447,18 +1460,6 @@
return range;
};

Opal.splat = function(value) {
if (value == null || value == nil) {
return [];
}
else if (typeof(value.$to_a) == "function" && !value.$to_a.$$stub) {
return value.$to_a();
}
else {
return [value];
}
};

Opal.ivar = function(name) {
if (name == "constructor" ||
name == "__proto__" ||

0 comments on commit f052ec1

Please sign in to comment.