therubyracer 0.8.0.pre → 0.8.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of therubyracer might be problematic. Click here for more details.
- data/Rakefile +1 -1
- data/ext/v8/v8_date.cpp +12 -3
- data/lib/v8.rb +1 -1
- data/lib/v8/portal.rb +2 -2
- data/spec/redjs/jsapi_spec.rb +20 -3
- data/therubyracer.gemspec +2 -2
- metadata +4 -4
data/Rakefile
CHANGED
@@ -7,7 +7,7 @@ manifest.exclude "lib/v8/*.bundle", "lib/v8/*.so", "ext/**/test/*", "ext/**/test
|
|
7
7
|
Gem::Specification.new do |gemspec|
|
8
8
|
$gemspec = gemspec
|
9
9
|
gemspec.name = gemspec.rubyforge_project = "therubyracer"
|
10
|
-
gemspec.version = "0.8.0.
|
10
|
+
gemspec.version = "0.8.0.pre2"
|
11
11
|
gemspec.summary = "Embed the V8 Javascript interpreter into Ruby"
|
12
12
|
gemspec.description = "Call javascript code and manipulate javascript objects from ruby. Call ruby code and manipulate ruby objects from javascript."
|
13
13
|
gemspec.email = "cowboyd@thefrontside.net"
|
data/ext/v8/v8_date.cpp
CHANGED
@@ -6,18 +6,27 @@
|
|
6
6
|
using namespace v8;
|
7
7
|
|
8
8
|
namespace {
|
9
|
-
|
9
|
+
|
10
10
|
VALUE DateClass;
|
11
|
-
|
11
|
+
|
12
12
|
VALUE New(VALUE self, VALUE time) {
|
13
13
|
HandleScope scope;
|
14
|
-
return rr_v8_ref_create(self, Date::New(NUM2DBL(
|
14
|
+
return rr_v8_ref_create(self, Date::New(NUM2DBL(time)));
|
15
|
+
}
|
16
|
+
|
17
|
+
// Override Value::NumberValue in order to ensure that we call the more specific and optimized
|
18
|
+
// Number Value in v8::Date
|
19
|
+
VALUE NumberValue(VALUE self) {
|
20
|
+
HandleScope scope;
|
21
|
+
Local<Date> date = V8_Ref_Get<Date>(self);
|
22
|
+
return rr_v82rb(date->NumberValue());
|
15
23
|
}
|
16
24
|
}
|
17
25
|
|
18
26
|
void rr_init_v8_date() {
|
19
27
|
DateClass = rr_define_class("Date", rr_cV8_C_Value);
|
20
28
|
rr_define_singleton_method(DateClass, "New", New, 1);
|
29
|
+
rr_define_method(DateClass, "NumberValue", NumberValue, 0);
|
21
30
|
}
|
22
31
|
|
23
32
|
VALUE rr_reflect_v8_date(Handle<Value> value) {
|
data/lib/v8.rb
CHANGED
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
4
|
module V8
|
5
|
-
VERSION = '0.8.0.
|
5
|
+
VERSION = '0.8.0.pre2'
|
6
6
|
require 'v8/v8' #native glue
|
7
7
|
require 'v8/portal'
|
8
8
|
require 'v8/portal/functions'
|
data/lib/v8/portal.rb
CHANGED
@@ -82,7 +82,7 @@ module V8
|
|
82
82
|
when V8::C::Array then peer(value) {V8::Array}
|
83
83
|
when V8::C::Object then peer(value) {V8::Object}
|
84
84
|
when V8::C::String then value.Utf8Value()
|
85
|
-
when V8::C::Date then Time.at(value.NumberValue())
|
85
|
+
when V8::C::Date then Time.at(value.NumberValue() / 1000)
|
86
86
|
when V8::C::Value then nil if value.IsEmpty()
|
87
87
|
else
|
88
88
|
value
|
@@ -112,7 +112,7 @@ module V8
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
when ::Time
|
115
|
-
C::Date::New(value)
|
115
|
+
C::Date::New(value.to_f * 1000)
|
116
116
|
when ::Class
|
117
117
|
@embedded_constructors[value].GetFunction().tap do |f|
|
118
118
|
f.SetHiddenValue(C::String::NewSymbol("TheRubyRacer::RubyObject"), C::External::New(value))
|
data/spec/redjs/jsapi_spec.rb
CHANGED
@@ -52,6 +52,18 @@ describe "Ruby Javascript API" do
|
|
52
52
|
@cxt.eval("'#{lorem}'").should == lorem
|
53
53
|
end
|
54
54
|
|
55
|
+
it "translates JavaScript dates properly into ruby Time objects" do
|
56
|
+
now = Time.now
|
57
|
+
@cxt.eval('new Date()').tap do |time|
|
58
|
+
time.should be_kind_of(Time)
|
59
|
+
time.year.should == now.year
|
60
|
+
time.day.should == now.day
|
61
|
+
time.month.should == now.month
|
62
|
+
time.min.should == now.min
|
63
|
+
time.sec.should == now.sec
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
55
67
|
it "can pass objects back to ruby" do
|
56
68
|
@cxt.eval("({foo: 'bar', baz: 'bang', '5': 5, embedded: {badda: 'bing'}})").tap do |object|
|
57
69
|
object.should_not be_nil
|
@@ -129,14 +141,19 @@ describe "Ruby Javascript API" do
|
|
129
141
|
end
|
130
142
|
|
131
143
|
it "translates ruby Time to Javascript Date" do
|
144
|
+
now = Time.now
|
132
145
|
class_eval do
|
146
|
+
@@now = now
|
133
147
|
def ruby_time
|
134
|
-
|
148
|
+
@@now
|
135
149
|
end
|
136
150
|
end
|
137
151
|
evaljs('o.ruby_time instanceof Date').should == true
|
138
|
-
evaljs('o.ruby_time.
|
139
|
-
evaljs('
|
152
|
+
evaljs('o.ruby_time.getFullYear()').should == now.year
|
153
|
+
evaljs('o.ruby_time.getMonth() + 1').should == now.month
|
154
|
+
evaljs('o.ruby_time.getDate()').should == now.day
|
155
|
+
evaljs('o.ruby_time.getMinutes()').should == now.min
|
156
|
+
evaljs('o.ruby_time.getSeconds()').should == now.sec
|
140
157
|
end
|
141
158
|
|
142
159
|
it "translates ruby true to Javascript true" do
|
data/therubyracer.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{therubyracer}
|
5
|
-
s.version = "0.8.0.
|
5
|
+
s.version = "0.8.0.pre2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Charles Lowell", "Bill Robertson"]
|
9
|
-
s.date = %q{2010-
|
9
|
+
s.date = %q{2010-10-11}
|
10
10
|
s.description = %q{Call javascript code and manipulate javascript objects from ruby. Call ruby code and manipulate ruby objects from javascript.}
|
11
11
|
s.email = %q{cowboyd@thefrontside.net}
|
12
12
|
s.executables = ["therubyracer", "v8"]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: therubyracer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: -1876988255
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 8
|
9
9
|
- 0
|
10
|
-
-
|
11
|
-
version: 0.8.0.
|
10
|
+
- pre2
|
11
|
+
version: 0.8.0.pre2
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Charles Lowell
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-
|
20
|
+
date: 2010-10-11 00:00:00 -05:00
|
21
21
|
default_executable:
|
22
22
|
dependencies: []
|
23
23
|
|