JSObject class
A JavaScript object. A JSObject is a JSValue.
Constructors
-
JSObject(JSContext context, Pointer<
NativeType> pointer) -
JSObject.make(JSContext context, JSClass jsClass, {Pointer<
NativeType> ? data}) - Creates a JavaScript object. The default object class does not allocate storage for private data, so you must provide a non-NULL jsClass to JSObjectMake if you want your object to be able to store private data.
- JSObject.makeArray(JSContext context, JSValuePointer arguments, {JSValuePointer? exception})
-
Creates a JavaScript Array object.
The behavior of this function does not exactly match the behavior of the built-in Array constructor. Specifically, if one argument
is supplied, this function returns an array with one element.
arguments
A JSValue array of data to populate the Array with. Pass NULL if argumentCount is 0.exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. -
JSObject.makeArrayBufferWithBytesNoCopy(JSContext context, Bytes bytes, Pointer<
NativeFunction< ? bytesDeallocator, Pointer<JSTypedArrayBytesDeallocator> >NativeType> deallocatorContext, {JSValuePointer? exception}) -
Creates a JavaScript Array Buffer object from an existing pointer.
If an exception is thrown during this function the bytesDeallocator will always be called.
bytes
(void*) A pointer to the byte buffer to be used as the backing store of the Typed Array object.bytesDeallocator
(JSTypedArrayBytesDeallocator) The allocator to use to deallocate the external buffer when the Typed Array data object is deallocated.deallocatorContext
(void*) A pointer to pass back to the deallocator.exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. -
JSObject.makeConstructor(JSContext context, JSClass jsClass, Pointer<
NativeFunction< ? callAsConstructor)JSObjectCallAsConstructorCallback> > -
Convenience method for creating a JavaScript constructor.
The default object constructor takes no arguments and constructs an object of class jsClass with no private data.
jsClass
A JSClass that is the class your constructor will assign to the objects its constructs. jsClass will be used to set the constructor's .prototype property, and to evaluate 'instanceof' expressions. Pass NULL to use the default object class.callAsConstructor
A JSObjectCallAsConstructorCallback to invoke when your constructor is used in a 'new' expression. Pass NULL to use the default object constructor. - JSObject.makeDate(JSContext context, JSValuePointer arguments, {JSValuePointer? exception})
-
Creates a JavaScript Date object, as if by invoking the built-in Date constructor.
arguments
A JSValue array of arguments to pass to the Date Constructor. Pass NULL if argumentCount is 0.exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. - JSObject.makeDeferredPromise(JSContext context, JSObjectPointer resolve, JSObjectPointer reject, {JSValuePointer? exception})
-
Creates a JavaScript promise object by invoking the provided executor.
resolve
(JSObjectRef*) A pointer to a JSObjectRef in which to store the resolve function for the new promise. Pass NULL if you do not care to store the resolve callback.reject
(JSObjectRef*) A pointer to a JSObjectRef in which to store the reject function for the new promise. Pass NULL if you do not care to store the reject callback.exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. - JSObject.makeError(JSContext context, JSValuePointer arguments, {JSValuePointer? exception})
-
Creates a JavaScript Error object, as if by invoking the built-in Error constructor.
arguments
(JSValueRef[]) A JSValue array of arguments to pass to the Error Constructor. Pass NULL if argumentCount is 0.exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. - JSObject.makeFunction(JSContext context, String name, JSStringPointer parameterNames, String body, String sourceURL, {JSValuePointer? exception, int startingLineNumber = 0})
-
Creates a function with a given script as its body.
Use this method when you want to execute a script repeatedly, to avoid the cost of re-parsing the script before each execution.
name
A JSString containing the function's name. This will be used when converting the function to string. Pass NULL to create an anonymous function.parameterNames
(JSStringRef[]) A JSString array containing the names of the function's parameters. Pass NULL if parameterCount is 0.body
A JSString containing the script to use as the function's body.sourceURL
A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.startingLineNumber
(int) An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. The value is one-based, so the first line is line 1 and invalid values are clamped to 1.exception
(JSValueRef*) A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception. -
JSObject.makeFunctionWithCallback(JSContext context, String name, Pointer<
NativeFunction< ? callAsFunction)JSObjectCallAsFunctionCallback> > -
Convenience method for creating a JavaScript function with a given callback as its implementation.
name
A JSString containing the function's name. This will be used when converting the function to string. Pass NULL to create an anonymous function.callAsFunction
The JSObjectCallAsFunctionCallback to invoke when the function is called. - JSObject.makeRegExp(JSContext context, JSValuePointer arguments, {JSValuePointer? exception})
-
Creates a JavaScript RegExp object, as if by invoking the built-in RegExp constructor.
arguments
(JSValueRef[]) A JSValue array of arguments to pass to the RegExp Constructor. Pass NULL if argumentCount is 0.exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. - JSObject.makeTypedArray(JSContext context, JSTypedArrayType arrayType, int length, {JSValuePointer? exception})
-
Creates a JavaScript Typed Array object with the given number of elements.
arrayType
A value JSTypedArrayType identifying the type of array to create. If arrayType is kJSTypedArrayTypeNone or kJSTypedArrayTypeArrayBuffer then NULL will be returned.length
(size_t) The number of elements to be in the new Typed Array.exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. - JSObject.makeTypedArrayWithArrayBuffer(JSContext context, JSTypedArrayType arrayType, JSObject buffer, {JSValuePointer? exception})
-
Creates a JavaScript Typed Array object from an existing JavaScript Array Buffer object.
arrayType
A value JSTypedArrayType identifying the type of array to create. If arrayType is kJSTypedArrayTypeNone or kJSTypedArrayTypeArrayBuffer then NULL will be returned.buffer
An Array Buffer object that should be used as the backing store for the created JavaScript Typed Array object.exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. - JSObject.makeTypedArrayWithArrayBufferAndOffset(JSContext context, JSTypedArrayType arrayType, JSObject buffer, int byteOffset, int length, {JSValuePointer? exception})
-
Creates a JavaScript Typed Array object from an existing JavaScript Array Buffer object with the given offset and length.
arrayType
A value JSTypedArrayType identifying the type of array to create. If arrayType is kJSTypedArrayTypeNone or kJSTypedArrayTypeArrayBuffer then NULL will be returned.buffer
(JSObjectRef) An Array Buffer object that should be used as the backing store for the created JavaScript Typed Array object.byteOffset
(size_t) The byte offset for the created Typed Array. byteOffset should aligned with the element size of arrayType.length
(size_t) The number of elements to include in the Typed Array.exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. -
JSObject.makeTypedArrayWithBytesNoCopy(JSContext context, JSTypedArrayType arrayType, Bytes bytes, Pointer<
NativeFunction< ? bytesDeallocator, Pointer<JSTypedArrayBytesDeallocator> >NativeType> deallocatorContext, {JSValuePointer? exception}) -
Creates a JavaScript Typed Array object from an existing pointer.
If an exception is thrown during this function the bytesDeallocator will always be called.
arrayType
A value JSTypedArrayType identifying the type of array to create. If arrayType is kJSTypedArrayTypeNone or kJSTypedArrayTypeArrayBuffer then NULL will be returned.bytes
(void*) A pointer to the byte buffer to be used as the backing store of the Typed Array object.byteLength
The number of bytes pointed to by the parameter bytes.bytesDeallocator
(JSTypedArrayBytesDeallocator) The allocator to use to deallocate the external buffer when the JSTypedArrayData object is deallocated.deallocatorContext
(void*) A pointer to pass back to the deallocator.exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Properties
- context → JSContext
-
JavaScript context
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isConstructor → bool
-
Tests whether an object can be called as a constructor.
no setter
- isFunction → bool
-
Tests whether an object can be called as a function.
no setter
-
pointer
→ Pointer<
NativeType> -
C pointer
final
-
private
→ Pointer<
NativeType> -
Gets an object's private data.
no setter
- prototype ↔ JSValue
-
Gets an object's prototype.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
arrayBufferBytes(
{JSValuePointer? exception}) → Bytes -
Returns a pointer to the data buffer that serves as the backing store for a JavaScript Typed Array object.
The pointer returned by this function is temporary and is not guaranteed to remain valid across JavaScriptCore API calls.
exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. -
callAsConstructor(
JSValuePointer arguments, {JSValuePointer? exception}) → JSObject -
Calls an object as a constructor.
arguments
(JSValueRef[]) A JSValue array of arguments to pass to the constructor. Pass NULL if argumentCount is 0.exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.@result
(JSObjectRef) The JSObject that results from calling object as a constructor, or NULL if an exception is thrown or object is not a constructor. -
callAsFunction(
JSObject thisObject, JSValuePointer arguments, {JSValuePointer? exception}) → JSValue -
Calls an object as a function.
thisObject
(JSObjectRef) The object to use as "this," or NULL to use the global object as "this."arguments
(JSValueRef[]) A JSValue array of arguments to pass to the function. Pass NULL if argumentCount is 0.exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.@result
(JSValue) The JSValue that results from calling object as a function, or NULL if an exception is thrown or object is not a function. -
copyPropertyNames(
) → JSPropertyNameArray - Gets the names of an object's enumerable properties.
-
deleteProperty(
String propertyName, {JSValuePointer? exception}) → bool -
Deletes a property from an object.
propertyName
A JSString containing the property's name.exception
A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.@result
(bool) true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set). -
getProperty(
String propertyName, {JSValuePointer? exception}) → JSValue -
Tests whether an object has a given property.
propertyName
(JSStringRef) A JSString containing the property's name.exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. -
getPropertyAtIndex(
int propertyIndex, {JSValuePointer? exception}) → JSValue -
Gets a property from an object by numeric index.
Calling JSObjectGetPropertyAtIndex is equivalent to calling JSObjectGetProperty with a string containing propertyIndex, but JSObjectGetPropertyAtIndex provides optimized access to numeric properties.
propertyIndex
(unsigned) An integer value that is the property's name.exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. -
getPropertyForKey(
String propertyKey, {JSValuePointer? exception}) → JSValue -
Gets a property from an object using a JSValueRef as the property key.
This function is the same as performing "object
propertyKey
" from JavaScript.propertyKey
A JSValueRef containing the property key to use when looking up the property.exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. -
hasProperty(
String propertyName) → bool -
Tests whether an object has a given property.
propertyName
(JSStringRef) A JSString containing the property's name. -
hasPropertyForKey(
String propertyKey, {JSValuePointer? exception}) → bool -
Tests whether an object has a given property using a JSValueRef as the property key.
This function is the same as performing "propertyKey in object" from JavaScript.
propertyKey
A JSValueRef containing the property key to use when looking up the property.exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
propertyNameAccumulatorAddName(
JSPropertyNameAccumulator accumulator, String propertyName) → void -
Adds a property name to a JavaScript property name accumulator.
accumulator
(JSPropertyNameAccumulatorRef) The accumulator object to which to add the property name.propertyName
(JSStringRef) The property name to add. -
setPrivate(
Pointer< NativeType> data) → bool -
Sets a pointer to private data on an object.
The default object class does not allocate storage for private data. Only objects created with a non-NULL JSClass can store private data.
data
(void*) A void* to set as the object's private data. -
setProperty(
String propertyName, JSValue value, JSPropertyAttributes attributes, {JSValuePointer? exception}) → void -
Sets a property on an object.
propertyName
A JSString containing the property's name.value
A JSValueRef to use as the property's value.attributes
(JSPropertyAttributes) A logically ORed set of JSPropertyAttributes to give to the property.exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. -
setPropertyAtIndex(
int propertyIndex, JSValue value, {JSValuePointer? exception}) → void -
Sets a property on an object by numeric index.
Calling JSObjectSetPropertyAtIndex is equivalent to calling JSObjectSetProperty with a string containing propertyIndex, but JSObjectSetPropertyAtIndex provides optimized access to numeric properties.
propertyIndex
(unsigned) The property's name as a number.value
(JSValueRef) A JSValue to use as the property's value.exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. -
setPropertyForKey(
String propertyKey, JSValue value, JSPropertyAttributes attributes, {JSValuePointer? exception}) → void -
Sets a property on an object using a JSValueRef as the property key.
This function is the same as performing "object
propertyKey
= value" from JavaScript.propertyKey
(JSValueRef) A JSValueRef containing the property key to use when looking up the property.value
(JSValueRef) A JSValueRef to use as the property's value.attributes
(JSPropertyAttributes) A logically ORed set of JSPropertyAttributes to give to the property.exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. -
toString(
) → String -
A string representation of this object.
inherited
-
toValue(
) → JSValue - JSObject to JSValue
-
typedArrayBuffer(
{JSValuePointer? exception}) → JSObject -
Returns the JavaScript Array Buffer object that is used as the backing of a JavaScript Typed Array object.
exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. -
typedArrayByteLength(
{JSValuePointer? exception}) → int -
Returns the byte length of a JavaScript Typed Array object.
exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. -
typedArrayByteOffset(
{JSValuePointer? exception}) → int -
Returns the byte offset of a JavaScript Typed Array object.
exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. -
typedArrayBytes(
{JSValuePointer? exception}) → Bytes -
Returns a temporary pointer to the backing store of a JavaScript Typed Array object.
The pointer returned by this function is temporary and is not guaranteed to remain valid across JavaScriptCore API calls.
exception
(JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited