/// <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;
			}
		}
Esempio n. 2
0
		public static IntPtr JS_ValueToString(IntPtr cx, JsVal v)
		{
			if (Xpcom.Is32Bit)
			{
				if (Xpcom.IsLinux)
					return JS_ValueToString_Linux32(cx, ref v);
				
				return JS_ValueToString_Win32(cx, ref v);
			}
			else
			{
				if (Xpcom.IsLinux)
					return JS_ValueToString_Linux64(cx, ref v);

				return JS_ValueToString_Win64(cx, ref v);
			}
		}
Esempio n. 3
0
		public static JSType JS_TypeOfValue(IntPtr cx, JsVal jsVal)
		{
			if (Xpcom.Is32Bit)
			{
				if (Xpcom.IsLinux)
					return JS_TypeOfValue_Linux32(cx, ref jsVal);

				return JS_TypeOfValue_Win32(cx, ref jsVal);
			}
			else
			{
				if (Xpcom.IsLinux)
					return JS_TypeOfValue_Linux64(cx, ref jsVal);

				return JS_TypeOfValue_Win64(cx, ref jsVal);
			}
		}		
Esempio n. 4
0
		public JsVal EvaluateScript(string javaScript)
		{
			string msg = String.Empty;
			var old = SpiderMonkey.JS_SetErrorReporter(_cx, (cx, message, report) => { msg = message; });
			try
			{
			var jsValue = new JsVal();
				var ret = SpiderMonkey.JS_EvaluateScript(_cx, PeekCompartmentScope(), javaScript, (uint) javaScript.Length, "script",
					1, ref jsValue);

			if (!ret)
			{
					throw new GeckoJavaScriptException(String.Format("JSError : {0}", msg));
			}

			return jsValue;
		}
			finally
			{
				SpiderMonkey.JS_SetErrorReporter(_cx, old);
			}
		}
 /// <summary>
 /// Evaluate javascript in the current context.
 /// </summary>
 /// <param name="jsScript"></param>
 /// <param name="thisObject">a nsISupports com object that this is set too.</param>
 /// <param name="result"></param>
 /// <returns></returns>
 public bool EvaluateScript(string jsScript, nsISupports thisObject, out string result)
 {
     try
     {
         Guid guid = typeof(nsISupports).GUID;
         IntPtr globalObject = SpiderMonkey.JS_GetGlobalForScopeChain(_cx);
         var ptr = new JsVal();
         var wrapper = XPConnect.WrapNative(_cx, globalObject, thisObject, ref guid);
         bool ret = SpiderMonkey.JS_EvaluateScript(_cx, wrapper.GetJSObjectAttribute(), jsScript, (uint)jsScript.Length, "script", 1, ref ptr);
         IntPtr jsStringPtr = SpiderMonkey.JS_ValueToString(_cx, ptr);
         result = Marshal.PtrToStringAnsi(SpiderMonkey.JS_EncodeString(_cx, jsStringPtr));
         return ret;
     }
     catch (Exception e)
     {
         Console.WriteLine("Exception {0}", e);
         result = String.Empty;
         return false;
     }
 }
 /// <summary>
 /// Evaluate javascript in the current context.
 /// </summary>
 /// <param name="jsScript"></param>
 /// <param name="jsval"></param>
 /// <returns></returns>
 public bool EvaluateFullTrustScriptForCurrentContext(string jsScript, out string result)
 {
     var ptr = new JsVal();
     IntPtr globalObject = SpiderMonkey.JS_GetGlobalForScopeChain(_cx);
     bool ret;
     using (var security = new FullTrustSecMan(XPConnect, _cx))
     {
         ret = SpiderMonkey.JS_EvaluateScript(_cx, globalObject, jsScript, (uint)jsScript.Length, "script", 1, ref ptr);
         IntPtr jsStringPtr = SpiderMonkey.JS_ValueToString(_cx, ptr);
         result = Marshal.PtrToStringAnsi(SpiderMonkey.JS_EncodeString(_cx, jsStringPtr));
     }
     return ret;
 }
