Created
March 3, 2017 01:01
-
-
Save niuk/da6a9e58a41384763a8e3a4ab398ff00 to your computer and use it in GitHub Desktop.
JavaScriptCore wrapper; doesn't work, but could serve as a starting point for something that does.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.InteropServices; | |
using JSObject = WebKit.JSValue; | |
using JSGlobalContext = WebKit.JSContext; | |
namespace WebKit { | |
#region JSBase.h | |
public unsafe struct JSContextGroup { } | |
public unsafe struct JSContext { } | |
public unsafe struct JSString { } | |
public unsafe struct JSClass { } | |
public unsafe struct JSPropertyNameArray { } | |
public unsafe struct JSPropertyNameAccumulator { } | |
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | |
public unsafe delegate void JSTypedArrayBytesDeallocator(IntPtr bytes, IntPtr deallocatorContext); | |
public unsafe struct JSValue { } | |
[StructLayout(LayoutKind.Sequential)] | |
public unsafe struct JSValueRef { | |
public IntPtr p; | |
public static implicit operator JSValueRef(JSValue* v) { | |
return new JSValueRef { p = (IntPtr)v }; | |
} | |
public static implicit operator JSValue*(JSValueRef r) { | |
return (JSValue*)r.p; | |
} | |
} | |
#endregion | |
#region JSObjectRef.h | |
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | |
public unsafe delegate void JSObjectInitializeCallback(JSContext* ctx, JSObject* @object); | |
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | |
public unsafe delegate void JSObjectFinalizeCallback(JSObject* @object); | |
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | |
public unsafe delegate bool JSObjectHasPropertyCallback(JSContext* ctx, JSObject* @object, JSString* propertyName); | |
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | |
public unsafe delegate JSValue* JSObjectGetPropertyCallback(JSContext* ctx, JSObject* @object, JSString* propertyName, JSValue** exception); | |
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | |
public unsafe delegate bool JSObjectSetPropertyCallback(JSContext* ctx, JSObject* @object, JSString* propertyName, JSValue* value, JSValue** exception); | |
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | |
public unsafe delegate bool JSObjectDeletePropertyCallback(JSContext* ctx, JSObject* @object, JSString* propertyName, JSValue** exception); | |
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | |
public unsafe delegate void JSObjectGetPropertyNamesCallback(JSContext* ctx, JSObject* @object, JSPropertyNameAccumulator* propertyNames); | |
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | |
public unsafe delegate JSValue* JSObjectCallAsFunctionCallback(JSContext* ctx, JSObject* function, JSObject* thisObject, ulong argumentCount, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] JSValue*[] arguments, JSValue** exception); | |
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | |
public unsafe delegate JSObject* JSObjectCallAsConstructorCallback(JSContext* ctx, JSObject* constructor, ulong argumentCount, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] JSValue*[] arguments, JSValue** exception); | |
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | |
public unsafe delegate bool JSObjectHasInstanceCallback(JSContext* ctx, JSObject* constructor, JSValue* possibleInstance, JSValue** exception); | |
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | |
public unsafe delegate JSValue* JSObjectConvertToTypeCallback(JSContext* ctx, JSObject* @object, JSType type, JSValue** exception); | |
[StructLayout(LayoutKind.Sequential)] | |
public class JSStaticValue { | |
[MarshalAs(UnmanagedType.LPStr)] | |
public string name; | |
public JSObjectGetPropertyCallback getProperty; | |
public JSObjectSetPropertyCallback setProperty; | |
public uint attributes; | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
public class JSStaticFunction { | |
[MarshalAs(UnmanagedType.LPStr)] | |
public string name; | |
public JSObjectCallAsFunctionCallback callAsFunction; | |
public uint attributes; | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
public unsafe class JSClassDefinition { | |
public int version; /* current (and only) version is 0 */ | |
public uint attributes; | |
[MarshalAs(UnmanagedType.LPStr)] | |
public string className; | |
public JSClass* parentClass; | |
public JSStaticValue staticValues; // JSStaticValue* | |
public JSStaticFunction staticFunctions; // JSStaticFunction* | |
public JSObjectInitializeCallback initialize; | |
public JSObjectFinalizeCallback finalize; | |
public JSObjectHasPropertyCallback hasProperty; | |
public JSObjectGetPropertyCallback getProperty; | |
public JSObjectSetPropertyCallback setProperty; | |
public JSObjectDeletePropertyCallback deleteProperty; | |
public JSObjectGetPropertyNamesCallback getPropertyNames; | |
public JSObjectCallAsFunctionCallback callAsFunction; | |
public JSObjectCallAsConstructorCallback callAsConstructor; | |
public JSObjectHasInstanceCallback hasInstance; | |
public JSObjectConvertToTypeCallback convertToType; | |
public static JSClassDefinition kJSClassDefinitionEmpty { | |
get { | |
return new JSClassDefinition { /* 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 */ }; | |
} | |
} | |
} | |
#endregion | |
#region JSValueRef.h | |
public enum JSType { | |
kJSTypeUndefined, | |
kJSTypeNull, | |
kJSTypeBoolean, | |
kJSTypeNumber, | |
kJSTypeString, | |
kJSTypeObject | |
} | |
public enum JSTypedArrayType { | |
kJSTypedArrayTypeInt8Array, | |
kJSTypedArrayTypeInt16Array, | |
kJSTypedArrayTypeInt32Array, | |
kJSTypedArrayTypeUint8Array, | |
kJSTypedArrayTypeUint8ClampedArray, | |
kJSTypedArrayTypeUint16Array, | |
kJSTypedArrayTypeUint32Array, | |
kJSTypedArrayTypeFloat32Array, | |
kJSTypedArrayTypeFloat64Array, | |
kJSTypedArrayTypeArrayBuffer, | |
kJSTypedArrayTypeNone, | |
} | |
#endregion | |
public unsafe static class JavaScriptCore { | |
#if UNITY_IPHONE && !UNITY_EDITOR | |
private const string PLATFORM_DLL = "__Internal"; | |
#else | |
private const string PLATFORM_DLL = "JavaScriptCore"; | |
#endif | |
#region JSBase.h | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSValue* JSEvaluateScript(JSContext* ctx, JSString* script, JSObject* thisObject, JSString* sourceURL, int startingLineNumber, JSValue** exception); | |
[DllImport(PLATFORM_DLL)] | |
public static extern bool JSCheckScriptSyntax(JSContext* ctx, JSString* script, JSString* sourceURL, int startingLineNumber, JSValue** exception); | |
[DllImport(PLATFORM_DLL)] | |
public static extern void JSGarbageCollect(JSContext* ctx); | |
#endregion | |
#region JSContextRef.h | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSContextGroup* JSContextGroupCreate(); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSContextGroup* JSContextGroupRetain(JSContextGroup* group); | |
[DllImport(PLATFORM_DLL)] | |
public static extern void JSContextGroupRelease(JSContextGroup* group); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSGlobalContext* JSGlobalContextCreate(JSClass* globalObjectClass); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSGlobalContext* JSGlobalContextCreateInGroup(JSContextGroup* group, JSClass* globalObjectClass); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSGlobalContext* JSGlobalContextRetain(JSGlobalContext* ctx); | |
[DllImport(PLATFORM_DLL)] | |
public static extern void JSGlobalContextRelease(JSGlobalContext* ctx); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSObject* JSContextGetGlobalObject(JSContext* ctx); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSContextGroup* JSContextGetGroup(JSContext* ctx); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSGlobalContext* JSContextGetGlobalContext(JSContext* ctx); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSString* JSGlobalContextCopyName(JSGlobalContext* ctx); | |
[DllImport(PLATFORM_DLL)] | |
public static extern void JSGlobalContextSetName(JSGlobalContext* ctx, JSString* name); | |
#endregion | |
#region JSObjectRef.h | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSClass* JSClassCreate(JSClassDefinition definition); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSClass* JSClassRetain(JSClass* jsClass); | |
[DllImport(PLATFORM_DLL)] | |
public static extern void JSClassRelease(JSClass* jsClass); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSObject* JSObjectMake(JSContext* ctx, JSClass* jsClass, IntPtr data); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSObject* JSObjectMakeFunctionWithCallback(JSContext* ctx, JSString* name, JSObjectCallAsFunctionCallback callAsFunction); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSObject* JSObjectMakeConstructor(JSContext* ctx, JSClass* jsClass, JSObjectCallAsConstructorCallback callAsConstructor); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSObject* JSObjectMakeArray(JSContext* ctx, ulong argumentCount, JSValue*[] arguments, JSValue** exception); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSObject* JSObjectMakeDate(JSContext* ctx, ulong argumentCount, JSValue*[] arguments, JSValue** exception); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSObject* JSObjectMakeError(JSContext* ctx, ulong argumentCount, JSValue*[] arguments, JSValue** exception); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSObject* JSObjectMakeRegExp(JSContext* ctx, ulong argumentCount, JSValue*[] arguments, JSValue** exception); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSObject* JSObjectMakeFunction(JSContext* ctx, JSString* name, uint parameterCount, JSString*[] parameterNames, JSString* body, JSString* sourceURL, int startingLineNumber, JSValue** exception); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSValue* JSObjectGetPrototype(JSContext* ctx, JSObject* @object); | |
[DllImport(PLATFORM_DLL)] | |
public static extern void JSObjectSetPrototype(JSContext* ctx, JSObject* @object, JSValue* value); | |
[DllImport(PLATFORM_DLL)] | |
public static extern bool JSObjectHasProperty(JSContext* ctx, JSObject* @object, JSString* propertyName); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSValue* JSObjectGetProperty(JSContext* ctx, JSObject* @object, JSString* propertyName, JSValue** exception); | |
[DllImport(PLATFORM_DLL)] | |
public static extern void JSObjectSetProperty(JSContext* ctx, JSObject* @object, JSString* propertyName, JSValue* value, uint attributes, JSValue** exception); | |
[DllImport(PLATFORM_DLL)] | |
public static extern bool JSObjectDeleteProperty(JSContext* ctx, JSObject* @object, JSString* propertyName, JSValue** exception); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSValue* JSObjectGetPropertyAtIndex(JSContext* ctx, JSObject* @object, uint propertyIndex, JSValue** exception); | |
[DllImport(PLATFORM_DLL)] | |
public static extern void JSObjectSetPropertyAtIndex(JSContext* ctx, JSObject* @object, uint propertyIndex, JSValue* value, JSValue** exception); | |
[DllImport(PLATFORM_DLL)] | |
public static extern IntPtr JSObjectGetPrivate(JSObject* @object); | |
[DllImport(PLATFORM_DLL)] | |
public static extern bool JSObjectSetPrivate(JSObject* @object, IntPtr data); | |
[DllImport(PLATFORM_DLL)] | |
public static extern bool JSObjectIsFunction(JSContext* ctx, JSObject* @object); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSValue* JSObjectCallAsFunction(JSContext* ctx, JSObject* @object, JSObject* thisObject, ulong argumentCount, JSValue*[] arguments, JSValue** exception); | |
[DllImport(PLATFORM_DLL)] | |
public static extern bool JSObjectIsConstructor(JSContext* ctx, JSObject* @object); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSObject* JSObjectCallAsConstructor(JSContext* ctx, JSObject* @object, ulong argumentCount, JSValue*[] arguments, [Out] JSValue** exception); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSPropertyNameArray* JSObjectCopyPropertyNames(JSContext* ctx, JSObject* @object); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSPropertyNameArray* JSPropertyNameArrayRetain(JSPropertyNameArray* array); | |
[DllImport(PLATFORM_DLL)] | |
public static extern void JSPropertyNameArrayRelease(JSPropertyNameArray* array); | |
[DllImport(PLATFORM_DLL)] | |
public static extern ulong JSPropertyNameArrayGetCount(JSPropertyNameArray* array); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSString* JSPropertyNameArrayGetNameAtIndex(JSPropertyNameArray* array, ulong index); | |
[DllImport(PLATFORM_DLL)] | |
public static extern void JSPropertyNameAccumulatorAddName(JSPropertyNameAccumulator* accumulator, JSString* propertyName); | |
#endregion | |
#region JSStringRef.h | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSString* JSStringCreateWithCharacters(ushort[] chars, ulong numChars); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSString* JSStringCreateWithUTF8CString(byte[] @string); | |
[DllImport(PLATFORM_DLL)] | |
public static extern void JSStringRelease(JSString* @string); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSString* JSStringRetain(JSString* @string); | |
[DllImport(PLATFORM_DLL)] | |
public static extern ushort[] JSStringGetCharactersPtr(JSString* @string); | |
[DllImport(PLATFORM_DLL)] | |
public static extern ulong JSStringGetLength(JSString* @string); | |
[DllImport(PLATFORM_DLL)] | |
public static extern ulong JSStringGetMaximumUTF8CStringSize(JSString* @string); | |
[DllImport(PLATFORM_DLL)] | |
public static extern ulong JSStringGetUTF8CString(JSString* @string, byte[] buffer, ulong bufferSize); | |
[DllImport(PLATFORM_DLL)] | |
public static extern bool JSStringIsEqual(JSString* a, JSString* b); | |
[DllImport(PLATFORM_DLL)] | |
public static extern bool JSStringIsEqualToUTF8CString(JSString* a, byte[] b); | |
#endregion | |
#region JSValueRef.h | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSType JSValueGetType(JSContext* ctx, JSValue* value); | |
[DllImport(PLATFORM_DLL)] | |
public static extern bool JSValueIsUndefined(JSContext* ctx, JSValue* value); | |
[DllImport(PLATFORM_DLL)] | |
public static extern bool JSValueIsNull(JSContext* ctx, JSValue* value); | |
[DllImport(PLATFORM_DLL)] | |
public static extern bool JSValueIsBoolean(JSContext* ctx, JSValue* value); | |
[DllImport(PLATFORM_DLL)] | |
public static extern bool JSValueIsNumber(JSContext* ctx, JSValue* value); | |
[DllImport(PLATFORM_DLL)] | |
public static extern bool JSValueIsString(JSContext* ctx, JSValue* value); | |
[DllImport(PLATFORM_DLL)] | |
public static extern bool JSValueIsObject(JSContext* ctx, JSValue* value); | |
[DllImport(PLATFORM_DLL)] | |
public static extern bool JSValueIsObjectOfClass(JSContext* ctx, JSValue* value, JSClass* jsClass); | |
[DllImport(PLATFORM_DLL)] | |
public static extern bool JSValueIsArray(JSContext* ctx, JSValue* value); | |
[DllImport(PLATFORM_DLL)] | |
public static extern bool JSValueIsDate(JSContext* ctx, JSValue* value); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSTypedArrayType JSValueGetTypedArrayType(JSContext* ctx, JSValue* value, JSValue** exception); | |
[DllImport(PLATFORM_DLL)] | |
public static extern bool JSValueIsEqual(JSContext* ctx, JSValue* a, JSValue* b, JSValue** exception); | |
[DllImport(PLATFORM_DLL)] | |
public static extern bool JSValueIsStrictEqual(JSContext* ctx, JSValue* a, JSValue* b); | |
[DllImport(PLATFORM_DLL)] | |
public static extern bool JSValueIsInstanceOfConstructor(JSContext* ctx, JSValue* value, JSObject* constructor, JSValue** exception); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSValue* JSValueMakeUndefined(JSContext* ctx); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSValue* JSValueMakeNull(JSContext* ctx); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSValue* JSValueMakeBoolean(JSContext* ctx, bool boolean); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSValue* JSValueMakeNumber(JSContext* ctx, double number); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSValue* JSValueMakeString(JSContext* ctx, JSString* @string); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSValue* JSValueMakeFromJSONString(JSContext* ctx, JSString* @string); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSString* JSValueCreateJSONString(JSContext* ctx, JSValue* value, uint indent, JSValue** exception); | |
[DllImport(PLATFORM_DLL)] | |
public static extern bool JSValueToBoolean(JSContext* ctx, JSValue* value); | |
[DllImport(PLATFORM_DLL)] | |
public static extern double JSValueToNumber(JSContext* ctx, JSValue* value, JSValue** exception); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSString* JSValueToStringCopy(JSContext* ctx, JSValue* value, JSValue** exception); | |
[DllImport(PLATFORM_DLL)] | |
public static extern JSObject* JSValueToObject(JSContext* ctx, JSValue* value, JSValue** exception); | |
[DllImport(PLATFORM_DLL)] | |
public static extern void JSValueProtect(JSContext* ctx, JSValue* value); | |
[DllImport(PLATFORM_DLL)] | |
public static extern void JSValueUnprotect(JSContext* ctx, JSValue* value); | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment