mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
Conversion trick for 64-bit Fixnums
This commit is contained in:
parent
22682755a3
commit
fde0d8ae9a
4 changed files with 46 additions and 3 deletions
|
@ -20,6 +20,7 @@ require 'v8/conversion/proc'
|
|||
require 'v8/conversion/method'
|
||||
require 'v8/conversion/symbol'
|
||||
require 'v8/conversion/string'
|
||||
require 'v8/conversion/fixnum'
|
||||
require 'v8/conversion'
|
||||
require 'v8/access/names'
|
||||
require 'v8/access/indices'
|
||||
|
|
|
@ -12,13 +12,13 @@ class V8::Conversion
|
|||
end
|
||||
end
|
||||
|
||||
for type in [TrueClass, FalseClass, NilClass, Float, Fixnum] do
|
||||
for type in [TrueClass, FalseClass, NilClass, Float] do
|
||||
type.class_eval do
|
||||
include V8::Conversion::Primitive
|
||||
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
|
||||
include V8::Conversion.const_get(type.name)
|
||||
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 'bigdecimal'
|
||||
describe V8::Conversion do
|
||||
|
||||
let(:cxt) { V8::Context.new }
|
||||
|
||||
it "can embed BigDecimal values" do
|
||||
cxt = V8::Context.new
|
||||
cxt['big'] = BigDecimal.new('1.1')
|
||||
cxt['big'].should eql BigDecimal.new('1.1')
|
||||
end
|
||||
|
@ -18,4 +20,33 @@ describe V8::Conversion do
|
|||
|
||||
klass.test.should be_instance_of(::Set)
|
||||
end
|
||||
|
||||
context "::Fixnum" do
|
||||
context "for 32-bit numbers" do
|
||||
it "should convert positive integer" do
|
||||
cxt['fixnum_a'] = 0xFFFFFFFF
|
||||
cxt['fixnum_a'].should == 0xFFFFFFFF
|
||||
cxt['fixnum_a'].should be_instance_of(Fixnum)
|
||||
end
|
||||
|
||||
it "should convert negative integer" do
|
||||
cxt['fixnum_b'] = -0xFFFF
|
||||
cxt['fixnum_b'].should == -0xFFFF
|
||||
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'] = -0xFFFFFFFF
|
||||
cxt['fixnum_d'].should == -0xFFFFFFFF
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue