Sha256: e37c096d86809a7893bd74550faee0b877f838a5a650178afcfc6a223104ebea

Contents?: true

Size: 1.49 KB

Versions: 34

Compression:

Stored size: 1.49 KB

Contents

require 'spec_helper'

describe V8::C::Object do

  it "can store and retrieve a value" do
    o = V8::C::Object::New()
    key = V8::C::String::New("foo")
    value = V8::C::String::New("bar")
    o.Set(key, value)
    o.Get(key).Utf8Value().should eql "bar"
  end

  it "can retrieve all property names" do
    o = V8::C::Object::New()
    o.Set(V8::C::String::New("foo"), V8::C::String::New("bar"))
    o.Set(V8::C::String::New("baz"), V8::C::String::New("bang"))
    names = o.GetPropertyNames()
    names.Length().should eql 2
    names.Get(0).Utf8Value().should eql "foo"
    names.Get(1).Utf8Value().should eql "baz"
  end
  it "can set an accessor from ruby" do
    o = V8::C::Object::New()
    property = V8::C::String::New("statement")
    callback_data = V8::C::String::New("I am Legend")
    left = V8::C::String::New("Yo! ")
    getter = proc do |name, info|
      info.This().StrictEquals(o).should be_true
      info.Holder().StrictEquals(o).should be_true
      V8::C::String::Concat(left, info.Data())
    end
    setter = proc do |name, value, info|
      left = value
    end
    o.SetAccessor(property, getter, setter, callback_data)
    o.Get(property).Utf8Value().should eql "Yo! I am Legend"
    o.Set(property, V8::C::String::New("Bro! "))
    o.Get(property).Utf8Value().should eql "Bro! I am Legend"
  end
  it "always returns the same ruby object for the same V8 object" do
    one = V8::C::Object::New()
    two = V8::C::Object::New()
    one.Set("two", two)
    one.Get("two").should be two
  end
end

Version data entries

34 entries across 34 versions & 7 rubygems

Version Path
arcabouco-0.2.13 vendor/bundle/gems/therubyracer-0.12.2/spec/c/object_spec.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/therubyracer-0.11.4/spec/c/object_spec.rb
therubyracer-tmpfork-0.12.2 spec/c/object_spec.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/therubyracer-0.12.2/spec/c/object_spec.rb
therubyracer-0.12.2 spec/c/object_spec.rb
therubyracer-0.12.1 spec/c/object_spec.rb
therubyracer-discourse-0.12.0 spec/c/object_spec.rb
therubyracer-0.12.0 spec/c/object_spec.rb
therubyracer-0.11.4 spec/c/object_spec.rb
therubyracer-0.11.3 spec/c/object_spec.rb
therubyracer-0.11.2 spec/c/object_spec.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/therubyracer-0.11.0/spec/c/object_spec.rb
therubyracer-0.11.1 spec/c/object_spec.rb
therubyracer-0.11.1beta1 spec/c/object_spec.rb
therubyracer-0.11.0 spec/c/object_spec.rb
therubyracer-0.11.0beta8-x86-freebsd-9 spec/c/object_spec.rb
therubyracer-0.11.0beta8-x86_64-linux spec/c/object_spec.rb
therubyracer-0.11.0beta8-x86-linux spec/c/object_spec.rb
therubyracer-0.11.0beta8 spec/c/object_spec.rb
therubyracer-0.11.0beta7-x86_64-linux spec/c/object_spec.rb