Value Creation
These functions create new JavaScript values from C types. All creation functions return a newJSValue that must be freed with JS_FreeValue() when no longer needed.
Primitive Values
JS_NewBool
Creates a JavaScript boolean value.ctx- JavaScript contextval- Boolean value (0 for false, non-zero for true)
JS_NewInt32
Creates a JavaScript number from a 32-bit integer.ctx- JavaScript contextval- 32-bit signed integer value
JS_NewInt64
Creates a JavaScript number from a 64-bit integer. Uses int32 representation if the value fits, otherwise converts to float64.ctx- JavaScript contextval- 64-bit signed integer value
JS_NewUint32
Creates a JavaScript number from an unsigned 32-bit integer.ctx- JavaScript contextval- 32-bit unsigned integer value
JS_NewFloat64
Creates a JavaScript number from a double-precision floating point value.ctx- JavaScript contextval- Double-precision floating point value
JS_NewNumber
Creates a JavaScript number from a double, choosing the optimal internal representation.ctx- JavaScript contextd- Double value
BigInt Values
JS_NewBigInt64
Creates a JavaScript BigInt from a 64-bit signed integer.ctx- JavaScript contextv- 64-bit signed integer value
JS_NewBigUint64
Creates a JavaScript BigInt from a 64-bit unsigned integer.ctx- JavaScript contextv- 64-bit unsigned integer value
String Values
JS_NewString
Creates a JavaScript string from a null-terminated C string.ctx- JavaScript contextstr- Null-terminated UTF-8 or ASCII string
JS_NewStringLen
Creates a JavaScript string from a C string with explicit length.ctx- JavaScript contextstr1- UTF-8 or ASCII string (need not be null-terminated)len1- Length of the string in bytes
JS_NewStringUTF16
Creates a JavaScript string from a UTF-16 encoded buffer.ctx- JavaScript contextbuf- UTF-16 encoded string bufferlen- Length in uint16_t units (not code points)
JS_NewAtomString
Creates a JavaScript string from a null-terminated C string, using atom optimization.ctx- JavaScript contextstr- Null-terminated UTF-8 or ASCII string
Object Values
JS_NewObject
Creates a new JavaScript object with the default Object prototype.ctx- JavaScript context
JS_NewObjectProto
Creates a new JavaScript object with a specific prototype.ctx- JavaScript contextproto- Prototype object orJS_NULL
JS_NewObjectClass
Creates a new JavaScript object of a specific class.ctx- JavaScript contextclass_id- Class ID for the object
JS_NewObjectProtoClass
Creates a new JavaScript object with a specific prototype and class.ctx- JavaScript contextproto- Prototype object orJS_NULLclass_id- Class ID for the object
JS_NewObjectFrom
Creates a new JavaScript object from arrays of atoms and values.ctx- JavaScript contextcount- Number of propertiesprops- Array of property name atomsvalues- Array of property values (ownership transferred)
values array.
JS_NewObjectFromStr
Creates a new JavaScript object from arrays of string names and values.ctx- JavaScript contextcount- Number of propertiesprops- Array of property name stringsvalues- Array of property values (ownership transferred)
values array.
Array Values
JS_NewArray
Creates a new JavaScript array.ctx- JavaScript context
JS_NewArrayFrom
Creates a new JavaScript array from a C array of values.ctx- JavaScript contextcount- Number of elementsvalues- Array of values (ownership transferred)
values array.