therubyracer 0.4.1 → 0.4.2

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.

@@ -15,6 +15,7 @@
15
15
  * \tparam DEST destination type for the converted data
16
16
  * \tparam RET is the return type of T's methods
17
17
  */
18
+
18
19
  template<class DEST, class RET> class RubyValueSource {
19
20
 
20
21
  /**
@@ -27,22 +28,28 @@ template<class DEST, class RET> class RubyValueSource {
27
28
  ~RubyValueSource() {}
28
29
 
29
30
 
30
- RET operator() (VALUE& value) {
31
+ bool operator() (VALUE& value, RET& result) {
31
32
  switch (TYPE(value)) {
32
33
  case T_FIXNUM:
33
- return dest.pushInt(FIX2INT(value));
34
+ result = dest.pushInt(FIX2INT(value));
35
+ return true;
34
36
  case T_FLOAT:
35
- return dest.pushDouble(NUM2DBL(value));
37
+ result = dest.pushDouble(NUM2DBL(value));
38
+ return true;
36
39
  case T_STRING:
37
- return convertString(value);
40
+ result = convertString(value);
41
+ return true;
38
42
  case T_NIL:
39
- return dest.pushNull();
43
+ result = dest.pushNull();
44
+ return true;
40
45
  case T_TRUE:
41
- return dest.pushBool(true);
46
+ result = dest.pushBool(true);
47
+ return true;
42
48
  case T_FALSE:
43
- return dest.pushBool(false);
49
+ result = dest.pushBool(false);
50
+ return true;
44
51
  }
45
- return dest.pushUndefined();
52
+ return false;
46
53
  }
47
54
 
48
55
  private:
@@ -24,22 +24,29 @@ VALUE V82RB(Handle<Value>& value) {
24
24
  return Qnil;
25
25
  }
26
26
 
27
- Local<Value> RB2V8(VALUE value) {
28
-
27
+ Local<Value> RB2V8(VALUE value) {
29
28
  VALUE valueClass = rb_class_of(value);
30
29
 
31
30
  if(valueClass == rb_cProc || valueClass == rb_cMethod) {
32
31
  Local<FunctionTemplate> t = FunctionTemplate::New(RacerRubyInvocationCallback, External::Wrap((void *)value));
33
32
  return t->GetFunction();
34
33
  }
35
-
36
34
  convert_rb_to_v8_t convert;
37
- return convert(value);
38
- }
39
-
40
- std::string RB2String(VALUE value) {
41
- convert_rb_to_string_t convert;
42
- return convert(value);
35
+ Local<Value> result;
36
+ if (convert(value, result)) {
37
+ return result;
38
+ }
39
+
40
+ Local<ObjectTemplate> tmpl = ObjectTemplate::New();
41
+ VALUE methods = rb_funcall(value, rb_intern("public_methods"), 1, Qfalse);
42
+ int len = RARRAY(methods)->len;
43
+ for (int i = 0; i < len; i++) {
44
+ VALUE method_name = RARRAY(methods)->ptr[i];
45
+ VALUE method = rb_funcall(value, rb_intern("method"), 1, method_name);
46
+ Local<String> keystr = (String *)*RB2V8(method_name);
47
+ tmpl->Set(keystr, RB2V8(method));
48
+ }
49
+ return tmpl->NewInstance();
43
50
  }
44
51
 
45
52
  std::string V82String(Handle<Value>& value) {
@@ -4,11 +4,10 @@ using namespace v8;
4
4
 
5
5
 
6
6
  v8_ref::v8_ref(Handle<void> object, VALUE ref) : handle(Persistent<void>::New(object)), references(ref) {
7
- //printf("Allocating v8 reference\n");
7
+
8
8
  }
9
9
 
10
10
  v8_ref::~v8_ref() {
11
- //printf("Disposing v8 reference\n");
12
11
  handle.Dispose();
13
12
  }
14
13
 
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.4.1'
5
+ VERSION = '0.4.2'
6
6
  require 'v8/v8' #native glue
7
7
  require 'v8/to'
8
8
  require 'v8/context'
@@ -6,12 +6,12 @@ Gem::Specification.new do |s|
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Charles Lowell", "Bill Robertson"]
9
- s.date = %q{2010-01-09}
9
+ s.date = %q{2010-01-10}
10
10
  s.description = %q{Embed the V8 Javascript interpreter into Ruby.}
11
11
  s.email = ["cowboyd@thefrontside.net", "billrobertson42@gmail.com"]
12
12
  s.extensions = ["ext/v8/extconf.rb"]
13
13
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "docs/data_conversion.txt"]
14
- s.files = ["Doxyfile", "History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "docs/data_conversion.txt", "ext/v8/convert_ruby.cpp", "ext/v8/convert_ruby.h", "ext/v8/convert_string.cpp", "ext/v8/convert_string.h", "ext/v8/convert_v8.cpp", "ext/v8/convert_v8.h", "ext/v8/converters.cpp", "ext/v8/converters.h", "ext/v8/extconf.rb", "ext/v8/v8.cpp", "ext/v8/v8_cxt.cpp", "ext/v8/v8_cxt.h", "ext/v8/v8_func.cpp", "ext/v8/v8_func.h", "ext/v8/v8_msg.cpp", "ext/v8/v8_msg.h", "ext/v8/v8_obj.cpp", "ext/v8/v8_obj.h", "ext/v8/v8_ref.cpp", "ext/v8/v8_ref.h", "ext/v8/v8_script.cpp", "ext/v8/v8_script.h", "ext/v8/v8_standalone.cpp", "ext/v8/v8_standalone.h", "ext/v8/v8_str.cpp", "ext/v8/v8_str.h", "ext/v8/v8_template.cpp", "ext/v8/v8_template.h", "lib/v8.rb", "lib/v8/context.rb", "lib/v8/object.rb", "lib/v8/to.rb", "script/console", "script/destroy", "script/generate", "spec/redjs/README.txt", "spec/redjs/jsapi_spec.rb", "spec/redjs_helper.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake", "therubyracer.gemspec"]
14
+ s.files = ["Doxyfile", "History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "docs/data_conversion.txt", "ext/v8/callbacks.cpp", "ext/v8/callbacks.h", "ext/v8/convert_ruby.cpp", "ext/v8/convert_ruby.h", "ext/v8/convert_string.cpp", "ext/v8/convert_string.h", "ext/v8/convert_v8.cpp", "ext/v8/convert_v8.h", "ext/v8/converters.cpp", "ext/v8/converters.h", "ext/v8/extconf.rb", "ext/v8/v8.cpp", "ext/v8/v8_cxt.cpp", "ext/v8/v8_cxt.h", "ext/v8/v8_func.cpp", "ext/v8/v8_func.h", "ext/v8/v8_msg.cpp", "ext/v8/v8_msg.h", "ext/v8/v8_obj.cpp", "ext/v8/v8_obj.h", "ext/v8/v8_ref.cpp", "ext/v8/v8_ref.h", "ext/v8/v8_script.cpp", "ext/v8/v8_script.h", "ext/v8/v8_standalone.cpp", "ext/v8/v8_standalone.h", "ext/v8/v8_str.cpp", "ext/v8/v8_str.h", "ext/v8/v8_template.cpp", "ext/v8/v8_template.h", "lib/v8.rb", "lib/v8/context.rb", "lib/v8/object.rb", "lib/v8/to.rb", "script/console", "script/destroy", "script/generate", "spec/redjs/README.txt", "spec/redjs/jsapi_spec.rb", "spec/redjs_helper.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake", "therubyracer.gemspec"]
15
15
  s.homepage = %q{http://github.com/cowboyd/therubyracer}
16
16
  s.rdoc_options = ["--main", "README.rdoc"]
17
17
  s.require_paths = ["lib", "ext"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: therubyracer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charles Lowell
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-01-09 00:00:00 +02:00
13
+ date: 2010-01-10 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency