quickjs 0.8.1 → 0.9.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.
@@ -64,12 +64,18 @@ typedef uint32_t JSAtom;
64
64
  #define JS_NAN_BOXING
65
65
  #endif
66
66
 
67
+ #if defined(__SIZEOF_INT128__) && (INTPTR_MAX >= INT64_MAX)
68
+ #define JS_LIMB_BITS 64
69
+ #else
70
+ #define JS_LIMB_BITS 32
71
+ #endif
72
+
73
+ #define JS_SHORT_BIG_INT_BITS JS_LIMB_BITS
74
+
67
75
  enum {
68
76
  /* all tags with a reference count are negative */
69
- JS_TAG_FIRST = -11, /* first negative tag */
70
- JS_TAG_BIG_DECIMAL = -11,
71
- JS_TAG_BIG_INT = -10,
72
- JS_TAG_BIG_FLOAT = -9,
77
+ JS_TAG_FIRST = -9, /* first negative tag */
78
+ JS_TAG_BIG_INT = -9,
73
79
  JS_TAG_SYMBOL = -8,
74
80
  JS_TAG_STRING = -7,
75
81
  JS_TAG_MODULE = -3, /* used internally */
@@ -83,7 +89,8 @@ enum {
83
89
  JS_TAG_UNINITIALIZED = 4,
84
90
  JS_TAG_CATCH_OFFSET = 5,
85
91
  JS_TAG_EXCEPTION = 6,
86
- JS_TAG_FLOAT64 = 7,
92
+ JS_TAG_SHORT_BIG_INT = 7,
93
+ JS_TAG_FLOAT64 = 8,
87
94
  /* any larger tag is FLOAT64 if JS_NAN_BOXING */
88
95
  };
89
96
 
@@ -108,6 +115,7 @@ typedef const struct __JSValue *JSValueConst;
108
115
  #define JS_VALUE_GET_INT(v) (int)((intptr_t)(v) >> 4)
109
116
  #define JS_VALUE_GET_BOOL(v) JS_VALUE_GET_INT(v)
110
117
  #define JS_VALUE_GET_FLOAT64(v) (double)JS_VALUE_GET_INT(v)
118
+ #define JS_VALUE_GET_SHORT_BIG_INT(v) JS_VALUE_GET_INT(v)
111
119
  #define JS_VALUE_GET_PTR(v) (void *)((intptr_t)(v) & ~0xf)
112
120
 
113
121
  #define JS_MKVAL(tag, val) (JSValue)(intptr_t)(((val) << 4) | (tag))
@@ -127,6 +135,11 @@ static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)
127
135
  return 0;
128
136
  }
129
137
 
138
+ static inline JSValue __JS_NewShortBigInt(JSContext *ctx, int32_t d)
139
+ {
140
+ return JS_MKVAL(JS_TAG_SHORT_BIG_INT, d);
141
+ }
142
+
130
143
  #elif defined(JS_NAN_BOXING)
131
144
 
132
145
  typedef uint64_t JSValue;
@@ -136,6 +149,7 @@ typedef uint64_t JSValue;
136
149
  #define JS_VALUE_GET_TAG(v) (int)((v) >> 32)
137
150
  #define JS_VALUE_GET_INT(v) (int)(v)
138
151
  #define JS_VALUE_GET_BOOL(v) (int)(v)
152
+ #define JS_VALUE_GET_SHORT_BIG_INT(v) (int)(v)
139
153
  #define JS_VALUE_GET_PTR(v) (void *)(intptr_t)(v)
140
154
 
141
155
  #define JS_MKVAL(tag, val) (((uint64_t)(tag) << 32) | (uint32_t)(val))
@@ -192,12 +206,22 @@ static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)
192
206
  return tag == (JS_NAN >> 32);
193
207
  }
194
208
 
209
+ static inline JSValue __JS_NewShortBigInt(JSContext *ctx, int32_t d)
210
+ {
211
+ return JS_MKVAL(JS_TAG_SHORT_BIG_INT, d);
212
+ }
213
+
195
214
  #else /* !JS_NAN_BOXING */
