mini_racer 0.17.0.pre8 → 0.17.0.pre9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +3 -0
- data/ext/mini_racer_extension/mini_racer_extension.c +68 -21
- data/lib/mini_racer/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3be215eb4d4e72b01480ffa28863ea7ff1947b3f8cf0b6dcd860ffde2e48799
|
4
|
+
data.tar.gz: adcae327e54c2c372871c255e4bfd19a07b28964cd4c7c51cbc1cc251d1f71db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98bdc234f17c0e16ae995c8fe3566f6ec80cbd92c569e4aa31ac1999d309ae2a197b0c7cb1c5de62f542f25b4f73287d0a34ab7967e1e24c32d02fc73ade33f2
|
7
|
+
data.tar.gz: 7ade32c683f240c3e19eaa58b6a044192f57b1e651966c042654d401f1f5dae1aff20d1c545dd7fd05afb2b0f70659080825b5a788ab82379b119c497ac31e47
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
- 0.17.0.pre9 - 13-01-2025
|
2
|
+
- For backwards compatibility convert v8 return values to UTF-8 (invalidly encoded string still get returned using V8 encoding)
|
3
|
+
|
1
4
|
- 0.17.0.pre8 - 11-01-2025
|
2
5
|
- Fix handling of UTF 32 LE and Ascii encoding strings - Ben Noordhuis
|
3
6
|
- Handle rare edge case in V8 serialization - Ben Noordhuis
|
@@ -164,12 +164,6 @@ static VALUE js_function_class;
|
|
164
164
|
static pthread_mutex_t flags_mtx = PTHREAD_MUTEX_INITIALIZER;
|
165
165
|
static Buf flags; // protected by |flags_mtx|
|
166
166
|
|
167
|
-
struct rendezvous_nogvl
|
168
|
-
{
|
169
|
-
Context *context;
|
170
|
-
Buf *req, *res;
|
171
|
-
};
|
172
|
-
|
173
167
|
// arg == &(struct rendezvous_nogvl){...}
|
174
168
|
static void *rendezvous_callback(void *arg);
|
175
169
|
|
@@ -184,16 +178,30 @@ typedef struct DesCtx
|
|
184
178
|
{
|
185
179
|
State *tos;
|
186
180
|
VALUE refs; // array
|
181
|
+
uint8_t transcode_latin1:1;
|
187
182
|
char err[64];
|
188
183
|
State stack[512];
|
189
184
|
} DesCtx;
|
190
185
|
|
186
|
+
struct rendezvous_nogvl
|
187
|
+
{
|
188
|
+
Context *context;
|
189
|
+
Buf *req, *res;
|
190
|
+
};
|
191
|
+
|
192
|
+
struct rendezvous_des
|
193
|
+
{
|
194
|
+
DesCtx *d;
|
195
|
+
Buf *res;
|
196
|
+
};
|
197
|
+
|
191
198
|
static void DesCtx_init(DesCtx *c)
|
192
199
|
{
|
193
200
|
c->tos = c->stack;
|
194
201
|
c->refs = rb_ary_new();
|
195
202
|
*c->tos = (State){Qundef, Qundef};
|
196
203
|
*c->err = '\0';
|
204
|
+
c->transcode_latin1 = 1; // convert to utf8
|
197
205
|
}
|
198
206
|
|
199
207
|
static void put(DesCtx *c, VALUE v)
|
@@ -321,9 +329,22 @@ static void des_string(void *arg, const char *s, size_t n)
|
|
321
329
|
put(arg, rb_utf8_str_new(s, n));
|
322
330
|
}
|
323
331
|
|
332
|
+
static VALUE str_encode_bang(VALUE v)
|
333
|
+
{
|
334
|
+
// TODO cache these? this function can get called often
|
335
|
+
return rb_funcall(v, rb_intern("encode!"), 1, rb_str_new_cstr("UTF-8"));
|
336
|
+
}
|
337
|
+
|
324
338
|
static void des_string8(void *arg, const uint8_t *s, size_t n)
|
325
339
|
{
|
326
|
-
|
340
|
+
DesCtx *c;
|
341
|
+
VALUE v;
|
342
|
+
|
343
|
+
c = arg;
|
344
|
+
v = rb_enc_str_new((char *)s, n, rb_ascii8bit_encoding());
|
345
|
+
if (c->transcode_latin1)
|
346
|
+
v = str_encode_bang(v); // cannot fail
|
347
|
+
put(c, v);
|
327
348
|
}
|
328
349
|
|
329
350
|
// des_string16: |s| is not word aligned
|
@@ -331,7 +352,9 @@ static void des_string8(void *arg, const uint8_t *s, size_t n)
|
|
331
352
|
static void des_string16(void *arg, const void *s, size_t n)
|
332
353
|
{
|
333
354
|
rb_encoding *e;
|
355
|
+
VALUE v, r;
|
334
356
|
DesCtx *c;
|
357
|
+
int exc;
|
335
358
|
|
336
359
|
c = arg;
|
337
360
|
if (*c->err)
|
@@ -344,7 +367,15 @@ static void des_string16(void *arg, const void *s, size_t n)
|
|
344
367
|
snprintf(c->err, sizeof(c->err), "no UTF16-LE encoding");
|
345
368
|
return;
|
346
369
|
}
|
347
|
-
|
370
|
+
v = rb_enc_str_new((char *)s, n, e);
|
371
|
+
// JS strings can contain unmatched or illegal surrogate pairs
|
372
|
+
// that Ruby won't decode; return the string as-is in that case
|
373
|
+
r = rb_protect(str_encode_bang, v, &exc);
|
374
|
+
if (exc) {
|
375
|
+
rb_set_errinfo(Qnil);
|
376
|
+
r = v;
|
377
|
+
}
|
378
|
+
put(c, r);
|
348
379
|
}
|
349
380
|
|
350
381
|
// ruby doesn't really have a concept of a byte array so store it as
|
@@ -740,25 +771,25 @@ static void *v8_thread_start(void *arg)
|
|
740
771
|
return NULL;
|
741
772
|
}
|
742
773
|
|
743
|
-
static VALUE deserialize1(const uint8_t *p, size_t n)
|
774
|
+
static VALUE deserialize1(DesCtx *d, const uint8_t *p, size_t n)
|
744
775
|
{
|
745
776
|
char err[64];
|
746
|
-
DesCtx d;
|
747
777
|
|
748
|
-
|
749
|
-
if (des(&err, p, n, &d))
|
778
|
+
if (des(&err, p, n, d))
|
750
779
|
rb_raise(runtime_error, "%s", err);
|
751
|
-
if (d
|
780
|
+
if (d->tos != d->stack) // should not happen
|
752
781
|
rb_raise(runtime_error, "parse stack not empty");
|
753
|
-
return d
|
782
|
+
return d->tos->a;
|
754
783
|
}
|
755
784
|
|
756
785
|
static VALUE deserialize(VALUE arg)
|
757
786
|
{
|
787
|
+
struct rendezvous_des *a;
|
758
788
|
Buf *b;
|
759
789
|
|
760
|
-
|
761
|
-
|
790
|
+
a = (void *)arg;
|
791
|
+
b = a->res;
|
792
|
+
return deserialize1(a->d, b->buf, b->len);
|
762
793
|
}
|
763
794
|
|
764
795
|
// called with |rr_mtx| and GVL held; can raise exception
|
@@ -767,6 +798,7 @@ static VALUE rendezvous_callback_do(VALUE arg)
|
|
767
798
|
struct rendezvous_nogvl *a;
|
768
799
|
VALUE func, args;
|
769
800
|
Context *c;
|
801
|
+
DesCtx d;
|
770
802
|
Buf *b;
|
771
803
|
|
772
804
|
a = (void *)arg;
|
@@ -774,7 +806,8 @@ static VALUE rendezvous_callback_do(VALUE arg)
|
|
774
806
|
c = a->context;
|
775
807
|
assert(b->len > 0);
|
776
808
|
assert(*b->buf == 'c');
|
777
|
-
|
809
|
+
DesCtx_init(&d);
|
810
|
+
args = deserialize1(&d, b->buf+1, b->len-1); // skip 'c' marker
|
778
811
|
func = rb_ary_pop(args); // callback id
|
779
812
|
func = rb_ary_entry(c->procs, FIX2LONG(func));
|
780
813
|
return rb_funcall2(func, rb_intern("call"), RARRAY_LENINT(args), RARRAY_PTR(args));
|
@@ -866,14 +899,14 @@ static void rendezvous_no_des(Context *c, Buf *req, Buf *res)
|
|
866
899
|
|
867
900
|
// send request to & receive reply from v8 thread; takes ownership of |req|
|
868
901
|
// can raise exceptions and longjmp away but won't leak |req|
|
869
|
-
static VALUE
|
902
|
+
static VALUE rendezvous1(Context *c, Buf *req, DesCtx *d)
|
870
903
|
{
|
871
904
|
VALUE r;
|
872
905
|
Buf res;
|
873
906
|
int exc;
|
874
907
|
|
875
908
|
rendezvous_no_des(c, req, &res); // takes ownership of |req|
|
876
|
-
r = rb_protect(deserialize, (VALUE)&res, &exc);
|
909
|
+
r = rb_protect(deserialize, (VALUE)&(struct rendezvous_des){d, &res}, &exc);
|
877
910
|
buf_reset(&res);
|
878
911
|
if (exc) {
|
879
912
|
r = rb_errinfo();
|
@@ -888,6 +921,14 @@ static VALUE rendezvous(Context *c, Buf *req)
|
|
888
921
|
return r;
|
889
922
|
}
|
890
923
|
|
924
|
+
static VALUE rendezvous(Context *c, Buf *req)
|
925
|
+
{
|
926
|
+
DesCtx d;
|
927
|
+
|
928
|
+
DesCtx_init(&d);
|
929
|
+
return rendezvous1(c, req, &d);
|
930
|
+
}
|
931
|
+
|
891
932
|
static void handle_exception(VALUE e)
|
892
933
|
{
|
893
934
|
const char *s;
|
@@ -1469,6 +1510,7 @@ static VALUE snapshot_initialize(int argc, VALUE *argv, VALUE self)
|
|
1469
1510
|
VALUE a, e, code, cv;
|
1470
1511
|
Snapshot *ss;
|
1471
1512
|
Context *c;
|
1513
|
+
DesCtx d;
|
1472
1514
|
Ser s;
|
1473
1515
|
|
1474
1516
|
TypedData_Get_Struct(self, Snapshot, &snapshot_type, ss);
|
@@ -1483,7 +1525,9 @@ static VALUE snapshot_initialize(int argc, VALUE *argv, VALUE self)
|
|
1483
1525
|
ser_init1(&s, 'T');
|
1484
1526
|
add_string(&s, code);
|
1485
1527
|
// response is [arraybuffer, error]
|
1486
|
-
|
1528
|
+
DesCtx_init(&d);
|
1529
|
+
d.transcode_latin1 = 0; // don't mangle snapshot binary data
|
1530
|
+
a = rendezvous1(c, &s.b, &d);
|
1487
1531
|
e = rb_ary_pop(a);
|
1488
1532
|
context_dispose(cv);
|
1489
1533
|
if (*RSTRING_PTR(e))
|
@@ -1497,6 +1541,7 @@ static VALUE snapshot_warmup(VALUE self, VALUE arg)
|
|
1497
1541
|
VALUE a, e, cv;
|
1498
1542
|
Snapshot *ss;
|
1499
1543
|
Context *c;
|
1544
|
+
DesCtx d;
|
1500
1545
|
Ser s;
|
1501
1546
|
|
1502
1547
|
TypedData_Get_Struct(self, Snapshot, &snapshot_type, ss);
|
@@ -1511,7 +1556,9 @@ static VALUE snapshot_warmup(VALUE self, VALUE arg)
|
|
1511
1556
|
add_string(&s, arg);
|
1512
1557
|
ser_array_end(&s, 2);
|
1513
1558
|
// response is [arraybuffer, error]
|
1514
|
-
|
1559
|
+
DesCtx_init(&d);
|
1560
|
+
d.transcode_latin1 = 0; // don't mangle snapshot binary data
|
1561
|
+
a = rendezvous1(c, &s.b, &d);
|
1515
1562
|
e = rb_ary_pop(a);
|
1516
1563
|
context_dispose(cv);
|
1517
1564
|
if (*RSTRING_PTR(e))
|
data/lib/mini_racer/version.rb
CHANGED
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.17.0.
|
4
|
+
version: 0.17.0.pre9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-01-
|
11
|
+
date: 2025-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -123,9 +123,9 @@ licenses:
|
|
123
123
|
- MIT
|
124
124
|
metadata:
|
125
125
|
bug_tracker_uri: https://github.com/discourse/mini_racer/issues
|
126
|
-
changelog_uri: https://github.com/discourse/mini_racer/blob/v0.17.0.
|
127
|
-
documentation_uri: https://www.rubydoc.info/gems/mini_racer/0.17.0.
|
128
|
-
source_code_uri: https://github.com/discourse/mini_racer/tree/v0.17.0.
|
126
|
+
changelog_uri: https://github.com/discourse/mini_racer/blob/v0.17.0.pre9/CHANGELOG
|
127
|
+
documentation_uri: https://www.rubydoc.info/gems/mini_racer/0.17.0.pre9
|
128
|
+
source_code_uri: https://github.com/discourse/mini_racer/tree/v0.17.0.pre9
|
129
129
|
post_install_message:
|
130
130
|
rdoc_options: []
|
131
131
|
require_paths:
|