quickjs 0.19.0 → 0.20.0.rc1

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.
@@ -95,6 +95,7 @@ enum {
95
95
  /* any larger tag is FLOAT64 if JS_NAN_BOXING */
96
96
  };
97
97
 
98
+ /* must match the layout of 'JSMallocBlockHeader' */
98
99
  typedef struct JSRefCountHeader {
99
100
  int ref_count;
100
101
  } JSRefCountHeader;
@@ -215,7 +216,7 @@ static inline JSValue __JS_NewShortBigInt(JSContext *ctx, int32_t d)
215
216
  #else /* !JS_NAN_BOXING */
216
217
 
217
218
  typedef union JSValueUnion {
218
- int32_t int32;
219
+ uint64_t uint64;
219
220
  double float64;
220
221
  void *ptr;
221
222
  #if JS_SHORT_BIG_INT_BITS == 32
@@ -235,13 +236,15 @@ typedef struct JSValue {
235
236
  #define JS_VALUE_GET_TAG(v) ((int32_t)(v).tag)
236
237
  /* same as JS_VALUE_GET_TAG, but return JS_TAG_FLOAT64 with NaN boxing */
237
238
  #define JS_VALUE_GET_NORM_TAG(v) JS_VALUE_GET_TAG(v)
238
- #define JS_VALUE_GET_INT(v) ((v).u.int32)
239
- #define JS_VALUE_GET_BOOL(v) ((v).u.int32)
239
+ #define JS_VALUE_GET_INT(v) ((int)(v).u.uint64)
240
+ #define JS_VALUE_GET_BOOL(v) ((int)(v).u.uint64)
240
241
  #define JS_VALUE_GET_FLOAT64(v) ((v).u.float64)
241
242
  #define JS_VALUE_GET_SHORT_BIG_INT(v) ((v).u.short_big_int)
242
243
  #define JS_VALUE_GET_PTR(v) ((v).u.ptr)
243
244
 
244
- #define JS_MKVAL(tag, val) (JSValue){ (JSValueUnion){ .int32 = val }, tag }
245
+ /* avoid uninitialized data by using a 64 bit field even if only 32
246
+ bits are needed because some compilers generate slower code */
247
+ #define JS_MKVAL(tag, val) (JSValue){ (JSValueUnion){ .uint64 = (uint32_t)(val) }, tag }
245
248
  #define JS_MKPTR(tag, p) (JSValue){ (JSValueUnion){ .ptr = p }, tag }
246
249
 
247
250
  #define JS_TAG_IS_FLOAT64(tag) ((unsigned)(tag) == JS_TAG_FLOAT64)
@@ -319,8 +322,7 @@ static inline JSValue __JS_NewShortBigInt(JSContext *ctx, int64_t d)
319
322
  (JS_SetProperty) */
320
323
  #define JS_PROP_THROW_STRICT (1 << 15)
321
324
 
322
- #define JS_PROP_NO_ADD (1 << 16) /* internal use */
323
- #define JS_PROP_NO_EXOTIC (1 << 17) /* internal use */
325
+ #define JS_PROP_NO_EXOTIC (1 << 16) /* internal use */
324
326
 
325
327
  #ifndef JS_DEFAULT_STACK_SIZE
326
328
  #define JS_DEFAULT_STACK_SIZE (1024 * 1024)
@@ -395,18 +397,18 @@ JSValue JS_GetClassProto(JSContext *ctx, JSClassID class_id);
395
397
  /* the following functions are used to select the intrinsic object to
396
398
  save memory */
397
399
  JSContext *JS_NewContextRaw(JSRuntime *rt);
398
- void JS_AddIntrinsicBaseObjects(JSContext *ctx);
399
- void JS_AddIntrinsicDate(JSContext *ctx);
400
- void JS_AddIntrinsicEval(JSContext *ctx);
401
- void JS_AddIntrinsicStringNormalize(JSContext *ctx);
400
+ int JS_AddIntrinsicBaseObjects(JSContext *ctx);
401
+ int JS_AddIntrinsicDate(JSContext *ctx);
402
+ int JS_AddIntrinsicEval(JSContext *ctx);
403
+ int JS_AddIntrinsicStringNormalize(JSContext *ctx);
402
404
  void JS_AddIntrinsicRegExpCompiler(JSContext *ctx);
403
- void JS_AddIntrinsicRegExp(JSContext *ctx);
404
- void JS_AddIntrinsicJSON(JSContext *ctx);
405
- void JS_AddIntrinsicProxy(JSContext *ctx);
406
- void JS_AddIntrinsicMapSet(JSContext *ctx);
407
- void JS_AddIntrinsicTypedArrays(JSContext *ctx);
408
- void JS_AddIntrinsicPromise(JSContext *ctx);
409
- void JS_AddIntrinsicWeakRef(JSContext *ctx);
405
+ int JS_AddIntrinsicRegExp(JSContext *ctx);
406
+ int JS_AddIntrinsicJSON(JSContext *ctx);
407
+ int JS_AddIntrinsicProxy(JSContext *ctx);
408
+ int JS_AddIntrinsicMapSet(JSContext *ctx);
409
+ int JS_AddIntrinsicTypedArrays(JSContext *ctx);
410
+ int JS_AddIntrinsicPromise(JSContext *ctx);
411
+ int JS_AddIntrinsicWeakRef(JSContext *ctx);
410
412
 
411
413
  JSValue js_string_codePointRange(JSContext *ctx, JSValueConst this_val,
412
414
  int argc, JSValueConst *argv);
@@ -676,10 +678,16 @@ JSValue __js_printf_like(2, 3) JS_ThrowInternalError(JSContext *ctx, const char
676
678
  JSValue JS_ThrowOutOfMemory(JSContext *ctx);
677
679
 
678
680
  void __JS_FreeValue(JSContext *ctx, JSValue v);
681
+
682
+ static inline JSRefCountHeader *__js_rc(void *ptr)
683
+ {
684
+ return (JSRefCountHeader *)((uint32_t *)ptr - 1);
685
+ }
686
+
679
687
  static inline void JS_FreeValue(JSContext *ctx, JSValue v)
680
688
  {
681
689
  if (JS_VALUE_HAS_REF_COUNT(v)) {
682
- JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
690
+ JSRefCountHeader *p = __js_rc(JS_VALUE_GET_PTR(v));
683
691
  if (--p->ref_count <= 0) {
684
692
  __JS_FreeValue(ctx, v);
685
693
  }
@@ -689,7 +697,7 @@ void __JS_FreeValueRT(JSRuntime *rt, JSValue v);
689
697
  static inline void JS_FreeValueRT(JSRuntime *rt, JSValue v)
690
698
  {
691
699
  if (JS_VALUE_HAS_REF_COUNT(v)) {
692
- JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
700
+ JSRefCountHeader *p = __js_rc(JS_VALUE_GET_PTR(v));
693
701
  if (--p->ref_count <= 0) {
694
702
  __JS_FreeValueRT(rt, v);
695
703
  }
@@ -699,7 +707,7 @@ static inline void JS_FreeValueRT(JSRuntime *rt, JSValue v)
699
707
  static inline JSValue JS_DupValue(JSContext *ctx, JSValueConst v)
700
708
  {
701
709
  if (JS_VALUE_HAS_REF_COUNT(v)) {
702
- JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
710
+ JSRefCountHeader *p = __js_rc(JS_VALUE_GET_PTR(v));
703
711
  p->ref_count++;
704
712
  }
705
713
  return (JSValue)v;
@@ -708,7 +716,7 @@ static inline JSValue JS_DupValue(JSContext *ctx, JSValueConst v)
708
716
  static inline JSValue JS_DupValueRT(JSRuntime *rt, JSValueConst v)
709
717
  {
710
718
  if (JS_VALUE_HAS_REF_COUNT(v)) {
711
- JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
719
+ JSRefCountHeader *p = __js_rc(JS_VALUE_GET_PTR(v));
712
720
  p->ref_count++;
713
721
  }
714
722
  return (JSValue)v;
@@ -1053,8 +1061,8 @@ static inline JSValue JS_NewCFunctionMagic(JSContext *ctx, JSCFunctionMagic *fun
1053
1061
  JSCFunctionType ft = { .generic_magic = func };
1054
1062
  return JS_NewCFunction2(ctx, ft.generic, name, length, cproto, magic);
1055
1063
  }
1056
- void JS_SetConstructor(JSContext *ctx, JSValueConst func_obj,
1057
- JSValueConst proto);
1064
+ int JS_SetConstructor(JSContext *ctx, JSValueConst func_obj,
1065
+ JSValueConst proto);
1058
1066
 
1059
1067
  /* C property definition */
1060
1068
 
@@ -1098,6 +1106,8 @@ typedef struct JSCFunctionListEntry {
1098
1106
  #define JS_DEF_PROP_UNDEFINED 7
1099
1107
  #define JS_DEF_OBJECT 8
1100
1108
  #define JS_DEF_ALIAS 9
1109
+ #define JS_DEF_PROP_ATOM 10
1110
+ #define JS_DEF_PROP_BOOL 11
1101
1111
 
1102
1112
  /* Note: c++ does not like nested designators */
1103
1113
  #define JS_CFUNC_DEF(name, length, func1) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_CFUNC, 0, .u = { .func = { length, JS_CFUNC_generic, { .generic = func1 } } } }
@@ -1111,6 +1121,8 @@ typedef struct JSCFunctionListEntry {
1111
1121
  #define JS_PROP_INT64_DEF(name, val, prop_flags) { name, prop_flags, JS_DEF_PROP_INT64, 0, .u = { .i64 = val } }
1112
1122
  #define JS_PROP_DOUBLE_DEF(name, val, prop_flags) { name, prop_flags, JS_DEF_PROP_DOUBLE, 0, .u = { .f64 = val } }
1113
1123
  #define JS_PROP_UNDEFINED_DEF(name, prop_flags) { name, prop_flags, JS_DEF_PROP_UNDEFINED, 0, .u = { .i32 = 0 } }
1124
+ #define JS_PROP_ATOM_DEF(name, val, prop_flags) { name, prop_flags, JS_DEF_PROP_ATOM, 0, .u = { .i32 = val } }
1125
+ #define JS_PROP_BOOL_DEF(name, val, prop_flags) { name, prop_flags, JS_DEF_PROP_BOOL, 0, .u = { .i32 = val } }
1114
1126
  #define JS_OBJECT_DEF(name, tab, len, prop_flags) { name, prop_flags, JS_DEF_OBJECT, 0, .u = { .prop_list = { tab, len } } }
1115
1127
  #define JS_ALIAS_DEF(name, from) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_ALIAS, 0, .u = { .alias = { from, -1 } } }
1116
1128
  #define JS_ALIAS_BASE_DEF(name, from, base) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_ALIAS, 0, .u = { .alias = { from, base } } }