196
215
 
197
216
  typedef union JSValueUnion {
198
217
  int32_t int32;
199
218
  double float64;
200
219
  void *ptr;
220
+ #if JS_SHORT_BIG_INT_BITS == 32
221
+ int32_t short_big_int;
222
+ #else
223
+ int64_t short_big_int;
224
+ #endif
201
225
  } JSValueUnion;
202
226
 
203
227
  typedef struct JSValue {
@@ -213,6 +237,7 @@ typedef struct JSValue {
213
237
  #define JS_VALUE_GET_INT(v) ((v).u.int32)
214
238
  #define JS_VALUE_GET_BOOL(v) ((v).u.int32)
215
239
  #define JS_VALUE_GET_FLOAT64(v) ((v).u.float64)
240
+ #define JS_VALUE_GET_SHORT_BIG_INT(v) ((v).u.short_big_int)
216
241
  #define JS_VALUE_GET_PTR(v) ((v).u.ptr)
217
242
 
218
243
  #define JS_MKVAL(tag, val) (JSValue){ (JSValueUnion){ .int32 = val }, tag }
@@ -242,6 +267,14 @@ static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)
242
267
  return (u.u64 & 0x7fffffffffffffff) > 0x7ff0000000000000;
243
268
  }
244
269
 
270
+ static inline JSValue __JS_NewShortBigInt(JSContext *ctx, int64_t d)
271
+ {
272
+ JSValue v;
273
+ v.tag = JS_TAG_SHORT_BIG_INT;
274
+ v.u.short_big_int = d;
275
+ return v;
276
+ }
277
+
245
278
  #endif /* !JS_NAN_BOXING */
246
279
 
247
280
  #define JS_VALUE_IS_BOTH_INT(v1, v2) ((JS_VALUE_GET_TAG(v1) | JS_VALUE_GET_TAG(v2)) == 0)
@@ -373,13 +406,6 @@ void JS_AddIntrinsicProxy(JSContext *ctx);
373
406
  void JS_AddIntrinsicMapSet(JSContext *ctx);
374
407
  void JS_AddIntrinsicTypedArrays(JSContext *ctx);
375
408
  void JS_AddIntrinsicPromise(JSContext *ctx);
376
- void JS_AddIntrinsicBigInt(JSContext *ctx);
377
- void JS_AddIntrinsicBigFloat(JSContext *ctx);
378
- void JS_AddIntrinsicBigDecimal(JSContext *ctx);
379
- /* enable operator overloading */
380
- void JS_AddIntrinsicOperators(JSContext *ctx);
381
- /* enable "use math" */
382
- void JS_EnableBignumExt(JSContext *ctx, JS_BOOL enable);
383
409
 
384
410
  JSValue js_string_codePointRange(JSContext *ctx, JSValueConst this_val,
385
411
  int argc, JSValueConst *argv);
@@ -576,19 +602,7 @@ static inline JS_BOOL JS_IsNumber(JSValueConst v)
576
602
  static inline JS_BOOL JS_IsBigInt(JSContext *ctx, JSValueConst v)
577
603
  {
578
604
  int tag = JS_VALUE_GET_TAG(v);
579
- return tag == JS_TAG_BIG_INT;
580
- }
581
-
582
- static inline JS_BOOL JS_IsBigFloat(JSValueConst v)
583
- {
584
- int tag = JS_VALUE_GET_TAG(v);
585
- return tag == JS_TAG_BIG_FLOAT;
586
- }
587
-
588
- static inline JS_BOOL JS_IsBigDecimal(JSValueConst v)
589
- {
590
- int tag = JS_VALUE_GET_TAG(v);
591
- return tag == JS_TAG_BIG_DECIMAL;
605
+ return tag == JS_TAG_BIG_INT || tag == JS_TAG_SHORT_BIG_INT;
592
606
  }
