quickjs 0.7.1 → 0.8.1
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 +4 -4
- data/README.md +4 -4
- data/ext/quickjsrb/quickjsrb.c +13 -20
- data/ext/quickjsrb/quickjsrb.h +2 -4
- data/lib/quickjs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7de66a3eb1ddd2b9ab50dcbf88f083e42466a8b91343a79af6f01b847d99d01
|
4
|
+
data.tar.gz: f0bab5aa5a676731737633e67c463572dc5b52f959bf9f897883f0034927d314
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52f0a7a7419f0b7bb3cb1efb0f6b33442b7446d95cee7567dcb5e959c0ccdbf12ceaa02144e1d66730e411eba734bfd06923b1f2ce83b5d96611bb11c6e49964
|
7
|
+
data.tar.gz: 9f32de511d5dfcaff34dc2cf63970743d8d933286a617178e188bc2d56407159b694af92f7a5466c32a69a618a25f1c365d10a435051e7a05b588a750e9f5a7c
|
data/README.md
CHANGED
@@ -58,8 +58,8 @@ vm = Quickjs.eval_code(features: [::Quickjs::MODULE_STD])
|
|
58
58
|
# Enable `os` module by quickjs: https://bellard.org/quickjs/quickjs.html#os-module
|
59
59
|
vm = Quickjs.eval_code(features: [::Quickjs::MODULE_OS])
|
60
60
|
|
61
|
-
#
|
62
|
-
vm = Quickjs.eval_code(features: [::Quickjs::
|
61
|
+
# Provide `setTimeout` managed by CRuby
|
62
|
+
vm = Quickjs.eval_code(features: [::Quickjs::FEATURE_TIMEOUT])
|
63
63
|
|
64
64
|
# Inject the polyfill of Intl
|
65
65
|
vm = Quickjs.eval_code(features: [::Quickjs::POLYFILL_INTL])
|
@@ -98,8 +98,8 @@ vm = Quickjs::VM.new(features: [::Quickjs::MODULE_STD])
|
|
98
98
|
# Enable `os` module by quickjs: https://bellard.org/quickjs/quickjs.html#os-module
|
99
99
|
vm = Quickjs::VM.new(features: [::Quickjs::MODULE_OS])
|
100
100
|
|
101
|
-
#
|
102
|
-
vm = Quickjs::VM.new(features: [::Quickjs::
|
101
|
+
# Provide `setTimeout` managed by CRuby
|
102
|
+
vm = Quickjs::VM.new(features: [::Quickjs::FEATURE_TIMEOUT])
|
103
103
|
|
104
104
|
# Inject the polyfill of Intl
|
105
105
|
vm = Quickjs::VM.new(features: [::Quickjs::POLYFILL_INTL])
|
data/ext/quickjsrb/quickjsrb.c
CHANGED
@@ -311,7 +311,7 @@ static JSValue js_quickjsrb_call_global(JSContext *ctx, JSValueConst _this, int
|
|
311
311
|
const char *funcName = JS_ToCString(ctx, func_data[0]);
|
312
312
|
|
313
313
|
VMData *data = JS_GetContextOpaque(ctx);
|
314
|
-
VALUE r_proc = rb_hash_aref(data->defined_functions,
|
314
|
+
VALUE r_proc = rb_hash_aref(data->defined_functions, ID2SYM(rb_intern(funcName)));
|
315
315
|
// Shouldn't happen
|
316
316
|
if (r_proc == Qnil)
|
317
317
|
{
|
@@ -542,22 +542,7 @@ static VALUE vm_m_initialize(int argc, VALUE *argv, VALUE r_self)
|
|
542
542
|
JSValue j_osEval = JS_Eval(data->context, enableOs, strlen(enableOs), "<vm>", JS_EVAL_TYPE_MODULE);
|
543
543
|
JS_FreeValue(data->context, j_osEval);
|
544
544
|
}
|
545
|
-
else if (RTEST(rb_funcall(r_features, rb_intern("include?"), 1, QUICKJSRB_SYM(
|
546
|
-
{
|
547
|
-
char *filename = random_string();
|
548
|
-
js_init_module_os(data->context, filename); // Better if this is limited just only for setTimeout and clearTimeout
|
549
|
-
const char *enableTimeoutTemplate = "import * as _os from '%s';\n"
|
550
|
-
"globalThis.setTimeout = _os.setTimeout;\n"
|
551
|
-
"globalThis.clearTimeout = _os.clearTimeout;\n";
|
552
|
-
int length = snprintf(NULL, 0, enableTimeoutTemplate, filename);
|
553
|
-
char *enableTimeout = (char *)malloc(length + 1);
|
554
|
-
snprintf(enableTimeout, length + 1, enableTimeoutTemplate, filename);
|
555
|
-
|
556
|
-
JSValue j_timeoutEval = JS_Eval(data->context, enableTimeout, strlen(enableTimeout), "<vm>", JS_EVAL_TYPE_MODULE);
|
557
|
-
free(enableTimeout);
|
558
|
-
JS_FreeValue(data->context, j_timeoutEval);
|
559
|
-
}
|
560
|
-
else if (RTEST(rb_funcall(r_features, rb_intern("include?"), 1, QUICKJSRB_SYM(featureOsTimeoutBetaId))))
|
545
|
+
else if (RTEST(rb_funcall(r_features, rb_intern("include?"), 1, QUICKJSRB_SYM(featureTimeoutId))))
|
561
546
|
{
|
562
547
|
JS_SetPropertyStr(
|
563
548
|
data->context, j_global, "setTimeout",
|
@@ -643,11 +628,19 @@ static VALUE vm_m_defineGlobalFunction(int argc, VALUE *argv, VALUE r_self)
|
|
643
628
|
VALUE r_block;
|
644
629
|
rb_scan_args(argc, argv, "10*&", &r_name, &r_flags, &r_block);
|
645
630
|
|
631
|
+
if (!(SYMBOL_P(r_name) || RB_TYPE_P(r_name, T_STRING)))
|
632
|
+
{
|
633
|
+
rb_raise(rb_eTypeError, "function's name should be a Symbol or a String");
|
634
|
+
}
|
635
|
+
|
646
636
|
VMData *data;
|
647
637
|
TypedData_Get_Struct(r_self, VMData, &vm_type, data);
|
648
638
|
|
649
|
-
|
650
|
-
|
639
|
+
VALUE r_name_sym = rb_funcall(r_name, rb_intern("to_sym"), 0);
|
640
|
+
|
641
|
+
rb_hash_aset(data->defined_functions, r_name_sym, r_block);
|
642
|
+
VALUE r_name_str = rb_funcall(r_name, rb_intern("to_s"), 0);
|
643
|
+
char *funcName = StringValueCStr(r_name_str);
|
651
644
|
|
652
645
|
JSValueConst ruby_data[2];
|
653
646
|
ruby_data[0] = JS_NewString(data->context, funcName);
|
@@ -661,7 +654,7 @@ static VALUE vm_m_defineGlobalFunction(int argc, VALUE *argv, VALUE r_self)
|
|
661
654
|
JS_FreeValue(data->context, ruby_data[0]);
|
662
655
|
JS_FreeValue(data->context, ruby_data[1]);
|
663
656
|
|
664
|
-
return
|
657
|
+
return r_name_sym;
|
665
658
|
}
|
666
659
|
|
667
660
|
static VALUE vm_m_import(int argc, VALUE *argv, VALUE r_self)
|
data/ext/quickjsrb/quickjsrb.h
CHANGED
@@ -17,8 +17,7 @@ extern const uint8_t qjsc_polyfill_intl_en_min;
|
|
17
17
|
|
18
18
|
const char *featureStdId = "feature_std";
|
19
19
|
const char *featureOsId = "feature_os";
|
20
|
-
const char *
|
21
|
-
const char *featureOsTimeoutBetaId = "feature_os_timeout_beta";
|
20
|
+
const char *featureTimeoutId = "feature_timeout";
|
22
21
|
const char *featurePolyfillIntlId = "feature_polyfill_intl";
|
23
22
|
|
24
23
|
const char *undefinedId = "undefined";
|
@@ -137,8 +136,7 @@ static void r_define_constants(VALUE r_parent_class)
|
|
137
136
|
{
|
138
137
|
rb_define_const(r_parent_class, "MODULE_STD", QUICKJSRB_SYM(featureStdId));
|
139
138
|
rb_define_const(r_parent_class, "MODULE_OS", QUICKJSRB_SYM(featureOsId));
|
140
|
-
rb_define_const(r_parent_class, "
|
141
|
-
rb_define_const(r_parent_class, "FEATURES_TIMEOUT_BETA", QUICKJSRB_SYM(featureOsTimeoutBetaId));
|
139
|
+
rb_define_const(r_parent_class, "FEATURE_TIMEOUT", QUICKJSRB_SYM(featureTimeoutId));
|
142
140
|
rb_define_const(r_parent_class, "POLYFILL_INTL", QUICKJSRB_SYM(featurePolyfillIntlId));
|
143
141
|
|
144
142
|
VALUE rb_cQuickjsValue = rb_define_class_under(r_parent_class, "Value", rb_cObject);
|
data/lib/quickjs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quickjs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hmsk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|