Esempio n. 7
0
		private static extern bool JS_EvaluateScript_Win64(IntPtr cx, IntPtr obj, string src, UInt32 length, string filename, UInt32 lineno, ref JsVal jsval);
Esempio n. 8
0
 public static extern bool JS_EvaluateScript(IntPtr cx, IntPtr obj, string src, UInt32 length, string filename, UInt32 lineno, ref JsVal jsval);
 private static extern IntPtr JS_ValueToString_Win32(IntPtr cx, JsVal v);
Esempio n. 10
0
 public void SetOndeviceorientationAttribute(JsVal aOndeviceorientation, IntPtr jsContext)
 {
     throw new NotImplementedException();
 }
Esempio n. 11
0
        public static string JsValToString(IntPtr cx, JsVal jsVal)
        {
            IntPtr ptr = SpiderMonkey.ToString(cx, ref jsVal);

            return(StringFromNativeUtf8(ptr));
        }
Esempio n. 12
0
 public static bool JS_SetProperty(IntPtr cx, IntPtr jsObject, string name, JsVal value)
 {
     return(JS_SetProperty(cx, ref jsObject, name, ref value));
 }
Esempio n. 13
0
 public static JSType JS_TypeOfValue(IntPtr cx, JsVal jsVal)
 {
     return(JS_TypeOfValue(cx, ref jsVal));
 }
 public MutableJSVal(JsVal val)
 {
     _val = val;
 }
        public static bool JS_EvaluateScript(IntPtr cx, IntPtr obj, string src, UInt32 length, string filename, UInt32 lineno, ref JsVal jsval)
        {
            if (Xpcom.IsLinux)
            {
                throw new NotImplementedException();
            }

            return(JS_EvaluateScript_Win32(cx, obj, src, length, filename, lineno, ref jsval));
        }
 private static extern bool JS_EvaluateScriptForPrincipals_Win32(IntPtr cx, IntPtr obj, IntPtr principals, string src, UInt32 length, string filename, UInt32 lineno, ref JsVal jsval);
Esempio n. 17
0
		internal string ConvertValueToString(JsVal value)
		{
			IntPtr jsp = SpiderMonkey.JS_ValueToString(_cx, value);
			if (jsp != IntPtr.Zero)
			{
				uint length;
				var chars = SpiderMonkey.JS_GetStringCharsAndLength(_cx, jsp, out length);
				if (chars != IntPtr.Zero)
					return Marshal.PtrToStringUni(chars, (int)length);
			}
			return null;
		}
Esempio n. 18
0
 public void SetOnafterprintAttribute(JsVal aOnafterprint, IntPtr jsContext)
 {
     throw new NotImplementedException();
 }
Esempio n. 19
0
 public static IntPtr ToStringSlow(IntPtr cx, JsVal v)
 {
     return(ToStringSlow(cx, ref v));
 }
Esempio n. 20
0
 public void SetOnmouseenterAttribute(JsVal aOnmouseenter, IntPtr jsContext)
 {
     throw new NotImplementedException();
 }
Esempio n. 21
0
 internal static extern bool JS_CallFunctionValue(IntPtr cx, IntPtr jsObject, ref JsVal fval,
                                                  IntPtr passZero, ref MutableHandleValue jsValue);
 public static extern IntPtr JS_ValueToString(IntPtr cx, JsVal v);
Esempio n. 23
0
 internal static extern IntPtr ToString(IntPtr cx, ref JsVal jsValue);
Esempio n. 24
0
		// JS_ValueToObject(JSContext *cx, JS::HandleValue v, JS::MutableHandleObject objp);
		private static extern bool JS_ValueToObject_Win64(IntPtr cx, ref JsVal jsValue, ref MutableHandle jsObject);
Esempio n. 25
0
 public static extern bool JS_SetProperty(IntPtr cx, ref IntPtr jsObject, string name, ref JsVal jsValue);
Esempio n. 26
0
		private static extern bool JS_GetProperty_Linux32(IntPtr cx, ref IntPtr jsObject, string name, ref JsVal jsValue);
