Skip to content

Commit 303c1de

Browse files
JaroslavTulachFrizi
authored andcommitted
getEventListeners returns ProxyArray (#13057)
1 parent f075103 commit 303c1de

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

lib/java/ydoc-polyfill/src/main/java/org/enso/ydoc/polyfill/web/EventTarget.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.function.Function;
77
import org.enso.ydoc.polyfill.Arguments;
88
import org.graalvm.polyglot.Value;
9+
import org.graalvm.polyglot.proxy.ProxyArray;
910
import org.graalvm.polyglot.proxy.ProxyExecutable;
1011
import org.slf4j.Logger;
1112
import org.slf4j.LoggerFactory;
@@ -86,8 +87,9 @@ private static final class EventStore {
8687
this.listeners = listeners;
8788
}
8889

89-
public Value[] getEventListeners(String type) {
90-
return listeners.getOrDefault(type, Set.of()).toArray(new Value[0]);
90+
public ProxyArray getEventListeners(String type) {
91+
var arr = listeners.getOrDefault(type, Set.of()).toArray(new Value[0]);
92+
return ProxyArray.fromArray((Object[]) arr);
9193
}
9294

9395
public void addEventListener(String type, Value listener) {

lib/java/ydoc-polyfill/src/main/java/org/enso/ydoc/polyfill/web/WebEnvironment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
public final class WebEnvironment {
1212

1313
public static final HostAccess.Builder defaultHostAccess =
14-
HostAccess.newBuilder(HostAccess.EXPLICIT).allowArrayAccess(true).allowBufferAccess(true);
14+
HostAccess.newBuilder(HostAccess.EXPLICIT).allowBufferAccess(true);
1515

1616
private WebEnvironment() {}
1717

lib/java/ydoc-polyfill/src/test/java/org/enso/ydoc/polyfill/web/EventTargetTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ public void dispatchEvent() throws Exception {
4343
"""
4444
var count = 0;
4545
var et = new EventTarget();
46-
et.addEventListener('inc', () => count += 1);
46+
var l = () => count += 1;
47+
et.addEventListener('inc', l);
48+
var arr = et.getEventListeners('inc');
49+
if (arr.length != 1) {
50+
throw 'Expecting one listener';
51+
}
52+
if (arr[0] != l) {
53+
throw 'Expecting the one listener!';
54+
}
4755
et.dispatchEvent({type: 'inc'});
4856
count;
4957
""";

0 commit comments

Comments
 (0)