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: f12cd678594c
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7c8afa677e2d
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Mar 4, 2015

  1. Revert "Fix Opal.alias_native "

    This reverts commit b88a94a.
    meh committed Mar 4, 2015
    Copy the full SHA
    68cbc3d View commit details
  2. Revert "Move Module#alias_method and Module#alias_native semantics to…

    … runtime"
    
    This reverts commit e6a6acd.
    meh committed Mar 4, 2015
    Copy the full SHA
    7c8afa6 View commit details
Showing with 15 additions and 57 deletions.
  1. +15 −2 opal/corelib/module.rb
  2. +0 −46 opal/corelib/runtime.js
  3. +0 −9 spec/opal/stdlib/native/alias_native_spec.rb
17 changes: 15 additions & 2 deletions opal/corelib/module.rb
Original file line number Diff line number Diff line change
@@ -46,11 +46,24 @@ def <(other)
end

def alias_method(newname, oldname)
`Opal.alias(self, 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
end

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

def ancestors
46 changes: 0 additions & 46 deletions opal/corelib/runtime.js
Original file line number Diff line number Diff line change
@@ -1141,52 +1141,6 @@
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, native_name) {
var id = '$' + name,
body = obj.$$proto[native_name];

if (typeof(body) !== "function" || body.$$stub) {
throw Opal.NameError.$new("undefined native method `" + native_name + "' 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];
9 changes: 0 additions & 9 deletions spec/opal/stdlib/native/alias_native_spec.rb
Original file line number Diff line number Diff line change
@@ -25,12 +25,3 @@
}.new(`{ a: 42 }`).a.should == 42
end
end

describe 'Module#alias_native' do
it 'exposes a native method' do
klass = Class.new
`klass.$$proto.a = function() { return 123 }`
klass.alias_native :a, :a
klass.new.a.should == 123
end
end