Skip to content

Commit

Permalink
Showing 3 changed files with 23 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/opal/parser.rb
Original file line number Diff line number Diff line change
@@ -1235,6 +1235,10 @@ def js_def(recvr, mid, args, stmts, line, end_line, sexp)
uses_super = @scope.uses_super

code = [fragment("#{arity_code}#@indent", sexp), @scope.to_vars, code]

if @scope.uses_zuper
code.unshift fragment("var $zuper = __slice.call(arguments, 0);", sexp)
end
end
end

@@ -2077,7 +2081,12 @@ def process_super(sexp, level)
#
# s(:zsuper)
def process_zsuper(exp, level)
js_super fragment("__slice.call(arguments)", exp), exp
if @scope.def?
@scope.uses_zuper = true
js_super fragment("$zuper", exp), exp
else
js_super fragment("__slice.call(arguments)", exp), exp
end
end

def js_super args, sexp
5 changes: 5 additions & 0 deletions lib/opal/target_scope.rb
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ class TargetScope

# uses parents super method
attr_accessor :uses_super
attr_accessor :uses_zuper

# @param [Symbol] type the scope type (:class, :module, :iter, :def, :top)
# @param [Opal::Parser] parser a parser instance used to create this scope
@@ -88,6 +89,10 @@ def iter?
@type == :iter
end

def def?
@type == :def
end

# Is this a normal def method directly inside a class? This is
# used for optimizing ivars as we can set them to nil in the
# class body
8 changes: 8 additions & 0 deletions spec/opal/language/super_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'spec_helper'

# FIXME: we cant make a better test case than this??? For some reason, a single test cannot be deduced
describe "The 'super' keyword" do
it "passes the right arguments when a variable rewrites special `arguments` js object" do
Struct.new(:a, :b, :c).new(1, 2, 3).b.should == 2
end
end

0 comments on commit ad90bb3

Please sign in to comment.