Esempio n. 27
0
 public static extern JSType JS_TypeOfValue(IntPtr cx, ref JsVal jsVal);
        /// <summary>
        /// Evaluate javascript in the current context.
        /// </summary>
        /// <param name="jsScript"></param>
        /// <param name="jsval"></param>
        /// <returns></returns>
        public bool EvaluateScript(string jsScript, out string result)
        {
            var ptr = new JsVal();
            IntPtr globalObject = SpiderMonkey.JS_GetGlobalForScopeChain(_cx);
            bool ret = SpiderMonkey.JS_EvaluateScript(_cx, globalObject, jsScript, (uint)jsScript.Length, "script", 1, ref ptr);
            // TODO: maybe getting JS_EvaluateScriptForPrincipals working would increase priviliges of the running script.
            //bool ret = SpiderMonkey.JS_EvaluateScriptForPrincipals(_cx, globalObject, ..., jsScript, (uint)jsScript.Length,"script", 1, ref ptr);

            IntPtr jsStringPtr = SpiderMonkey.JS_ValueToString(_cx, ptr);
            result = Marshal.PtrToStringAnsi(SpiderMonkey.JS_EncodeString(_cx, jsStringPtr));
            return ret;
        }
Esempio n. 29
0
 internal static extern bool JS_ValueToObject(IntPtr cx, ref JsVal jsValue, ref MutableHandle jsObject);
Esempio n. 30
0
		/// <summary>
		/// Evaluate javascript in the current context.
		/// </summary>
		/// <param name="jsScript"></param>
		/// <param name="jsval"></param>
		/// <returns></returns>
		public bool EvaluateScript(string jsScript, out string result)
		{
			var ptr = new JsVal();
			bool ret = SpiderMonkey.JS_EvaluateScript(_cx, GetGlobalObject(), jsScript, (uint)jsScript.Length, "script", 1, ref ptr);
			
			//bool ret = SpiderMonkey.JS_EvaluateScriptForPrincipals(_cx, globalObject, ..., jsScript, (uint)jsScript.Length,"script", 1, ref ptr);


			result = ret ? ConvertValueToString(ptr) : null;
			return ret;
		}
Esempio n. 31
0
 public static extern IntPtr ToStringSlow(IntPtr cx, ref JsVal v);
Esempio n. 32
0
		/// <summary>
		/// Evaluate javascript in the current context.
		/// </summary>
		/// <param name="jsScript"></param>
		/// <param name="thisObject">a nsISupports com object that this is set too.</param>
		/// <param name="result"></param>
		/// <returns></returns>
		public bool EvaluateScript(string jsScript, nsISupports thisObject, out string result)
		{
			try
			{
				Guid guid = typeof(nsISupports).GUID;
				var ptr = new JsVal();
				IntPtr globalObject = ConvertCOMObjectToJSObject(thisObject);
				using (new JSAutoCompartment(_cx, globalObject))
				{
					bool ret = SpiderMonkey.JS_EvaluateScript(_cx, globalObject, jsScript, (uint)jsScript.Length, "script", 1, ref ptr);
					result = ret ? ConvertValueToString(ptr) : null;
					return ret;
				}
			}
			catch (Exception e)
			{
				Console.WriteLine("Exception {0}", e);
				result = String.Empty;
				return false;
			}
		}
Esempio n. 33
0
		public static bool JS_EvaluateScriptForPrincipals(IntPtr cx, IntPtr obj, IntPtr principals, string src, UInt32 length, string filename, UInt32 lineno, ref JsVal jsval)
		{
			src = EncodeUnicodeScript(src);
			length = (uint)src.Length;
			if (Xpcom.Is32Bit)
			{
				if (Xpcom.IsLinux)
					return JS_EvaluateScriptForPrincipals_Linux32(cx, obj, principals, src, length, filename, lineno, ref jsval);

				return JS_EvaluateScriptForPrincipals_Win32(cx, obj, principals, src, length, filename, lineno, ref jsval);
			}
			else
			{
				if (Xpcom.IsLinux)
					return JS_EvaluateScriptForPrincipals_Linux64(cx, obj, principals, src, length, filename, lineno, ref jsval);

				return JS_EvaluateScriptForPrincipals_Win64(cx, obj, principals, src, length, filename, lineno, ref jsval);
			}
		}
