Skip to content

Commit

Permalink
Javenode v0.1.1 (#1)
Browse files Browse the repository at this point in the history
* Added `JNEventLoopOptions`
* Added module `console`
    * `assert(value[, ...message])`
    * `clear()`
    * `count([label])`
    * `countReset([label])`
    * `debug([data][, ...args])`
    * `error([data][, ...args])`
    * `info([data][, ...args])`
    * `log([data][, ...args])`
    * `time([label])`
    * `timeEnd([label])`
    * `timeLog([label][, ...data])`
    * `trace([message][, ...args])`
    * `warn([data][, ...args])`
  • Loading branch information
caoccao authored Oct 7, 2021
1 parent 18d623e commit 3c9ce8b
Show file tree
Hide file tree
Showing 149 changed files with 70,794 additions and 156 deletions.
64 changes: 28 additions & 36 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Major Features
* Native Event Loop (vert.x)
* Same Modules as Node.js
* Modules
* console
* timers
* timers/promises

Expand All @@ -48,63 +49,54 @@ Maven
<dependency>
<groupId>com.caoccao.javet</groupId>
<artifactId>javenode</artifactId>
<version>0.1.0</version>
<version>0.1.1</version>
</dependency>
Gradle Kotlin DSL
^^^^^^^^^^^^^^^^^

.. code-block:: kotlin
implementation("com.caoccao.javet:javenode:0.1.0")
implementation("com.caoccao.javet:javenode:0.1.1")
Gradle Groovy DSL
^^^^^^^^^^^^^^^^^

.. code-block:: groovy
implementation 'com.caoccao.javet:javenode:0.1.0'
implementation 'com.caoccao.javet:javenode:0.1.1'
Hello Javenode (Sync)
---------------------
Hello Javenode (Static Import)
------------------------------

.. code-block:: java
try (V8Runtime v8Runtime = V8Host.getV8Instance().createV8Runtime()) {
JavetStandardConsoleInterceptor consoleInterceptor = new JavetStandardConsoleInterceptor(v8Runtime);
consoleInterceptor.register(v8Runtime.getGlobalObject());
try (JNEventLoop eventLoop = new JNEventLoop(v8Runtime)) {
eventLoop.loadStaticModule(JNModuleType.TIMERS);
v8Runtime.getExecutor("const a = [];\n" +
"setTimeout(() => a.push('Hello Javenode'), 10);").executeVoid();
} finally {
v8Runtime.getExecutor("console.log(a[0]);").executeVoid();
consoleInterceptor.unregister(v8Runtime.getGlobalObject());
v8Runtime.lowMemoryNotification();
}
try (V8Runtime v8Runtime = V8Host.getV8Instance().createV8Runtime();
JNEventLoop eventLoop = new JNEventLoop(v8Runtime)) {
eventLoop.loadStaticModules(JNModuleType.CONSOLE, JNModuleType.TIMERS);
v8Runtime.getExecutor("const a = [];\n" +
"setTimeout(() => a.push('Hello Javenode'), 10);").executeVoid();
eventLoop.await();
v8Runtime.getExecutor("console.log(a[0]);").executeVoid();
}
Hello Javenode (Async)
----------------------
Hello Javenode (Dynamic Import)
-------------------------------

.. code-block:: java
try (V8Runtime v8Runtime = V8Host.getV8Instance().createV8Runtime()) {
JavetStandardConsoleInterceptor consoleInterceptor = new JavetStandardConsoleInterceptor(v8Runtime);
consoleInterceptor.register(v8Runtime.getGlobalObject());
try (JNEventLoop eventLoop = new JNEventLoop(v8Runtime)) {
eventLoop.registerDynamicModule(JNModuleType.TIMERS_PROMISES);
v8Runtime.getExecutor(
"import { setTimeout } from 'timers/promises';\n" +
"const a = [];\n" +
"setTimeout(10, 'Hello Javenode')\n" +
" .then(result => a.push(result));\n" +
"globalThis.a = a;").setModule(true).executeVoid();
} finally {
v8Runtime.getExecutor("console.log(a[0]);").executeVoid();
consoleInterceptor.unregister(v8Runtime.getGlobalObject());
v8Runtime.lowMemoryNotification();
}
try (V8Runtime v8Runtime = V8Host.getV8Instance().createV8Runtime();
JNEventLoop eventLoop = new JNEventLoop(v8Runtime)) {
eventLoop.loadStaticModules(JNModuleType.CONSOLE);
eventLoop.registerDynamicModules(JNModuleType.TIMERS_PROMISES);
v8Runtime.getExecutor(
"import { setTimeout } from 'timers/promises';\n" +
"const a = [];\n" +
"setTimeout(10, 'Hello Javenode')\n" +
" .then(result => a.push(result));\n" +
"globalThis.a = a;").setModule(true).executeVoid();
eventLoop.await();
v8Runtime.getExecutor("console.log(a[0]);").executeVoid();
}
TODO
Expand All @@ -122,4 +114,4 @@ Documents
=========

* `Javet <https://github.com/caoccao/Javet>`_
* `Release Notes <docs/release_notes.rst>`_
* `Javenode Document Portal <https://www.caoccao.com/Javenode/>`_
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ repositories {
}

group = "com.caoccao.javet"
version = "0.1.0"
version = "0.1.1"


repositories {
Expand Down
Empty file added docs/.nojekyll
Empty file.
Loading

0 comments on commit 3c9ce8b

Please sign in to comment.