Sha256: df25862e342c5767ec5511e38ce0e1efbc6fab4dc7113b1ebb9742659cf1b113

Contents?: true

Size: 1.1 KB

Versions: 74

Compression:

Stored size: 1.1 KB

Contents

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

74 entries across 74 versions & 3 rubygems

Version Path
opal-1.7.4 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.7.3 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.7.2 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.7.1 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.7.0 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.7.0.rc1 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.6.1 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.6.0 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.6.0.rc1 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.6.0.alpha1 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.5.1 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.5.0 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.5.0.rc1 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.4.1 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.4.0 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.4.0.alpha1 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.3.2 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.3.1 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.3.0 spec/opal/stdlib/native/method_missing_spec.rb
opal-1.3.0.rc1 spec/opal/stdlib/native/method_missing_spec.rb