Class JSInteropUtil

java.lang.Object
com.oracle.truffle.js.runtime.interop.JSInteropUtil

public final class JSInteropUtil extends Object
Utility class for interop operations. Provides methods that can be used in Cached annotations of the TruffleDSL to create interop nodes just for specific specializations.
  • Method Details

    • getArraySize

      public static long getArraySize(Object foreignObj, com.oracle.truffle.api.interop.InteropLibrary interop, com.oracle.truffle.api.nodes.Node originatingNode)
    • setArraySize

      public static boolean setArraySize(Object obj, Object value, boolean isStrict, com.oracle.truffle.api.interop.InteropLibrary interop, com.oracle.truffle.api.nodes.Node originatingNode, com.oracle.truffle.api.profiles.BranchProfile errorBranch)
    • getOrDefault

      public static Object getOrDefault(JSContext context, Object target, Object propertyKey, Object receiver, Object defaultValue)
    • readMemberOrDefault

      public static Object readMemberOrDefault(Object obj, Object member, Object defaultValue)
    • readMemberOrDefault

      public static Object readMemberOrDefault(Object obj, Object member, Object defaultValue, com.oracle.truffle.api.interop.InteropLibrary interop, ImportValueNode importValue)
    • readArrayElementOrDefault

      public static Object readArrayElementOrDefault(Object obj, long index, Object defaultValue, com.oracle.truffle.api.interop.InteropLibrary interop, ImportValueNode importValue)
    • readArrayElementOrDefault

      public static Object readArrayElementOrDefault(Object obj, long index, Object defaultValue)
    • set

      public static boolean set(JSContext context, Object target, Object propertyKey, Object value, boolean strict)
    • writeMember

      public static boolean writeMember(Object obj, Object member, Object value)
    • writeMember

      public static boolean writeMember(Object obj, Object member, Object value, com.oracle.truffle.api.interop.InteropLibrary interop, ExportValueNode exportValue, boolean strict, com.oracle.truffle.api.nodes.Node originatingNode)
    • toPrimitiveOrDefaultLossy

      public static Object toPrimitiveOrDefaultLossy(Object obj, Object defaultValue, com.oracle.truffle.api.interop.InteropLibrary interop, com.oracle.truffle.api.nodes.Node originatingNode)
      Converts foreign objects to JS primitive values, coercing all numbers to double precision.
    • toPrimitiveOrDefaultLossless

      public static Object toPrimitiveOrDefaultLossless(Object obj, Object defaultValue, com.oracle.truffle.api.interop.InteropLibrary interop, com.oracle.truffle.api.strings.TruffleString.SwitchEncodingNode switchEncoding, com.oracle.truffle.api.nodes.Node originatingNode)
      Converts a foreign object to a JS primitive value. Attempts to keep the precise numeric value when converting foreign numbers, relevant for comparisons and ToString/ToBigInt conversion. Returned BigInt values are marked as foreign so that they are handled correctly by subsequent ToNumeric, ToNumber (i.e., coerced to double), or ToBigInt.
    • keys

      public static List<Object> keys(Object obj)
    • hasProperty

      public static boolean hasProperty(Object obj, Object key)
    • delete

      public static boolean delete(JSContext context, Object target, Object propertyKey, boolean strict)
    • deleteArrayElement

      public static boolean deleteArrayElement(Object target, long index, com.oracle.truffle.api.interop.InteropLibrary interop, boolean strict)
    • deleteHashEntry

      public static boolean deleteHashEntry(Object target, Object key, com.oracle.truffle.api.interop.InteropLibrary interop, boolean strict) throws com.oracle.truffle.api.interop.UnknownKeyException
      Throws:
      com.oracle.truffle.api.interop.UnknownKeyException
    • deleteMember

      public static boolean deleteMember(Object target, com.oracle.truffle.api.strings.TruffleString name, com.oracle.truffle.api.interop.InteropLibrary interop, boolean strict)
    • call

      public static Object call(Object function, Object[] args)
    • construct

      public static Object construct(Object target, Object[] args)
    • isBoxedPrimitive

      public static boolean isBoxedPrimitive(Object receiver, com.oracle.truffle.api.interop.InteropLibrary interop)
    • getOwnProperty

      public static PropertyDescriptor getOwnProperty(Object object, com.oracle.truffle.api.strings.TruffleString propertyKey)
    • getOwnProperty

      public static PropertyDescriptor getOwnProperty(Object object, com.oracle.truffle.api.strings.TruffleString propertyKey, com.oracle.truffle.api.interop.InteropLibrary interop, ImportValueNode importValueNode, com.oracle.truffle.api.strings.TruffleString.ReadCharUTF16Node charAtNode)
    • getExistingMemberProperty

      public static PropertyDescriptor getExistingMemberProperty(Object object, String key, com.oracle.truffle.api.interop.InteropLibrary interop, ImportValueNode importValueNode) throws com.oracle.truffle.api.interop.InteropException
      Throws:
      com.oracle.truffle.api.interop.InteropException
    • getArrayElementProperty

      public static PropertyDescriptor getArrayElementProperty(Object object, long index, com.oracle.truffle.api.interop.InteropLibrary interop, ImportValueNode importValueNode) throws com.oracle.truffle.api.interop.InteropException
      Throws:
      com.oracle.truffle.api.interop.InteropException
    • formatError

      public static String formatError(Object error, com.oracle.truffle.api.interop.InteropLibrary interopExc, com.oracle.truffle.api.interop.InteropLibrary interopStr)
    • jsInteropBufferAsByteBuffer

      public static ByteBuffer jsInteropBufferAsByteBuffer(JSArrayBufferObject interopArrayBuffer, com.oracle.truffle.api.interop.InteropLibrary interop, JSRealm realm)
    • foreignInteropBufferAsByteBuffer

      public static ByteBuffer foreignInteropBufferAsByteBuffer(Object foreignInteropBuffer, com.oracle.truffle.api.interop.InteropLibrary interop, JSRealm realm)