Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1e5b6e6d6ee7
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e6a6acd22718
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Feb 24, 2015

  1. Copy the full SHA
    98c0791 View commit details
  2. Copy the full SHA
    e6a6acd View commit details
Showing with 57 additions and 23 deletions.
  1. +4 −23 opal/corelib/module.rb
  2. +53 −0 opal/corelib/runtime.js
27 changes: 4 additions & 23 deletions opal/corelib/module.rb
Original file line number Diff line number Diff line change
@@ -46,24 +46,11 @@ def <(other)
end

def alias_method(newname, oldname)
%x{
var newjsid = '$' + newname,
body = self.$$proto['$' + oldname];
if (self.$$is_singleton) {
self.$$proto[newjsid] = body;
}
else {
Opal.defn(self, newjsid, body);
}
return self;
}
self
`Opal.alias(self, newname, oldname)`
end

def alias_native(mid, jsid = mid)
`self.$$proto['$' + mid] = self.$$proto[jsid]`
`Opal.alias_native(self, mid, jsid)`
end

def ancestors
@@ -274,15 +261,9 @@ def define_method(name, method = undefined, &block)
end

def remove_method(name)
%x{
var jsid = '$' + name;
var current = self.$$proto[jsid];
delete self.$$proto[jsid];
`Opal.undef(self, '$' + name)`

// Check if we need to reverse Opal.donate
// Opal.retire(self, [jsid]);
return self;
}
self
end

def include(*mods)
53 changes: 53 additions & 0 deletions opal/corelib/runtime.js
Original file line number Diff line number Diff line change
@@ -1134,6 +1134,59 @@
}
}

/*
* Called to remove a method.
*/
Opal.undef = function(obj, jsid) {
delete obj.$$proto[jsid];
};

function wrap(body) {
var wrapped = function() {
body.$$p = wrapped.$$p;
body.$$s = wrapped.$$s;

return body.apply(this, arguments);
}

return wrapped;
}

Opal.alias = function(obj, name, old) {
var id = '$' + name;
body = obj.$$proto['$' + old];

if (typeof(body) !== "function" || body.$$stub) {
var ancestor = obj.$$super;

while (typeof(body) !== "function" && ancestor.$$super) {
body = ancestor['$' + old];
ancestor = ancestor.$$super;
}

if (typeof(body) !== "function" || body.$$stub) {
throw Opal.NameError.$new("undefined method `" + old + "' for class `" + obj.$name() + "'")
}
}

Opal.defn(obj, id, wrap(body));

return obj;
};

Opal.alias_native = function(obj, name, old) {
var id = '$' + name,
body = obj.$$proto['$' + old];

if (typeof(body) !== "function" || body.$$stub) {
throw Opal.NameError.$new("undefined method `" + old + "' for class `" + obj.$name() + "'")
}

Opal.defn(obj, id, wrap(body));

return obj;
};

Opal.hash = function() {
if (arguments.length == 1 && arguments[0].$$class == Opal.Hash) {
return arguments[0];