therubyracer-freebsd 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/.gitignore +13 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +8 -0
  4. data/.yardopts +1 -0
  5. data/Changelog.md +231 -0
  6. data/Gemfile +3 -0
  7. data/README.md +167 -0
  8. data/Rakefile +26 -0
  9. data/bin/therubyracer +11 -0
  10. data/ext/v8/extconf.rb +26 -0
  11. data/ext/v8/rr.cpp +189 -0
  12. data/ext/v8/rr.h +41 -0
  13. data/ext/v8/v8.cpp +48 -0
  14. data/ext/v8/v8_array.cpp +48 -0
  15. data/ext/v8/v8_array.h +8 -0
  16. data/ext/v8/v8_callbacks.cpp +81 -0
  17. data/ext/v8/v8_callbacks.h +8 -0
  18. data/ext/v8/v8_context.cpp +92 -0
  19. data/ext/v8/v8_context.h +6 -0
  20. data/ext/v8/v8_date.cpp +40 -0
  21. data/ext/v8/v8_date.h +6 -0
  22. data/ext/v8/v8_debug.cpp +17 -0
  23. data/ext/v8/v8_debug.h +6 -0
  24. data/ext/v8/v8_exception.cpp +133 -0
  25. data/ext/v8/v8_exception.h +11 -0
  26. data/ext/v8/v8_external.cpp +70 -0
  27. data/ext/v8/v8_external.h +8 -0
  28. data/ext/v8/v8_function.cpp +69 -0
  29. data/ext/v8/v8_function.h +11 -0
  30. data/ext/v8/v8_handle.cpp +186 -0
  31. data/ext/v8/v8_handle.h +48 -0
  32. data/ext/v8/v8_locker.cpp +139 -0
  33. data/ext/v8/v8_locker.h +6 -0
  34. data/ext/v8/v8_message.cpp +67 -0
  35. data/ext/v8/v8_message.h +10 -0
  36. data/ext/v8/v8_object.cpp +122 -0
  37. data/ext/v8/v8_object.h +10 -0
  38. data/ext/v8/v8_script.cpp +36 -0
  39. data/ext/v8/v8_script.h +8 -0
  40. data/ext/v8/v8_string.cpp +52 -0
  41. data/ext/v8/v8_string.h +9 -0
  42. data/ext/v8/v8_template.cpp +344 -0
  43. data/ext/v8/v8_template.h +8 -0
  44. data/ext/v8/v8_try_catch.cpp +70 -0
  45. data/ext/v8/v8_try_catch.h +5 -0
  46. data/ext/v8/v8_v8.cpp +34 -0
  47. data/ext/v8/v8_v8.h +6 -0
  48. data/ext/v8/v8_value.cpp +175 -0
  49. data/ext/v8/v8_value.h +10 -0
  50. data/ext/v8/v8_weakref.cpp +61 -0
  51. data/ext/v8/v8_weakref.h +29 -0
  52. data/lib/v8.rb +23 -0
  53. data/lib/v8/access.rb +92 -0
  54. data/lib/v8/array.rb +17 -0
  55. data/lib/v8/c/locker.rb +18 -0
  56. data/lib/v8/cli.rb +133 -0
  57. data/lib/v8/context.rb +111 -0
  58. data/lib/v8/error.rb +130 -0
  59. data/lib/v8/function.rb +44 -0
  60. data/lib/v8/object.rb +69 -0
  61. data/lib/v8/portal.rb +86 -0
  62. data/lib/v8/portal/caller.rb +37 -0
  63. data/lib/v8/portal/constructor.rb +98 -0
  64. data/lib/v8/portal/function.rb +63 -0
  65. data/lib/v8/portal/interceptors.rb +152 -0
  66. data/lib/v8/portal/proxies.rb +151 -0
  67. data/lib/v8/portal/templates.rb +73 -0
  68. data/lib/v8/stack.rb +66 -0
  69. data/lib/v8/tap.rb +9 -0
  70. data/lib/v8/version.rb +3 -0
  71. data/spec/ext/array_spec.rb +15 -0
  72. data/spec/ext/cxt_spec.rb +57 -0
  73. data/spec/ext/ext_spec_helper.rb +27 -0
  74. data/spec/ext/func_spec.rb +64 -0
  75. data/spec/ext/object_spec.rb +10 -0
  76. data/spec/ext/string_spec.rb +11 -0
  77. data/spec/ext/try_catch_spec.rb +60 -0
  78. data/spec/redjs_spec.rb +9 -0
  79. data/spec/spec_helper.rb +9 -0
  80. data/spec/v8/error_spec.rb +131 -0
  81. data/spec/v8/portal/proxies_spec.rb +106 -0
  82. data/specmem/handle_memspec.rb +41 -0
  83. data/specmem/object_memspec.rb +14 -0
  84. data/specmem/proxies_memspec.rb +49 -0
  85. data/specmem/spec_helper.rb +24 -0
  86. data/specthread/spec_helper.rb +2 -0
  87. data/specthread/threading_spec.rb +13 -0
  88. data/thefrontside.png +0 -0
  89. data/therubyracer.gemspec +27 -0
  90. metadata +183 -0
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'v8'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ require 'v8'
8
+ end
9
+ require 'v8/cli'
10
+
11
+ V8::CLI.run(File.basename(__FILE__), ARGV)
@@ -0,0 +1,26 @@
1
+ require 'mkmf'
2
+ require 'set'
3
+ begin
4
+ require 'libv8'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ require 'libv8'
8
+ end
9
+
10
+ have_library('objc') if RUBY_PLATFORM =~ /darwin/
11
+
12
+ #we have to manually prepend the libv8 include path to INCFLAGS
13
+ #since find_header() does not actually work as advertized.
14
+ #see https://github.com/cowboyd/therubyracer/issues/91
15
+ $INCFLAGS.insert 0, "-I#{Libv8.include_path} "
16
+
17
+ $CPPFLAGS += " -Wall" unless $CPPFLAGS.split.include? "-Wall"
18
+ $CPPFLAGS += " -g" unless $CPPFLAGS.split.include? "-g"
19
+ $CPPFLAGS += " -rdynamic" unless $CPPFLAGS.split.include? "-rdynamic"
20
+
21
+ $LDFLAGS.insert 0, "#{Libv8.library_path}/libv8.#{$LIBEXT} "
22
+ $LIBS << ' -lpthread'
23
+
24
+ CONFIG['LDSHARED'] = '$(CXX) -shared' unless RUBY_PLATFORM =~ /darwin/
25
+
26
+ create_makefile('v8')
@@ -0,0 +1,189 @@
1
+ #include "rr.h"
2
+ #include "v8_context.h"
3
+ #include "v8_handle.h"
4
+ #include "v8_value.h"
5
+ #include "v8_object.h"
6
+ #include "v8_function.h"
7
+ #include "v8_array.h"
8
+ #include "v8_string.h"
9
+ #include "v8_date.h"
10
+ #include "v8_message.h"
11
+ #include "v8_external.h"
12
+ #include "v8_exception.h"
13
+
14
+ using namespace v8;
15
+
16
+ VALUE rr_define_class(const char *name, VALUE superclass) {
17
+ VALUE V8 = rb_define_module("V8");
18
+ VALUE V8_C = rb_define_module_under(V8, "C");
19
+ VALUE klass = rb_define_class_under(V8_C, name, superclass);
20
+ rb_funcall(klass, rb_intern("private_class_method"), 1, rb_str_new2("new"));
21
+ return klass;
22
+ }
23
+
24
+ VALUE rr_define_module(const char *name) {
25
+ VALUE V8 = rb_define_module("V8");
26
+ VALUE V8_C = rb_define_module_under(V8, "C");
27
+ return rb_define_module_under(V8_C, name);
28
+ }
29
+
30
+ VALUE rr_define_const(const char *name, VALUE value) {
31
+ VALUE V8 = rb_define_module("V8");
32
+ VALUE V8_C = rb_define_module_under(V8, "C");
33
+ rb_define_const(V8_C, name, value);
34
+ return value;
35
+ }
36
+
37
+ VALUE rr_const_get(const char *name) {
38
+ VALUE V8 = rb_define_module("V8");
39
+ VALUE V8_C = rb_define_module_under(V8, "C");
40
+ return rb_const_get(V8_C, rb_intern(name));
41
+ }
42
+
43
+ VALUE rr_define_finalizer(VALUE object, void* finalizer, VALUE data) {
44
+ VALUE finalizer_proc = rb_proc_new((VALUE (*)(...))finalizer, data);
45
+ rb_iv_set(finalizer_proc, "data", data);
46
+ VALUE ospace = rb_const_get(rb_cObject, rb_intern("ObjectSpace"));
47
+ rb_funcall(ospace, rb_intern("define_finalizer"), 2, object, finalizer_proc);
48
+ }
49
+
50
+ VALUE rr_v82rb(Handle<Value> value) {
51
+ if (value.IsEmpty()) {
52
+ return rr_v8_value_empty();
53
+ }
54
+ if (value->IsUndefined() || value->IsNull()) {
55
+ return Qnil;
56
+ }
57
+ if (value->IsExternal()) {
58
+ return rr_reflect_v8_external(value);
59
+ }
60
+ if (value->IsUint32()) {
61
+ return UINT2NUM(value->Uint32Value());
62
+ }
63
+ if (value->IsInt32()) {
64
+ return INT2FIX(value->Int32Value());
65
+ }
66
+ if (value->IsBoolean()) {
67
+ return value->BooleanValue() ? Qtrue : Qfalse;
68
+ }
69
+ if (value->IsNumber()) {
70
+ return rb_float_new(value->NumberValue());
71
+ }
72
+ if (value->IsString()) {
73
+ return rr_reflect_v8_string(value);
74
+ }
75
+ if (value->IsFunction()) {
76
+ return rr_reflect_v8_function(value);
77
+ }
78
+ if (value->IsArray()) {
79
+ return rr_reflect_v8_array(value);
80
+ }
81
+ if (value->IsDate()) {
82
+ return rr_reflect_v8_date(value);
83
+ }
84
+ if (value->IsObject()) {
85
+ return rr_reflect_v8_object(value);
86
+ }
87
+ return rr_wrap_v8_value(value);
88
+ }
89
+
90
+ VALUE rr_v82rb(Handle<Message> value) {
91
+ return rr_reflect_v8_message(value);
92
+ }
93
+ VALUE rr_v82rb(Handle<StackTrace> value) {
94
+ return rr_reflect_v8_stacktrace(value);
95
+ }
96
+ VALUE rr_v82rb(Handle<StackFrame> value) {
97
+ return rr_reflect_v8_stackframe(value);
98
+ }
99
+
100
+ VALUE rr_v82rb(Handle<Boolean> value) {
101
+ return rr_v82rb((Handle<Value>)value);
102
+ }
103
+ VALUE rr_v82rb(Handle<Number> value) {
104
+ return rr_v82rb((Handle<Value>)value);
105
+ }
106
+ VALUE rr_v82rb(Handle<String> value) {
107
+ return rr_v82rb((Handle<Value>)value);
108
+ }
109
+ VALUE rr_v82rb(Handle<Object> value) {
110
+ return rr_v82rb((Handle<Value>)value);
111
+ }
112
+ VALUE rr_v82rb(Handle<Array> value) {
113
+ return rr_v82rb((Handle<Value>)value);
114
+ }
115
+ VALUE rr_v82rb(v8::Handle<v8::Function> value) {
116
+ return rr_v82rb((Handle<Value>)value);
117
+ }
118
+ VALUE rr_v82rb(Handle<Integer> value) {
119
+ return rr_v82rb((Handle<Value>)value);
120
+ }
121
+ VALUE rr_v82rb(Handle<Uint32> value) {
122
+ return rr_v82rb((Handle<Value>)value);
123
+ }
124
+ VALUE rr_v82rb(Handle<Int32> value) {
125
+ return rr_v82rb((Handle<Value>)value);
126
+ }
127
+ VALUE rr_v82rb(bool value) {
128
+ return value ? Qtrue : Qfalse;
129
+ }
130
+ VALUE rr_v82rb(double value) {
131
+ return rb_float_new(value);
132
+ }
133
+ VALUE rr_v82rb(int64_t value) {
134
+ return LONG2NUM(value);
135
+ }
136
+ VALUE rr_v82rb(uint32_t value) {
137
+ return UINT2NUM(value);
138
+ }
139
+ VALUE rr_v82rb(int32_t value) {
140
+ return INT2FIX(value);
141
+ }
142
+
143
+ Handle<Value> rr_rb2v8(VALUE value) {
144
+ switch (TYPE(value)) {
145
+ case T_FIXNUM:
146
+ // TODO: use this conversion if value will fit in 32 bits.
147
+ // return Integer::New(FIX2LONG(value));
148
+ case T_FLOAT:
149
+ return Number::New(NUM2DBL(value));
150
+ case T_STRING:
151
+ return String::New(RSTRING_PTR(value), RSTRING_LEN(value));
152
+ case T_NIL:
153
+ return Null();
154
+ case T_TRUE:
155
+ return True();
156
+ case T_FALSE:
157
+ return False();
158
+ case T_DATA:
159
+ return rr_v8_handle<Value>(value);
160
+ case T_OBJECT:
161
+ case T_CLASS:
162
+ case T_ICLASS:
163
+ case T_MODULE:
164
+ case T_REGEXP:
165
+ case T_MATCH:
166
+ case T_ARRAY:
167
+ case T_HASH:
168
+ case T_STRUCT:
169
+ case T_BIGNUM:
170
+ case T_FILE:
171
+ case T_SYMBOL:
172
+ // case T_BLKTAG: (not in 1.9)
173
+ case T_UNDEF:
174
+ // case T_VARMAP: (not in 1.9)
175
+ // case T_SCOPE: (not in 1.9)
176
+ case T_NODE:
177
+ default:
178
+ rb_warn("unknown conversion to V8 for: %s", RSTRING_PTR(rb_inspect(value)));
179
+ return String::New("Undefined Conversion");
180
+ }
181
+
182
+ return Undefined();
183
+ }
184
+ // VALUE rr_v82rb(v8::ScriptData *data) {
185
+ // return rr_thunk(rr_wrap_script_data(data));
186
+ // }
187
+
188
+
189
+
@@ -0,0 +1,41 @@
1
+ #ifndef _THE_RUBY_RACER_
2
+ #define _THE_RUBY_RACER_
3
+
4
+ #include <ruby.h>
5
+ #include <v8.h>
6
+
7
+ #define rr_define_method(klass, name, impl, argc) rb_define_method(klass, name, (VALUE(*)(...))impl, argc)
8
+ #define rr_define_singleton_method(object, name, impl, argc) rb_define_singleton_method(object, name, (VALUE(*)(...))impl, argc)
9
+
10
+ VALUE rr_define_class(const char *name, VALUE superclass = rb_cObject);
11
+ VALUE rr_define_module(const char *name);
12
+ VALUE rr_define_const(const char *name, VALUE value);
13
+ VALUE rr_const_get(const char *name);
14
+ VALUE rr_define_finalizer(VALUE object, void* finalizer, VALUE data);
15
+
16
+ extern "C" VALUE rb_proc_new(VALUE (*)(ANYARGS/* VALUE yieldarg[, VALUE procarg] */), VALUE);
17
+
18
+
19
+ VALUE rr_v82rb(v8::Handle<v8::Value> value);
20
+ VALUE rr_v82rb(v8::Handle<v8::Boolean> value);
21
+ VALUE rr_v82rb(v8::Handle<v8::Number> value);
22
+ VALUE rr_v82rb(v8::Handle<v8::String> value);
23
+ VALUE rr_v82rb(v8::Handle<v8::Object> value);
24
+ VALUE rr_v82rb(v8::Handle<v8::Array> value);
25
+ VALUE rr_v82rb(v8::Handle<v8::Function> value);
26
+ VALUE rr_v82rb(v8::Handle<v8::Integer> value);
27
+ VALUE rr_v82rb(v8::Handle<v8::Uint32> value);
28
+ VALUE rr_v82rb(v8::Handle<v8::Int32> value);
29
+ VALUE rr_v82rb(v8::Handle<v8::Message> value);
30
+ VALUE rr_v82rb(v8::Handle<v8::StackTrace> value);
31
+ VALUE rr_v82rb(v8::Handle<v8::StackFrame> value);
32
+
33
+ VALUE rr_v82rb(bool value);
34
+ VALUE rr_v82rb(double value);
35
+ VALUE rr_v82rb(int64_t value);
36
+ VALUE rr_v82rb(uint32_t value);
37
+ VALUE rr_v82rb(int32_t value);
38
+
39
+ v8::Handle<v8::Value> rr_rb2v8(VALUE value);
40
+
41
+ #endif
@@ -0,0 +1,48 @@
1
+ #include "v8_handle.h"
2
+ #include "v8_context.h"
3
+ #include "v8_value.h"
4
+ #include "v8_string.h"
5
+ #include "v8_object.h"
6
+ #include "v8_array.h"
7
+ #include "v8_message.h"
8
+ #include "v8_function.h"
9
+ #include "v8_date.h"
10
+ #include "v8_script.h"
11
+ #include "v8_template.h"
12
+ #include "v8_try_catch.h"
13
+ #include "v8_callbacks.h"
14
+ #include "v8_external.h"
15
+ #include "v8_exception.h"
16
+ #include "v8_locker.h"
17
+ #include "v8_debug.h"
18
+ #include "v8_v8.h"
19
+
20
+ #include <stdio.h>
21
+
22
+ extern "C" {
23
+ void Init_v8();
24
+ }
25
+
26
+ extern "C" {
27
+ void Init_v8() {
28
+ v8::Locker locker;
29
+ rr_init_handle();
30
+ rr_init_context();
31
+ rr_init_value();
32
+ rr_init_string();
33
+ rr_init_script();
34
+ rr_init_template();
35
+ rr_init_object();
36
+ rr_init_function();
37
+ rr_init_v8_array();
38
+ rr_init_v8_date();
39
+ rr_init_message();
40
+ rr_init_v8_try_catch();
41
+ rr_init_v8_callbacks();
42
+ rr_init_v8_external();
43
+ rr_init_v8_exception();
44
+ rr_init_v8_locker();
45
+ rr_init_v8_debug();
46
+ rr_init_v8_v8();
47
+ }
48
+ }
@@ -0,0 +1,48 @@
1
+ #include "v8_handle.h"
2
+ #include "v8_array.h"
3
+ #include "v8_object.h"
4
+
5
+ using namespace v8;
6
+
7
+
8
+ namespace {
9
+
10
+ VALUE ArrayClass;
11
+
12
+ Persistent<Array>& unwrap(VALUE self) {
13
+ return rr_v8_handle<Array>(self);
14
+ }
15
+
16
+ VALUE New(int argc, VALUE *argv, VALUE self) {
17
+ if (!Context::InContext()) {
18
+ rb_raise(rb_eScriptError, "must be in a context to call Array::New()");
19
+ return Qnil;
20
+ }
21
+ VALUE length;
22
+ rb_scan_args(argc, argv, "01", &length);
23
+ if (NIL_P(length)) {
24
+ length = INT2FIX(0);
25
+ }
26
+ HandleScope scope;
27
+ return rr_v8_handle_new(self, Array::New(NUM2INT(length)));
28
+ }
29
+
30
+ VALUE Length(VALUE self) {
31
+ return rr_v82rb(unwrap(self)->Length());
32
+ }
33
+
34
+ VALUE CloneElementAt(VALUE self, VALUE index) {
35
+ return rr_v82rb(unwrap(self)->CloneElementAt(NUM2UINT(index)));
36
+ }
37
+ }
38
+
39
+ void rr_init_v8_array() {
40
+ ArrayClass = rr_define_class("Array", rr_v8_object_class());
41
+ rr_define_singleton_method(ArrayClass, "New", New, -1);
42
+ rr_define_method(ArrayClass, "Length", Length, 0);
43
+ rr_define_method(ArrayClass, "CloneElementAt", CloneElementAt, 1);
44
+ }
45
+
46
+ VALUE rr_reflect_v8_array(Handle<Value> value) {
47
+ return rr_reflect_v8_object_as(value, ArrayClass);
48
+ }
@@ -0,0 +1,8 @@
1
+ #ifndef _RR_V8_ARRAY_
2
+ #define _RR_V8_ARRAY_
3
+
4
+ #include "rr.h"
5
+
6
+ void rr_init_v8_array();
7
+ VALUE rr_reflect_v8_array(v8::Handle<v8::Value> value);
8
+ #endif
@@ -0,0 +1,81 @@
1
+ #include "v8_callbacks.h"
2
+ #include "rr.h"
3
+
4
+ using namespace v8;
5
+
6
+
7
+ namespace {
8
+ VALUE ArgumentsClass;
9
+ VALUE AccessorInfoClass;
10
+
11
+ VALUE _Data(VALUE self) {
12
+ return rb_iv_get(self, "data");
13
+ }
14
+
15
+ namespace Accessor {
16
+ AccessorInfo *info(VALUE value) {
17
+ AccessorInfo* i = 0;
18
+ Data_Get_Struct(value, class AccessorInfo, i);
19
+ return i;
20
+ }
21
+ VALUE This(VALUE self) {
22
+ return rr_v82rb(info(self)->This());
23
+ }
24
+ VALUE Holder(VALUE self) {
25
+ return rr_v82rb(info(self)->Holder());
26
+ }
27
+ }
28
+
29
+ namespace Args {
30
+ Arguments* args(VALUE value) {
31
+ Arguments *arguments = 0;
32
+ Data_Get_Struct(value, class Arguments, arguments);
33
+ return arguments;
34
+ }
35
+ VALUE This(VALUE self) {
36
+ return rr_v82rb(args(self)->This());
37
+ }
38
+
39
+ VALUE Holder(VALUE self) {
40
+ return rr_v82rb(args(self)->Holder());
41
+ }
42
+
43
+ VALUE Length(VALUE self) {
44
+ return rr_v82rb(args(self)->Length());
45
+ }
46
+ VALUE Get(VALUE self, VALUE index) {
47
+ int i = NUM2INT(index);
48
+ return rr_v82rb((*args(self))[i]);
49
+ }
50
+ VALUE Callee(VALUE self) {
51
+ return rr_v82rb(args(self)->Callee());
52
+ }
53
+ VALUE IsConstructCall(VALUE self) {
54
+ return rr_v82rb(args(self)->IsConstructCall());
55
+ }
56
+ }
57
+
58
+ }
59
+
60
+ void rr_init_v8_callbacks() {
61
+ AccessorInfoClass = rr_define_class("AccessorInfo");
62
+ rr_define_method(AccessorInfoClass, "This", Accessor::This, 0);
63
+ rr_define_method(AccessorInfoClass, "Holder", Accessor::Holder, 0);
64
+ rr_define_method(AccessorInfoClass, "Data", _Data, 0);
65
+
66
+ ArgumentsClass = rr_define_class("Arguments");
67
+ rr_define_method(ArgumentsClass, "This", Args::This, 0);
68
+ rr_define_method(ArgumentsClass, "Holder", Args::Holder, 0);
69
+ rr_define_method(ArgumentsClass, "Data", _Data, 0);
70
+ rr_define_method(ArgumentsClass, "Length", Args::Length, 0);
71
+ rr_define_method(ArgumentsClass, "Callee", Args::Callee, 0);
72
+ rr_define_method(ArgumentsClass, "IsConstructCall", Args::IsConstructCall, 0);
73
+ rr_define_method(ArgumentsClass, "[]", Args::Get, 1);
74
+ }
75
+
76
+ VALUE rr_v82rb(const AccessorInfo& info) {
77
+ return Data_Wrap_Struct(AccessorInfoClass, 0, 0, (void*)&info);
78
+ }
79
+ VALUE rr_v82rb(const Arguments& arguments) {
80
+ return Data_Wrap_Struct(ArgumentsClass, 0, 0, (void*)&arguments);
81
+ }