Class Terms

java.lang.Object
io.karatelabs.js.Terms

public class Terms extends Object
  • Field Details

    • UNDEFINED

      public static final JsUndefined UNDEFINED
  • Method Details

    • toNumber

      public static Number toNumber(String text)
    • stringToNumber

      public static Number stringToNumber(String text)
      Spec ToNumber for string runtime input (StringNumericLiteral §7.1.4.1.1). Strips spec whitespace (StrWhiteSpace + LineTerminator), rejects numeric separators (`_`), accepts `0b`/`0o`/`0x` radix prefixes, returns NaN on malformed input — never throws. The lexer's literal path uses literalToNumber(String) which permits `_`.
    • literalValue

      public static Object literalValue(Token token)
      Value of a literal token, memoized on the token. A literal inside a loop body is evaluated on every iteration, and without this each evaluation re-ran Double.parseDouble (or the BigInt / string-unquoting path) over text that cannot have changed.
    • sameValue

      public static boolean sameValue(Object lhs, Object rhs)
      Spec SameValue (§7.2.10) — like === except SameValue(NaN, NaN) === true and SameValue(+0, -0) === false. Used by descriptor-redefinition checks ([[DefineOwnProperty]] on a non-configurable non-writable data property must SameValue-match the existing value to avoid TypeError) and by Object.is.
    • narrow

      public static Number narrow(double d)
    • isTruthy

      public static boolean isTruthy(Object value)
    • typeOf

      public static String typeOf(Object value)
    • toPropertyKey

      public static String toPropertyKey(Object o)
      Spec ToPropertyKey (§7.1.18) — converts an arbitrary value to the canonical string form used as a property name. Most callers pass an already-string key, so the common path is a single instanceof. The number cases follow Number::toString (§6.1.6.1.13): -0 → "0", NaN → "NaN", infinities, and integer-valued doubles drop the ".0" (so Double.toString(30.0)'s "30.0" doesn't leak into property-key comparisons).

      BigInt keys, accessor-descriptor receivers, and Symbol.toPrimitive are out of scope here — symbol keys are the broader Slice #7 work.

    • toPropertyKey

      public static String toPropertyKey(Object o, io.karatelabs.js.CoreContext ctx)
      Context-aware ToPropertyKey (§7.1.19). Adds the spec's ToPrimitive(hint=string) → ToString dispatch for ObjectLike receivers — so a callback that returns {toString(){return 1}} coerces to "1", and a toString that throws propagates the error via ctx.error (matching IfAbruptCloseIterator semantics). Without ctx, ObjectLike values fall back to Object.toString() as before.
    • numberToString

      public static String numberToString(Number n)
      Spec Number::toString (§6.1.6.1.13) — the single seam every user-visible number → string site routes through (ToPropertyKey, ToString coercion, Number.prototype.toString, JSON output). Java's Double.toString disagrees at both ends of the range (1.0E21 vs 1e+21, -0.0 vs 0, 30.0 vs 30).

      On the interpreter hot path (property keys, string concat), so the int / long cases short-circuit ahead of any double inspection — narrow(double) collapses most engine values to those types.

    • requireObjectCoercible

      public static void requireObjectCoercible(Object value, String methodName)
      Spec RequireObjectCoercible (§7.2.1) — gate at the top of every built-in whose receiver feeds ToObject / ToString (e.g. String.prototype.*). null / undefined throw TypeError; everything else passes through. methodName is woven into the message so the thrown error reads like a JS engine's, not a generic NPE.
    • toStringCoerce

      public static String toStringCoerce(Object o, io.karatelabs.js.CoreContext context)