예제 #1
0
		public virtual void TestContinuationsInlineFunctionsSerialization()
		{
			Scriptable globalScope;
			Context cx = Context.Enter();
			try
			{
				globalScope = cx.InitStandardObjects();
				cx.SetOptimizationLevel(-1);
				// must use interpreter mode
				globalScope.Put("myObject", globalScope, Context.JavaToJS(new ContinuationsApiTest.MyClass(), globalScope));
			}
			finally
			{
				Context.Exit();
			}
			cx = Context.Enter();
			try
			{
				cx.SetOptimizationLevel(-1);
				// must use interpreter mode
				cx.EvaluateString(globalScope, "function f(a) { var k = eval(myObject.h()); var t = []; return k; }", "function test source", 1, null);
				Function f = (Function)globalScope.Get("f", globalScope);
				object[] args = new object[] { 7 };
				cx.CallFunctionWithContinuations(f, globalScope, args);
				NUnit.Framework.Assert.Fail("Should throw ContinuationPending");
			}
			catch (ContinuationPending pending)
			{
				// serialize
				MemoryStream baos = new MemoryStream();
				ScriptableOutputStream sos = new ScriptableOutputStream(baos, globalScope);
				sos.WriteObject(globalScope);
				sos.WriteObject(pending.GetContinuation());
				sos.Close();
				baos.Close();
				byte[] serializedData = baos.ToArray();
				// deserialize
				MemoryStream bais = new MemoryStream(serializedData);
				ScriptableInputStream sis = new ScriptableInputStream(bais, globalScope);
				globalScope = (Scriptable)sis.ReadObject();
				object continuation = sis.ReadObject();
				sis.Close();
				bais.Close();
				object result = cx.ResumeContinuation(continuation, globalScope, "2+3");
				NUnit.Framework.Assert.AreEqual(5, System.Convert.ToInt32(((Number)result)));
			}
			finally
			{
				Context.Exit();
			}
		}
예제 #2
0
파일: Global.cs 프로젝트: hazzik/Rhino.Net
		/// <exception cref="System.IO.IOException"></exception>
		public static void Serialize(Context cx, Scriptable thisObj, object[] args, Function funObj)
		{
			if (args.Length < 2)
			{
				throw Context.ReportRuntimeError("Expected an object to serialize and a filename to write " + "the serialization to");
			}
			object obj = args[0];
			string filename = Context.ToString(args[1]);
			FileOutputStream fos = new FileOutputStream(filename);
			Scriptable scope = ScriptableObject.GetTopLevelScope(thisObj);
			ScriptableOutputStream @out = new ScriptableOutputStream(fos, scope);
			@out.WriteObject(obj);
			@out.Close();
		}