private static JsVal CreateJsVal(AutoJSContext cx, string jscript) { if (cx == null) { return(CreateJsVal(jscript)); } var ptr = new JsVal(); bool ret = SpiderMonkey.JS_EvaluateScript(cx.ContextPointer, jscript, (uint)jscript.Length, "script", 1, ref ptr); Assert.IsTrue(ret); return(ptr); }
/// <summary> /// Unittest helper method to create a String JsVal /// </summary> /// <param name="value"></param> /// <returns></returns> private static JsVal CreateJsVal(string jscript) { using (AutoJSContext cx = new AutoJSContext(GlobalJSContextHolder.BackstageJSContext)) { var ptr = new JsVal(); var _securityManager = Xpcom.GetService <nsIScriptSecurityManager>("@mozilla.org/scriptsecuritymanager;1"); var _systemPrincipal = _securityManager.GetSystemPrincipal(); IntPtr globalObject = SpiderMonkey.JS_GetGlobalForScopeChain(cx.ContextPointer); bool ret = SpiderMonkey.JS_EvaluateScript(cx.ContextPointer, globalObject, jscript, (uint)jscript.Length, "script", 1, ref ptr); Assert.IsTrue(ret); Marshal.ReleaseComObject(_securityManager); return(ptr); } }
public IEnumerable <KeyValuePair <string, Action <IntPtr> > > EntryPoints() { 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_TypeOfValue", (c) => SpiderMonkey.JS_TypeOfValue(IntPtr.Zero, default(JsVal)))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_ValueToString", (c) => SpiderMonkey.JS_ValueToString(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_NewStringCopyN", (c) => SpiderMonkey.JS_NewStringCopyN(c, "", 0))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_GetGlobalForObject", (c) => SpiderMonkey.JS_GetGlobalForObject(c, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("GetGlobalForObjectCrossCompartment", (c) => SpiderMonkey.GetGlobalForObjectCrossCompartment(IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_SaveFrameChain", (c) => SpiderMonkey.JS_SaveFrameChain(c))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_NewObject", (c) => SpiderMonkey.JS_NewObject(c, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_GetParent", (c) => SpiderMonkey.JS_GetParent(IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_GetScriptedGlobal", (c) => SpiderMonkey.JS_GetScriptedGlobal(c))); yield return(new KeyValuePair <string, Action <IntPtr> >("CurrentGlobalOrNull", (c) => SpiderMonkey.CurrentGlobalOrNull(c))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_NewContext", (c) => SpiderMonkey.JS_NewContext(IntPtr.Zero, 0))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_GetRuntime", (c) => SpiderMonkey.JS_GetRuntime(c))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_GetContextPrivate", (c) => SpiderMonkey.JS_GetContextPrivate(c))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_SetContextPrivate", (c) => SpiderMonkey.JS_SetContextPrivate(c, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("DefaultObjectForContextOrNull", (c) => SpiderMonkey.DefaultObjectForContextOrNull(c))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_BeginRequest", (c) => SpiderMonkey.JS_BeginRequest(c))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_EndRequest", (c) => SpiderMonkey.JS_EndRequest(c))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_EvaluateScript", (c) => { var jsVal = new JsVal(); SpiderMonkey.JS_EvaluateScript(c, IntPtr.Zero, "", 0, "", 0, ref jsVal); })); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_EvaluateScriptForPrincipals", (c) => { var jsVal = new JsVal(); SpiderMonkey.JS_EvaluateScriptForPrincipals(c, IntPtr.Zero, IntPtr.Zero, "", 0, "", 0, ref jsVal); })); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_GetClassObject", (c) => SpiderMonkey.JS_GetClassObject(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_ContextIterator", (c) => { var pt = IntPtr.Zero; SpiderMonkey.JS_ContextIterator(IntPtr.Zero, ref pt); })); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_SetContextCallback", (c) => SpiderMonkey.JS_SetContextCallback(IntPtr.Zero, null))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_EnterCompartment", (c) => SpiderMonkey.JS_EnterCompartment(c, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_LeaveCompartment", (c) => SpiderMonkey.JS_LeaveCompartment(c, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_Free", (c) => SpiderMonkey.JS_Free(c, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_WrapObject", (c) => SpiderMonkey.JS_WrapObject(c, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("IsObjectInContextCompartment", (c) => SpiderMonkey.IsObjectInContextCompartment(IntPtr.Zero, c))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_DestroyRuntime", (c) => SpiderMonkey.JS_DestroyRuntime(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_GetProperty", (c) => SpiderMonkey.JS_GetProperty(c, IntPtr.Zero, ""))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_SetCompartmentPrincipals", (c) => SpiderMonkey.JS_SetCompartmentPrincipals(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_SetTrustedPrincipals", (c) => SpiderMonkey.JS_SetTrustedPrincipals(IntPtr.Zero, IntPtr.Zero))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_GetPendingException", (c) => SpiderMonkey.JS_GetPendingException(c))); yield return(new KeyValuePair <string, Action <IntPtr> >("JS_SetErrorReporter", (c) => SpiderMonkey.JS_SetErrorReporter(c, (cx, message, report) => {}))); }