Skip to content

Commit ad90bb3

Browse files
committedJul 29, 2013
Fix bug in calling super with no parens/args
We could not find an isolated test case, but know the bug exists (yes, poor excuse). We know this fails with Struct.new() so we use that as the test case
1 parent 97e6c98 commit ad90bb3

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed
 

Diff for: ‎lib/opal/parser.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,10 @@ def js_def(recvr, mid, args, stmts, line, end_line, sexp)
12351235
uses_super = @scope.uses_super
12361236

12371237
code = [fragment("#{arity_code}#@indent", sexp), @scope.to_vars, code]
1238+
1239+
if @scope.uses_zuper
1240+
code.unshift fragment("var $zuper = __slice.call(arguments, 0);", sexp)
1241+
end
12381242
end
12391243
end
12401244

@@ -2077,7 +2081,12 @@ def process_super(sexp, level)
20772081
#
20782082
# s(:zsuper)
20792083
def process_zsuper(exp, level)
2080-
js_super fragment("__slice.call(arguments)", exp), exp
2084+
if @scope.def?
2085+
@scope.uses_zuper = true
2086+
js_super fragment("$zuper", exp), exp
2087+
else
2088+
js_super fragment("__slice.call(arguments)", exp), exp
2089+
end
20812090
end
20822091

20832092
def js_super args, sexp

Diff for: ‎lib/opal/target_scope.rb

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class TargetScope
3333

3434
# uses parents super method
3535
attr_accessor :uses_super
36+
attr_accessor :uses_zuper
3637

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

92+
def def?
93+
@type == :def
94+
end
95+
9196
# Is this a normal def method directly inside a class? This is
9297
# used for optimizing ivars as we can set them to nil in the
9398
# class body

Diff for: ‎spec/opal/language/super_spec.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require 'spec_helper'
2+
3+
# FIXME: we cant make a better test case than this??? For some reason, a single test cannot be deduced
4+
describe "The 'super' keyword" do
5+
it "passes the right arguments when a variable rewrites special `arguments` js object" do
6+
Struct.new(:a, :b, :c).new(1, 2, 3).b.should == 2
7+
end
8+
end

0 commit comments

Comments
 (0)
Please sign in to comment.