private static List <JsVal> ConvertTypes(object[] paramObjects, AutoJSContext context) { var collection = new List <JsVal>(); foreach (var p in paramObjects) { JsVal val; if (p is nsAString || p is nsACString || p is nsAUTF8String || p is String) { SpiderMonkey.JS_ExecuteScript(context.ContextPointer, '"' + p.ToString() + '"', out val); } else if (p is nsISupports) { // This returns a [xpconnect wrapped nsISupports] - why may or may not be good enought - if not could try and access the objects wrappedJSObject property? // val = SpiderMonkey.JS_CallFunctionName(context.ContextPointer, jsObject, "valueOf"); // Replaced CallFunctionName 'valueOf' method with 'managed convert' (for speed reasons) val = JsVal.FromPtr(context.ConvertCOMObjectToJSObject((nsISupports)p)); } else if (p is bool) { SpiderMonkey.JS_ExecuteScript(context.ContextPointer, ((bool)p) ? "true;" : "false;", out val); } else if (p is double) { val = JsVal.FromDouble((double)p); } else { SpiderMonkey.JS_ExecuteScript(context.ContextPointer, p.ToString(), out val); } collection.Add(val); } return(collection); }
private static JsVal CreateBoolJsVal(AutoJSContext context, bool b) { JsVal val; SpiderMonkey.JS_ExecuteScript(context.ContextPointer, ((bool)b) ? "true;" : "false;", out val); return(val); }
/// <summary> /// Please keep these in alphabetical order. /// </summary> /// <returns></returns> public IEnumerable <KeyValuePair <string, Action <IntPtr> > > EntryPoints() { yield return(new KeyValuePair <string, Action <IntPtr> >("CurrentGlobalOrNull", (c) => SpiderMonkey.CurrentGlobalOrNull(c))); yield return(new KeyValuePair <string, Action <IntPtr> >("GetGlobalForObjectCrossCompartment", (c) => SpiderMonkey.GetGlobalForObjectCrossCompartment(IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("IsObjectInContextCompartment", (c) => SpiderMonkey.IsObjectInContextCompartment(IntPtr.Zero, c))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_BeginRequest", (c) => SpiderMonkey.JS_BeginRequest(c))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_CallFunctionName", (c) => SpiderMonkey.JS_CallFunctionName(c, IntPtr.Zero, "", new JsVal[0]))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_CallFunctionValue", (c) => SpiderMonkey.JS_CallFunctionValue(c, IntPtr.Zero, new JsVal()))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_EncodeString", (c) => SpiderMonkey.JS_EncodeString(IntPtr.Zero, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_EncodeStringToUTF8", (c) => SpiderMonkey.JS_EncodeStringToUTF8(c, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_EndRequest", (c) => SpiderMonkey.JS_EndRequest(c))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_EnterCompartment", (c) => SpiderMonkey.JS_EnterCompartment(c, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_ExecuteScript", (c) => { JsVal val; SpiderMonkey.JS_ExecuteScript(c, "", out val); })); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_Free", (c) => SpiderMonkey.JS_Free(c, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_GetClass", (c) => SpiderMonkey.JS_GetClass(IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_GetClassObject", (c) => SpiderMonkey.JS_GetClassObject(c, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_GetCompartmentPrincipals", (c) => SpiderMonkey.JS_GetCompartmentPrincipals(c))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_ContextIterator", (c) => { var pt = IntPtr.Zero; SpiderMonkey.JS_ContextIterator(IntPtr.Zero, ref pt); })); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_GetContextPrivate", (c) => SpiderMonkey.JS_GetContextPrivate(c))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_GetEmptyStringValue", (c) => SpiderMonkey.JS_GetEmptyStringValue(c))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_GetGlobalForObject", (c) => SpiderMonkey.JS_GetGlobalForObject(c, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_GetProperty", (c) => SpiderMonkey.JS_GetProperty(c, IntPtr.Zero, ""))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_GetStringLength", (c) => SpiderMonkey.JS_GetStringLength(IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_GetStringEncodingLength", (c) => SpiderMonkey.JS_GetStringEncodingLength(c, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_HasProperty", (c) => SpiderMonkey.JS_HasProperty(c, IntPtr.Zero, ""))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_GetNegativeInfinityValue", (c) => SpiderMonkey.JS_GetNegativeInfinityValue(IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_GetPendingException", (c) => SpiderMonkey.JS_GetPendingException(c))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_LeaveCompartment", (c) => SpiderMonkey.JS_LeaveCompartment(c, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_NewContext", (c) => SpiderMonkey.JS_NewContext(IntPtr.Zero, 0))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_NewPlainObject", (c) => SpiderMonkey.JS_NewPlainObject(c))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_NewStringCopyN", (c) => SpiderMonkey.JS_NewStringCopyN(c, "", 0))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_SaveFrameChain", (c) => SpiderMonkey.JS_SaveFrameChain(c))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_SetCompartmentPrincipals", (c) => SpiderMonkey.JS_SetCompartmentPrincipals(c, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_SetContextCallback", (c) => SpiderMonkey.JS_SetContextCallback(IntPtr.Zero, null))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_SetContextPrivate", (c) => SpiderMonkey.JS_SetContextPrivate(c, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_SetErrorReporter", (c) => SpiderMonkey.JS_SetErrorReporter(c, (cx, message, report) => { }))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_SetProperty", (c) => SpiderMonkey.JS_SetProperty(c, IntPtr.Zero, "", new JsVal()))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_SetTrustedPrincipals", (c) => SpiderMonkey.JS_SetTrustedPrincipals(IntPtr.Zero, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_TypeOfValue", (c) => SpiderMonkey.JS_TypeOfValue(IntPtr.Zero, default(JsVal)))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_ValueToObject", (c) => SpiderMonkey.JS_ValueToObject(IntPtr.Zero, default(JsVal)))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_WrapObject", (c) => SpiderMonkey.JS_WrapObject(IntPtr.Zero, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("ToStringSlow", (c) => SpiderMonkey.ToStringSlow(IntPtr.Zero, default(JsVal)))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_GetRuntime", (c) => SpiderMonkey.JS_GetRuntime(c))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_WrapObject", (c) => SpiderMonkey.JS_WrapObject(c, IntPtr.Zero))); }
/// <summary> /// Please keep these in alphabetical order. /// </summary> /// <returns></returns> public IEnumerable <KeyValuePair <string, Action <IntPtr, IntPtr> > > EntryPoints() { yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("CurrentGlobalOrNull", (c, j) => SpiderMonkey.CurrentGlobalOrNull(c))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("GetGlobalForObjectCrossCompartment", (c, j) => SpiderMonkey.GetGlobalForObjectCrossCompartment(j))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("IsObjectInContextCompartment", (c, j) => SpiderMonkey.IsObjectInContextCompartment(j, c))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_BeginRequest", (c, j) => SpiderMonkey.JS_BeginRequest(c))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_CallFunctionName", (c, j) => SpiderMonkey.JS_CallFunctionName(c, j, "", new JsVal[0]))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_CallFunctionValue", (c, j) => SpiderMonkey.JS_CallFunctionValue(c, j, new JsVal()))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_EncodeString", (c, j) => SpiderMonkey.JS_EncodeString(c, TestString(c)))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_EndRequest", (c, j) => SpiderMonkey.JS_EndRequest(c))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_EnterCompartment", (c, j) => SpiderMonkey.JS_EnterCompartment(c, j))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_ExecuteScript", (c, j) => { JsVal val; SpiderMonkey.JS_ExecuteScript(c, "", out val); })); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_Free", (c, j) => SpiderMonkey.JS_Free(c, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_GetClass", (c, j) => SpiderMonkey.JS_GetClass(j))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_GetClassObject", (c, j) => SpiderMonkey.JS_GetClassObject(c, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_GetCompartmentPrincipals", (c, j) => SpiderMonkey.JS_GetCompartmentPrincipals(c))); #if PORTFF60 // unstable yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_GetEmptyStringValue", (c, j) => SpiderMonkey.JS_GetEmptyStringValue(c))); #endif yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_GetGlobalForObject", (c, j) => SpiderMonkey.JS_GetGlobalForObject(c, j))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_GetProperty", (c, j) => SpiderMonkey.JS_GetProperty(c, j, ""))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_GetStringLength", (c, j) => SpiderMonkey.JS_GetStringLength(TestString(c)))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_GetStringEncodingLength", (c, j) => SpiderMonkey.JS_GetStringEncodingLength(c, TestString(c)))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_HasProperty", (c, j) => SpiderMonkey.JS_HasProperty(c, j, ""))); #if PORTFF60 // unstable yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_GetNegativeInfinityValue", (c, j) => SpiderMonkey.JS_GetNegativeInfinityValue(c))); #endif yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_GetPendingException", (c, j) => SpiderMonkey.JS_GetPendingException(c))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_LeaveCompartment", (c, j) => SpiderMonkey.JS_LeaveCompartment(c, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_NewPlainObject", (c, j) => SpiderMonkey.JS_NewPlainObject(c))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_NewStringCopyN", (c, j) => SpiderMonkey.JS_NewStringCopyN(c, "", 0))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_SetCompartmentPrincipals", (c, j) => SpiderMonkey.JS_SetCompartmentPrincipals(c, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_SetProperty", (c, j) => SpiderMonkey.JS_SetProperty(c, j, "", new JsVal()))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_TypeOfValue", (c, j) => SpiderMonkey.JS_TypeOfValue(c, default(JsVal)))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_ValueToObject", (c, j) => SpiderMonkey.JS_ValueToObject(c, default(JsVal)))); yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_WrapObject", (c, j) => SpiderMonkey.JS_WrapObject(c, j))); #if PORTFF60 yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("ToStringSlow", (c, j) => SpiderMonkey.ToStringSlow(IntPtr.Zero, default(JsVal)))); #endif yield return(new KeyValuePair <string, Action <IntPtr, IntPtr> >("JS_GetRuntime", (c, j) => SpiderMonkey.JS_GetRuntime(c))); }
private static List <JsVal> ConvertTypes(object[] paramObjects, AutoJSContext context, out DisposablCollection toDispose) { List <IDisposable> list = new List <IDisposable>(); toDispose = new DisposablCollection(list); var collection = new List <JsVal>(); if (paramObjects == null) { return(collection); } foreach (var p in paramObjects) { JsVal val; if (p is nsAString || p is nsACString || p is nsAUTF8String || p is String) { val = SpiderMonkey.StringToJsVal(context.ContextPointer, p.ToString()); } else if (p is nsISupports) { // This returns a [xpconnect wrapped nsISupports] - why may or may not be good enought - if not could try and access the objects wrappedJSObject property? // val = SpiderMonkey.JS_CallFunctionName(context.ContextPointer, jsObject, "valueOf"); // Replaced CallFunctionName 'valueOf' method with 'managed convert' (for speed reasons) var jso = context.ConvertCOMObjectToJSObject((nsISupports)p, false); list.Add(jso); val = JsVal.FromPtr(jso.JSObject); } else if (p is bool) { val = CreateBoolJsVal(context, (bool)p); } else if (p is double) { val = JsVal.FromDouble((double)p); } else if (p is int) { val = JsVal.FromDouble(Convert.ToDouble(p)); } else if (p is WebIDLUnionBase) { WebIDLUnionBase b = (WebIDLUnionBase)p; if (b.IsNull()) { SpiderMonkey.JS_ExecuteScript(context.ContextPointer, "null", out val); } else if (b.IsComObject()) { var item = ((WebIDLUnionBase)p).ToComObject(); var jso = context.ConvertCOMObjectToJSObject(item, false); list.Add(jso); val = JsVal.FromPtr(jso.JSObject); } else if (b.IsBool()) { val = CreateBoolJsVal(context, b.ToBool()); } else { throw new NotImplementedException("WebIDLUnion are currently only supported for nsISupport and bool types and null's."); } } else { SpiderMonkey.JS_ExecuteScript(context.ContextPointer, (p ?? "null").ToString(), out val); } collection.Add(val); } return(collection); }