Skip to content

Commit

Permalink
Methods defined inside block should donate to modules (if inside module)
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Oct 11, 2013
1 parent 7712501 commit 18e1002
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 15 additions & 0 deletions corelib/runtime.js
Expand Up @@ -566,6 +566,21 @@
}
};

Opal.defn = function(obj, jsid, body) {
if (obj.__mod__) {
obj._proto[jsid] = body;
Opal.donate(obj, [jsid]);
}
else if (obj._isClass) {
obj._proto[jsid] = body;
}
else {
obj[jsid] = body;
}

return nil;
};

// Initialization
// --------------

Expand Down
4 changes: 3 additions & 1 deletion lib/opal/parser.rb
Expand Up @@ -1180,7 +1180,9 @@ def js_def(recvr, mid, args, stmts, line, end_line, sexp, level)
end

[f("#{uses_super}#{@scope.proto}#{jsid} = ", sexp), result]
else # :top, :iter
elsif @scope.iter?
[f("$opal.defn(self, '$#{mid}', "), result, f(")")]
else # :top
[f("def#{jsid} = ", sexp), result]
end

Expand Down

0 comments on commit 18e1002

Please sign in to comment.