mini_racer 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef7d560456c68712a83c6167b76c27fa2f145da2
4
- data.tar.gz: f299b830d1df20a115fdc8f63aea4a7c9f0328b3
3
+ metadata.gz: 0508a6995a631050ed4470222e522e2794322f2a
4
+ data.tar.gz: a42ed52c3df8490ce8e3a5766ecb5389dc813971
5
5
  SHA512:
6
- metadata.gz: 007738356ef3475876ea8c125cc4ccd487df22c6cbdd1ae5a793865825ffdae79c6b578e9f038845462314ca9fcf1745c75f97818fc36ff4186f58ed202cafa7
7
- data.tar.gz: 6f3da0e1c5a6898f63fa625499704a0ed4e31d47af042e90c796dd99d635723522357c7f36e1cf530844b7ff7a8f97ee13efa0d135aca3b53665b82755b6264b
6
+ metadata.gz: 963c946ed997001fb18d8f81e2da1a0a17c9554588b693a129a88a830631c5bf8c7a0a222944443ec97efe393d72f6981da0d938c24e1d0a5454a780c5b7d646
7
+ data.tar.gz: 26aa65a782780c47bb3e3683ca196e4cd26f2bd03fdf6ceca1862bb8d22f2bdf2477845b5ff096cf28cdb1713fddb35b7a3cbbc1703947772b3dca397bee5852
data/CHANGELOG CHANGED
@@ -1,5 +1,11 @@
1
1
  19-05-2016
2
2
 
3
+ - 0.1.4
4
+
5
+ - Set upper bound for libv8 inclusion @ignisf
6
+ - Support conversion of Date, Time and DateTime from Ruby to JS @seanmakesgames
7
+ - Support conversion of large numbers back from Ruby to JS @seanmakesgames
8
+
3
9
  - 0.1.3
4
10
 
5
11
  - Support more conversions from Ruby back to JS (Hash, Symbol, Array)
data/README.md CHANGED
@@ -6,7 +6,7 @@ Minimal, modern embedded V8 for Ruby.
6
6
 
7
7
  MiniRacer provides a minimal two way bridge between the V8 JavaScript engine and Ruby.
8
8
 
