mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
Merge remote-tracking branch 'meredian/master'
This commit is contained in:
commit
e8fd9facfd
4 changed files with 46 additions and 3 deletions
|
@ -18,6 +18,7 @@ require 'v8/conversion/proc'
|
||||||
require 'v8/conversion/method'
|
require 'v8/conversion/method'
|
||||||
require 'v8/conversion/symbol'
|
require 'v8/conversion/symbol'
|
||||||
require 'v8/conversion/string'
|
require 'v8/conversion/string'
|
||||||
|
require 'v8/conversion/fixnum'
|
||||||
require 'v8/conversion'
|
require 'v8/conversion'
|
||||||
require 'v8/access/names'
|
require 'v8/access/names'
|
||||||
require 'v8/access/indices'
|
require 'v8/access/indices'
|
||||||
|
|
|
@ -12,13 +12,13 @@ class V8::Conversion
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for type in [TrueClass, FalseClass, NilClass, Float, Fixnum] do
|
for type in [TrueClass, FalseClass, NilClass, Float] do
|
||||||
type.class_eval do
|
type.class_eval do
|
||||||
include V8::Conversion::Primitive
|
include V8::Conversion::Primitive
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for type in [Class, Object, Array, Hash, String, Symbol, Time, Proc, Method] do
|
for type in [Class, Object, Array, Hash, String, Symbol, Time, Proc, Method, Fixnum] do
|
||||||
type.class_eval do
|
type.class_eval do
|
||||||
include V8::Conversion.const_get(type.name)
|
include V8::Conversion.const_get(type.name)
|
||||||
end
|
end
|
||||||
|
|
11
lib/v8/conversion/fixnum.rb
Normal file
11
lib/v8/conversion/fixnum.rb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
class V8::Conversion
|
||||||
|
module Fixnum
|
||||||
|
def to_ruby
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_v8
|
||||||
|
self.to_f.to_v8
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,8 +1,10 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
require 'bigdecimal'
|
require 'bigdecimal'
|
||||||
describe V8::Conversion do
|
describe V8::Conversion do
|
||||||
|
|
||||||
|
let(:cxt) { V8::Context.new }
|
||||||
|
|
||||||
it "can embed BigDecimal values" do
|
it "can embed BigDecimal values" do
|
||||||
cxt = V8::Context.new
|
|
||||||
cxt['big'] = BigDecimal.new('1.1')
|
cxt['big'] = BigDecimal.new('1.1')
|
||||||
cxt['big'].should eql BigDecimal.new('1.1')
|
cxt['big'].should eql BigDecimal.new('1.1')
|
||||||
end
|
end
|
||||||
|
@ -18,4 +20,33 @@ describe V8::Conversion do
|
||||||
|
|
||||||
klass.test.should be_instance_of(::Set)
|
klass.test.should be_instance_of(::Set)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "::Fixnum" do
|
||||||
|
context "for 32-bit numbers" do
|
||||||
|
it "should convert positive integer" do
|
||||||
|
cxt['fixnum_a'] = 123
|
||||||
|
cxt['fixnum_a'].should == 123
|
||||||
|
cxt['fixnum_a'].should be_instance_of(Fixnum)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should convert negative integer" do
|
||||||
|
cxt['fixnum_b'] = -123
|
||||||
|
cxt['fixnum_b'].should == -123
|
||||||
|
cxt['fixnum_b'].should be_instance_of(Fixnum)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "for 64-bit numbers" do
|
||||||
|
it "should convert positive integer" do
|
||||||
|
cxt['fixnum_c'] = 0x100000000
|
||||||
|
cxt['fixnum_c'].should == 0x100000000
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should convert negative integer" do
|
||||||
|
cxt['fixnum_d'] = -0x100000000
|
||||||
|
cxt['fixnum_d'].should == -0x100000000
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue