therubyracer 0.7.1 → 0.7.2.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.

Files changed (49) hide show
  1. data/Rakefile +3 -2
  2. data/ext/v8/rr.cpp +5 -18
  3. data/ext/v8/rr.h +0 -3
  4. data/ext/v8/upstream/Makefile +1 -1
  5. data/ext/v8/v8_array.cpp +3 -9
  6. data/ext/v8/v8_callbacks.cpp +1 -1
  7. data/ext/v8/v8_cxt.cpp +19 -36
  8. data/ext/v8/v8_cxt.h +0 -7
  9. data/ext/v8/v8_exception.cpp +2 -1
  10. data/ext/v8/v8_external.cpp +18 -11
  11. data/ext/v8/v8_external.h +1 -0
  12. data/ext/v8/v8_func.cpp +2 -5
  13. data/ext/v8/v8_func.h +0 -2
  14. data/ext/v8/v8_msg.cpp +1 -2
  15. data/ext/v8/v8_obj.cpp +3 -13
  16. data/ext/v8/v8_obj.h +0 -1
  17. data/ext/v8/v8_ref.cpp +1 -6
  18. data/ext/v8/v8_ref.h +1 -2
  19. data/ext/v8/v8_script.cpp +0 -2
  20. data/ext/v8/v8_str.cpp +9 -3
  21. data/ext/v8/v8_str.h +0 -2
  22. data/ext/v8/v8_template.cpp +49 -37
  23. data/ext/v8/v8_template.h +0 -4
  24. data/ext/v8/v8_try_catch.cpp +0 -1
  25. data/ext/v8/v8_value.cpp +1 -2
  26. data/lib/v8.rb +2 -1
  27. data/lib/v8/access.rb +90 -1
  28. data/lib/v8/array.rb +1 -1
  29. data/lib/v8/context.rb +8 -23
  30. data/lib/v8/error.rb +111 -0
  31. data/lib/v8/function.rb +6 -5
  32. data/lib/v8/object.rb +1 -1
  33. data/lib/v8/to.rb +26 -30
  34. data/spec/redjs/jsapi_spec.rb +55 -14
  35. data/spec/v8/error_spec.rb +118 -0
  36. data/therubyracer.gemspec +4 -4
  37. metadata +14 -21
  38. data/ext/v8/callbacks.cpp +0 -185
  39. data/ext/v8/callbacks.h +0 -14
  40. data/ext/v8/convert_ruby.cpp +0 -8
  41. data/ext/v8/convert_ruby.h +0 -99
  42. data/ext/v8/convert_string.cpp +0 -10
  43. data/ext/v8/convert_string.h +0 -73
  44. data/ext/v8/convert_v8.cpp +0 -9
  45. data/ext/v8/convert_v8.h +0 -124
  46. data/ext/v8/converters.cpp +0 -84
  47. data/ext/v8/converters.h +0 -21
  48. data/ext/v8/v8.bundle +0 -0
  49. data/lib/v8/callbacks.rb +0 -88
