duktape 1.3.0.6 → 2.6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +20 -0
- data/ext/duktape/duk_config.h +2475 -2518
- data/ext/duktape/duktape.c +52913 -33505
- data/ext/duktape/duktape.h +742 -816
- data/ext/duktape/duktape_ext.c +55 -48
- data/lib/duktape/version.rb +1 -1
- metadata +7 -8
data/ext/duktape/duktape_ext.c
CHANGED
@@ -27,7 +27,6 @@ static rb_encoding *utf16enc;
|
|
27
27
|
static VALUE sDefaultFilename;
|
28
28
|
static ID id_complex_object;
|
29
29
|
|
30
|
-
static void error_handler(duk_context *, int, const char *);
|
31
30
|
static int ctx_push_hash_element(VALUE key, VALUE val, VALUE extra);
|
32
31
|
|
33
32
|
static unsigned long
|
@@ -38,11 +37,15 @@ utf8_to_uv(const char *p, long *lenp);
|
|
38
37
|
|
39
38
|
struct state {
|
40
39
|
duk_context *ctx;
|
40
|
+
int is_fatal;
|
41
41
|
VALUE complex_object;
|
42
42
|
int was_complex;
|
43
43
|
VALUE blocks;
|
44
44
|
};
|
45
45
|
|
46
|
+
static void error_handler(void *, const char *);
|
47
|
+
static void check_fatal(struct state *);
|
48
|
+
|
46
49
|
static void ctx_dealloc(void *ptr)
|
47
50
|
{
|
48
51
|
struct state *state = (struct state *)ptr;
|
@@ -58,7 +61,14 @@ static void ctx_mark(struct state *state)
|
|
58
61
|
|
59
62
|
static VALUE ctx_alloc(VALUE klass)
|
60
63
|
{
|
61
|
-
|
64
|
+
struct state *state = malloc(sizeof(struct state));
|
65
|
+
|
66
|
+
duk_context *ctx = duk_create_heap(NULL, NULL, NULL, state, error_handler);
|
67
|
+
|
68
|
+
state->ctx = ctx;
|
69
|
+
state->is_fatal = 0;
|
70
|
+
state->complex_object = oComplexObject;
|
71
|
+
state->blocks = rb_ary_new();
|
62
72
|
|
63
73
|
// Undefine require property
|
64
74
|
duk_push_global_object(ctx);
|
@@ -66,50 +76,9 @@ static VALUE ctx_alloc(VALUE klass)
|
|
66
76
|
duk_del_prop(ctx, -2);
|
67
77
|
duk_set_top(ctx, 0);
|
68
78
|
|
69
|
-
struct state *state = malloc(sizeof(struct state));
|
70
|
-
state->ctx = ctx;
|
71
|
-
state->complex_object = oComplexObject;
|
72
|
-
state->blocks = rb_ary_new();
|
73
79
|
return Data_Wrap_Struct(klass, ctx_mark, ctx_dealloc, state);
|
74
80
|
}
|
75
81
|
|
76
|
-
static VALUE error_code_class(int code) {
|
77
|
-
switch (code) {
|
78
|
-
case DUK_ERR_UNIMPLEMENTED_ERROR:
|
79
|
-
return eUnimplementedError;
|
80
|
-
case DUK_ERR_UNSUPPORTED_ERROR:
|
81
|
-
return eUnsupportedError;
|
82
|
-
case DUK_ERR_INTERNAL_ERROR:
|
83
|
-
return eInternalError;
|
84
|
-
case DUK_ERR_ALLOC_ERROR:
|
85
|
-
return eAllocError;
|
86
|
-
case DUK_ERR_ASSERTION_ERROR:
|
87
|
-
return eAssertionError;
|
88
|
-
case DUK_ERR_API_ERROR:
|
89
|
-
return eAPIError;
|
90
|
-
case DUK_ERR_UNCAUGHT_ERROR:
|
91
|
-
return eUncaughtError;
|
92
|
-
|
93
|
-
case DUK_ERR_ERROR:
|
94
|
-
return eError;
|
95
|
-
case DUK_ERR_EVAL_ERROR:
|
96
|
-
return eEvalError;
|
97
|
-
case DUK_ERR_RANGE_ERROR:
|
98
|
-
return eRangeError;
|
99
|
-
case DUK_ERR_REFERENCE_ERROR:
|
100
|
-
return eReferenceError;
|
101
|
-
case DUK_ERR_SYNTAX_ERROR:
|
102
|
-
return eSyntaxError;
|
103
|
-
case DUK_ERR_TYPE_ERROR:
|
104
|
-
return eTypeError;
|
105
|
-
case DUK_ERR_URI_ERROR:
|
106
|
-
return eURIError;
|
107
|
-
|
108
|
-
default:
|
109
|
-
return eInternalError;
|
110
|
-
}
|
111
|
-
}
|
112
|
-
|
113
82
|
static VALUE error_name_class(const char* name)
|
114
83
|
{
|
115
84
|
if (strcmp(name, "EvalError") == 0) {
|
@@ -251,13 +220,17 @@ static void ctx_push_ruby_object(struct state *state, VALUE obj)
|
|
251
220
|
|
252
221
|
switch (TYPE(obj)) {
|
253
222
|
case T_FIXNUM:
|
254
|
-
|
223
|
+
duk_push_number(ctx, NUM2LONG(obj));
|
255
224
|
return;
|
256
225
|
|
257
226
|
case T_FLOAT:
|
258
227
|
duk_push_number(ctx, NUM2DBL(obj));
|
259
228
|
return;
|
260
229
|
|
230
|
+
case T_BIGNUM:
|
231
|
+
duk_push_number(ctx, NUM2DBL(obj));
|
232
|
+
return;
|
233
|
+
|
261
234
|
case T_SYMBOL:
|
262
235
|
#ifdef HAVE_RB_SYM2STR
|
263
236
|
obj = rb_sym2str(obj);
|
@@ -351,6 +324,7 @@ static VALUE ctx_eval_string(int argc, VALUE *argv, VALUE self)
|
|
351
324
|
{
|
352
325
|
struct state *state;
|
353
326
|
Data_Get_Struct(self, struct state, state);
|
327
|
+
check_fatal(state);
|
354
328
|
|
355
329
|
VALUE source;
|
356
330
|
VALUE filename;
|
@@ -395,6 +369,7 @@ static VALUE ctx_exec_string(int argc, VALUE *argv, VALUE self)
|
|
395
369
|
{
|
396
370
|
struct state *state;
|
397
371
|
Data_Get_Struct(self, struct state, state);
|
372
|
+
check_fatal(state);
|
398
373
|
|
399
374
|
VALUE source;
|
400
375
|
VALUE filename;
|
@@ -488,6 +463,7 @@ static VALUE ctx_get_prop(VALUE self, VALUE prop)
|
|
488
463
|
{
|
489
464
|
struct state *state;
|
490
465
|
Data_Get_Struct(self, struct state, state);
|
466
|
+
check_fatal(state);
|
491
467
|
|
492
468
|
ctx_get_nested_prop(state, prop);
|
493
469
|
|
@@ -513,10 +489,10 @@ static VALUE ctx_call_prop(int argc, VALUE* argv, VALUE self)
|
|
513
489
|
{
|
514
490
|
struct state *state;
|
515
491
|
Data_Get_Struct(self, struct state, state);
|
492
|
+
check_fatal(state);
|
516
493
|
|
517
494
|
VALUE prop;
|
518
|
-
|
519
|
-
rb_scan_args(argc, argv, "1*", &prop, &prop_args);
|
495
|
+
rb_scan_args(argc, argv, "1*", &prop, NULL);
|
520
496
|
|
521
497
|
ctx_get_nested_prop(state, prop);
|
522
498
|
|
@@ -587,6 +563,8 @@ static VALUE ctx_define_function(VALUE self, VALUE prop)
|
|
587
563
|
|
588
564
|
// get the context
|
589
565
|
Data_Get_Struct(self, struct state, state);
|
566
|
+
check_fatal(state);
|
567
|
+
|
590
568
|
ctx = state->ctx;
|
591
569
|
|
592
570
|
// the c function is available in the global scope
|
@@ -628,9 +606,37 @@ static VALUE ctx_is_valid(VALUE self)
|
|
628
606
|
}
|
629
607
|
}
|
630
608
|
|
631
|
-
|
609
|
+
/*
|
610
|
+
* :nodoc:
|
611
|
+
*
|
612
|
+
* Invokes duk_fatal(). Only used for testing.
|
613
|
+
*/
|
614
|
+
static VALUE ctx_invoke_fatal(VALUE self)
|
632
615
|
{
|
633
|
-
|
616
|
+
struct state *state;
|
617
|
+
Data_Get_Struct(self, struct state, state);
|
618
|
+
|
619
|
+
duk_fatal(state->ctx, "induced fatal error");
|
620
|
+
|
621
|
+
return Qnil;
|
622
|
+
}
|
623
|
+
|
624
|
+
static void error_handler(void *udata, const char *msg)
|
625
|
+
{
|
626
|
+
struct state *state = (struct state *)udata;
|
627
|
+
|
628
|
+
if (msg == NULL) {
|
629
|
+
msg = "fatal error";
|
630
|
+
}
|
631
|
+
state->is_fatal = 1;
|
632
|
+
rb_raise(eInternalError, "%s", msg);
|
633
|
+
}
|
634
|
+
|
635
|
+
static void check_fatal(struct state *state)
|
636
|
+
{
|
637
|
+
if (state->is_fatal) {
|
638
|
+
rb_raise(eInternalError, "fatal error");
|
639
|
+
}
|
634
640
|
}
|
635
641
|
|
636
642
|
VALUE complex_object_instance(VALUE self)
|
@@ -718,6 +724,7 @@ void Init_duktape_ext()
|
|
718
724
|
rb_define_method(cContext, "call_prop", ctx_call_prop, -1);
|
719
725
|
rb_define_method(cContext, "define_function", ctx_define_function, 1);
|
720
726
|
rb_define_method(cContext, "_valid?", ctx_is_valid, 0);
|
727
|
+
rb_define_method(cContext, "_invoke_fatal", ctx_invoke_fatal, 0);
|
721
728
|
|
722
729
|
oComplexObject = rb_obj_alloc(cComplexObject);
|
723
730
|
rb_define_singleton_method(cComplexObject, "instance", complex_object_instance, 0);
|
data/lib/duktape/version.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: duktape
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.6.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magnus Holm
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description:
|
14
14
|
email: judofyr@gmail.com
|
15
15
|
executables: []
|
16
16
|
extensions:
|
@@ -30,7 +30,7 @@ homepage: https://github.com/judofyr/duktape.rb
|
|
30
30
|
licenses:
|
31
31
|
- MIT
|
32
32
|
metadata: {}
|
33
|
-
post_install_message:
|
33
|
+
post_install_message:
|
34
34
|
rdoc_options: []
|
35
35
|
require_paths:
|
36
36
|
- lib
|
@@ -45,9 +45,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
47
|
requirements: []
|
48
|
-
|
49
|
-
|
50
|
-
signing_key:
|
48
|
+
rubygems_version: 3.0.3
|
49
|
+
signing_key:
|
51
50
|
specification_version: 4
|
52
51
|
summary: Bindings to the Duktape JavaScript interpreter
|
53
52
|
test_files: []
|