Class CallInfo

java.lang.Object
io.karatelabs.js.CallInfo

public class CallInfo extends Object
Provides reflection-like awareness for callables about their invocation context.

This solves the JavaScript quirk where built-in constructors like Number, String, and Boolean behave differently when called with vs without the 'new' keyword:

  • Number(5) returns primitive 5
  • new Number(5) returns a boxed Number object

Callables can check context.getCallInfo() to determine how they were invoked and return the appropriate value. For normal function calls, getCallInfo() returns null (no overhead). CallInfo is only created for special invocation contexts.

Future extensions could include:

  • Tracking .call() and .apply() invocations
  • Supporting proper Date, Promise, or RegExp construction
  • Enabling better error messages with call-site information
See Also:
  • Field Details

    • constructor

      public final boolean constructor
      True if invoked with the 'new' keyword
    • called

      public final Object called
      The function or callable being invoked