593
607
 
594
608
  static inline JS_BOOL JS_IsBool(JSValueConst v)
@@ -274,6 +274,7 @@ VALUE to_rb_value(JSContext *ctx, JSValue j_val)
274
274
  return Qnil;
275
275
  }
276
276
  case JS_TAG_BIG_INT:
277
+ case JS_TAG_SHORT_BIG_INT:
277
278
  {
278
279
  JSValue j_toStringFunc = JS_GetPropertyStr(ctx, j_val, "toString");
279
280
  JSValue j_strigified = JS_Call(ctx, j_toStringFunc, j_val, 0, NULL);
@@ -286,8 +287,6 @@ VALUE to_rb_value(JSContext *ctx, JSValue j_val)
286
287
 
287
288
  return rb_funcall(r_str, rb_intern("to_i"), 0);
288
289
  }
289
- case JS_TAG_BIG_FLOAT:
290
- case JS_TAG_BIG_DECIMAL:
291
290
  case JS_TAG_SYMBOL:
292
291
  default:
293
292
  return Qnil;
@@ -515,11 +514,6 @@ static VALUE vm_m_initialize(int argc, VALUE *argv, VALUE r_self)
515
514
  JS_SetMemoryLimit(runtime, NUM2UINT(r_memory_limit));
516
515
  JS_SetMaxStackSize(runtime, NUM2UINT(r_max_stack_size));
517
516
 
518
- JS_AddIntrinsicBigFloat(data->context);
519
- JS_AddIntrinsicBigDecimal(data->context);
520
- JS_AddIntrinsicOperators(data->context);
521
- JS_EnableBignumExt(data->context, TRUE);
522
-
523
517
  JS_SetModuleLoaderFunc(runtime, NULL, js_module_loader, NULL);
524
518
  js_std_init_handlers(runtime);
525
519
 
@@ -677,9 +671,14 @@ static VALUE vm_m_import(int argc, VALUE *argv, VALUE r_self)
677
671
 
678
672
  char *filename = random_string();
679
673
  char *source = StringValueCStr(r_from);
680
- JSValue func = JS_Eval(data->context, source, strlen(source), filename, JS_EVAL_TYPE_MODULE | JS_EVAL_FLAG_COMPILE_ONLY);
681
- js_module_set_import_meta(data->context, func, TRUE, FALSE);
682
- JS_FreeValue(data->context, func);
674
+ JSValue module = JS_Eval(data->context, source, strlen(source), filename, JS_EVAL_TYPE_MODULE | JS_EVAL_FLAG_COMPILE_ONLY);
675
+ if (JS_IsException(module))
676
+ {
677
+ JS_FreeValue(data->context, module);
678
+ return to_rb_value(data->context, module);
679
+ }
680
+ js_module_set_import_meta(data->context, module, TRUE, FALSE);
681
+ JS_FreeValue(data->context, module);
683
682
 
684
683
  VALUE r_import_settings = rb_funcall(
685
684
  rb_const_get(rb_cClass, rb_intern("Quickjs")),
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Quickjs
4
- VERSION = "0.8.1"
4
+ VERSION = "0.9.0"
5
5
  end
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.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - hmsk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-18 00:00:00.000000000 Z
11
+ date: 2025-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -54,8 +54,8 @@ files:
54
54
  - ext/quickjsrb/quickjs/LICENSE
55
55
  - ext/quickjsrb/quickjs/cutils.c
56
56
  - ext/quickjsrb/quickjs/cutils.h
57
- - ext/quickjsrb/quickjs/libbf.c
58
- - ext/quickjsrb/quickjs/libbf.h
57
+ - ext/quickjsrb/quickjs/dtoa.c
58
+ - ext/quickjsrb/quickjs/dtoa.h
59
59
  - ext/quickjsrb/quickjs/libregexp-opcode.h
60
60
  - ext/quickjsrb/quickjs/libregexp.c
61
61
  - ext/quickjsrb/quickjs/libregexp.h