Class JsBoolean
- All Implemented Interfaces:
JsValue,ObjectLike,Map<String,Object>
new Boolean(x). The global
Boolean constructor lives on JsBooleanConstructor.-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleancontainsKey(Object key) booleancontainsValue(Object value) entrySet()booleanReturns the idiomatic Java representation of this object.Raw-value accessor — returns the stored data value, ornullfor accessor descriptors (which have no extractable raw value).JS-semantic resolved read.bytegetOwnAttrs(String name) Spec-correct attribute byte for an intrinsic own property.Returns the prototype (__proto__) for prototype chain walking.inthashCode()booleanhasOwnIntrinsic(String name) True iff this object exposesnameas an "own" intrinsic property (e.g.booleanisEmpty()booleanbooleanisFrozen()booleanisOwnProperty(String name) True iffnameis an own property on this object — covers non-tombstoned own slots and intrinsic properties declared by subclasses (viahasOwnIntrinsic).booleanisSealed()Iterable<io.karatelabs.js.KeyValue> Returns an iterable for JS for-in/for-of iteration with KeyValue pairs.Iterable<io.karatelabs.js.KeyValue> jsEntries(io.karatelabs.js.CoreContext ctx) JS-semantic iteration variant — accessor descriptors invoke their getters withctxwhenctx != null; otherwise behaves as the no-argjsEntries()(raw values, accessors → null).keySet()protected static io.karatelabs.js.JsBuiltinMethodSugar for the canonicalnew JsBuiltinMethod(name, length, delegate)call used by built-in constructor singletons in theirresolveMemberswitches.orderedOwnKeys(Set<String> insertionOrder) Spec §9.1.11.1 OrdinaryOwnPropertyKeys ordering applied to an insertion-order key set: integer-index keys (perJsArray.parseIndex(java.lang.String)) move to the front in ascending numeric order, then remaining string keys keep their insertion order.Names this subclass exposes as own intrinsics — the discovery seam used byObject.getOwnPropertyDescriptors(and any future caller that needs to enumerate intrinsics not materialized inObjectLike.toMap()).voidvoidvoidStrict-aware[[Set]](ES 10.4.7 OrdinarySetWithOwnDescriptor).voidremoveMember(String name) voidremoveMember(String name, io.karatelabs.js.CoreContext ctx, boolean strict) Strict-aware[[Delete]](ES 13.5.1.2 / DeletePropertyOrThrow).protected ObjectresolveOwnIntrinsic(String name) Subclass extension hook for "own" intrinsic members that are not stored inprops— e.g.voidsetExtensible(boolean extensible) voidsetFrozen(boolean frozen) voidsetPrototype(ObjectLike proto) voidsetSealed(boolean sealed) intsize()toMap()Java-interop snapshot of own data.values()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.karatelabs.js.JsValue
getJsValue, getOriginalJavaValueMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Method Details
-
getJavaValue
Description copied from interface:JsValueReturns the idiomatic Java representation of this object. Used when values leave the JS engine and need to be consumed by Java code.Examples: JsNumber → Number, JsDate → Date, JsUint8Array → byte[]
- Specified by:
getJavaValuein interfaceJsValue
-
getPrototype
Description copied from interface:ObjectLikeReturns the prototype (__proto__) for prototype chain walking. Default returns null (no prototype chain).- Specified by:
getPrototypein interfaceObjectLike
-
setPrototype
-
hasOwnIntrinsic
True iff this object exposesnameas an "own" intrinsic property (e.g.Date.prototype,Date.now,Date.UTC). Derived directly fromresolveOwnIntrinsic(String)— a non-null resolution is, by definition, an own intrinsic; a null resolution means the name is not on this object. Single source of truth eliminates the old "subclass declares the name set twice" drift risk (concretely:JsFunction.constructoronce appeared in the boolean override but not the value resolver, sof.hasOwnProperty('constructor')reported true even thoughconstructorlives onFunction.prototype, not on each function instance).Subclasses with non-resolveOwnIntrinsic-based storage (
JsGlobalThisbindings,JsArraynumeric indices) overrideObjectLike.isOwnProperty(String)directly and bypass this hook.Hot-path note: callers that only need an existence check pay the cost of building the resolved value. Subclasses whose
resolveOwnIntrinsicallocates per call (built-in method lambdas, etc.) should install those on the prototype instead — the prototype'sbuiltinsmap caches a single instance. -
getMember
Description copied from interface:ObjectLikeRaw-value accessor — returns the stored data value, ornullfor accessor descriptors (which have no extractable raw value). Internal map / Java-interop callers (toMap, Map.get, jsEntries) and subclasssuper.getMember(name)chains use this.For JS-semantic reads that must invoke an accessor's getter, use
ObjectLike.getMember(String, Object, CoreContext)instead.- Specified by:
getMemberin interfaceObjectLike
-
getMember
Description copied from interface:ObjectLikeJS-semantic resolved read. For data descriptors returns the value; for accessor descriptors invokes the getter withreceiverbound asthis.receiveris the object the property is being read on (may differ fromthiswhen walking a prototype chain).ctxthreads through to the getter call. Default delegates toObjectLike.getMember(String)— implementations with accessor storage (JsObject,JsArray) override.- Specified by:
getMemberin interfaceObjectLike
-
resolveOwnIntrinsic
Subclass extension hook for "own" intrinsic members that are not stored inprops— e.g.JsString.length,JsRegex.source,JsFunction.name/length/prototype. Returns the intrinsic value at this level only (no prototype walk);nullmeans "not an own intrinsic", letting the caller fall through to the prototype chain.Replaces the historical pattern where each subclass overrode the 1-arg
ObjectLike.getMember(String)and prefixed its body withObject own = super.getMember(name); if (own != null) return own;. Centralizing the intrinsic resolution here lets the 3-arg getMember single-pass through (own slot → intrinsic hook → proto chain) and avoids the double prototype walk that the 1-arg fallback caused for accessor descriptors on the chain. -
ownIntrinsicNames
Names this subclass exposes as own intrinsics — the discovery seam used byObject.getOwnPropertyDescriptors(and any future caller that needs to enumerate intrinsics not materialized inObjectLike.toMap()). Default returns nothing; subclasses with aresolveOwnIntrinsic(java.lang.String)override return the closed name set they resolve.Each subclass returns its own complete list (no chaining via
super) — matches the structure ofresolveOwnIntrinsic(java.lang.String), which any subclass that resolves intrinsics already overrides end-to-end. Built-in constructors install their methods as actual own slots viadefineOwn(so they surface throughtoMap()directly) and inherit theJsFunctionlist for theprototype/name/lengthsurface. -
isOwnProperty
True iffnameis an own property on this object — covers non-tombstoned own slots and intrinsic properties declared by subclasses (viahasOwnIntrinsic). Use this forObject.getOwnPropertyDescriptor/hasOwn/insemantics; rawprops.containsKeywould include tombstones.- Specified by:
isOwnPropertyin interfaceObjectLike
-
putMember
- Specified by:
putMemberin interfaceObjectLike
-
putMember
Description copied from interface:ObjectLikeStrict-aware[[Set]](ES 10.4.7 OrdinarySetWithOwnDescriptor). Same store asObjectLike.putMember(String, Object), but when the write is rejected — frozen object, non-extensible new key, non-writable data property, or a get-only accessor — a sloppy caller gets the silent no-op while astrictcaller gets aJsErrorExceptionTypeError.ctxthreads through for accessor setters.Default delegates to the lenient
ObjectLike.putMember(String, Object)— host bridges that don't model property attributes are perpetually writable, so there is nothing to reject.JsObject/JsArrayoverride to enforce.- Specified by:
putMemberin interfaceObjectLike
-
getOwnAttrs
Spec-correct attribute byte for an intrinsic own property. Default reads the slot's attrs viagetAttrs(String). Subclasses (especially built-in constructors / prototypes / theJsFunctionhierarchy) override to return tighter attributes for intrinsic members declared viahasOwnIntrinsic(String)— e.g. built-in method properties default to{writable: true, enumerable: false, configurable: true}; built-in constants default to all-false.The owner of this method is also responsible for declaring the same key via
hasOwnIntrinsic— otherwisegetOwnPropertyDescriptorwon't reach this lookup at all. -
isExtensible
public boolean isExtensible()- Specified by:
isExtensiblein interfaceObjectLike
-
isSealed
public boolean isSealed()- Specified by:
isSealedin interfaceObjectLike
-
isFrozen
public boolean isFrozen()- Specified by:
isFrozenin interfaceObjectLike
-
setExtensible
public void setExtensible(boolean extensible) - Specified by:
setExtensiblein interfaceObjectLike
-
setSealed
public void setSealed(boolean sealed) - Specified by:
setSealedin interfaceObjectLike
-
setFrozen
public void setFrozen(boolean frozen) - Specified by:
setFrozenin interfaceObjectLike
-
method
protected static io.karatelabs.js.JsBuiltinMethod method(String methodName, int length, io.karatelabs.js.JsCallable delegate) Sugar for the canonicalnew JsBuiltinMethod(name, length, delegate)call used by built-in constructor singletons in theirresolveMemberswitches. Same shape asPrototype.install(String, int, JsCallable)— written so that each switch case readscase "isFinite" -> method(name, 1, (JsInvokable) this::isFinite)with the case label value flowing into the wrap as a single source of truth. -
removeMember
- Specified by:
removeMemberin interfaceObjectLike
-
removeMember
Description copied from interface:ObjectLikeStrict-aware[[Delete]](ES 13.5.1.2 / DeletePropertyOrThrow). Same removal asObjectLike.removeMember(String), but a non-configurable own property is a silent no-op for a sloppy caller and a TypeError for astrictcaller. Default delegates to the lenientObjectLike.removeMember(String);JsObject/JsArrayoverride to enforce.- Specified by:
removeMemberin interfaceObjectLike
-
toMap
Java-interop snapshot of own data. Accessor descriptors surface asnullentries — this is the no-side-effects boundary where the absence of aCoreContextwould force getters to silently fail anyway.Map.get(java.lang.Object),Map.values(),Map.containsValue(java.lang.Object),Map.entrySet()and the no-argjsEntries()all follow the same rule for the same reason.Spec-correct iteration that must invoke accessor getters (
Object.keys / values / entries / assign) goes throughjsEntries(CoreContext)— Refactor E carved that out as the single ctx-aware seam. If you find yourself reaching fortoMapfrom JS-semantic code, you probably wantjsEntries(ctx)instead.- Specified by:
toMapin interfaceObjectLike
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKeyin interfaceMap<String,Object>
-
containsValue
- Specified by:
containsValuein interfaceMap<String,Object>
-
get
-
put
-
remove
-
putAll
-
clear
public void clear() -
keySet
-
values
-
entrySet
-
jsEntries
Returns an iterable for JS for-in/for-of iteration with KeyValue pairs. Used internally by JS iteration constructs and byTerms.toIterable(java.lang.Object), which is the back-end forObject.keys / values / entries / assignandfor...in. All of those filter by enumerable per spec.Iterates
propsdirectly so each yielded value reads the slot's current value at next() time — callback-driven mutations during iteration are visible (test262Array.prototype.map's "callback mutates earlier index, later index sees update" semantics rely on this). Subclasses with alternate storage (JsGlobalThis) override. Routes throughisEnumerableso subclassgetOwnAttrsoverrides (e.g. JsMath returningWRITABLE | CONFIGURABLE— no enumerable bit — for its built-in methods) win.The no-arg form is the Java-interop seam — accessor properties have no extractable raw value here and surface as
null. ThejsEntries(CoreContext)overload is the spec-correct iteration forObject.keys/values/entries/assign(invokes accessor getters viaPropertySlot.read(java.lang.Object, io.karatelabs.js.CoreContext)). -
orderedOwnKeys
Spec §9.1.11.1 OrdinaryOwnPropertyKeys ordering applied to an insertion-order key set: integer-index keys (perJsArray.parseIndex(java.lang.String)) move to the front in ascending numeric order, then remaining string keys keep their insertion order. Returns the input unchanged when no integer-index keys are present (the common case for plain object literals with named properties only).Used at every spec seam that reports own keys for an ordinary object —
jsEntries(CoreContext)(drivesObject.keys / values / entries / assign) andJsObjectConstructor.ownKeys(drivesObject.getOwnPropertyNames / getOwnPropertyDescriptors / defineProperties).JsArrayhas its own integer-first iteration via the dense list; this helper is for plainJsObject/ObjectLikebacked by an insertion-ordered prop map. -
jsEntries
JS-semantic iteration variant — accessor descriptors invoke their getters withctxwhenctx != null; otherwise behaves as the no-argjsEntries()(raw values, accessors → null). This is the back-end called fromObject.keys / values / entries / assignviaTerms.toIterable(Object, CoreContext)so accessor descriptors observe their spec invocation.Yields entries in §9.1.11.1 OrdinaryOwnPropertyKeys order — integer indices ascending, then string keys insertion-order. Slots are partitioned in a single pre-pass; values are still re-read at yield time so callback-mutated values propagate.
-
hashCode
public int hashCode() -
equals
-