-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DRAFT: working language server connection
- Loading branch information
Showing
9 changed files
with
143 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
lib/java/polyglot-ydoc-server/src/main/java/org/enso/polyfill/web/PerformancePolyfill.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.enso.polyfill.web; | ||
|
||
import java.util.Arrays; | ||
import org.enso.polyfill.Polyfill; | ||
import org.graalvm.polyglot.Context; | ||
import org.graalvm.polyglot.Source; | ||
import org.graalvm.polyglot.Value; | ||
import org.graalvm.polyglot.proxy.ProxyExecutable; | ||
|
||
public final class PerformancePolyfill implements ProxyExecutable, Polyfill { | ||
|
||
private static final String NOW = "now"; | ||
|
||
private static final String PERFORMANCE_POLYFILL_JS = "performance-polyfill.js"; | ||
|
||
public PerformancePolyfill() { | ||
} | ||
|
||
@Override | ||
public void initialize(Context ctx) { | ||
Source performancePolyfillJs = Source | ||
.newBuilder("js", PerformancePolyfill.class.getResource(PERFORMANCE_POLYFILL_JS)) | ||
.buildLiteral(); | ||
|
||
ctx.eval(performancePolyfillJs).execute(this); | ||
} | ||
|
||
@Override | ||
public Object execute(Value... arguments) { | ||
var command = arguments[0].asString(); | ||
System.err.println(command + " " + Arrays.toString(arguments)); | ||
|
||
return switch (command) { | ||
case NOW -> | ||
System.currentTimeMillis(); | ||
|
||
default -> | ||
throw new IllegalStateException(command); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...ava/polyglot-ydoc-server/src/main/resources/org/enso/polyfill/web/performance-polyfill.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
(function (jvm) { | ||
|
||
class Performance { | ||
|
||
now() { | ||
return jvm('now'); | ||
}; | ||
} | ||
|
||
globalThis.performance = new Performance(); | ||
|
||
}) |
57 changes: 57 additions & 0 deletions
57
lib/java/polyglot-ydoc-server/src/test/java/org/enso/polyfill/PerformanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.enso.polyfill; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import org.enso.polyfill.web.PerformancePolyfill; | ||
import org.graalvm.polyglot.Context; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class PerformanceTest { | ||
|
||
private Context context; | ||
private ExecutorService executor; | ||
|
||
public PerformanceTest() { | ||
} | ||
|
||
@Before | ||
public void setup() throws Exception { | ||
executor = Executors.newSingleThreadExecutor(); | ||
var eventTarget = new PerformancePolyfill(); | ||
var b = Context.newBuilder("js"); | ||
|
||
var chromePort = Integer.getInteger("inspectPort", -1); | ||
if (chromePort > 0) { | ||
b.option("inspect", ":" + chromePort); | ||
} | ||
|
||
context = CompletableFuture | ||
.supplyAsync(() -> { | ||
var ctx = b.build(); | ||
eventTarget.initialize(ctx); | ||
return ctx; | ||
}, executor) | ||
.get(); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
executor.close(); | ||
context.close(); | ||
} | ||
|
||
@Test | ||
public void now() throws Exception { | ||
var result = CompletableFuture | ||
.supplyAsync(() -> context.eval("js", "performance.now()"), executor) | ||
.get(); | ||
|
||
Assert.assertTrue(result.asLong() > 0); | ||
Assert.assertTrue(result.asLong() <= System.currentTimeMillis()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters