karatelabs/karate · error · JsErrorException (typeError)

BigInts have no unsigned right shift, use >> instead

Error message

BigInts have no unsigned right shift, use >> instead

What it means

A TypeError implementing the spec rule that BigInt has no unsigned right shift operator: `>>>` always throws for BigInt operands, even when both sides are BigInt, because the semantics are undefined for arbitrary-precision integers. The message tells you to use the signed `>>` instead.

Solutions

  1. Replace `>>>` with the signed `>>` when operands are BigInt and the values fit the signed range.
  2. Convert operands to Numbers before `>>>` when the values fit in 32 bits: `Number(a) >>> Number(b)`.
  3. Restructure the algorithm to avoid unsigned shift on BigInt (e.g. mask with BigInt: `a & 0xFFFFFFFFn` then `>>`).
  4. Keep BigInt values out of hashing code paths; do those computations in Java helpers instead.

Example fix

// before
* eval hash = bigIntValue >>> 16
// after
* eval hash = bigIntValue >> 16n
// or, if it fits 32 bits:
* eval hash = Number(bigIntValue) >>> 16
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof a === 'bigint' || typeof b === 'bigint') { /* use >> or mask */ } else { result = a >>> b; }

Type guard

function usesBigInt(a, b) { return typeof a === 'bigint' || typeof b === 'bigint'; }

Prevention

When it happens

Trigger: Evaluating `a >>> b` in the embedded JS engine where `a` or `b` is a BigInt/BigInteger (isBigIntOp true), regardless of whether the other operand is a plain number.

Common situations: Porting bit-manipulation JavaScript that uses `>>>` for hashing/parsing into Karate JS while feeding BigInt values (e.g. from Java bridges or `BigInt()` conversions).

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12). Data as JSON: /api/errors/5a7a29b75ab0cf6c. Report an issue: GitHub.

Appendix: source

Thrown at karate-js/src/main/java/io/karatelabs/js/Terms.java:723

        Number lhs = toNumericOperand(lhsObject, context);
        if (context != null && context.isError()) return UNDEFINED;
        Number rhs = toNumericOperand(rhsObject, context);
        if (context != null && context.isError()) return UNDEFINED;
        if (isBigIntOp(lhs, rhs)) {
            requireBothBigInt(lhs, rhs, "<<");
            return narrowBigInt(((BigInteger) lhs).shiftLeft(((BigInteger) rhs).intValueExact()));
        }
        return lhs.intValue() << rhs.intValue();
    }

    static Object bitShiftRightUnsigned(Object lhsObject, Object rhsObject, CoreContext context) {
        Number lhs = toNumericOperand(lhsObject, context);
        if (context != null && context.isError()) return UNDEFINED;
        Number rhs = toNumericOperand(rhsObject, context);
        if (context != null && context.isError()) return UNDEFINED;
        if (isBigIntOp(lhs, rhs)) {
            // spec: unsigned right shift on BigInt always TypeError, even when both operands are BigInt
            throw JsErrorException.typeError("BigInts have no unsigned right shift, use >> instead");
        }
        return narrow((lhs.intValue() & 0xFFFFFFFFL) >>> rhs.intValue());
    }

    static Object bitNot(Object value, CoreContext context) {
        Number number = toNumericOperand(value, context);
        if (context != null && context.isError()) return UNDEFINED;
        if (number instanceof BigInteger bi) {
            return narrowBigInt(bi.not());
        }
        return ~number.intValue();
    }

    static Object mul(Object lhsObject, Object rhsObject, CoreContext context) {
        Number lhs = toNumericOperand(lhsObject, context);
        if (context != null && context.isError()) return UNDEFINED;
        Number rhs = toNumericOperand(rhsObject, context);
        if (context != null && context.isError()) return UNDEFINED;

View on GitHub (pinned to a22eb90246)