Skip to content

Commit

Permalink
WIP [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
elia committed Oct 12, 2013
1 parent 09f7778 commit 8f4424f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions corelib/runtime.js
Expand Up @@ -394,7 +394,7 @@
};

// Super dispatcher
Opal.dispatch_super = function(obj, jsid, current_func, args, iter, defs) {
Opal.find_super_dispatcher = function(obj, jsid, current_func, iter, defs) {
var dispatcher;

if (defs) {
Expand All @@ -412,7 +412,7 @@
dispatcher = dispatcher['$' + jsid];
dispatcher._p = iter;

return dispatcher.apply(obj, args);
return dispatcher;
};

var find_obj_super_dispatcher = function(obj, jsid, current_func) {
Expand Down
26 changes: 20 additions & 6 deletions lib/opal/parser.rb
Expand Up @@ -651,6 +651,9 @@ def process_defined(sexp, level)
f("($hasOwn.call($gvars, #{gvar_name.inspect}) ? 'global-variable', : nil)", sexp)
when :yield
f("(#{js_block_given(sexp, level)} ? 'yield' : nil)", sexp)
when :super
process_super(part, level, :skip_call)
# f("(Opal.find_super_dispatcher(self, ) ? 'super' : nil)", sexp)
when :lasgn, :iasgn, :gasgn, :cvdecl, :masgn,
:op_asgn_or, :op_asgn_and
f("'assignment'", sexp)
Expand Down Expand Up @@ -2035,10 +2038,12 @@ def process_casgn3(sexp, level)
# super a, b, c
#
# s(:super, arg1, arg2, ...)
def process_super(sexp, level)
def process_super(sexp, level, skip_call=false)
args, iter = sexp[0], sexp[1]

if args or iter
if skip_call
args = [f('[]')]
elsif args or iter
if iter
iter = process(iter)
else
Expand Down Expand Up @@ -2072,17 +2077,26 @@ def process_super(sexp, level)
cls_name = @scope.parent.name || "self._klass._proto"

if @scope.defs
[f("$opal.dispatch_super(this, #{@scope.mid.to_s.inspect}, #{scope},", sexp), args, f(", "), iter, f(", #{cls_name})", sexp)]
_super = [f("$opal.find_super_dispatcher(this, #{@scope.mid.to_s.inspect}, #{scope}, ", sexp), f(", "), iter, f(", #{cls_name})", sexp)]
else
[f("$opal.dispatch_super(self, #{@scope.mid.to_s.inspect}, #{scope}, ", sexp), args, f(", "), iter, f(")", sexp)]
_super = [f("$opal.find_super_dispatcher(self, #{@scope.mid.to_s.inspect}, #{scope}, ", sexp), f(", "), iter, f(")", sexp)]
end

unless skip_call
_super << f('.apply(this, ', sexp)
_super << args
_super << f(')', sexp)

This comment has been minimized.

Copy link
@elia

elia Oct 12, 2013

Author Member

also tried with _super += [f('.apply(this, ', sexp), args, f(')', sexp)]

end
_super

elsif @scope.type == :iter
chain, _, mid = @scope.get_super_chain
trys = chain.map { |c| "#{c}._sup" }.join ' || '
[f("(#{trys} || self._klass._super._proto[#{mid}]).apply(self, ", sexp), args, f(")", sexp)]
super_method = "#{trys} || self._klass._super._proto[#{mid}]"
skip_call ? [f("(#{super_method})")] :
[f("(#{super_method}).apply(self, ", sexp), args, f(")", sexp)]
else
raise "Cannot call super() from outside a method block"
skip_call ? [f("null")] : raise("Cannot call super() from outside a method block")
end
end

Expand Down

0 comments on commit 8f4424f

Please sign in to comment.