Class ScriptableInputStream is used to read in a JavaScript object or function previously serialized with a ScriptableOutputStream.
Class ScriptableInputStream is used to read in a JavaScript object or function previously serialized with a ScriptableOutputStream. References to names in the exclusion list replaced with references to the top-level scope specified during creation of the ScriptableInputStream.
Inheritance: Sharpen.ObjectInputStream
コード例 #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>
		/// <exception cref="System.TypeLoadException"></exception>
		public static object Deserialize(Context cx, Scriptable thisObj, object[] args, Function funObj)
		{
			if (args.Length < 1)
			{
				throw Context.ReportRuntimeError("Expected a filename to read the serialization from");
			}
			string filename = Context.ToString(args[0]);
			FileInputStream fis = new FileInputStream(filename);
			Scriptable scope = ScriptableObject.GetTopLevelScope(thisObj);
			ObjectInputStream @in = new ScriptableInputStream(fis, scope);
			object deserialized = @in.ReadObject();
			@in.Close();
			return Context.ToObject(deserialized, scope);
		}