duktape 1.6.1.0 → 2.0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/ext/duktape/duk_config.h +166 -1094
- data/ext/duktape/duktape.c +24025 -19343
- data/ext/duktape/duktape.h +509 -428
- data/ext/duktape/duktape_ext.c +50 -47
- data/lib/duktape/version.rb +1 -1
- metadata +3 -3
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) {
|
@@ -351,6 +320,7 @@ static VALUE ctx_eval_string(int argc, VALUE *argv, VALUE self)
|
|
351
320
|
{
|
352
321
|
struct state *state;
|
353
322
|
Data_Get_Struct(self, struct state, state);
|
323
|
+
check_fatal(state);
|
354
324
|
|
355
325
|
VALUE source;
|
356
326
|
VALUE filename;
|
@@ -395,6 +365,7 @@ static VALUE ctx_exec_string(int argc, VALUE *argv, VALUE self)
|
|
395
365
|
{
|
396
366
|
struct state *state;
|
397
367
|
Data_Get_Struct(self, struct state, state);
|
368
|
+
check_fatal(state);
|
398
369
|
|
399
370
|
VALUE source;
|
400
371
|
VALUE filename;
|
@@ -488,6 +459,7 @@ static VALUE ctx_get_prop(VALUE self, VALUE prop)
|
|
488
459
|
{
|
489
460
|
struct state *state;
|
490
461
|
Data_Get_Struct(self, struct state, state);
|
462
|
+
check_fatal(state);
|
491
463
|
|
492
464
|
ctx_get_nested_prop(state, prop);
|
493
465
|
|
@@ -513,10 +485,10 @@ static VALUE ctx_call_prop(int argc, VALUE* argv, VALUE self)
|
|
513
485
|
{
|
514
486
|
struct state *state;
|
515
487
|
Data_Get_Struct(self, struct state, state);
|
488
|
+
check_fatal(state);
|
516
489
|
|
517
490
|
VALUE prop;
|
518
|
-
|
519
|
-
rb_scan_args(argc, argv, "1*", &prop, &prop_args);
|
491
|
+
rb_scan_args(argc, argv, "1*", &prop, NULL);
|
520
492
|
|
521
493
|
ctx_get_nested_prop(state, prop);
|
522
494
|
|
@@ -587,6 +559,8 @@ static VALUE ctx_define_function(VALUE self, VALUE prop)
|
|
587
559
|
|
588
560
|
// get the context
|
589
561
|
Data_Get_Struct(self, struct state, state);
|
562
|
+
check_fatal(state);
|
563
|
+
|
590
564
|
ctx = state->ctx;
|
591
565
|
|
592
566
|
// the c function is available in the global scope
|
@@ -628,9 +602,37 @@ static VALUE ctx_is_valid(VALUE self)
|
|
628
602
|
}
|
629
603
|
}
|
630
604
|
|
631
|
-
|
605
|
+
/*
|
606
|
+
* :nodoc:
|
607
|
+
*
|
608
|
+
* Invokes duk_fatal(). Only used for testing.
|
609
|
+
*/
|
610
|
+
static VALUE ctx_invoke_fatal(VALUE self)
|
632
611
|
{
|
633
|
-
|
612
|
+
struct state *state;
|
613
|
+
Data_Get_Struct(self, struct state, state);
|
614
|
+
|
615
|
+
duk_fatal(state->ctx, "induced fatal error");
|
616
|
+
|
617
|
+
return Qnil;
|
618
|
+
}
|
619
|
+
|
620
|
+
static void error_handler(void *udata, const char *msg)
|
621
|
+
{
|
622
|
+
struct state *state = (struct state *)udata;
|
623
|
+
|
624
|
+
if (msg == NULL) {
|
625
|
+
msg = "fatal error";
|
626
|
+
}
|
627
|
+
state->is_fatal = 1;
|
628
|
+
rb_raise(eInternalError, "%s", msg);
|
629
|
+
}
|
630
|
+
|
631
|
+
static void check_fatal(struct state *state)
|
632
|
+
{
|
633
|
+
if (state->is_fatal) {
|
634
|
+
rb_raise(eInternalError, "fatal error");
|
635
|
+
}
|
634
636
|
}
|
635
637
|
|
636
638
|
VALUE complex_object_instance(VALUE self)
|
@@ -718,6 +720,7 @@ void Init_duktape_ext()
|
|
718
720
|
rb_define_method(cContext, "call_prop", ctx_call_prop, -1);
|
719
721
|
rb_define_method(cContext, "define_function", ctx_define_function, 1);
|
720
722
|
rb_define_method(cContext, "_valid?", ctx_is_valid, 0);
|
723
|
+
rb_define_method(cContext, "_invoke_fatal", ctx_invoke_fatal, 0);
|
721
724
|
|
722
725
|
oComplexObject = rb_obj_alloc(cComplexObject);
|
723
726
|
rb_define_singleton_method(cComplexObject, "instance", complex_object_instance, 0);
|
data/lib/duktape/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: duktape
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magnus Holm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: judofyr@gmail.com
|
@@ -46,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
46
|
version: '0'
|
47
47
|
requirements: []
|
48
48
|
rubyforge_project:
|
49
|
-
rubygems_version: 2.6.
|
49
|
+
rubygems_version: 2.6.11
|
50
50
|
signing_key:
|
51
51
|
specification_version: 4
|
52
52
|
summary: Bindings to the Duktape JavaScript interpreter
|