@@ -1,9 +0,0 @@
1
- #include "convert_v8.h"
2
-
3
- V8LocalDest::V8LocalDest() {
4
-
5
- }
6
-
7
- V8LocalDest::~V8LocalDest() {
8
-
9
- }
data/ext/v8/convert_v8.h DELETED
@@ -1,124 +0,0 @@
1
- #ifndef __convert_v8_h__
2
- #define __convert_v8_h__
3
-
4
- #include <v8.h>
5
- #include <stdint.h>
6
- #include <stdio.h>
7
- #include <string>
8
-
9
- template<class T, class R> class V8HandleSource {
10
-
11
- T dest;
12
-
13
- public:
14
-
15
- V8HandleSource() {}
16
- ~V8HandleSource() {}
17
-
18
- bool operator() (v8::Handle<v8::Value>& value, R& result) {
19
-
20
- // a bit klunky, but alternative is to evaluate what type the
21
- // object is twice, which is unappealing
22
-
23
- if (value.IsEmpty()) {
24
- result = dest.pushNull();
25
- return true;
26
- }
27
-
28
- if (value->IsUndefined()) {
29
- result = dest.pushNull();
30
- return true;
31
- }
32
-
33
- if(value->IsNull()) {
34
- result = dest.pushNull();
35
- return true;
36
- }
37
-
38
- if(value->IsTrue()) {
39
- result = dest.pushBool(true);
40
- return true;
41
- }
42
-
43
- if(value->IsFalse()) {
44
- result = dest.pushBool(false);
45
- return true;
46
- }
47
-
48
- if(value->IsString()) {
49
- v8::Local<v8::String> str = value->ToString();
50
- result = convertString(str);
51
- return true;
52
- }
53
-
54
- if(value->IsInt32()) {
55
- result = dest.pushInt(value->Int32Value());
56
- return true;
57
- }
58
-
59
- if(value->IsNumber()) {
60
- result = dest.pushDouble(value->NumberValue());
61
- return true;
62
- }
63
-
64
- result = dest.pushNull();
65
- return false;
66
- }
67
-
68
- R convertString(v8::Local<v8::String>& str) {
69
- char buffer[1024];
70
- int total = 0;
71
- int remaining = str->Length();
72
- std::string output;
73
- while (remaining > 0) {
74
- int toCopy = remaining > sizeof(buffer) ? sizeof(buffer) : remaining;
75
- str->WriteAscii(buffer, total, toCopy);
76
- output.append(buffer, toCopy);
77
- total += toCopy;
78
- remaining -= toCopy;
79
- }
80
- return dest.pushString(output);
81
- }
82
-
83
-
84
- };
85
-
86
- /**
87
- * StringDest is a data type conversion destination that converts
88
- * any argument into a string. It should have all methods listed
89
- * in data_conversion.txt so it can be used as a template argument
90
- * for a conversion source class.
91
- */
92
- class V8LocalDest {
93
-
94
- public:
95
- V8LocalDest();
96
- ~V8LocalDest();
97
-
98
- v8::Local<v8::Value> pushString(const std::string& value) {
99
- return v8::Local<v8::Value>::New(v8::String::New(value.c_str()));
100
- }
101
-
102
- v8::Local<v8::Value> pushInt(int64_t value) {
103
- return v8::Local<v8::Value>::New(v8::Integer::New(value));
104
- }
105
-
106
- v8::Local<v8::Value> pushDouble(double value) {
107
- return v8::Local<v8::Value>::New(v8::Number::New(value));
108
- }
109
-
110
- v8::Local<v8::Value> pushBool(bool value) {
111
- return v8::Local<v8::Value>::New(v8::Boolean::New(value));
112
- }
113
-
114
- v8::Local<v8::Value> pushNull() {
115
- return v8::Local<v8::Value>::New(v8::Null());
116
- }
117
-
118
- v8::Local<v8::Value> pushUndefined() {
119
- return v8::Local<v8::Value>::New(v8::Undefined());
120
- }
121
- };
122
-
123
-
124
- #endif
@@ -1,84 +0,0 @@
1
- #include "converters.h"
2
- #include "callbacks.h"
3
- #include "v8_ref.h"
4
- #include "v8_obj.h"
5
- #include "v8_cxt.h"
6
- #include "v8_func.h"
7
- #include "v8_template.h"
8
- #include "v8_external.h"
9
-
10
- using namespace v8;
11
-
12
- namespace {
13
- std::string UNDEFINED_STR("undefined");
14
- }
15
-
16
- VALUE V82RB(Handle<Value>& value) {
17
- convert_v8_to_rb_t convert;
18
- VALUE result;
19
- VALUE type = rr_cV8_C_Object;
20
- if(convert(value, result)) {
21
- return result;
22
- }
23
-
24
- if (value->IsArray()) {
25
- Local<Array> array(Array::Cast(*value));
26
- VALUE rb_array = rb_ary_new2(array->Length());
27
- for (unsigned int i = 0; i < array->Length(); i++) {
28
- Local<Value> value = array->Get(Integer::New(i));
29
- rb_ary_push(rb_array, V82RB(value));
30
- }
31
- return rb_array;
32
- }
33
-
34
- if (value->IsFunction()) {
35
- type = rr_cV8_C_Function;
36
- }
37
-
38
- if (value->IsObject()) {
39
- Local<Object> object(Object::Cast(*value));
40
- Local<Value> peer = object->GetHiddenValue(String::New("TheRubyRacer::RubyObject"));
41
- if (peer.IsEmpty()) {
42
- VALUE context_ref = V8_Ref_Create(V8_C_Context, Context::GetEntered());
43
- object->SetHiddenValue(String::New("TheRubyRacer::Context"), rr_v8_external_create(context_ref));
44
- return V8_Ref_Create(type, value, context_ref);
45
- } else {
46
- return (VALUE)External::Unwrap(peer);
47
- }
48
- }
49
- return Qnil;
50
- }
51
-
52
- Local<Value> RB2V8(VALUE value) {
53
- VALUE valueClass = rb_class_of(value);
54
- if(valueClass == rb_cProc || valueClass == rb_cMethod) {
55
- Local<FunctionTemplate> t = FunctionTemplate::New(RacerRubyInvocationCallback, rr_v8_external_create(value));
56
- return t->GetFunction();
57
- }
58
- convert_rb_to_v8_t convert;
59
- Local<Value> result;
60
- if (convert(value, result)) {
61
- return result;
62
- }
63
- Local<Object> o = Racer_Create_V8_ObjectTemplate(value)->NewInstance();
64
- o->SetHiddenValue(String::New("TheRubyRacer::RubyObject"), rr_v8_external_create(value));
65
- return o;
66
- }
67
-
68
- std::string V82String(Handle<Value>& value) {
69
- convert_v8_to_string_t convert;
70
- std::string result;
71
- if(convert(value, result)) {
72
- return result;
73
- }
74
-
75
- if (value->IsObject()) {
76
- Local<Object> object(Object::Cast(*value));
77
- Local<String> str = object->ToString();
78
- if(convert(value, result)) {
79
- return result;
80
- }
81
- }
82
-
83
- return UNDEFINED_STR;
84
- }
data/ext/v8/converters.h DELETED
@@ -1,21 +0,0 @@
1
- #ifndef __converters_h__
2
- #define __converters_h__
3
-
4
- #include "convert_ruby.h"
5
- #include "convert_string.h"
6
- #include "convert_v8.h"
7
- #include <cstring>
8
-
9
- typedef RubyValueSource<V8LocalDest, v8::Local<v8::Value> > convert_rb_to_v8_t;
10
- typedef V8HandleSource<RubyValueDest, VALUE> convert_v8_to_rb_t;
11
-
12
- typedef RubyValueSource<StringDest, std::string> convert_rb_to_string_t;
13
- typedef V8HandleSource<StringDest, std::string> convert_v8_to_string_t;
14
-
15
- VALUE V82RB(v8::Handle<v8::Value>& value);
16
- v8::Local<v8::Value> RB2V8(VALUE value);
17
-
18
- std::string RB2String(VALUE value);
19
- std::string V82String(v8::Handle<v8::Value>& value);
20
-
21
- #endif
data/ext/v8/v8.bundle DELETED
Binary file
data/lib/v8/callbacks.rb DELETED
@@ -1,88 +0,0 @@
1
-
2
- module V8
3
- module C
4
- class MethodInfo
5
-
6
- attr_reader :perl_methods, :camel_methods
7
-
8
- def initialize(object)
9
- @object = object
10
- @methods = Set.new
11
- for name in object.public_methods(false) do
12
- @methods << name.to_s
13
- end
14
- end
15
-
16
- def find(name)
17
- for format in [name, To.perl_case(name), To.camel_case(name)]
18
- return @object.method(format) if @methods.include?(format)
19
- end
20
- end
21
- end
22
- end
23
-
24
- class NamedPropertyGetter
25
- def self.call(property, info)
26
- methods = MethodInfo(To.rb(info.This()))
27
-
28
- if method = methods.find(To.rb(property))
29
- if method.arity == 0
30
- To.v8(method.call)
31
- else
32
- To.v8(method)
33
- end
34
- else
35
- C::Empty
36
- end
37
-
38
- # method_name = if methods.include?(name)
39
- # name
40
- # elsif methods.include?(perl_name)
41
- # perl_name
42
- # end
43
- # if method_name
44
- # method = obj.method(method_name)
45
- # if method.arity == 0
46
- # To.v8(method.call())
47
- # else
48
- # To.v8(method)
49
- # end
50
- # else
51
- # C::Empty
52
- # end
53
- # end
54
- end
55
-
56
- class NamedPropertySetter
57
- def self.call(property, value, info)
58
- obj = To.rb(info.This())
59
- setter = To.rb(property) + "="
60
- camel_name = To.camel_case(setter)
61
- perl_name = To.perl_case(setter)
62
- methods = obj.public_methods(false).map(&:to_s)
63
- if methods.include?(perl_name)
64
- obj.send(perl_name, To.rb(value))
65
- elsif methods.include?(camel_name)
66
- obj.send(camel_name, To.rb(value))
67
- else
68
- C::Empty
69
- end
70
- end
71
- end
72
-
73
- class NamedPropertyEnumerator
74
- def self.call(info)
75
- obj = To.rb(info.This())
76
- camel_methods = obj.public_methods(false).inject(Set.new) do |set, name|
77
- set.tap do
78
- set << To.camel_case(name)
79
- end
80
- end
81
- names = V8::C::Array::New(camel_methods.length)
82
- camel_methods.each_with_index do |name, i|
83
- names.Set(i, C::String::New(name))
84
- end
85
- return names
86
- end
87
- end
88
- end