quickjs 0.6.5 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31bcb05285a3c4c80c6e5c06ec043793debf795c75f82362b317d74d3eb8cf96
4
- data.tar.gz: 9032bf6cb129ea65dc52ae5df5ff394056f440c9de52947ab3029e5c0626c554
3
+ metadata.gz: 44eedd9a617b8106c963b40fde4ffd9e9c3093be07a9d1528ae3cdac357abd9d
4
+ data.tar.gz: 83821e76a40a152fea3516c4720e5a5240129f866dc44db2d2ef8350672ff80b
5
5
  SHA512:
6
- metadata.gz: 2a12da5b5c71c5d350af754f5b50e47104a379aa53cde68625da76bf6b3e165a804b3ec9d764d52f7e8c87a696a870d948d17381bb044b13536b6e96992e9cea
7
- data.tar.gz: 1b0b05872129c9d3850e66b0e5f77c779bb2554801e132380a0937a2d21d393b23317364e775ab9c0779ba074da157d46fdd6779a1b5f0ba690c55e2cbedccbd
6
+ metadata.gz: 5b8f7d797869c7f02a7c529f47d0340831b700e7c91fd0f351df040e8e09f4e4a0e8ae42c9da0609603cd451d50246d6f491619c512e383ecd1f4a6a53c14feb
7
+ data.tar.gz: 71bf4c8fd5d6f94db5edb6f341005dcc153b1bba13b4dbcdc1974b3eca01be2893de6dee5cf3a4e9be815afe1777febf2cd0c718df334f4e175fd25e01267ca6
data/README.md CHANGED
@@ -49,20 +49,22 @@ Quickjs.eval_code(code, { memory_limit: 1024 ** 3 })
49
49
  Quickjs.eval_code(code, { max_stack_size: 1024 ** 2 })
50
50
  ```
51
51
 
52
- #### Built-in modules
53
-
54
- To enable [std module](https://bellard.org/quickjs/quickjs.html#std-module) and [os module](https://bellard.org/quickjs/quickjs.html#os-module) selectively.
52
+ #### Toggle features
55
53
 
56
54
  ```rb
57
- # enable std module
58
- Quickjs.eval_code(code, { features: [Quickjs::MODULE_STD] })
55
+ # Enable `std` module by quickjs: https://bellard.org/quickjs/quickjs.html#std-module
56
+ vm = Quickjs.eval_code(features: [::Quickjs::MODULE_STD])
57
+
58
+ # Enable `os` module by quickjs: https://bellard.org/quickjs/quickjs.html#os-module
59
+ vm = Quickjs.eval_code(features: [::Quickjs::MODULE_OS])
59
60
 
60
- # enable os module
61
- Quickjs.eval_code(code, { features: [Quickjs::MODULE_OS] })
61
+ # Expose `os.setTimouet` and `os.clearTimeout` from `os` module
62
+ vm = Quickjs.eval_code(features: [::Quickjs::FEATURES_TIMEOUT])
62
63
 
63
- # enable timeout features `setTimeout`, `clearTimeout` from os module specifically
64
- Quickjs.eval_code(code, { features: [Quickjs::FEATURES_TIMEOUT] })
64
+ # Inject the polyfill of Intl
65
+ vm = Quickjs.eval_code(features: [::Quickjs::POLYFILL_INTL])
65
66
  ```
67
+
66
68
  </details>
67
69
 
68
70
  ### `Quickjs::VM`: Maintain a consistent VM/runtime
@@ -87,19 +89,20 @@ vm = Quickjs::VM.new(
87
89
  )
88
90
  ```
89
91
 