9
- It was created as an alternative to the excellent [therubyracer](https://github.com/cowboyd/therubyracer). Unlike therubyracer, mini_racer only implements a minimal bridge. This reduces the surface area making upgrading v8 much simpler and exahustive testing simpler.
9
+ It was created as an alternative to the excellent [therubyracer](https://github.com/cowboyd/therubyracer). Unlike therubyracer, mini_racer only implements a minimal bridge. This reduces the surface area making upgrading v8 much simpler and exhaustive testing simpler.
10
10
 
11
11
  MiniRacer has an adapter for [execjs](https://github.com/sstephenson/execjs) so it can be used directly with Rails projects to minify assets, run babel or compile CoffeeScript.
12
12
 
@@ -137,6 +137,20 @@ Or install it yourself as:
137
137
 
138
138
  **Note** using v8.h and compiling MiniRacer requires a C++11 standard compiler, more specifically clang 3.5 (or later) or gcc 4.8 (or later).
139
139
 
140
+
141
+ ## Travis-ci
142
+
143
+ To install `mini-racer` you will need a version of gcc that supports C++11 (gcc 4.8) this is included by default in ubuntu trusty based images.
144
+
145
+ Travis today ships by default with a precise based image. Precise Pangolin (12.04 LTS) was first released in August 2012. Even though you can install GCC 4.8 on precise the simpler approach is to opt for the trusty based image.
146
+
147
+ Add this to your .travis.yml file:
148
+
149
+ ```
150
+ - sudo: required
151
+ - dist: trusty
152
+ ```
153
+
140
154
  ## Similar Projects
141
155
 
142
156
  ###therubyracer
@@ -47,6 +47,8 @@ static VALUE rb_eParseError;
47
47
  static VALUE rb_eScriptRuntimeError;
48
48
  static VALUE rb_cJavaScriptFunction;
49
49
 
50
+ static VALUE rb_cDateTime = Qnil;
51
+
50
52
  static Platform* current_platform = NULL;
51
53
 
52
54
  static void init_v8() {
@@ -106,30 +108,40 @@ nogvl_context_eval(void* arg) {
106
108
 
107
109
  result->executed = !maybe_value.IsEmpty();
108
110
 
109
- if (!result->executed) {
110
- if (trycatch.HasCaught()) {
111
- if (!trycatch.Exception()->IsNull()) {
112
- result->message = new Persistent<Value>();
113
- result->message->Reset(isolate, trycatch.Exception()->ToString());
114
- } else if(trycatch.HasTerminated()) {
115
- result->terminated = true;
116
- result->message = new Persistent<Value>();
117
- Local<String> tmp = String::NewFromUtf8(isolate, "JavaScript was terminated (either by timeout or explicitly)");
118
- result->message->Reset(isolate, tmp);
119
- }
120
-
121
- if (!trycatch.StackTrace().IsEmpty()) {
122
- result->backtrace = new Persistent<Value>();
123
- result->backtrace->Reset(isolate, trycatch.StackTrace()->ToString());
124
- }
125
- }
126
- } else {
111
+ if (result->executed) {
127
112
  Persistent<Value>* persistent = new Persistent<Value>();
128
113
  persistent->Reset(isolate, maybe_value.ToLocalChecked());
129
114
  result->value = persistent;
130
115
  }
131
116
  }
132
117
 
118
+ if (!result->executed || !result->parsed) {
119
+ if (trycatch.HasCaught()) {
120
+ if (!trycatch.Exception()->IsNull()) {
121
+ result->message = new Persistent<Value>();
122
+ Local<Message> message = trycatch.Message();
123
+ char buf[1000];
124
+ int len;
125
+ len = snprintf(buf, sizeof(buf), "%s at %s:%i:%i", *String::Utf8Value(message->Get()),
126
+ *String::Utf8Value(message->GetScriptResourceName()->ToString()),
127
+ message->GetLineNumber(),
128
+ message->GetStartColumn());
129
+
130
+ Local<String> v8_message = String::NewFromUtf8(isolate, buf, NewStringType::kNormal, (int)len).ToLocalChecked();
131
+ result->message->Reset(isolate, v8_message);
132
+ } else if(trycatch.HasTerminated()) {
133
+ result->terminated = true;
134
+ result->message = new Persistent<Value>();
135
+ Local<String> tmp = String::NewFromUtf8(isolate, "JavaScript was terminated (either by timeout or explicitly)");
136
+ result->message->Reset(isolate, tmp);
137
+ }
138
+ if (!trycatch.StackTrace().IsEmpty()) {
139
+ result->backtrace = new Persistent<Value>();
140
+ result->backtrace->Reset(isolate, trycatch.StackTrace()->ToString());
141
+ }
142
+ }
143
+ }
144
+
133
145
  return NULL;
134
146
  }
135
147
 
@@ -172,6 +184,14 @@ static VALUE convert_v8_to_ruby(Isolate* isolate, Handle<Value> &value) {
172
184
  return rb_funcall(rb_cJavaScriptFunction, rb_intern("new"), 0);
173
185
  }
174
186
 
187
+ if (value->IsDate()){
188
+ double ts = Local<Date>::Cast(value)->ValueOf();
189
+ double secs = ts/1000;
190
+ long nanos = round((secs - floor(secs)) * 1000000);
191
+
192
+ return rb_time_new(secs, nanos);
193
+ }
194
+
175
195
  if (value->IsObject()) {
176
196
  VALUE rb_hash = rb_hash_new();
177
197
  Local<Context> context = Context::New(isolate);
@@ -191,7 +211,7 @@ static VALUE convert_v8_to_ruby(Isolate* isolate, Handle<Value> &value) {
191
211
  }
192
212
 
193
213
  Local<String> rstr = value->ToString();
194
- return rb_enc_str_new(*v8::String::Utf8Value(rstr), rstr->Utf8Length(), rb_enc_find("utf-8"));
214
+ return rb_enc_str_new(*String::Utf8Value(rstr), rstr->Utf8Length(), rb_enc_find("utf-8"));
195
215
  }
196
216
 
197
217
  static Handle<Value> convert_ruby_to_v8(Isolate* isolate, VALUE value) {
@@ -201,11 +221,20 @@ static Handle<Value> convert_ruby_to_v8(Isolate* isolate, VALUE value) {
201
221
  Local<Object> object;
202
222
  VALUE hash_as_array;
203
223
  VALUE pair;
204
- int length,i;
224
+ int i;
225
+ long length;
226
+ long fixnum;
227
+ VALUE klass;
205
228
 
206
229
  switch (TYPE(value)) {
207
230
  case T_FIXNUM:
208
- return scope.Escape(Integer::New(isolate, NUM2INT(value)));
231
+ fixnum = NUM2LONG(value);
232
+ if (fixnum > INT_MAX)
233
+ {
234
+ return scope.Escape(Number::New(isolate, (double)fixnum));
235
+ }
236
+
237
+ return scope.Escape(Integer::New(isolate, (int)fixnum));
209
238
  case T_FLOAT:
210
239
  return scope.Escape(Number::New(isolate, NUM2DBL(value)));
211
240
  case T_STRING:
@@ -218,7 +247,7 @@ static Handle<Value> convert_ruby_to_v8(Isolate* isolate, VALUE value) {
218
247
  return scope.Escape(False(isolate));
219
248
  case T_ARRAY:
220
249
  length = RARRAY_LEN(value);
221
- array = Array::New(isolate, length);
250
+ array = Array::New(isolate, (int)length);
222
251
  for(i=0; i<length; i++) {
223
252
  array->Set(i, convert_ruby_to_v8(isolate, rb_ary_entry(value, i)));
224
253
  }
@@ -237,6 +266,17 @@ static Handle<Value> convert_ruby_to_v8(Isolate* isolate, VALUE value) {
237
266
  value = rb_funcall(value, rb_intern("to_s"), 0);
238
267
  return scope.Escape(String::NewFromUtf8(isolate, RSTRING_PTR(value), NewStringType::kNormal, (int)RSTRING_LEN(value)).ToLocalChecked());
239
268
  case T_DATA:
269
+ klass = rb_funcall(value, rb_intern("class"), 0);
270
+ if (klass == rb_cTime || klass == rb_cDateTime)
271
+ {
272
+ if (klass == rb_cDateTime)
273
+ {
274
+ value = rb_funcall(value, rb_intern("to_time"), 0);
275
+ }
276
+
277
+ value = rb_funcall(value, rb_intern("to_f"), 0);
278
+ return scope.Escape(Date::New(isolate, NUM2DBL(value) * 1000));
279
+ }
240
280
  case T_OBJECT:
241
281
  case T_CLASS:
242
282
  case T_ICLASS:
@@ -320,13 +360,12 @@ static VALUE rb_context_eval_unsafe(VALUE self, VALUE str) {
320
360
  }
321
361
 
322
362
  if (!eval_result.executed) {
323
-
324
363
  VALUE ruby_exception = rb_iv_get(self, "@current_exception");
325
364
  if (ruby_exception == Qnil) {
326
365
  ruby_exception = eval_result.terminated ? rb_eScriptTerminatedError : rb_eScriptRuntimeError;
327
366
  // exception report about what happened
328
- if(TYPE(message) == T_STRING && TYPE(backtrace) == T_STRING) {
329
- rb_raise(ruby_exception, "%s/n%s", RSTRING_PTR(message), RSTRING_PTR(backtrace));
367
+ if(TYPE(backtrace) == T_STRING) {
368
+ rb_raise(ruby_exception, "%s", RSTRING_PTR(backtrace));
330
369
  } else if(TYPE(message) == T_STRING) {
331
370
  rb_raise(ruby_exception, "%s", RSTRING_PTR(message));
332
371
  } else {
@@ -564,6 +603,11 @@ VALUE allocate(VALUE klass) {
564
603
  context_info->context = new Persistent<Context>();
565
604
  context_info->context->Reset(context_info->isolate, context);
566
605
 
606
+ if (Qnil == rb_cDateTime && rb_funcall(rb_cObject, rb_intern("const_defined?"), 1, rb_str_new2("DateTime")) == Qtrue)
607
+ {
608
+ rb_cDateTime = rb_const_get(rb_cObject, rb_intern("DateTime"));
609
+ }
610
+
567
611
  return Data_Wrap_Struct(klass, NULL, deallocate, (void*)context_info);
568
612
  }
569
613
 
@@ -5,7 +5,6 @@ require "thread"
5
5
  module MiniRacer
6
6
 
7
7
  class EvalError < StandardError; end
8
-
9
8
  class ScriptTerminatedError < EvalError; end
10
9
  class ParseError < EvalError; end
11
10
 
@@ -18,7 +17,6 @@ module MiniRacer
18
17
  else
19
18
  @js_backtrace = nil
20
19
  end
21
-
22
20
  super(message)
23
21
  end
24
22
 
@@ -31,7 +29,6 @@ module MiniRacer
31
29
  val
32
30
  end
33
31
  end
34
-
35
32
  end
36
33
 
37
34
  # helper class returned when we have a JavaScript function
@@ -1,3 +1,3 @@
1
1
  module MiniRacer
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -25,11 +25,10 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "minitest", "~> 5.0"
26
26
  spec.add_development_dependency "rake-compiler"
27
27
 
28
- spec.add_dependency 'libv8', '~> 5.0'
28
+ spec.add_dependency 'libv8', '~> 5.0', '< 5.1.11'
29
29
  spec.require_paths = ["lib", "ext"]
30
30
 
31
31
  spec.extensions = ["ext/mini_racer_extension/extconf.rb"]
32
32
 
33
33
  spec.required_ruby_version = '>= 2.0'
34
-
35
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_racer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-19 00:00:00.000000000 Z
11
+ date: 2016-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,6 +73,9 @@ dependencies:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '5.0'
76
+ - - "<"
77
+ - !ruby/object:Gem::Version
78
+ version: 5.1.11
76
79
  type: :runtime
77
80
  prerelease: false
78
81
  version_requirements: !ruby/object:Gem::Requirement
@@ -80,6 +83,9 @@ dependencies:
80
83
  - - "~>"
81
84
  - !ruby/object:Gem::Version
82
85
  version: '5.0'
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: 5.1.11
83
89
  description: Minimal embedded v8 engine for Ruby
84
90
  email:
85
91
  - sam.saffron@gmail.com