Sha256: a209273df46a0a18029e62793237bcf7923b147607260522d0dca8fc0eb1dd17

Contents?: true

Size: 1.12 KB

Versions: 6

Compression:

Stored size: 1.12 KB

Contents

# backtick_javascript: true

require 'native'

describe "Native::Object#method_missing" do
  it "should return values" do
    Native(`{ a: 23 }`).a.should == 23
    Native(`{ a: { b: 42 } }`).a.b.should == 42
  end

  it "should call functions" do
    Native(`{ a: function() { return 42 } }`).a.should == 42
  end

  it "should pass the proper this to functions" do
    %x{
      function foo() {
        this.baz = 42;
      }

      foo.prototype.bar = function () {
        return this.baz;
      }
    }

    obj = `new foo()`
    Native(obj).bar.should == 42
    Native(obj).baz = 23
    Native(obj).bar.should == 23
  end

  it "should set values" do
    var = `{}`

    Native(var).a = 42
    `#{var}.a`.should == 42
    Native(var).a.should == 42
  end

  it "should pass the block as function" do
    Native(`{ a: function(func) { return func(); } }`).a { 42 }.should == 42
  end

  it "should unwrap arguments" do
    x = `{}`

    Native(`{ a: function(a, b) { return a === b } }`).a(Native(x), x).should == true
  end

  it "should wrap result" do
    Native(`{ a: function() { return {}; } }`).a.class.should == Native::Object
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
opal-1.8.3.rc1 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.8.2 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.8.1 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.8.0 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.8.0.beta1 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.8.0.alpha1 spec/opal/stdlib/native/method_missing_spec.rb