Package io.karatelabs.js
Class Terms
java.lang.Object
io.karatelabs.js.Terms
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanstatic ObjectliteralValue(Token token) Value of a literal token, memoized on the token.static Numbernarrow(double d) static StringSpecNumber::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).static voidrequireObjectCoercible(Object value, String methodName) SpecRequireObjectCoercible(§7.2.1) — gate at the top of every built-in whose receiver feedsToObject/ToString(e.g.static booleanSpecSameValue(§7.2.10) — like===exceptSameValue(NaN, NaN) === trueandSameValue(+0, -0) === false.static NumberstringToNumber(String text) Spec ToNumber for string runtime input (StringNumericLiteral §7.1.4.1.1).static Numberstatic StringSpecToPropertyKey(§7.1.18) — converts an arbitrary value to the canonical string form used as a property name.static StringtoPropertyKey(Object o, io.karatelabs.js.CoreContext ctx) Context-awareToPropertyKey(§7.1.19).static StringtoStringCoerce(Object o, io.karatelabs.js.CoreContext context) static String
-
Field Details
-
UNDEFINED
-
-
Method Details
-
toNumber
-
stringToNumber
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 usesliteralToNumber(String)which permits `_`. -
literalValue
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-ranDouble.parseDouble(or the BigInt / string-unquoting path) over text that cannot have changed. -
sameValue
SpecSameValue(§7.2.10) — like===exceptSameValue(NaN, NaN) === trueandSameValue(+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 byObject.is. -
narrow
-
isTruthy
-
typeOf
-
toPropertyKey
SpecToPropertyKey(§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 followNumber::toString(§6.1.6.1.13):-0→"0",NaN→"NaN", infinities, and integer-valued doubles drop the".0"(soDouble.toString(30.0)'s"30.0"doesn't leak into property-key comparisons).BigIntkeys, accessor-descriptor receivers, andSymbol.toPrimitiveare out of scope here — symbol keys are the broader Slice #7 work. -
toPropertyKey
Context-awareToPropertyKey(§7.1.19). Adds the spec'sToPrimitive(hint=string) → ToStringdispatch forObjectLikereceivers — so a callback that returns{toString(){return 1}}coerces to"1", and atoStringthat throws propagates the error viactx.error(matching IfAbruptCloseIterator semantics). Without ctx, ObjectLike values fall back toObject.toString()as before. -
numberToString
SpecNumber::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'sDouble.toStringdisagrees at both ends of the range (1.0E21vs1e+21,-0.0vs0,30.0vs30).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
SpecRequireObjectCoercible(§7.2.1) — gate at the top of every built-in whose receiver feedsToObject/ToString(e.g.String.prototype.*). null / undefined throw TypeError; everything else passes through.methodNameis woven into the message so the thrown error reads like a JS engine's, not a generic NPE. -
toStringCoerce
-