final public T convertNoThrow(Environment env, TraceInfo trace, Memory arg) { try { return convert(env, trace, arg); } catch (Throwable throwable) { env.forwardThrow(throwable); return null; } }
default Memory callMethod(Environment env, String name, Memory... args) { try { return env.invokeMethod(this, name, args); } catch (Throwable throwable) { env.forwardThrow(throwable); return Memory.NULL; } }
final public Memory unconvertNoThow(Environment env, TraceInfo trace, T arg) { try { return unconvert(env, trace, arg); } catch (Throwable throwable) { env.forwardThrow(throwable); return Memory.NULL; } }
@Override public int compare(Memory o1, Memory o2) { if (invoker == null) { return 0; } try { return invoker.call(o1, o2).toInteger(); } catch (Throwable throwable) { env.forwardThrow(throwable); return 0; } } };
@Override public Memory formatTo(Environment env, Memory... args) { try { args[1].toObject(Stream.class).write(env, format(env, args), Memory.NULL); } catch (IOException e) { env.forwardThrow(e); } return Memory.NULL; } }
@Override public Memory call(Memory[] args) { try { return ObjectMemory.valueOf( promise.then(env, Invoker.create(env, args[0]), Invoker.create(env, args[1])) ); } catch (Exception e) { env.forwardThrow(e); return Memory.NULL; } } }));
public static OutputStream getOutputStream(Environment env, Memory arg){ try { if (arg.instanceOf(FileObject.class)){ return new FileOutputStream(arg.toObject(FileObject.class).file); } else if (arg.instanceOf(Stream.class)){ return new StreamOutputStream(env, arg.toObject(Stream.class)); } else { StreamOutputStream outputStream = new StreamOutputStream(env, Stream.create(env, arg.toString(), "w+")); outputStream.autoClose = true; return outputStream; } } catch (IOException e){ env.exception(WrapIOException.class, e.getMessage()); } catch (Throwable throwable) { env.forwardThrow(throwable); } return null; }
/** * @param arg - File path or Stream object * @return */ public static InputStream getInputStream(Environment env, Memory arg){ try { if (arg.instanceOf(FileObject.class)){ return new FileInputStream(arg.toObject(FileObject.class).file); } else if (arg.instanceOf(Stream.class)){ if (arg.instanceOf(ResourceStream.class)) { return arg.toObject(ResourceStream.class).getInputStream(); } return new StreamInputStream(env, arg.toObject(Stream.class)); } else { StreamInputStream inputStream = new StreamInputStream(env, Stream.create(env, arg.toString(), "r")); inputStream.autoClose = true; return inputStream; } } catch (IOException e){ env.exception(WrapIOException.class, e.getMessage()); } catch (Throwable throwable) { env.forwardThrow(throwable); } return null; }
@Runtime.Immutable public static Memory count(Environment env, TraceInfo trace, Memory var, int mode){ switch (var.type){ case ARRAY: if (mode == 1){ return LongMemory.valueOf(recursive_count(env, trace, var.toValue(ArrayMemory.class), null)); } else return LongMemory.valueOf(var.toValue(ArrayMemory.class).size()); case NULL: return Memory.CONST_INT_0; case OBJECT: ObjectMemory objectMemory = var.toValue(ObjectMemory.class); if (objectMemory.value instanceof Countable){ try { return env.invokeMethod(objectMemory, "count"); } catch (Throwable throwable) { env.forwardThrow(throwable); } } else { return Memory.CONST_INT_1; } default: return Memory.CONST_INT_1; } }
@Signature public void __construct(Environment env, @Nullable Invoker executor) { if (executor != null) { WrapInvoker makeFulfill = new WrapInvoker(env, ArrayMemory.of(ObjectMemory.valueOf(this), StringMemory.valueOf("makeFulfill"))); WrapInvoker makeReject = new WrapInvoker(env, ArrayMemory.of(ObjectMemory.valueOf(this), StringMemory.valueOf("makeReject"))); try { executor.call(ObjectMemory.valueOf(makeFulfill), ObjectMemory.valueOf(makeReject)); } catch (Throwable e) { try { if (e instanceof IObject) { makeReject.call(env, ObjectMemory.valueOf((IObject) e)); } else { makeReject.call(env, ObjectMemory.valueOf(new JavaException(env, e))); } } catch (Exception e2) { env.forwardThrow(e2); } } } }