Skip to content

Commit 9e6a50c

Browse files
committed
feat(graalvm): add support for MessageChannel
feat: add `MessageChannel` interface and basic impl feat: add `MessagePort` interface and basic impl test: add initial tests for channel messaging test: add `MessageChannel` and `MessagePort` to common minimum chore: re-pin api for `graalvm` module Fixes and closes #1317 Relates-to: #1317 Signed-off-by: Sam Gammon <[email protected]>
1 parent cde1743 commit 9e6a50c

File tree

12 files changed

+1035
-19
lines changed

12 files changed

+1035
-19
lines changed

packages/engine/src/main/kotlin/elide/runtime/core/PluginRegistry.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ package elide.runtime.core
2424
* @param configure A configuration DSL block to be applied to the plugin on installation.
2525
* @return A plugin instance added to the registry after installation.
2626
*/
27-
@Deprecated("Use installLazy instead", ReplaceWith("installLazy(plugin, configure)"))
27+
@Deprecated("Use configure instead, which is lazy", ReplaceWith("configure(plugin, configure)"))
2828
public fun <C : Any, I : Any> install(plugin: EnginePlugin<C, I>, configure: C.() -> Unit = { }): I
2929

3030
/**

packages/graalvm/api/graalvm.api

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,6 +2254,20 @@ public abstract interface class elide/runtime/intrinsics/js/MapLike$Entry {
22542254
public abstract fun getValue ()Ljava/lang/Object;
22552255
}
22562256

2257+
public abstract interface class elide/runtime/intrinsics/js/MessageChannel : elide/runtime/interop/ReadOnlyProxyObject {
2258+
public abstract fun getPort1 ()Lelide/runtime/intrinsics/js/MessagePort;
2259+
public abstract fun getPort2 ()Lelide/runtime/intrinsics/js/MessagePort;
2260+
}
2261+
2262+
public abstract interface class elide/runtime/intrinsics/js/MessagePort : elide/runtime/intrinsics/js/node/events/EventTarget, java/lang/AutoCloseable, org/graalvm/polyglot/proxy/ProxyObject {
2263+
public abstract fun close ()V
2264+
public fun postMessage (Ljava/lang/Object;Lelide/runtime/intrinsics/js/messaging/PostMessageOptions;)V
2265+
public fun postMessage (Ljava/lang/Object;Ljava/util/Collection;)V
2266+
public abstract fun postMessage (Ljava/lang/Object;Ljava/util/Collection;Lelide/runtime/intrinsics/js/messaging/PostMessageOptions;)V
2267+
public fun postMessage ([Lorg/graalvm/polyglot/Value;)V
2268+
public abstract fun start ()V
2269+
}
2270+
22572271
public abstract interface class elide/runtime/intrinsics/js/MultiMapLike : elide/runtime/intrinsics/js/MapLike {
22582272
public abstract fun getAll (Ljava/lang/Object;)Ljava/util/List;
22592273
}
@@ -2345,6 +2359,9 @@ public abstract interface class elide/runtime/intrinsics/js/Timers {
23452359
public static synthetic fun setTimeout$default (Lelide/runtime/intrinsics/js/Timers;Ljava/lang/Long;[Ljava/lang/Object;Lorg/graalvm/polyglot/Value;ILjava/lang/Object;)J
23462360
}
23472361

2362+
public abstract interface class elide/runtime/intrinsics/js/Transferable {
2363+
}
2364+
23482365
public abstract interface class elide/runtime/intrinsics/js/URL : java/io/Serializable, org/graalvm/polyglot/proxy/ProxyObject {
23492366
public abstract fun getHash ()Ljava/lang/String;
23502367
public abstract fun getHost ()Ljava/lang/String;
@@ -2681,6 +2698,31 @@ public abstract interface class elide/runtime/intrinsics/js/express/ExpressRespo
26812698
public abstract fun send (Lorg/graalvm/polyglot/Value;)V
26822699
}
26832700

2701+
public final class elide/runtime/intrinsics/js/messaging/PostMessageOptions : java/lang/Record {
2702+
public static final field Companion Lelide/runtime/intrinsics/js/messaging/PostMessageOptions$Companion;
2703+
public fun <init> ()V
2704+
public fun <init> (Ljava/util/Collection;)V
2705+
public synthetic fun <init> (Ljava/util/Collection;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
2706+
public final fun component1 ()Ljava/util/Collection;
2707+
public final fun copy (Ljava/util/Collection;)Lelide/runtime/intrinsics/js/messaging/PostMessageOptions;
2708+
public static synthetic fun copy$default (Lelide/runtime/intrinsics/js/messaging/PostMessageOptions;Ljava/util/Collection;ILjava/lang/Object;)Lelide/runtime/intrinsics/js/messaging/PostMessageOptions;
2709+
public static final fun empty ()Lelide/runtime/intrinsics/js/messaging/PostMessageOptions;
2710+
public fun equals (Ljava/lang/Object;)Z
2711+
public static final fun from (Lorg/graalvm/polyglot/Value;)Lelide/runtime/intrinsics/js/messaging/PostMessageOptions;
2712+
public fun hashCode ()I
2713+
public static final fun of (Ljava/util/Collection;)Lelide/runtime/intrinsics/js/messaging/PostMessageOptions;
2714+
public static final fun of ([Lelide/runtime/intrinsics/js/Transferable;)Lelide/runtime/intrinsics/js/messaging/PostMessageOptions;
2715+
public fun toString ()Ljava/lang/String;
2716+
public final fun transfer ()Ljava/util/Collection;
2717+
}
2718+
2719+
public final class elide/runtime/intrinsics/js/messaging/PostMessageOptions$Companion {
2720+
public final fun empty ()Lelide/runtime/intrinsics/js/messaging/PostMessageOptions;
2721+
public final fun from (Lorg/graalvm/polyglot/Value;)Lelide/runtime/intrinsics/js/messaging/PostMessageOptions;
2722+
public final fun of (Ljava/util/Collection;)Lelide/runtime/intrinsics/js/messaging/PostMessageOptions;
2723+
public final fun of ([Lelide/runtime/intrinsics/js/Transferable;)Lelide/runtime/intrinsics/js/messaging/PostMessageOptions;
2724+
}
2725+
26842726
public abstract interface class elide/runtime/intrinsics/js/node/AssertAPI : elide/runtime/intrinsics/js/node/NodeAPI {
26852727
public abstract fun assert (Ljava/lang/Object;Ljava/lang/String;)V
26862728
public static synthetic fun assert$default (Lelide/runtime/intrinsics/js/node/AssertAPI;Ljava/lang/Object;Ljava/lang/String;ILjava/lang/Object;)V
@@ -5818,6 +5860,24 @@ public abstract interface class elide/runtime/intrinsics/testing/TestingAPI$Test
58185860
public abstract interface class elide/runtime/intrinsics/testing/TestingAPI$TestGraphNode$Test : elide/runtime/intrinsics/testing/TestingAPI$TestGraphNode {
58195861
}
58205862

5863+
public synthetic class elide/runtime/javascript/$MessageChannelBuiltin$Definition : io/micronaut/context/AbstractInitializableBeanDefinitionAndReference {
5864+
public static final field $ANNOTATION_METADATA Lio/micronaut/core/annotation/AnnotationMetadata;
5865+
public fun <init> ()V
5866+
protected fun <init> (Ljava/lang/Class;Lio/micronaut/context/AbstractInitializableBeanDefinition$MethodOrFieldReference;)V
5867+
public fun instantiate (Lio/micronaut/context/BeanResolutionContext;Lio/micronaut/context/BeanContext;)Ljava/lang/Object;
5868+
public fun isEnabled (Lio/micronaut/context/BeanContext;)Z
5869+
public fun isEnabled (Lio/micronaut/context/BeanContext;Lio/micronaut/context/BeanResolutionContext;)Z
5870+
public fun load ()Lio/micronaut/inject/BeanDefinition;
5871+
}
5872+
5873+
public final synthetic class elide/runtime/javascript/$MessageChannelBuiltin$Introspection : io/micronaut/inject/beans/AbstractInitializableBeanIntrospectionAndReference {
5874+
public static final field $ANNOTATION_METADATA Lio/micronaut/core/annotation/AnnotationMetadata;
5875+
public fun <init> ()V
5876+
public fun hasBuilder ()Z
5877+
public fun instantiate ()Ljava/lang/Object;
5878+
public fun isBuildable ()Z
5879+
}
5880+
58215881
public synthetic class elide/runtime/javascript/$NavigatorBuiltin$Definition : io/micronaut/context/AbstractInitializableBeanDefinitionAndReference {
58225882
public static final field $ANNOTATION_METADATA Lio/micronaut/core/annotation/AnnotationMetadata;
58235883
public fun <init> ()V
@@ -5871,6 +5931,44 @@ public final synthetic class elide/runtime/javascript/$StructuredCloneBuiltin$In
58715931
public fun isBuildable ()Z
58725932
}
58735933

5934+
public final class elide/runtime/javascript/MessageChannelBuiltin : elide/runtime/gvm/internals/intrinsics/js/AbstractJsIntrinsic, org/graalvm/polyglot/proxy/ProxyInstantiable {
5935+
public fun <init> ()V
5936+
public fun install (Lelide/runtime/intrinsics/GuestIntrinsic$MutableIntrinsicBindings;)V
5937+
public fun newInstance ([Lorg/graalvm/polyglot/Value;)Lelide/runtime/javascript/MessageChannelBuiltin$MessageChannelInstance;
5938+
public synthetic fun newInstance ([Lorg/graalvm/polyglot/Value;)Ljava/lang/Object;
5939+
}
5940+
5941+
public final class elide/runtime/javascript/MessageChannelBuiltin$MessageChannelInstance : elide/runtime/interop/ReadOnlyProxyObject, elide/runtime/intrinsics/js/MessageChannel {
5942+
public fun getMember (Ljava/lang/String;)Ljava/lang/Object;
5943+
public synthetic fun getMemberKeys ()Ljava/lang/Object;
5944+
public fun getMemberKeys ()[Ljava/lang/String;
5945+
public fun getPort1 ()Lelide/runtime/intrinsics/js/MessagePort;
5946+
public fun getPort2 ()Lelide/runtime/intrinsics/js/MessagePort;
5947+
}
5948+
5949+
public final class elide/runtime/javascript/MessagePortBuiltin : elide/runtime/intrinsics/js/MessagePort, elide/runtime/intrinsics/js/node/events/EventTarget, org/graalvm/polyglot/proxy/ProxyObject {
5950+
public fun addEventListener (Ljava/lang/String;Lelide/runtime/intrinsics/js/node/events/AddEventListenerOptions;Lelide/runtime/intrinsics/js/node/events/EventListener;)V
5951+
public fun addEventListener (Ljava/lang/String;Lelide/runtime/intrinsics/js/node/events/EventListener;)V
5952+
public fun addEventListener (Ljava/lang/String;Lorg/graalvm/polyglot/Value;Lorg/graalvm/polyglot/Value;)V
5953+
public fun close ()V
5954+
public static final fun create (Ljava/lang/String;)Lelide/runtime/javascript/MessagePortBuiltin;
5955+
public fun dispatchEvent (Lelide/runtime/intrinsics/js/node/events/Event;)Z
5956+
public fun getMember (Ljava/lang/String;)Ljava/lang/Object;
5957+
public synthetic fun getMemberKeys ()Ljava/lang/Object;
5958+
public fun getMemberKeys ()[Ljava/lang/String;
5959+
public fun hasMember (Ljava/lang/String;)Z
5960+
public fun postMessage (Ljava/lang/Object;Ljava/util/Collection;Lelide/runtime/intrinsics/js/messaging/PostMessageOptions;)V
5961+
public fun putMember (Ljava/lang/String;Lorg/graalvm/polyglot/Value;)V
5962+
public fun removeEventListener (Ljava/lang/String;Lelide/runtime/intrinsics/js/node/events/EventListener;)V
5963+
public fun removeEventListener (Ljava/lang/String;Lelide/runtime/intrinsics/js/node/events/EventListener;Lelide/runtime/intrinsics/js/node/events/RemoveEventListenerOptions;)V
5964+
public fun removeEventListener (Ljava/lang/String;Lelide/runtime/intrinsics/js/node/events/EventListener;Lorg/graalvm/polyglot/Value;)V
5965+
public fun removeEventListener (Ljava/lang/String;Lorg/graalvm/polyglot/Value;)V
5966+
public fun removeEventListener (Ljava/lang/String;Lorg/graalvm/polyglot/Value;Lorg/graalvm/polyglot/Value;)V
5967+
public fun removeMember (Ljava/lang/String;)Z
5968+
public fun start ()V
5969+
public fun toString ()Ljava/lang/String;
5970+
}
5971+
58745972
public final class elide/runtime/javascript/NavigatorBuiltin : elide/runtime/gvm/internals/intrinsics/js/AbstractJsIntrinsic, elide/runtime/interop/ReadOnlyProxyObject {
58755973
public fun <init> ()V
58765974
public fun getMember (Ljava/lang/String;)Ljava/lang/Object;
@@ -6571,6 +6669,57 @@ public final class elide/runtime/node/events/EventAware$Companion {
65716669
public final fun create ([Ljava/lang/String;)Lelide/runtime/node/events/EventAware;
65726670
}
65736671

6672+
public final class elide/runtime/node/events/EventAwareProxy : elide/runtime/node/events/EventAware, org/graalvm/polyglot/proxy/ProxyObject {
6673+
public static final field Companion Lelide/runtime/node/events/EventAwareProxy$Companion;
6674+
public synthetic fun <init> (Lelide/runtime/node/events/EventAware;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
6675+
public fun addEventListener (Ljava/lang/String;Lelide/runtime/intrinsics/js/node/events/AddEventListenerOptions;Lelide/runtime/intrinsics/js/node/events/EventListener;)V
6676+
public fun addEventListener (Ljava/lang/String;Lelide/runtime/intrinsics/js/node/events/EventListener;)V
6677+
public fun addEventListener (Ljava/lang/String;Lorg/graalvm/polyglot/Value;Lorg/graalvm/polyglot/Value;)V
6678+
public fun addListener (Ljava/lang/String;Lelide/runtime/intrinsics/js/node/events/EventListener;)V
6679+
public fun addListener (Ljava/lang/String;Lorg/graalvm/polyglot/Value;)V
6680+
public fun close ()V
6681+
public static final fun create ()Lelide/runtime/node/events/EventAwareProxy;
6682+
public static final fun create (Ljava/lang/Iterable;)Lelide/runtime/node/events/EventAwareProxy;
6683+
public static final fun create ([Ljava/lang/String;)Lelide/runtime/node/events/EventAwareProxy;
6684+
public fun dispatchEvent (Lelide/runtime/intrinsics/js/node/events/Event;)Z
6685+
public fun emit (Ljava/lang/String;[Ljava/lang/Object;)Z
6686+
public fun eventNames ()Ljava/util/List;
6687+
public fun getMaxListeners ()I
6688+
public fun getMember (Ljava/lang/String;)Ljava/lang/Object;
6689+
public synthetic fun getMemberKeys ()Ljava/lang/Object;
6690+
public fun getMemberKeys ()Ljava/util/List;
6691+
public fun hasMember (Ljava/lang/String;)Z
6692+
public fun listenerCount (Ljava/lang/String;)I
6693+
public fun listeners (Ljava/lang/String;)Ljava/util/List;
6694+
public fun off (Ljava/lang/String;Lorg/graalvm/polyglot/Value;)V
6695+
public fun on (Ljava/lang/String;Lelide/runtime/intrinsics/js/node/events/EventListener;)Lelide/runtime/intrinsics/js/node/events/EventEmitter;
6696+
public fun on (Ljava/lang/String;Lorg/graalvm/polyglot/Value;)Lelide/runtime/intrinsics/js/node/events/EventEmitter;
6697+
public fun once (Ljava/lang/String;Lelide/runtime/intrinsics/js/node/events/EventListener;)V
6698+
public fun once (Ljava/lang/String;Lorg/graalvm/polyglot/Value;)V
6699+
public fun prependListener (Ljava/lang/String;Lelide/runtime/intrinsics/js/node/events/EventListener;)V
6700+
public fun prependListener (Ljava/lang/String;Lorg/graalvm/polyglot/Value;)V
6701+
public fun prependOnceListener (Ljava/lang/String;Lelide/runtime/intrinsics/js/node/events/EventListener;)V
6702+
public fun prependOnceListener (Ljava/lang/String;Lorg/graalvm/polyglot/Value;)V
6703+
public fun putMember (Ljava/lang/String;Lorg/graalvm/polyglot/Value;)V
6704+
public fun rawListeners (Ljava/lang/String;)Ljava/util/List;
6705+
public fun removeAllListeners ()V
6706+
public fun removeAllListeners (Ljava/lang/String;)V
6707+
public fun removeEventListener (Ljava/lang/String;Lelide/runtime/intrinsics/js/node/events/EventListener;)V
6708+
public fun removeEventListener (Ljava/lang/String;Lelide/runtime/intrinsics/js/node/events/EventListener;Lelide/runtime/intrinsics/js/node/events/RemoveEventListenerOptions;)V
6709+
public fun removeEventListener (Ljava/lang/String;Lelide/runtime/intrinsics/js/node/events/EventListener;Lorg/graalvm/polyglot/Value;)V
6710+
public fun removeEventListener (Ljava/lang/String;Lorg/graalvm/polyglot/Value;)V
6711+
public fun removeEventListener (Ljava/lang/String;Lorg/graalvm/polyglot/Value;Lorg/graalvm/polyglot/Value;)V
6712+
public fun removeListener (Ljava/lang/String;Lorg/graalvm/polyglot/Value;)V
6713+
public fun removeMember (Ljava/lang/String;)Z
6714+
public fun setMaxListeners (I)V
6715+
}
6716+
6717+
public final class elide/runtime/node/events/EventAwareProxy$Companion {
6718+
public final fun create ()Lelide/runtime/node/events/EventAwareProxy;
6719+
public final fun create (Ljava/lang/Iterable;)Lelide/runtime/node/events/EventAwareProxy;
6720+
public final fun create ([Ljava/lang/String;)Lelide/runtime/node/events/EventAwareProxy;
6721+
}
6722+
65746723
public abstract interface class elide/runtime/node/events/GuestEventListener : elide/runtime/intrinsics/js/node/events/EventListener, java/util/function/Consumer, org/graalvm/polyglot/proxy/ProxyExecutable {
65756724
public static final field Companion Lelide/runtime/node/events/GuestEventListener$Companion;
65766725
public fun accept (Lelide/runtime/intrinsics/js/node/events/Event;)V
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2024-2025 Elide Technologies, Inc.
3+
*
4+
* Licensed under the MIT license (the "License"); you may not use this file except in compliance
5+
* with the License. You may obtain a copy of the License at
6+
*
7+
* https://opensource.org/license/mit/
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
* License for the specific language governing permissions and limitations under the License.
12+
*/
13+
package elide.runtime.intrinsics.js
14+
15+
import elide.annotations.API
16+
import elide.runtime.interop.ReadOnlyProxyObject
17+
import elide.vm.annotations.Polyglot
18+
19+
/**
20+
* ## Message Channel
21+
*
22+
* Implements the `MessageChannel` global function for JavaScript, which is used to communicate between multiple
23+
* browsing or execution contexts.
24+
*
25+
* ### Standards Compliance
26+
*
27+
* The `MessageChannel` class is defined as part of the WinterTC Minimum Common API.
28+
*
29+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel)
30+
*/
31+
@API public interface MessageChannel : ReadOnlyProxyObject {
32+
/**
33+
* The first port created for this channel; initialized when the channel is constructed.
34+
*
35+
* Message ports are event-aware types. Events are delivered to the message port, and received via event handlers. See
36+
* [MessagePort] for usage.
37+
*/
38+
@get:Polyglot public val port1: MessagePort
39+
40+
/**
41+
* The second port created for this channel; initialized when the channel is constructed.
42+
*
43+
* Message ports are event-aware types. Events are delivered to the message port, and received via event handlers. See
44+
* [MessagePort] for usage.
45+
*/
46+
@get:Polyglot public val port2: MessagePort
47+
}

0 commit comments

Comments
 (0)