Java 类org.mozilla.javascript.serialize.ScriptableInputStream 实例源码

项目:rhino-android    文件:ContinuationsApiTest.java   
public void testSerializationWithContinuations()
    throws IOException, ClassNotFoundException
{
    Context cx = Context.enter();
    try {
        cx.setOptimizationLevel(-1); // must use interpreter mode
        cx.evaluateString(globalScope,
                "function f(a) { var k = myObject.f(a); var t = []; return k; }",
                "function test source", 1, null);
        Function f = (Function) globalScope.get("f", globalScope);
        Object[] args = { 7 };
        cx.callFunctionWithContinuations(f, globalScope, args);
        fail("Should throw ContinuationPending");
    } catch (ContinuationPending pending) {
        // serialize
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ScriptableOutputStream sos = new ScriptableOutputStream(baos, globalScope);
        sos.writeObject(globalScope);
        sos.writeObject(pending.getContinuation());
        sos.close();
        baos.close();
        byte[] serializedData = baos.toByteArray();

        // deserialize
        ByteArrayInputStream bais = new ByteArrayInputStream(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, 8);
        assertEquals(8, ((Number)result).intValue());
    } finally {
        Context.exit();
    }
}
项目:code404    文件:ContinuationsApiTest.java   
public void testSerializationWithContinuations()
    throws IOException, ClassNotFoundException
{
    Context cx = Context.enter();
    try {
        cx.setOptimizationLevel(-1); // must use interpreter mode
        cx.evaluateString(globalScope,
                "function f(a) { var k = myObject.f(a); var t = []; return k; }",
                "function test source", 1, null);
        Function f = (Function) globalScope.get("f", globalScope);
        Object[] args = { 7 };
        cx.callFunctionWithContinuations(f, globalScope, args);
        fail("Should throw ContinuationPending");
    } catch (ContinuationPending pending) {
        // serialize
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ScriptableOutputStream sos = new ScriptableOutputStream(baos, globalScope);
        sos.writeObject(globalScope);
        sos.writeObject(pending.getContinuation());
        sos.close();
        baos.close();
        byte[] serializedData = baos.toByteArray();

        // deserialize
        ByteArrayInputStream bais = new ByteArrayInputStream(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, 8);
        assertEquals(8, ((Number)result).intValue());
    } finally {
        Context.exit();
    }
}
项目:rhino-jscover    文件:ContinuationsApiTest.java   
public void testSerializationWithContinuations()
    throws IOException, ClassNotFoundException
{
    Context cx = Context.enter();
    try {
        cx.setOptimizationLevel(-1); // must use interpreter mode
        cx.evaluateString(globalScope,
                "function f(a) { var k = myObject.f(a); var t = []; return k; }",
                "function test source", 1, null);
        Function f = (Function) globalScope.get("f", globalScope);
        Object[] args = { 7 };
        cx.callFunctionWithContinuations(f, globalScope, args);
        fail("Should throw ContinuationPending");
    } catch (ContinuationPending pending) {
        // serialize
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ScriptableOutputStream sos = new ScriptableOutputStream(baos, globalScope);
        sos.writeObject(globalScope);
        sos.writeObject(pending.getContinuation());
        sos.close();
        baos.close();
        byte[] serializedData = baos.toByteArray();

        // deserialize
        ByteArrayInputStream bais = new ByteArrayInputStream(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, 8);
        assertEquals(8, ((Number)result).intValue());
    } finally {
        Context.exit();
    }
}
项目:astor    文件:ContinuationsApiTest.java   
public void testSerializationWithContinuations()
    throws IOException, ClassNotFoundException
{
    Context cx = Context.enter();
    try {
        cx.setOptimizationLevel(-1); // must use interpreter mode
        cx.evaluateString(globalScope,
                "function f(a) { var k = myObject.f(a); var t = []; return k; }",
                "function test source", 1, null);
        Function f = (Function) globalScope.get("f", globalScope);
        Object[] args = { 7 };
        cx.callFunctionWithContinuations(f, globalScope, args);
        fail("Should throw ContinuationPending");
    } catch (ContinuationPending pending) {
        // serialize
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ScriptableOutputStream sos = new ScriptableOutputStream(baos, globalScope);
        sos.writeObject(globalScope);
        sos.writeObject(pending.getContinuation());
        sos.close();
        baos.close();
        byte[] serializedData = baos.toByteArray();

        // deserialize
        ByteArrayInputStream bais = new ByteArrayInputStream(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, 8);
        assertEquals(8, ((Number)result).intValue());
    } finally {
        Context.exit();
    }
}
项目:Rhino-Prov-Mod    文件:ContinuationsApiTest.java   
public void testSerializationWithContinuations()
    throws IOException, ClassNotFoundException
{
    Context cx = Context.enter();
    try {
        cx.setOptimizationLevel(-1); // must use interpreter mode
        cx.evaluateString(globalScope,
                "function f(a) { var k = myObject.f(a); var t = []; return k; }",
                "function test source", 1, null);
        Function f = (Function) globalScope.get("f", globalScope);
        Object[] args = { 7 };
        cx.callFunctionWithContinuations(f, globalScope, args);
        fail("Should throw ContinuationPending");
    } catch (ContinuationPending pending) {
        // serialize
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ScriptableOutputStream sos = new ScriptableOutputStream(baos, globalScope);
        sos.writeObject(globalScope);
        sos.writeObject(pending.getContinuation());
        sos.close();
        baos.close();
        byte[] serializedData = baos.toByteArray();

        // deserialize
        ByteArrayInputStream bais = new ByteArrayInputStream(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, 8);
        assertEquals(8, ((Number)result).intValue());
    } finally {
        Context.exit();
    }
}
项目:rhino-android    文件:ContinuationsApiTest.java   
public void testContinuationsInlineFunctionsSerialization() throws IOException, ClassNotFoundException {

      Scriptable globalScope;
      Context cx = Context.enter();
      try {
          globalScope = cx.initStandardObjects();
          cx.setOptimizationLevel(-1); // must use interpreter mode
          globalScope.put("myObject", globalScope, Context.javaToJS(new 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 = { 7 };
          cx.callFunctionWithContinuations(f, globalScope, args);
          fail("Should throw ContinuationPending");
      } catch (ContinuationPending pending) {
          // serialize
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          ScriptableOutputStream sos = new ScriptableOutputStream(baos, globalScope);
          sos.writeObject(globalScope);
          sos.writeObject(pending.getContinuation());
          sos.close();
          baos.close();
          byte[] serializedData = baos.toByteArray();

          // deserialize
          ByteArrayInputStream bais = new ByteArrayInputStream(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");
          assertEquals(5, ((Number) result).intValue());
      } finally {
          Context.exit();
      }
  }
项目:code404    文件:ContinuationsApiTest.java   
public void testContinuationsInlineFunctionsSerialization() throws IOException, ClassNotFoundException {

      Scriptable globalScope;
      Context cx = Context.enter();
      try {
          globalScope = cx.initStandardObjects();
          cx.setOptimizationLevel(-1); // must use interpreter mode
          globalScope.put("myObject", globalScope, Context.javaToJS(new 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 = { 7 };
          cx.callFunctionWithContinuations(f, globalScope, args);
          fail("Should throw ContinuationPending");
      } catch (ContinuationPending pending) {
          // serialize
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          ScriptableOutputStream sos = new ScriptableOutputStream(baos, globalScope);
          sos.writeObject(globalScope);
          sos.writeObject(pending.getContinuation());
          sos.close();
          baos.close();
          byte[] serializedData = baos.toByteArray();

          // deserialize
          ByteArrayInputStream bais = new ByteArrayInputStream(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");
          assertEquals(5, ((Number) result).intValue());
      } finally {
          Context.exit();
      }
  }
项目:rhino-jscover    文件:ContinuationsApiTest.java   
public void testContinuationsInlineFunctionsSerialization() throws IOException, ClassNotFoundException {

      Scriptable globalScope;
      Context cx = Context.enter();
      try {
          globalScope = cx.initStandardObjects();
          cx.setOptimizationLevel(-1); // must use interpreter mode
          globalScope.put("myObject", globalScope, Context.javaToJS(new 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 = { 7 };
          cx.callFunctionWithContinuations(f, globalScope, args);
          fail("Should throw ContinuationPending");
      } catch (ContinuationPending pending) {
          // serialize
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          ScriptableOutputStream sos = new ScriptableOutputStream(baos, globalScope);
          sos.writeObject(globalScope);
          sos.writeObject(pending.getContinuation());
          sos.close();
          baos.close();
          byte[] serializedData = baos.toByteArray();

          // deserialize
          ByteArrayInputStream bais = new ByteArrayInputStream(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");
          assertEquals(5, ((Number) result).intValue());
      } finally {
          Context.exit();
      }
  }
项目:astor    文件:ContinuationsApiTest.java   
public void testContinuationsInlineFunctionsSerialization() throws IOException, ClassNotFoundException {

      Scriptable globalScope;
      Context cx = Context.enter();
      try {
          globalScope = cx.initStandardObjects();
          cx.setOptimizationLevel(-1); // must use interpreter mode
          globalScope.put("myObject", globalScope, Context.javaToJS(new 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 = { 7 };
          cx.callFunctionWithContinuations(f, globalScope, args);
          fail("Should throw ContinuationPending");
      } catch (ContinuationPending pending) {
          // serialize
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          ScriptableOutputStream sos = new ScriptableOutputStream(baos, globalScope);
          sos.writeObject(globalScope);
          sos.writeObject(pending.getContinuation());
          sos.close();
          baos.close();
          byte[] serializedData = baos.toByteArray();

          // deserialize
          ByteArrayInputStream bais = new ByteArrayInputStream(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");
          assertEquals(5, ((Number) result).intValue());
      } finally {
          Context.exit();
      }
  }
项目:Rhino-Prov-Mod    文件:ContinuationsApiTest.java   
public void testContinuationsInlineFunctionsSerialization() throws IOException, ClassNotFoundException {

      Scriptable globalScope;
      Context cx = Context.enter();
      try {
          globalScope = cx.initStandardObjects();
          cx.setOptimizationLevel(-1); // must use interpreter mode
          globalScope.put("myObject", globalScope, Context.javaToJS(new 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 = { 7 };
          cx.callFunctionWithContinuations(f, globalScope, args);
          fail("Should throw ContinuationPending");
      } catch (ContinuationPending pending) {
          // serialize
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          ScriptableOutputStream sos = new ScriptableOutputStream(baos, globalScope);
          sos.writeObject(globalScope);
          sos.writeObject(pending.getContinuation());
          sos.close();
          baos.close();
          byte[] serializedData = baos.toByteArray();

          // deserialize
          ByteArrayInputStream bais = new ByteArrayInputStream(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");
          assertEquals(5, ((Number) result).intValue());
      } finally {
          Context.exit();
      }
  }