@Test public void testUnwrapWithDate() throws ScriptException, NoSuchMethodException { engine.eval("function test() { return new Date(0); }"); ScriptObjectMirror object = (ScriptObjectMirror) ((Invocable) engine).invokeFunction("test"); Object obj = ScriptObjectMirrors.unwrap(object); assertTrue(obj instanceof Calendar); Calendar expectedCal = Calendar.getInstance(); expectedCal.setTimeInMillis(0); assertEquals(expectedCal, obj); }
public static Object unwrap(ScriptObjectMirror jso) { if (jso.isArray()) { return unwrapList(jso); } else if (JAVASCRIPT_MAP_CLASS_TYPE.equals(jso.getClassName())) { return unwrapMap(jso); } else if (JAVASCRIPT_DATE_CLASS_TYPE.equals(jso.getClassName())) { return unwrapDate(jso); } else if (JAVASCRIPT_GLOBAL_CLASS_TYPE.equals(jso.getClassName())) { return null; } else if (JAVASCRIPT_FUNCTION_CLASS_TYPE.equals(jso.getClassName())) { return null; } else { throw new UnsupportedOperationException(jso.getClassName() + " is not supported!"); } }
ScriptObjectMirrors { public static Object unwrap(ScriptObjectMirror jso) { if (jso.isArray()) { return unwrapList(jso); } else if (JAVASCRIPT_MAP_CLASS_TYPE.equals(jso.getClassName())) { return unwrapMap(jso); } else if (JAVASCRIPT_DATE_CLASS_TYPE.equals(jso.getClassName())) { return unwrapDate(jso); } else if (JAVASCRIPT_GLOBAL_CLASS_TYPE.equals(jso.getClassName())) { return null; } else if (JAVASCRIPT_FUNCTION_CLASS_TYPE.equals(jso.getClassName())) { return null; } else { throw new UnsupportedOperationException(jso.getClassName() + " is not supported!"); } } }
ScriptObjectMirrors { public static Object unwrap(ScriptObjectMirror jso) { if (jso.isArray()) { return unwrapList(jso); } else if (JAVASCRIPT_MAP_CLASS_TYPE.equals(jso.getClassName())) { return unwrapMap(jso); } else if (JAVASCRIPT_DATE_CLASS_TYPE.equals(jso.getClassName())) { return unwrapDate(jso); } else if (JAVASCRIPT_GLOBAL_CLASS_TYPE.equals(jso.getClassName())) { return null; } else if (JAVASCRIPT_FUNCTION_CLASS_TYPE.equals(jso.getClassName())) { return null; } else { throw new UnsupportedOperationException(jso.getClassName() + " is not supported!"); } } private  ScriptObjectMirrors(); }
ScriptObjectMirrors { public static Object unwrap(ScriptObjectMirror jso) { if (jso.isArray()) { return unwrapList(jso); } else if (JAVASCRIPT_MAP_CLASS_TYPE.equals(jso.getClassName())) { return unwrapMap(jso); } else if (JAVASCRIPT_DATE_CLASS_TYPE.equals(jso.getClassName())) { return unwrapDate(jso); } else if (JAVASCRIPT_GLOBAL_CLASS_TYPE.equals(jso.getClassName())) { return null; } else if (JAVASCRIPT_FUNCTION_CLASS_TYPE.equals(jso.getClassName())) { return null; } else { throw new UnsupportedOperationException(jso.getClassName() + " is not supported!"); } } private  ScriptObjectMirrors(); static Object unwrap(ScriptObjectMirror jso); static List<Object> unwrapList(ScriptObjectMirror jso); static Map<String, Object> unwrapMap(ScriptObjectMirror jso); static Calendar unwrapDate(ScriptObjectMirror jso); static Object wrap(Map<String, Object> map); }
ScriptObjectMirrors { public static Object unwrap(ScriptObjectMirror jso) { if (jso.isArray()) { return unwrapList(jso); } else if (JAVASCRIPT_MAP_CLASS_TYPE.equals(jso.getClassName())) { return unwrapMap(jso); } else if (JAVASCRIPT_DATE_CLASS_TYPE.equals(jso.getClassName())) { return unwrapDate(jso); } else if (JAVASCRIPT_GLOBAL_CLASS_TYPE.equals(jso.getClassName())) { return null; } else if (JAVASCRIPT_FUNCTION_CLASS_TYPE.equals(jso.getClassName())) { return null; } else { throw new UnsupportedOperationException(jso.getClassName() + " is not supported!"); } } private  ScriptObjectMirrors(); static Object unwrap(ScriptObjectMirror jso); static List<Object> unwrapList(ScriptObjectMirror jso); static Map<String, Object> unwrapMap(ScriptObjectMirror jso); static Calendar unwrapDate(ScriptObjectMirror jso); static Object wrap(Map<String, Object> map);  }