#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)]
#![warn(clippy::doc_markdown, missing_docs)]
use std::ptr;
#[doc(hidden)]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct OpaqueJSContextGroup([u8; 0]);
pub type JSContextGroupRef = *const OpaqueJSContextGroup;
#[doc(hidden)]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct OpaqueJSContext([u8; 0]);
pub type JSContextRef = *const OpaqueJSContext;
pub type JSGlobalContextRef = *mut OpaqueJSContext;
#[doc(hidden)]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct OpaqueJSString([u8; 0]);
pub type JSStringRef = *mut OpaqueJSString;
#[doc(hidden)]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct OpaqueJSClass([u8; 0]);
pub type JSClassRef = *mut OpaqueJSClass;
#[doc(hidden)]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct OpaqueJSPropertyNameArray([u8; 0]);
pub type JSPropertyNameArrayRef = *mut OpaqueJSPropertyNameArray;
#[doc(hidden)]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct OpaqueJSPropertyNameAccumulator([u8; 0]);
pub type JSPropertyNameAccumulatorRef = *mut OpaqueJSPropertyNameAccumulator;
pub type JSTypedArrayBytesDeallocator = ::std::option::Option<
unsafe extern "C" fn(
bytes: *mut ::std::os::raw::c_void,
deallocatorContext: *mut ::std::os::raw::c_void,
),
>;
#[doc(hidden)]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct OpaqueJSValue([u8; 0]);
pub type JSValueRef = *const OpaqueJSValue;
pub type JSObjectRef = *mut OpaqueJSValue;
extern "C" {
pub fn JSEvaluateScript(
ctx: JSContextRef,
script: JSStringRef,
thisObject: JSObjectRef,
sourceURL: JSStringRef,
startingLineNumber: ::std::os::raw::c_int,
exception: *mut JSValueRef,
) -> JSValueRef;
pub fn JSCheckScriptSyntax(
ctx: JSContextRef,
script: JSStringRef,
sourceURL: JSStringRef,
startingLineNumber: ::std::os::raw::c_int,
exception: *mut JSValueRef,
) -> bool;
pub fn JSGarbageCollect(ctx: JSContextRef);
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum JSType {
Undefined = 0,
Null = 1,
Boolean = 2,
Number = 3,
String = 4,
Object = 5,
Symbol = 6,
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum JSTypedArrayType {
Int8Array = 0,
Int16Array = 1,
Int32Array = 2,
Uint8Array = 3,
Uint8ClampedArray = 4,
Uint16Array = 5,
Uint32Array = 6,
Float32Array = 7,
Float64Array = 8,
ArrayBuffer = 9,
None = 10,
BigInt64Array = 11,
BigUint64Array = 12,
}
extern "C" {
pub fn JSValueGetType(ctx: JSContextRef, arg1: JSValueRef) -> JSType;
pub fn JSValueIsUndefined(ctx: JSContextRef, value: JSValueRef) -> bool;
pub fn JSValueIsNull(ctx: JSContextRef, value: JSValueRef) -> bool;
pub fn JSValueIsBoolean(ctx: JSContextRef, value: JSValueRef) -> bool;
pub fn JSValueIsNumber(ctx: JSContextRef, value: JSValueRef) -> bool;
pub fn JSValueIsString(ctx: JSContextRef, value: JSValueRef) -> bool;
pub fn JSValueIsSymbol(ctx: JSContextRef, value: JSValueRef) -> bool;
pub fn JSValueIsObject(ctx: JSContextRef, value: JSValueRef) -> bool;
pub fn JSValueIsObjectOfClass(
ctx: JSContextRef,
value: JSValueRef,
jsClass: JSClassRef,
) -> bool;
pub fn JSValueIsArray(ctx: JSContextRef, value: JSValueRef) -> bool;
pub fn JSValueIsDate(ctx: JSContextRef, value: JSValueRef) -> bool;
pub fn JSValueGetTypedArrayType(
ctx: JSContextRef,
value: JSValueRef,
exception: *mut JSValueRef,
) -> JSTypedArrayType;
pub fn JSValueIsEqual(
ctx: JSContextRef,
a: JSValueRef,
b: JSValueRef,
exception: *mut JSValueRef,
) -> bool;
pub fn JSValueIsStrictEqual(ctx: JSContextRef, a: JSValueRef, b: JSValueRef) -> bool;
pub fn JSValueIsInstanceOfConstructor(
ctx: JSContextRef,
value: JSValueRef,
constructor: JSObjectRef,
exception: *mut JSValueRef,
) -> bool;
pub fn JSValueMakeUndefined(ctx: JSContextRef) -> JSValueRef;
pub fn JSValueMakeNull(ctx: JSContextRef) -> JSValueRef;
pub fn JSValueMakeBoolean(ctx: JSContextRef, boolean: bool) -> JSValueRef;
pub fn JSValueMakeNumber(ctx: JSContextRef, number: f64) -> JSValueRef;
pub fn JSValueMakeString(ctx: JSContextRef, string: JSStringRef) -> JSValueRef;
pub fn JSValueMakeSymbol(ctx: JSContextRef, description: JSStringRef) -> JSValueRef;
pub fn JSValueMakeFromJSONString(ctx: JSContextRef, string: JSStringRef) -> JSValueRef;
pub fn JSValueCreateJSONString(
ctx: JSContextRef,
value: JSValueRef,
indent: ::std::os::raw::c_uint,
exception: *mut JSValueRef,
) -> JSStringRef;
pub fn JSValueToBoolean(ctx: JSContextRef, value: JSValueRef) -> bool;
pub fn JSValueToNumber(ctx: JSContextRef, value: JSValueRef, exception: *mut JSValueRef)
-> f64;
pub fn JSValueToStringCopy(
ctx: JSContextRef,
value: JSValueRef,
exception: *mut JSValueRef,
) -> JSStringRef;
pub fn JSValueToObject(
ctx: JSContextRef,
value: JSValueRef,
exception: *mut JSValueRef,
) -> JSObjectRef;
pub fn JSValueProtect(ctx: JSContextRef, value: JSValueRef);
pub fn JSValueUnprotect(ctx: JSContextRef, value: JSValueRef);
}
pub const kJSPropertyAttributeNone: ::std::os::raw::c_uint = 0;
pub const kJSPropertyAttributeReadOnly: ::std::os::raw::c_uint = 2;
pub const kJSPropertyAttributeDontEnum: ::std::os::raw::c_uint = 4;
pub const kJSPropertyAttributeDontDelete: ::std::os::raw::c_uint = 8;
pub type JSPropertyAttributes = ::std::os::raw::c_uint;
pub const kJSClassAttributeNone: ::std::os::raw::c_uint = 0;
pub const kJSClassAttributeNoAutomaticPrototype: ::std::os::raw::c_uint = 2;
pub type JSClassAttributes = ::std::os::raw::c_uint;
pub type JSObjectInitializeCallback =
::std::option::Option<unsafe extern "C" fn(ctx: JSContextRef, object: JSObjectRef)>;
pub type JSObjectFinalizeCallback =
::std::option::Option<unsafe extern "C" fn(object: JSObjectRef)>;
pub type JSObjectHasPropertyCallback = ::std::option::Option<
unsafe extern "C" fn(ctx: JSContextRef, object: JSObjectRef, propertyName: JSStringRef) -> bool,
>;
pub type JSObjectGetPropertyCallback = ::std::option::Option<
unsafe extern "C" fn(
ctx: JSContextRef,
object: JSObjectRef,
propertyName: JSStringRef,
exception: *mut JSValueRef,
) -> *const OpaqueJSValue,
>;
pub type JSObjectSetPropertyCallback = ::std::option::Option<
unsafe extern "C" fn(
ctx: JSContextRef,
object: JSObjectRef,
propertyName: JSStringRef,
value: JSValueRef,
exception: *mut JSValueRef,
) -> bool,
>;
pub type JSObjectDeletePropertyCallback = ::std::option::Option<
unsafe extern "C" fn(
ctx: JSContextRef,
object: JSObjectRef,
propertyName: JSStringRef,
exception: *mut JSValueRef,
) -> bool,
>;
pub type JSObjectGetPropertyNamesCallback = ::std::option::Option<
unsafe extern "C" fn(
ctx: JSContextRef,
object: JSObjectRef,
propertyNames: JSPropertyNameAccumulatorRef,
),
>;
pub type JSObjectCallAsFunctionCallback = ::std::option::Option<
unsafe extern "C" fn(
ctx: JSContextRef,
function: JSObjectRef,
thisObject: JSObjectRef,
argumentCount: usize,
arguments: *const JSValueRef,
exception: *mut JSValueRef,
) -> *const OpaqueJSValue,
>;
pub type JSObjectCallAsConstructorCallback = ::std::option::Option<
unsafe extern "C" fn(
ctx: JSContextRef,
constructor: JSObjectRef,
argumentCount: usize,
arguments: *const JSValueRef,
exception: *mut JSValueRef,
) -> *mut OpaqueJSValue,
>;
pub type JSObjectHasInstanceCallback = ::std::option::Option<
unsafe extern "C" fn(
ctx: JSContextRef,
constructor: JSObjectRef,
possibleInstance: JSValueRef,
exception: *mut JSValueRef,
) -> bool,
>;
pub type JSObjectConvertToTypeCallback = ::std::option::Option<
unsafe extern "C" fn(
ctx: JSContextRef,
object: JSObjectRef,
type_: JSType,
exception: *mut JSValueRef,
) -> *const OpaqueJSValue,
>;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct JSStaticValue {
pub name: *const ::std::os::raw::c_char,
pub getProperty: JSObjectGetPropertyCallback,
pub setProperty: JSObjectSetPropertyCallback,
pub attributes: JSPropertyAttributes,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct JSStaticFunction {
pub name: *const ::std::os::raw::c_char,
pub callAsFunction: JSObjectCallAsFunctionCallback,
pub attributes: JSPropertyAttributes,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct JSClassDefinition {
pub version: ::std::os::raw::c_int,
pub attributes: JSClassAttributes,
pub className: *const ::std::os::raw::c_char,
pub parentClass: JSClassRef,
pub staticValues: *const JSStaticValue,
pub staticFunctions: *const JSStaticFunction,
pub initialize: JSObjectInitializeCallback,
pub finalize: JSObjectFinalizeCallback,
pub hasProperty: JSObjectHasPropertyCallback,
pub getProperty: JSObjectGetPropertyCallback,
pub setProperty: JSObjectSetPropertyCallback,
pub deleteProperty: JSObjectDeletePropertyCallback,
pub getPropertyNames: JSObjectGetPropertyNamesCallback,
pub callAsFunction: JSObjectCallAsFunctionCallback,
pub callAsConstructor: JSObjectCallAsConstructorCallback,
pub hasInstance: JSObjectHasInstanceCallback,
pub convertToType: JSObjectConvertToTypeCallback,
}
impl Default for JSClassDefinition {
fn default() -> Self {
JSClassDefinition {
version: 0,
attributes: 0,
className: ptr::null(),
parentClass: ptr::null_mut(),
staticValues: ptr::null(),
staticFunctions: ptr::null(),
initialize: None,
finalize: None,
hasProperty: None,
getProperty: None,
setProperty: None,
deleteProperty: None,
getPropertyNames: None,
callAsFunction: None,
callAsConstructor: None,
hasInstance: None,
convertToType: None,
}
}
}
extern "C" {
pub fn JSClassCreate(definition: *const JSClassDefinition) -> JSClassRef;
pub fn JSClassRetain(jsClass: JSClassRef) -> JSClassRef;
pub fn JSClassRelease(jsClass: JSClassRef);
pub fn JSObjectMake(
ctx: JSContextRef,
jsClass: JSClassRef,
data: *mut ::std::os::raw::c_void,
) -> JSObjectRef;
pub fn JSObjectMakeFunctionWithCallback(
ctx: JSContextRef,
name: JSStringRef,
callAsFunction: JSObjectCallAsFunctionCallback,
) -> JSObjectRef;
pub fn JSObjectMakeConstructor(
ctx: JSContextRef,
jsClass: JSClassRef,
callAsConstructor: JSObjectCallAsConstructorCallback,
) -> JSObjectRef;
pub fn JSObjectMakeArray(
ctx: JSContextRef,
argumentCount: usize,
arguments: *const JSValueRef,
exception: *mut JSValueRef,
) -> JSObjectRef;
pub fn JSObjectMakeDate(
ctx: JSContextRef,
argumentCount: usize,
arguments: *const JSValueRef,
exception: *mut JSValueRef,
) -> JSObjectRef;
pub fn JSObjectMakeError(
ctx: JSContextRef,
argumentCount: usize,
arguments: *const JSValueRef,
exception: *mut JSValueRef,
) -> JSObjectRef;
pub fn JSObjectMakeRegExp(
ctx: JSContextRef,
argumentCount: usize,
arguments: *const JSValueRef,
exception: *mut JSValueRef,
) -> JSObjectRef;
pub fn JSObjectMakeDeferredPromise(
ctx: JSContextRef,
resolve: *mut JSObjectRef,
reject: *mut JSObjectRef,
exception: *mut JSValueRef,
) -> JSObjectRef;
pub fn JSObjectMakeFunction(
ctx: JSContextRef,
name: JSStringRef,
parameterCount: ::std::os::raw::c_uint,
parameterNames: *const JSStringRef,
body: JSStringRef,
sourceURL: JSStringRef,
startingLineNumber: ::std::os::raw::c_int,
exception: *mut JSValueRef,
) -> JSObjectRef;
pub fn JSObjectGetPrototype(ctx: JSContextRef, object: JSObjectRef) -> JSValueRef;
pub fn JSObjectSetPrototype(ctx: JSContextRef, object: JSObjectRef, value: JSValueRef);
pub fn JSObjectHasProperty(
ctx: JSContextRef,
object: JSObjectRef,
propertyName: JSStringRef,
) -> bool;
pub fn JSObjectGetProperty(
ctx: JSContextRef,
object: JSObjectRef,
propertyName: JSStringRef,
exception: *mut JSValueRef,
) -> JSValueRef;
pub fn JSObjectSetProperty(
ctx: JSContextRef,
object: JSObjectRef,
propertyName: JSStringRef,
value: JSValueRef,
attributes: JSPropertyAttributes,
exception: *mut JSValueRef,
);
pub fn JSObjectDeleteProperty(
ctx: JSContextRef,
object: JSObjectRef,
propertyName: JSStringRef,
exception: *mut JSValueRef,
) -> bool;
pub fn JSObjectHasPropertyForKey(
ctx: JSContextRef,
object: JSObjectRef,
propertyKey: JSValueRef,
exception: *mut JSValueRef,
) -> bool;
pub fn JSObjectGetPropertyForKey(
ctx: JSContextRef,
object: JSObjectRef,
propertyKey: JSValueRef,
exception: *mut JSValueRef,
) -> JSValueRef;
pub fn JSObjectSetPropertyForKey(
ctx: JSContextRef,
object: JSObjectRef,
propertyKey: JSValueRef,
value: JSValueRef,
attributes: JSPropertyAttributes,
exception: *mut JSValueRef,
);
pub fn JSObjectDeletePropertyForKey(
ctx: JSContextRef,
object: JSObjectRef,
propertyKey: JSValueRef,
exception: *mut JSValueRef,
) -> bool;
pub fn JSObjectGetPropertyAtIndex(
ctx: JSContextRef,
object: JSObjectRef,
propertyIndex: ::std::os::raw::c_uint,
exception: *mut JSValueRef,
) -> JSValueRef;
pub fn JSObjectSetPropertyAtIndex(
ctx: JSContextRef,
object: JSObjectRef,
propertyIndex: ::std::os::raw::c_uint,
value: JSValueRef,
exception: *mut JSValueRef,
);
pub fn JSObjectGetPrivate(object: JSObjectRef) -> *mut ::std::os::raw::c_void;
pub fn JSObjectSetPrivate(object: JSObjectRef, data: *mut ::std::os::raw::c_void) -> bool;
pub fn JSObjectIsFunction(ctx: JSContextRef, object: JSObjectRef) -> bool;
pub fn JSObjectCallAsFunction(
ctx: JSContextRef,
object: JSObjectRef,
thisObject: JSObjectRef,
argumentCount: usize,
arguments: *const JSValueRef,
exception: *mut JSValueRef,
) -> JSValueRef;
pub fn JSObjectIsConstructor(ctx: JSContextRef, object: JSObjectRef) -> bool;
pub fn JSObjectCallAsConstructor(
ctx: JSContextRef,
object: JSObjectRef,
argumentCount: usize,
arguments: *const JSValueRef,
exception: *mut JSValueRef,
) -> JSObjectRef;
pub fn JSObjectCopyPropertyNames(
ctx: JSContextRef,
object: JSObjectRef,
) -> JSPropertyNameArrayRef;
pub fn JSPropertyNameArrayRetain(array: JSPropertyNameArrayRef) -> JSPropertyNameArrayRef;
pub fn JSPropertyNameArrayRelease(array: JSPropertyNameArrayRef);
pub fn JSPropertyNameArrayGetCount(array: JSPropertyNameArrayRef) -> usize;
pub fn JSPropertyNameArrayGetNameAtIndex(
array: JSPropertyNameArrayRef,
index: usize,
) -> JSStringRef;
pub fn JSPropertyNameAccumulatorAddName(
accumulator: JSPropertyNameAccumulatorRef,
propertyName: JSStringRef,
);
pub fn JSContextGroupCreate() -> JSContextGroupRef;
pub fn JSContextGroupRetain(group: JSContextGroupRef) -> JSContextGroupRef;
pub fn JSContextGroupRelease(group: JSContextGroupRef);
pub fn JSGlobalContextCreate(globalObjectClass: JSClassRef) -> JSGlobalContextRef;
pub fn JSGlobalContextCreateInGroup(
group: JSContextGroupRef,
globalObjectClass: JSClassRef,
) -> JSGlobalContextRef;
pub fn JSGlobalContextRetain(ctx: JSGlobalContextRef) -> JSGlobalContextRef;
pub fn JSGlobalContextRelease(ctx: JSGlobalContextRef);
pub fn JSContextGetGlobalObject(ctx: JSContextRef) -> JSObjectRef;
pub fn JSContextGetGroup(ctx: JSContextRef) -> JSContextGroupRef;
pub fn JSContextGetGlobalContext(ctx: JSContextRef) -> JSGlobalContextRef;
pub fn JSGlobalContextCopyName(ctx: JSGlobalContextRef) -> JSStringRef;
pub fn JSGlobalContextSetName(ctx: JSGlobalContextRef, name: JSStringRef);
}
pub type JSChar = ::std::os::raw::c_ushort;
extern "C" {
pub fn JSStringCreateWithCharacters(chars: *const JSChar, numChars: usize) -> JSStringRef;
pub fn JSStringCreateWithUTF8CString(string: *const ::std::os::raw::c_char) -> JSStringRef;
pub fn JSStringRetain(string: JSStringRef) -> JSStringRef;
pub fn JSStringRelease(string: JSStringRef);
pub fn JSStringGetLength(string: JSStringRef) -> usize;
pub fn JSStringGetCharactersPtr(string: JSStringRef) -> *const JSChar;
pub fn JSStringGetMaximumUTF8CStringSize(string: JSStringRef) -> usize;
pub fn JSStringGetUTF8CString(
string: JSStringRef,
buffer: *mut ::std::os::raw::c_char,
bufferSize: usize,
) -> usize;
pub fn JSStringIsEqual(a: JSStringRef, b: JSStringRef) -> bool;
pub fn JSStringIsEqualToUTF8CString(a: JSStringRef, b: *const ::std::os::raw::c_char) -> bool;
pub fn JSObjectMakeTypedArray(
ctx: JSContextRef,
arrayType: JSTypedArrayType,
length: usize,
exception: *mut JSValueRef,
) -> JSObjectRef;
pub fn JSObjectMakeTypedArrayWithBytesNoCopy(
ctx: JSContextRef,
arrayType: JSTypedArrayType,
bytes: *mut ::std::os::raw::c_void,
byteLength: usize,
bytesDeallocator: JSTypedArrayBytesDeallocator,
deallocatorContext: *mut ::std::os::raw::c_void,
exception: *mut JSValueRef,
) -> JSObjectRef;
pub fn JSObjectMakeTypedArrayWithArrayBuffer(
ctx: JSContextRef,
arrayType: JSTypedArrayType,
buffer: JSObjectRef,
exception: *mut JSValueRef,
) -> JSObjectRef;
pub fn JSObjectMakeTypedArrayWithArrayBufferAndOffset(
ctx: JSContextRef,
arrayType: JSTypedArrayType,
buffer: JSObjectRef,
byteOffset: usize,
length: usize,
exception: *mut JSValueRef,
) -> JSObjectRef;
pub fn JSObjectGetTypedArrayBytesPtr(
ctx: JSContextRef,
object: JSObjectRef,
exception: *mut JSValueRef,
) -> *mut ::std::os::raw::c_void;
pub fn JSObjectGetTypedArrayLength(
ctx: JSContextRef,
object: JSObjectRef,
exception: *mut JSValueRef,
) -> usize;
pub fn JSObjectGetTypedArrayByteLength(
ctx: JSContextRef,
object: JSObjectRef,
exception: *mut JSValueRef,
) -> usize;
pub fn JSObjectGetTypedArrayByteOffset(
ctx: JSContextRef,
object: JSObjectRef,
exception: *mut JSValueRef,
) -> usize;
pub fn JSObjectGetTypedArrayBuffer(
ctx: JSContextRef,
object: JSObjectRef,
exception: *mut JSValueRef,
) -> JSObjectRef;
pub fn JSObjectMakeArrayBufferWithBytesNoCopy(
ctx: JSContextRef,
bytes: *mut ::std::os::raw::c_void,
byteLength: usize,
bytesDeallocator: JSTypedArrayBytesDeallocator,
deallocatorContext: *mut ::std::os::raw::c_void,
exception: *mut JSValueRef,
) -> JSObjectRef;
pub fn JSObjectGetArrayBufferBytesPtr(
ctx: JSContextRef,
object: JSObjectRef,
exception: *mut JSValueRef,
) -> *mut ::std::os::raw::c_void;
pub fn JSObjectGetArrayBufferByteLength(
ctx: JSContextRef,
object: JSObjectRef,
exception: *mut JSValueRef,
) -> usize;
}