about summary refs log tree commit diff stats
path: root/lib/quickjs/quickjs.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/quickjs/quickjs.c')
-rw-r--r--lib/quickjs/quickjs.c73
1 files changed, 41 insertions, 32 deletions
diff --git a/lib/quickjs/quickjs.c b/lib/quickjs/quickjs.c
index 6788ddf9..c52d7deb 100644
--- a/lib/quickjs/quickjs.c
+++ b/lib/quickjs/quickjs.c
@@ -36004,11 +36004,10 @@ static JSValue JS_ReadBigNum(BCReaderState *s, int tag)
     uint8_t v8;
     int32_t e;
     uint32_t len;
-    limb_t l, i, n, j;
+    limb_t l, i, n;
     JSBigFloat *p;
     limb_t v;
     bf_t *a;
-    int bpos, d;
 
     p = js_new_bf(s->ctx);
     if (!p)
@@ -36058,39 +36057,23 @@ static JSValue JS_ReadBigNum(BCReaderState *s, int tag)
             JS_ThrowInternalError(s->ctx, "invalid bignum length");
             goto fail;
         }
-        if (tag != BC_TAG_BIG_DECIMAL)
-            l = (len + sizeof(limb_t) - 1) / sizeof(limb_t);
-        else
+#ifdef CONFIG_BIGNUM
+        if (tag == BC_TAG_BIG_DECIMAL) {
             l = (len + LIMB_DIGITS - 1) / LIMB_DIGITS;
+        } else
+#endif
+        {
+            l = (len + sizeof(limb_t) - 1) / sizeof(limb_t);
+        }
         if (bf_resize(a, l)) {
             JS_ThrowOutOfMemory(s->ctx);
             goto fail;
         }
-        if (tag != BC_TAG_BIG_DECIMAL) {
-            n = len & (sizeof(limb_t) - 1);
-            if (n != 0) {
-                v = 0;
-                for(i = 0; i < n; i++) {
-                    if (bc_get_u8(s, &v8))
-                        goto fail;
-                    v |= (limb_t)v8 << ((sizeof(limb_t) - n + i) * 8);
-                }
-                a->tab[0] = v;
-                i = 1;
-            } else {
-                i = 0;
-            }
-            for(; i < l; i++) {
-#if LIMB_BITS == 32
-                if (bc_get_u32(s, &v))
-                    goto fail;
-#else
-                if (bc_get_u64(s, &v))
-                    goto fail;
-#endif
-                a->tab[i] = v;
-            }
-        } else {
+#ifdef CONFIG_BIGNUM
+        if (tag == BC_TAG_BIG_DECIMAL) {
+            limb_t j;
+            int bpos, d;
+
             bpos = 0;
             for(i = 0; i < l; i++) {
                 if (i == 0 && (n = len % LIMB_DIGITS) != 0) {
@@ -36117,6 +36100,32 @@ static JSValue JS_ReadBigNum(BCReaderState *s, int tag)
                 }
                 a->tab[i] = v;
             }
+        } else
+#endif  /* CONFIG_BIGNUM */
+        {
+            n = len & (sizeof(limb_t) - 1);
+            if (n != 0) {
+                v = 0;
+                for(i = 0; i < n; i++) {
+                    if (bc_get_u8(s, &v8))
+                        goto fail;
+                    v |= (limb_t)v8 << ((sizeof(limb_t) - n + i) * 8);
+                }
+                a->tab[0] = v;
+                i = 1;
+            } else {
+                i = 0;
+            }
+            for(; i < l; i++) {
+#if LIMB_BITS == 32
+                if (bc_get_u32(s, &v))
+                    goto fail;
+#else
+                if (bc_get_u64(s, &v))
+                    goto fail;
+#endif
+                a->tab[i] = v;
+            }
         }
     }
     bc_read_trace(s, "}\n");
@@ -50991,7 +51000,7 @@ static JSValue JS_ToBigIntCtorFree(JSContext *ctx, JSValue val)
             }
             if (!bf_is_finite(a)) {
                 JS_FreeValue(ctx, val);
-                val = JS_ThrowRangeError(ctx, "cannot convert NaN or Infinity to bigint");
+                val = JS_ThrowRangeError(ctx, "cannot convert NaN or Infinity to BigInt");
             } else {
                 JSValue val1 = JS_NewBigInt(ctx);
                 bf_t *r;
@@ -51009,7 +51018,7 @@ static JSValue JS_ToBigIntCtorFree(JSContext *ctx, JSValue val)
                     val = JS_ThrowOutOfMemory(ctx);
                 } else if (ret & BF_ST_INEXACT) {
                     JS_FreeValue(ctx, val1);
-                    val = JS_ThrowRangeError(ctx, "cannot convert to bigint: not an integer");
+                    val = JS_ThrowRangeError(ctx, "cannot convert to BigInt: not an integer");
                 } else {
                     val = JS_CompactBigInt(ctx, val1);
                 }
d='n301' href='#n301'>301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352