Skip to content

Commit

Permalink
Methods defined on BasicObject should also be donated to bridged classes
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Oct 11, 2013
1 parent 18e1002 commit 1cdbaea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
9 changes: 0 additions & 9 deletions corelib/kernel.rb
@@ -1,13 +1,4 @@
module Kernel
# bridged from BasicObject
alias :initialize :initialize
alias :== :==
alias :__send__ :__send__
alias :eql? :eql?
alias :equal? :equal?
alias :instance_eval :instance_eval
alias :instance_exec :instance_exec

def method_missing(symbol, *args, &block)
raise NoMethodError, "undefined method `#{symbol}' for #{inspect}"
end
Expand Down
10 changes: 10 additions & 0 deletions corelib/runtime.js
Expand Up @@ -573,6 +573,10 @@
}
else if (obj._isClass) {
obj._proto[jsid] = body;

if (obj === RubyBasicObject) {
define_basic_object_method(jsid, body);
}
}
else {
obj[jsid] = body;
Expand All @@ -581,6 +585,12 @@
return nil;
};

function define_basic_object_method(jsid, body) {
for (var i = 0, len = bridged_classes.length; i < len; i++) {
bridged_classes[i]._proto[jsid] = body;
}
}

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

Expand Down
4 changes: 3 additions & 1 deletion lib/opal/parser.rb
Expand Up @@ -1172,6 +1172,8 @@ def js_def(recvr, mid, args, stmts, line, end_line, sexp, level)
end
elsif @scope.class? and @scope.name == 'Object'
[f("self._defn('$#{mid}', ", sexp), result, f(")", sexp)]
elsif @scope.class? and @scope.name == 'BasicObject'
[f("$opal.defn(self, '$#{mid}', "), result, f(")")]
elsif @scope.class_scope?
@scope.methods << "$#{mid}"
if uses_super
Expand Down Expand Up @@ -1428,7 +1430,7 @@ def process_alias(exp, level)

if [:class, :module].include? @scope.type
@scope.methods << "$#{exp[0][1].to_s}"
f("%s%s = %s%s" % [@scope.proto, new, @scope.proto, old], exp)
f("$opal.defn(self, '$%s', %s%s)" % [exp[0][1], @scope.proto, old], exp)
else
f("%s._proto%s = %s._proto%s" % ['self', new, 'self', old], exp)
end
Expand Down

0 comments on commit 1cdbaea

Please sign in to comment.