Compare commits
5 Commits
0.9.8-beta
...
0.9.12-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
d8ea6557df
|
|||
|
5ba858545a
|
|||
|
446ecd8f2b
|
|||
|
fbf103439a
|
|||
|
b30f94de8f
|
2
.github/workflows/tagged-release.yml
vendored
2
.github/workflows/tagged-release.yml
vendored
@@ -3,7 +3,7 @@ name: "tagged-release"
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- "v*"
|
- "*"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
tagged-release:
|
tagged-release:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
project_group = me.topchetoeu
|
project_group = me.topchetoeu
|
||||||
project_name = jscript
|
project_name = jscript
|
||||||
project_version = 0.9.7-beta
|
project_version = 0.9.12-beta
|
||||||
main_class = me.topchetoeu.jscript.utils.JScriptRepl
|
main_class = me.topchetoeu.jscript.utils.JScriptRepl
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class AsyncFunctionLib extends FunctionValue {
|
|||||||
public void onReject(EngineException err) {
|
public void onReject(EngineException err) {
|
||||||
next(ctx, Values.NO_RETURN, err);
|
next(ctx, Values.NO_RETURN, err);
|
||||||
}
|
}
|
||||||
});
|
}.defer(ctx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public class AsyncGeneratorLib {
|
|||||||
@Override public void onReject(EngineException err) {
|
@Override public void onReject(EngineException err) {
|
||||||
next(ctx, Values.NO_RETURN, Values.NO_RETURN, err);
|
next(ctx, Values.NO_RETURN, Values.NO_RETURN, err);
|
||||||
}
|
}
|
||||||
});
|
}.defer(ctx));
|
||||||
}
|
}
|
||||||
else if (state == 2) {
|
else if (state == 2) {
|
||||||
var obj = new ObjectValue();
|
var obj = new ObjectValue();
|
||||||
|
|||||||
@@ -53,26 +53,29 @@ public class PromiseLib {
|
|||||||
private Object val;
|
private Object val;
|
||||||
|
|
||||||
private void resolveSynchronized(Context ctx, Object val, int newState) {
|
private void resolveSynchronized(Context ctx, Object val, int newState) {
|
||||||
if (!ctx.hasNotNull(EventLoop.KEY)) throw EngineException.ofError("No event loop");
|
this.val = val;
|
||||||
|
this.state = newState;
|
||||||
|
|
||||||
ctx.get(EventLoop.KEY).pushMsg(() -> {
|
for (var handle : handles) {
|
||||||
this.val = val;
|
if (newState == STATE_FULFILLED) handle.onFulfil(val);
|
||||||
this.state = newState;
|
if (newState == STATE_REJECTED) {
|
||||||
|
handle.onReject((EngineException)val);
|
||||||
for (var handle : handles) {
|
handled = true;
|
||||||
if (newState == STATE_FULFILLED) handle.onFulfil(val);
|
|
||||||
if (newState == STATE_REJECTED) {
|
|
||||||
handle.onReject((EngineException)val);
|
|
||||||
handled = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (state == STATE_REJECTED && !handled) {
|
if (state == STATE_REJECTED && !handled) {
|
||||||
Values.printError(((EngineException)val).setCtx(ctx), "(in promise)");
|
Values.printError(((EngineException)val).setCtx(ctx), "(in promise)");
|
||||||
}
|
}
|
||||||
|
|
||||||
handles = null;
|
handles = null;
|
||||||
}, true);
|
|
||||||
|
// ctx.get(EventLoop.KEY).pushMsg(() -> {
|
||||||
|
// if (!ctx.hasNotNull(EventLoop.KEY)) throw EngineException.ofError("No event loop");
|
||||||
|
|
||||||
|
|
||||||
|
// handles = null;
|
||||||
|
// }, true);
|
||||||
|
|
||||||
}
|
}
|
||||||
private synchronized void resolve(Context ctx, Object val, int newState) {
|
private synchronized void resolve(Context ctx, Object val, int newState) {
|
||||||
|
|||||||
@@ -2,11 +2,9 @@ package me.topchetoeu.jscript.runtime;
|
|||||||
|
|
||||||
import java.util.concurrent.PriorityBlockingQueue;
|
import java.util.concurrent.PriorityBlockingQueue;
|
||||||
|
|
||||||
import me.topchetoeu.jscript.common.Filename;
|
|
||||||
import me.topchetoeu.jscript.common.ResultRunnable;
|
import me.topchetoeu.jscript.common.ResultRunnable;
|
||||||
import me.topchetoeu.jscript.common.events.DataNotifier;
|
import me.topchetoeu.jscript.common.events.DataNotifier;
|
||||||
import me.topchetoeu.jscript.runtime.exceptions.InterruptException;
|
import me.topchetoeu.jscript.runtime.exceptions.InterruptException;
|
||||||
import me.topchetoeu.jscript.runtime.values.FunctionValue;
|
|
||||||
|
|
||||||
public class Engine implements EventLoop {
|
public class Engine implements EventLoop {
|
||||||
private static class Task<T> implements Comparable<Task<?>> {
|
private static class Task<T> implements Comparable<Task<?>> {
|
||||||
@@ -78,18 +76,6 @@ public class Engine implements EventLoop {
|
|||||||
return this.thread != null;
|
return this.thread != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataNotifier<Object> pushMsg(boolean micro, Environment env, FunctionValue func, Object thisArg, Object ...args) {
|
|
||||||
return pushMsg(() -> {
|
|
||||||
return func.call(new Context(env), thisArg, args);
|
|
||||||
}, micro);
|
|
||||||
}
|
|
||||||
public DataNotifier<Object> pushMsg(boolean micro, Environment env, Filename filename, String raw, Object thisArg, Object ...args) {
|
|
||||||
return pushMsg(() -> {
|
|
||||||
var ctx = new Context(env);
|
|
||||||
return ctx.compile(filename, raw).call(new Context(env), thisArg, args);
|
|
||||||
}, micro);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Engine() {
|
public Engine() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package me.topchetoeu.jscript.runtime;
|
package me.topchetoeu.jscript.runtime;
|
||||||
|
|
||||||
|
import me.topchetoeu.jscript.common.Filename;
|
||||||
import me.topchetoeu.jscript.common.ResultRunnable;
|
import me.topchetoeu.jscript.common.ResultRunnable;
|
||||||
import me.topchetoeu.jscript.common.events.DataNotifier;
|
import me.topchetoeu.jscript.common.events.DataNotifier;
|
||||||
import me.topchetoeu.jscript.runtime.exceptions.EngineException;
|
import me.topchetoeu.jscript.runtime.exceptions.EngineException;
|
||||||
|
import me.topchetoeu.jscript.runtime.values.FunctionValue;
|
||||||
|
|
||||||
public interface EventLoop {
|
public interface EventLoop {
|
||||||
public static final Key<EventLoop> KEY = new Key<>();
|
public static final Key<EventLoop> KEY = new Key<>();
|
||||||
@@ -20,4 +22,16 @@ public interface EventLoop {
|
|||||||
public default DataNotifier<Void> pushMsg(Runnable runnable, boolean micro) {
|
public default DataNotifier<Void> pushMsg(Runnable runnable, boolean micro) {
|
||||||
return pushMsg(() -> { runnable.run(); return null; }, micro);
|
return pushMsg(() -> { runnable.run(); return null; }, micro);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public default DataNotifier<Object> pushMsg(boolean micro, Environment env, FunctionValue func, Object thisArg, Object ...args) {
|
||||||
|
return pushMsg(() -> {
|
||||||
|
return func.call(new Context(env), thisArg, args);
|
||||||
|
}, micro);
|
||||||
|
}
|
||||||
|
public default DataNotifier<Object> pushMsg(boolean micro, Environment env, Filename filename, String raw, Object thisArg, Object ...args) {
|
||||||
|
return pushMsg(() -> {
|
||||||
|
var ctx = new Context(env);
|
||||||
|
return ctx.compile(filename, raw).call(new Context(env), thisArg, args);
|
||||||
|
}, micro);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,17 @@
|
|||||||
package me.topchetoeu.jscript.runtime;
|
package me.topchetoeu.jscript.runtime;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface Extensions {
|
public interface Extensions {
|
||||||
|
public static Extensions EMPTY = new Extensions() {
|
||||||
|
@Override public <T> void add(Key<T> key, T obj) { }
|
||||||
|
@Override public boolean remove(Key<?> key) { return false; }
|
||||||
|
|
||||||
|
@Override public <T> T get(Key<T> key) { return null; }
|
||||||
|
@Override public boolean has(Key<?> key) { return false; }
|
||||||
|
@Override public Iterable<Key<?>> keys() { return List.of(); }
|
||||||
|
};
|
||||||
|
|
||||||
<T> T get(Key<T> key);
|
<T> T get(Key<T> key);
|
||||||
<T> void add(Key<T> key, T obj);
|
<T> void add(Key<T> key, T obj);
|
||||||
Iterable<Key<?>> keys();
|
Iterable<Key<?>> keys();
|
||||||
@@ -35,4 +46,9 @@ public interface Extensions {
|
|||||||
add((Key<Object>)key, (Object)source.get(key));
|
add((Key<Object>)key, (Object)source.get(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Extensions wrap(Extensions ext) {
|
||||||
|
if (ext == null) return EMPTY;
|
||||||
|
else return ext;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user