Esempio n. 34
0
 public void PostMessage(JsVal message, nsAStringBase targetOrigin, IntPtr jsContext)
 {
     throw new NotImplementedException();
 }
Esempio n. 35
0
		public static JsVal JS_GetProperty(IntPtr cx, IntPtr jsObject, string name)
		{
			JsVal Value = new JsVal();
			if (Xpcom.Is32Bit)
			{
				if (Xpcom.IsLinux)
					JS_GetProperty_Linux32(cx, ref jsObject, name, ref Value);
				else
					JS_GetProperty_Win32(cx, ref jsObject, name, ref Value);
			}
			else
			{
				if (Xpcom.IsLinux)
					JS_GetProperty_Linux64(cx, ref jsObject, name, ref Value);
				else
					throw new NotImplementedException();
			}

			return Value;
		}
Esempio n. 36
0
 public void SetOnbeforeunloadAttribute(JsVal aOnbeforeunload, IntPtr jsContext)
 {
     throw new NotImplementedException();
 }
Esempio n. 37
0
 public void SetOnresizeAttribute(JsVal aOnresize, IntPtr jsContext)
 {
     throw new NotImplementedException();
 }
Esempio n. 38
0
 public void SetOndeviceproximityAttribute(JsVal aOndeviceproximity, IntPtr jsContext)
 {
     throw new NotImplementedException();
 }
 public static extern bool JS_EvaluateScriptForPrincipals(IntPtr cx, IntPtr obj, IntPtr principals, string src, UInt32 length, string filename, UInt32 lineno, ref JsVal jsval);
Esempio n. 40
0
 public void SetOnpageshowAttribute(JsVal aOnpageshow, IntPtr jsContext)
 {
     throw new NotImplementedException();
 }
 private static extern JSType JS_TypeOfValue_Win32(IntPtr cx, JsVal jsVal);
Esempio n. 42
0
		public static IntPtr JS_ValueToObject(IntPtr cx, JsVal v)
		{
			if (Xpcom.Is32Bit)
			{
				MutableHandle mutableHandle = new MutableHandle();
				if (Xpcom.IsLinux)
					JS_ValueToObject_Linux32(cx, ref v, ref mutableHandle);
				else
					JS_ValueToObject_Win32(cx, ref v, ref mutableHandle);
				return mutableHandle.Handle;
			}
			else
			{
				MutableHandle mutableHandle = new MutableHandle();
				if (Xpcom.IsLinux)
					JS_ValueToObject_Linux64(cx, ref v, ref mutableHandle);
				else
					JS_ValueToObject_Win64(cx, ref v, ref mutableHandle);
				return mutableHandle.Handle;
			}
		}
Esempio n. 43
0
		private static extern JSType JS_TypeOfValue_Win64(IntPtr cx, ref JsVal jsVal);		
 public static extern JSType JS_TypeOfValue(IntPtr cx, JsVal jsVal);
Esempio n. 45
0
		private static extern IntPtr JS_ValueToString_Win64(IntPtr cx, ref JsVal v);		
        /// <summary>
        /// Evaluate javascript in the current context.
        /// </summary>
        /// <param name="jsScript"></param>
        /// <param name="jsval"></param>
        /// <returns></returns>
        public bool EvaluateScript(string jsScript, out string result)
        {
            var ptr = new JsVal();
            IntPtr globalObject = SpiderMonkey.JS_GetGlobalForScopeChain(_cx);
            bool ret = SpiderMonkey.JS_EvaluateScript(_cx, globalObject, jsScript, (uint)jsScript.Length, "script", 1, ref ptr);

            IntPtr jsStringPtr = SpiderMonkey.JS_ValueToString(_cx, ptr);
            result = Marshal.PtrToStringAnsi(SpiderMonkey.JS_EncodeString(_cx, jsStringPtr));
            return ret;
        }
Esempio n. 47
0
 public static extern IntPtr JS_ValueToString(IntPtr cx, JsVal v);