Skip to content

Commit 3f68062

Browse files
committed
Prepare new version 2020-07-05.
1 parent b25571e commit 3f68062

File tree

9 files changed

+2186
-1296
lines changed

9 files changed

+2186
-1296
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# quickjs-build changelog
22

3+
## 2020-09-04 Version 2.0.0, @NickNaso
4+
5+
- modified JS_GetPrototype() to return a live value
6+
- REPL: support unicode characters larger than 16 bits
7+
- added os.Worker
8+
- improved object serialization
9+
- added std.parseExtJSON
10+
- misc bug fixes
11+
312
## 2020-06-08 Version 1.0.0, @NickNaso
413

514
Initial implementation.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![QuickJS Build Matrix](https://github.com/napi-bindings/quickjs-build/workflows/QuickJS%20Build%20Matrix/badge.svg?branch=master)
44

5-
## Version 2020-04-12
5+
## Version 2020-07-05
66

77
- [Introduction](#introduction)
88
- [Building](#building)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2020-04-12
1+
2020-07-05

include/quickjs.h

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ int JS_IsRegisteredClass(JSRuntime *rt, JSClassID class_id);
498498

499499
static js_force_inline JSValue JS_NewBool(JSContext *ctx, JS_BOOL val)
500500
{
501-
return JS_MKVAL(JS_TAG_BOOL, val);
501+
return JS_MKVAL(JS_TAG_BOOL, (val != 0));
502502
}
503503

504504
static js_force_inline JSValue JS_NewInt32(JSContext *ctx, int32_t val)
@@ -746,7 +746,7 @@ int JS_IsExtensible(JSContext *ctx, JSValueConst obj);
746746
int JS_PreventExtensions(JSContext *ctx, JSValueConst obj);
747747
int JS_DeleteProperty(JSContext *ctx, JSValueConst obj, JSAtom prop, int flags);
748748
int JS_SetPrototype(JSContext *ctx, JSValueConst obj, JSValueConst proto_val);
749-
JSValueConst JS_GetPrototype(JSContext *ctx, JSValueConst val);
749+
JSValue JS_GetPrototype(JSContext *ctx, JSValueConst val);
750750

751751
#define JS_GPN_STRING_MASK (1 << 0)
752752
#define JS_GPN_SYMBOL_MASK (1 << 1)
@@ -796,6 +796,9 @@ void *JS_GetOpaque2(JSContext *ctx, JSValueConst obj, JSClassID class_id);
796796
/* 'buf' must be zero terminated i.e. buf[buf_len] = '\0'. */
797797
JSValue JS_ParseJSON(JSContext *ctx, const char *buf, size_t buf_len,
798798
const char *filename);
799+
#define JS_PARSE_JSON_EXT (1 << 0) /* allow extended JSON */
800+
JSValue JS_ParseJSON2(JSContext *ctx, const char *buf, size_t buf_len,
801+
const char *filename, int flags);
799802
JSValue JS_JSONStringify(JSContext *ctx, JSValueConst obj,
800803
JSValueConst replacer, JSValueConst space0);
801804

@@ -810,6 +813,14 @@ JSValue JS_GetTypedArrayBuffer(JSContext *ctx, JSValueConst obj,
810813
size_t *pbyte_offset,
811814
size_t *pbyte_length,
812815
size_t *pbytes_per_element);
816+
typedef struct {
817+
void *(*sab_alloc)(void *opaque, size_t size);
818+
void (*sab_free)(void *opaque, void *ptr);
819+
void (*sab_dup)(void *opaque, void *ptr);
820+
void *sab_opaque;
821+
} JSSharedArrayBufferFunctions;
822+
void JS_SetSharedArrayBufferFunctions(JSRuntime *rt,
823+
const JSSharedArrayBufferFunctions *sf);
813824

814825
JSValue JS_NewPromiseCapability(JSContext *ctx, JSValue *resolving_funcs);
815826

@@ -853,14 +864,24 @@ JS_BOOL JS_IsJobPending(JSRuntime *rt);
853864
int JS_ExecutePendingJob(JSRuntime *rt, JSContext **pctx);
854865

855866
/* Object Writer/Reader (currently only used to handle precompiled code) */
856-
#define JS_WRITE_OBJ_BYTECODE (1 << 0) /* allow function/module */
857-
#define JS_WRITE_OBJ_BSWAP (1 << 1) /* byte swapped output */
867+
#define JS_WRITE_OBJ_BYTECODE (1 << 0) /* allow function/module */
868+
#define JS_WRITE_OBJ_BSWAP (1 << 1) /* byte swapped output */
869+
#define JS_WRITE_OBJ_SAB (1 << 2) /* allow SharedArrayBuffer */
870+
#define JS_WRITE_OBJ_REFERENCE (1 << 3) /* allow object references to
871+
encode arbitrary object
872+
graph */
858873
uint8_t *JS_WriteObject(JSContext *ctx, size_t *psize, JSValueConst obj,
859874
int flags);
875+
uint8_t *JS_WriteObject2(JSContext *ctx, size_t *psize, JSValueConst obj,
876+
int flags, uint8_t ***psab_tab, size_t *psab_tab_len);
877+
860878
#define JS_READ_OBJ_BYTECODE (1 << 0) /* allow function/module */
861879
#define JS_READ_OBJ_ROM_DATA (1 << 1) /* avoid duplicating 'buf' data */
880+
#define JS_READ_OBJ_SAB (1 << 2) /* allow SharedArrayBuffer */
881+
#define JS_READ_OBJ_REFERENCE (1 << 3) /* allow object references */
862882
JSValue JS_ReadObject(JSContext *ctx, const uint8_t *buf, size_t buf_len,
863883
int flags);
884+
864885
/* load the dependencies of the module 'obj'. Useful when JS_ReadObject()
865886
returns a module. */
866887
int JS_ResolveModule(JSContext *ctx, JSValueConst obj);

src/cutils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ void dbuf_free(DynBuf *s);
268268
static inline BOOL dbuf_error(DynBuf *s) {
269269
return s->error;
270270
}
271+
static inline void dbuf_set_error(DynBuf *s)
272+
{
273+
s->error = TRUE;
274+
}
271275

272276
#define UTF8_CHAR_LEN_MAX 6
273277

src/libbf.c

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3370,12 +3370,14 @@ slimb_t bf_mul_log2_radix(slimb_t a1, unsigned int radix, int is_inv,
33703370
}
33713371

33723372
/* 'n' is the number of output limbs */
3373-
static void bf_integer_to_radix_rec(bf_t *pow_tab,
3374-
limb_t *out, const bf_t *a, limb_t n,
3375-
int level, limb_t n0, limb_t radixl,
3376-
unsigned int radixl_bits)
3373+
static int bf_integer_to_radix_rec(bf_t *pow_tab,
3374+
limb_t *out, const bf_t *a, limb_t n,
3375+
int level, limb_t n0, limb_t radixl,
3376+
unsigned int radixl_bits)
33773377
{
33783378
limb_t n1, n2, q_prec;
3379+
int ret;
3380+
33793381
assert(n >= 1);
33803382
if (n == 1) {
33813383
out[0] = get_bits(a->tab, a->len, a->len * LIMB_BITS - a->expn);
@@ -3402,63 +3404,81 @@ static void bf_integer_to_radix_rec(bf_t *pow_tab,
34023404
n1 = n - n2;
34033405
B = &pow_tab[2 * level];
34043406
B_inv = &pow_tab[2 * level + 1];
3407+
ret = 0;
34053408
if (B->len == 0) {
34063409
/* compute BASE^n2 */
3407-
bf_pow_ui_ui(B, radixl, n2, BF_PREC_INF, BF_RNDZ);
3410+
ret |= bf_pow_ui_ui(B, radixl, n2, BF_PREC_INF, BF_RNDZ);
34083411
/* we use enough bits for the maximum possible 'n1' value,
34093412
i.e. n2 + 1 */
3410-
bf_set_ui(&R, 1);
3411-
bf_div(B_inv, &R, B, (n2 + 1) * radixl_bits + 2, BF_RNDN);
3413+
ret |= bf_set_ui(&R, 1);
3414+
ret |= bf_div(B_inv, &R, B, (n2 + 1) * radixl_bits + 2, BF_RNDN);
34123415
}
34133416
// printf("%d: n1=% " PRId64 " n2=%" PRId64 "\n", level, n1, n2);
34143417
q_prec = n1 * radixl_bits;
3415-
bf_mul(&Q, a, B_inv, q_prec, BF_RNDN);
3416-
bf_rint(&Q, BF_RNDZ);
3418+
ret |= bf_mul(&Q, a, B_inv, q_prec, BF_RNDN);
3419+
ret |= bf_rint(&Q, BF_RNDZ);
34173420

3418-
bf_mul(&R, &Q, B, BF_PREC_INF, BF_RNDZ);
3419-
bf_sub(&R, a, &R, BF_PREC_INF, BF_RNDZ);
3421+
ret |= bf_mul(&R, &Q, B, BF_PREC_INF, BF_RNDZ);
3422+
ret |= bf_sub(&R, a, &R, BF_PREC_INF, BF_RNDZ);
3423+
3424+
if (ret & BF_ST_MEM_ERROR)
3425+
goto fail;
34203426
/* adjust if necessary */
34213427
q_add = 0;
34223428
while (R.sign && R.len != 0) {
3423-
bf_add(&R, &R, B, BF_PREC_INF, BF_RNDZ);
3429+
if (bf_add(&R, &R, B, BF_PREC_INF, BF_RNDZ))
3430+
goto fail;
34243431
q_add--;
34253432
}
34263433
while (bf_cmpu(&R, B) >= 0) {
3427-
bf_sub(&R, &R, B, BF_PREC_INF, BF_RNDZ);
3434+
if (bf_sub(&R, &R, B, BF_PREC_INF, BF_RNDZ))
3435+
goto fail;
34283436
q_add++;
34293437
}
34303438
if (q_add != 0) {
3431-
bf_add_si(&Q, &Q, q_add, BF_PREC_INF, BF_RNDZ);
3439+
if (bf_add_si(&Q, &Q, q_add, BF_PREC_INF, BF_RNDZ))
3440+
goto fail;
3441+
}
3442+
if (bf_integer_to_radix_rec(pow_tab, out + n2, &Q, n1, level + 1, n0,
3443+
radixl, radixl_bits))
3444+
goto fail;
3445+
if (bf_integer_to_radix_rec(pow_tab, out, &R, n2, level + 1, n0,
3446+
radixl, radixl_bits)) {
3447+
fail:
3448+
bf_delete(&Q);
3449+
bf_delete(&R);
3450+
return -1;
34323451
}
3433-
bf_integer_to_radix_rec(pow_tab, out + n2, &Q, n1, level + 1, n0,
3434-
radixl, radixl_bits);
3435-
bf_integer_to_radix_rec(pow_tab, out, &R, n2, level + 1, n0,
3436-
radixl, radixl_bits);
34373452
bf_delete(&Q);
34383453
bf_delete(&R);
34393454
}
3455+
return 0;
34403456
}
34413457

3442-
static void bf_integer_to_radix(bf_t *r, const bf_t *a, limb_t radixl)
3458+
/* return 0 if OK != 0 if memory error */
3459+
static int bf_integer_to_radix(bf_t *r, const bf_t *a, limb_t radixl)
34433460
{
34443461
bf_context_t *s = r->ctx;
34453462
limb_t r_len;
34463463
bf_t *pow_tab;
3447-
int i, pow_tab_len;
3464+
int i, pow_tab_len, ret;
34483465

34493466
r_len = r->len;
34503467
pow_tab_len = (ceil_log2(r_len) + 2) * 2; /* XXX: check */
34513468
pow_tab = bf_malloc(s, sizeof(pow_tab[0]) * pow_tab_len);
3469+
if (!pow_tab)
3470+
return -1;
34523471
for(i = 0; i < pow_tab_len; i++)
34533472
bf_init(r->ctx, &pow_tab[i]);
34543473

3455-
bf_integer_to_radix_rec(pow_tab, r->tab, a, r_len, 0, r_len, radixl,
3456-
ceil_log2(radixl));
3474+
ret = bf_integer_to_radix_rec(pow_tab, r->tab, a, r_len, 0, r_len, radixl,
3475+
ceil_log2(radixl));
34573476

34583477
for(i = 0; i < pow_tab_len; i++) {
34593478
bf_delete(&pow_tab[i]);
34603479
}
34613480
bf_free(s, pow_tab);
3481+
return ret;
34623482
}
34633483

34643484
/* a must be >= 0. 'P' is the wanted number of digits in radix
@@ -3625,8 +3645,14 @@ static void output_digits(DynBuf *s, const bf_t *a1, int radix, limb_t n_digits,
36253645
a = &a_s;
36263646
bf_init(a1->ctx, a);
36273647
n = (n_digits + digits_per_limb - 1) / digits_per_limb;
3628-
bf_resize(a, n);
3629-
bf_integer_to_radix(a, a1, radixl);
3648+
if (bf_resize(a, n)) {
3649+
dbuf_set_error(s);
3650+
goto done;
3651+
}
3652+
if (bf_integer_to_radix(a, a1, radixl)) {
3653+
dbuf_set_error(s);
3654+
goto done;
3655+
}
36303656
radix_bits = 0;
36313657
pos = n;
36323658
pos_incr = 1;
@@ -3659,6 +3685,7 @@ static void output_digits(DynBuf *s, const bf_t *a1, int radix, limb_t n_digits,
36593685
buf_pos += l;
36603686
i += l;
36613687
}
3688+
done:
36623689
if (a != a1)
36633690
bf_delete(a);
36643691
}

0 commit comments

Comments
 (0)