mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
allow embedding BigDecimal
This commit is contained in:
parent
062cc582c5
commit
1349384c08
5 changed files with 22 additions and 3 deletions
|
@ -12,6 +12,7 @@ require 'v8/conversion/code'
|
|||
require 'v8/conversion/class'
|
||||
require 'v8/conversion/object'
|
||||
require 'v8/conversion/time'
|
||||
require 'v8/conversion/bigdecimal'
|
||||
require 'v8/conversion/hash'
|
||||
require 'v8/conversion/array'
|
||||
require 'v8/conversion/proc'
|
||||
|
|
|
@ -18,7 +18,7 @@ for type in [TrueClass, FalseClass, NilClass, Numeric] do
|
|||
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, BigDecimal, Proc, Method] do
|
||||
type.class_eval do
|
||||
include V8::Conversion.const_get(name)
|
||||
end
|
||||
|
|
11
lib/v8/conversion/bigdecimal.rb
Normal file
11
lib/v8/conversion/bigdecimal.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
require 'bigdecimal'
|
||||
class V8::Conversion
|
||||
module BigDecimal
|
||||
def to_v8
|
||||
context = V8::Context.current
|
||||
constructor = context.to_v8(self.class)
|
||||
object = constructor.NewInstance([V8::C::External::New(self)])
|
||||
return object
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,7 +1,5 @@
|
|||
class V8::Conversion
|
||||
module Object
|
||||
include V8::Util::Weakcell
|
||||
|
||||
def to_v8
|
||||
context = V8::Context.current
|
||||
constructor = context.to_v8(self.class)
|
||||
|
|
9
spec/v8/conversion_spec.rb
Normal file
9
spec/v8/conversion_spec.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe V8::Conversion do
|
||||
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
|
||||
end
|
Loading…
Add table
Reference in a new issue