therubyracer 0.7.5 → 0.8.0.pre

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.

@@ -1,82 +0,0 @@
1
- require 'weakref'
2
-
3
- module V8
4
- module To
5
- class << self
6
- def rb(value)
7
- case value
8
- when V8::C::Function then peer(value) {V8::Function}
9
- when V8::C::Array then peer(value) {V8::Array}
10
- when V8::C::Object then peer(value) {V8::Object}
11
- when V8::C::String then value.Utf8Value()
12
- when V8::C::Date then Time.at(value.NumberValue())
13
- when V8::C::Value then nil if value.IsEmpty()
14
- else
15
- value
16
- end
17
- end
18
-
19
- def v8(value)
20
- case value
21
- when V8::Object
22
- value.instance_eval {@native}
23
- when String
24
- C::String::New(value.to_s)
25
- when Symbol
26
- C::String::NewSymbol(value.to_s)
27
- when Proc,Method
28
- template = C::FunctionTemplate::New() do |arguments|
29
- rbargs = []
30
- for i in 0..arguments.Length() - 1
31
- rbargs << To.rb(arguments[i])
32
- end
33
- V8::Function.rubycall(value, *rbargs)
34
- end
35
- return template.GetFunction()
36
- when ::Array
37
- C::Array::New(value.length).tap do |a|
38
- value.each_with_index do |item, i|
39
- a.Set(i, To.v8(item))
40
- end
41
- end
42
- when ::Hash
43
- C::Object::New().tap do |o|
44
- value.each do |key, value|
45
- o.Set(To.v8(key), To.v8(value))
46
- end
47
- end
48
- when ::Time
49
- C::Date::New(value)
50
- when ::Class
51
- Constructors[value].GetFunction().tap do |f|
52
- f.SetHiddenValue(C::String::NewSymbol("TheRubyRacer::RubyObject"), C::External::New(value))
53
- end
54
- when nil,Numeric,TrueClass,FalseClass, C::Value
55
- value
56
- else
57
- args = C::Array::New(1)
58
- args.Set(0, C::External::New(value))
59
- obj = Access[value.class].GetFunction().NewInstance(args)
60
- return obj
61
- end
62
- end
63
-
64
- def peer(value)
65
- external = value.GetHiddenValue(C::String::NewSymbol("TheRubyRacer::RubyObject"))
66
- if external && !external.IsEmpty()
67
- external.Value()
68
- else
69
- yield.new(value)
70
- end
71
- end
72
-
73
- def camel_case(str)
74
- str.to_s.gsub(/_(\w)/) {$1.upcase}
75
- end
76
-
77
- def perl_case(str)
78
- str.gsub(/([A-Z])([a-z])/) {"_#{$1.downcase}#{$2}"}.downcase
79
- end
80
- end
81
- end
82
- end
@@ -1,14 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- include V8
4
-
5
- describe V8::To do
6
-
7
- it "can convert into perl case" do
8
- To.perl_case("foo").should == "foo"
9
- To.perl_case("fooBar").should == "foo_bar"
10
- To.perl_case("fooBarBaz").should == "foo_bar_baz"
11
- To.perl_case("XMLDocument").should == "xml_document"
12
- end
13
-
14
- end