90
- #### Built-in modules
91
-
92
- To enable [std module](https://bellard.org/quickjs/quickjs.html#std-module) and [os module](https://bellard.org/quickjs/quickjs.html#os-module) selectively.
92
+ #### Toggle features
93
93
 
94
94
  ```rb
95
- # enable std module
95
+ # Enable `std` module by quickjs: https://bellard.org/quickjs/quickjs.html#std-module
96
96
  vm = Quickjs::VM.new(features: [::Quickjs::MODULE_STD])
97
97
 
98
- # enable os module
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
- # enable timeout features `setTimeout`, `clearTimeout`
101
+ # Expose `os.setTimouet` and `os.clearTimeout` from `os` module
102
102
  vm = Quickjs::VM.new(features: [::Quickjs::FEATURES_TIMEOUT])
103
+
104
+ # Inject the polyfill of Intl
105
+ vm = Quickjs::VM.new(features: [::Quickjs::POLYFILL_INTL])
103
106
  ```
104
107
 
105
108
  #### VM timeout
@@ -158,6 +161,16 @@ vm.logs.last.raw #=> ['log me', nil]
158
161
 
159
162
  ## License
160
163
 
161
- Every file in `ext/quickjsrb/quickjs` is licensed under [the MIT License Copyright 2017-2021 by Fabrice Bellard and Charlie Gordon](https://github.com/bellard/quickjs/blob/6e2e68fd0896957f92eb6c242a2e048c1ef3cae0/LICENSE).
162
-
163
- For otherwise, [the MIT License, Copyright 2024 by Kengo Hamasaki](/LICENSE).
164
+ - `ext/quickjsrb/quickjs`
165
+ - [MIT License Copyright (c) 2017-2021 by Fabrice Bellard and Charlie Gordon](https://github.com/bellard/quickjs/blob/6e2e68fd0896957f92eb6c242a2e048c1ef3cae0/LICENSE).
166
+ - `ext/quickjsrb/vendor/polyfill-intl-en.min.js`
167
+ - MIT License Copyright (c) 2023 FormatJS
168
+ - `[@formatjs/intl-getcanonicallocales](https://github.com/formatjs/formatjs/blob/main/packages/intl-getcanonicallocales/LICENSE.md)
169
+ - `[@formatjs/intl-locale](https://github.com/formatjs/formatjs/blob/main/packages/intl-locale/LICENSE.md)
170
+ - `[@formatjs/intl-pluralrules](https://github.com/formatjs/formatjs/blob/main/packages/intl-pluralrules/LICENSE.md)
171
+ - `[@formatjs/intl-numberformat](https://github.com/formatjs/formatjs/blob/main/packages/intl-numberformat/LICENSE.md)
172
+ - `[@formatjs/intl-datetimeformat](https://github.com/formatjs/formatjs/blob/main/packages/intl-datetimeformat/LICENSE.md)
173
+ - MIT License Copyright (c) 2025 Michael Mclaughlin
174
+ - [decimal.js](https://www.npmjs.com/package/decimal.js)
175
+
176
+ Otherwise, [the MIT License, Copyright 2024 by Kengo Hamasaki](/LICENSE).
@@ -11,12 +11,12 @@ $srcs = [
11
11
  'cutils.c',
12
12
  'quickjs.c',
13
13
  'quickjs-libc.c',
14
+ 'polyfill-intl-en.min.c',
14
15
  'quickjsrb.c',
15
16
  ]
16
17
 
17
18
  append_cflags('-I$(srcdir)/quickjs')
18
19
 
19
-
20
20
  append_cflags('-g')
21
21
  append_cflags('-O2')
22
22
  append_cflags('-Wall')
@@ -51,4 +51,17 @@ abort('could not find quickjs-libc.h') unless find_header('quickjs-libc.h')
51
51
  append_cflags('-fvisibility=hidden')
52
52
  $warnflags = ''
53
53
 
54
- create_makefile('quickjs/quickjsrb')
54
+ create_makefile('quickjs/quickjsrb') do |conf|
55
+ conf.push <<COMPILE_POLYFILL
56
+ QJS_LIB_OBJS= quickjs.o libregexp.o libunicode.o cutils.o quickjs-libc.o libbf.o
57
+ POLYFILL_OPTS=-fno-string-normalize -fno-typedarray -fno-typedarray -fno-eval -fno-proxy -fno-module-loader -fno-bigint
58
+
59
+ qjsc: ./qjsc.o $(QJS_LIB_OBJS)
60
+ $(CC) -g -o $@ $^ -lm -ldl -lpthread
61
+ polyfill-intl-en.min.js:
62
+ $(COPY) $(srcdir)/vendor/$@ $@
63
+ polyfill-intl-en.min.c: ./qjsc polyfill-intl-en.min.js
64
+ ./qjsc $(POLYFILL_OPTS) -c -M polyfill/intl-en.so,intlen -m -o $@ polyfill-intl-en.min.js
65
+ COMPILE_POLYFILL
66
+ conf
67
+ end
@@ -525,6 +525,17 @@ static VALUE vm_m_initialize(int argc, VALUE *argv, VALUE r_self)
525
525
  JS_FreeValue(data->context, j_timeoutEval);
526
526
  }
527
527
 
528
+ if (RTEST(rb_funcall(r_features, rb_intern("include?"), 1, QUICKJSRB_SYM(featurePolyfillIntlId))))
529
+ {
530
+ const char *defineIntl = "Object.defineProperty(globalThis, 'Intl', { value:{} });\n";
531
+ JSValue j_defineIntl = JS_Eval(data->context, defineIntl, strlen(defineIntl), "<vm>", JS_EVAL_TYPE_GLOBAL);
532
+ JS_FreeValue(data->context, j_defineIntl);
533
+
534
+ JSValue j_polyfillIntlObject = JS_ReadObject(data->context, &qjsc_polyfill_intl_en_min, qjsc_polyfill_intl_en_min_size, JS_READ_OBJ_BYTECODE);
535
+ JSValue j_polyfillIntlResult = JS_EvalFunction(data->context, j_polyfillIntlObject); // Frees polyfillIntlObject
536
+ JS_FreeValue(data->context, j_polyfillIntlResult);
537
+ }
538
+
528
539
  JSValue j_console = JS_NewObject(data->context);
529
540
  JS_SetPropertyStr(
530
541
  data->context, j_console, "log",
@@ -12,9 +12,13 @@
12
12
  #include <string.h>
13
13
  #include <time.h>
14
14
 
15
+ extern const uint32_t qjsc_polyfill_intl_en_min_size;
16
+ extern const uint8_t qjsc_polyfill_intl_en_min;
17
+
15
18
  const char *featureStdId = "feature_std";
16
19
  const char *featureOsId = "feature_os";
17
20
  const char *featureOsTimeoutId = "feature_os_timeout";
21
+ const char *featurePolyfillIntlId = "feature_polyfill_intl";
18
22
 
19
23
  const char *undefinedId = "undefined";
20
24
  const char *nanId = "NaN";
@@ -133,6 +137,7 @@ static void r_define_constants(VALUE r_parent_class)
133
137
  rb_define_const(r_parent_class, "MODULE_STD", QUICKJSRB_SYM(featureStdId));
134
138
  rb_define_const(r_parent_class, "MODULE_OS", QUICKJSRB_SYM(featureOsId));
135
139
  rb_define_const(r_parent_class, "FEATURES_TIMEOUT", QUICKJSRB_SYM(featureOsTimeoutId));
140
+ rb_define_const(r_parent_class, "POLYFILL_INTL", QUICKJSRB_SYM(featurePolyfillIntlId));
136
141
 
137
142
  VALUE rb_cQuickjsValue = rb_define_class_under(r_parent_class, "Value", rb_cObject);
138
143
  rb_define_const(rb_cQuickjsValue, "UNDEFINED", QUICKJSRB_SYM(undefinedId));