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

Commits on Nov 14, 2013

  1. 2

    Verified

    This commit was signed with the committer’s verified signature.
    makenowjust Hiroya Fujinami
    Copy the full SHA
    c682171 View commit details
Showing with 60 additions and 0 deletions.
  1. +33 −0 spec/stdlib/native/exposure_spec.rb
  2. +14 −0 stdlib/native.rb
  3. +13 −0 stdlib/native_exposure.rb
33 changes: 33 additions & 0 deletions spec/stdlib/native/exposure_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'native'

describe 'Native exposure' do
describe Class do
describe '#native_alias' do
it 'exposes a method to javascript' do
c = Class.new do
def ruby_method
:ruby
end

native_alias :rubyMethod, :ruby_method
end

`#{c.new}.rubyMethod()`.should == :ruby
end
end

describe '#native_class' do
it 'exposes a Class on the JS global object' do
c = Class.new do
def self.name
'Pippo'
end

native_class
end

`Pippo`.should == c
end
end
end
end
14 changes: 14 additions & 0 deletions stdlib/native.rb
Original file line number Diff line number Diff line change
@@ -479,5 +479,19 @@ def to_n
end
end

class Module
def native_module
`Opal.global[#{self.name}] = #{self}`
end
end

class Class
def native_alias(jsid, mid)
`#{self}._proto[#{jsid}] = #{self}._proto['$' + #{mid}]`
end

alias native_class native_module
end

# native global
$$ = $global = Native(`Opal.global`)
13 changes: 13 additions & 0 deletions stdlib/native_exposure.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Module
def native_module
`Opal.global[#{self.name}] = #{self}`
end
end

class Class
def native_alias(jsid, mid)
`#{self}._proto[#{jsid}] = #{self}._proto['$' + #{mid}]`
end

alias native_class native_module
end