Skip to content

Commit

Permalink
[wip] continued labs/v5 work
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Gammon <sam@elide.dev>
  • Loading branch information
sgammon committed Mar 5, 2025
1 parent ed6e4b6 commit 1119660
Show file tree
Hide file tree
Showing 31 changed files with 431 additions and 313 deletions.
13 changes: 13 additions & 0 deletions packages/engine/api/engine.api
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,19 @@ public abstract interface class elide/runtime/gvm/loader/ModuleResolver {
public abstract fun load (Lelide/runtime/gvm/loader/ModuleInfo;)Ljava/lang/Object;
}

public abstract interface class elide/runtime/interop/InteropProxyObject : org/graalvm/polyglot/proxy/ProxyObject {
}

public abstract interface class elide/runtime/interop/ReadOnlyProxyObject : elide/runtime/interop/SealedProxyObject {
public fun putMember (Ljava/lang/String;Lorg/graalvm/polyglot/Value;)V
public fun removeMember (Ljava/lang/String;)Z
}

public abstract interface class elide/runtime/interop/SealedProxyObject : elide/runtime/interop/InteropProxyObject {
public abstract fun getMemberKeys ()[Ljava/lang/String;
public fun hasMember (Ljava/lang/String;)Z
}

public abstract interface class elide/runtime/lang/Language {
public abstract fun getLanguageId ()Ljava/lang/String;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2024-2025 Elide Technologies, Inc.
*
* Licensed under the MIT license (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://opensource.org/license/mit/
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under the License.
*/
package elide.runtime.interop

import org.graalvm.polyglot.proxy.ProxyObject

/**
* ## Interoperable Proxy Object
*
* Describes a [ProxyObject] which is usable by guest languages.
*/
public sealed interface InteropProxyObject : ProxyObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2024-2025 Elide Technologies, Inc.
*
* Licensed under the MIT license (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://opensource.org/license/mit/
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under the License.
*/
package elide.runtime.interop

import org.graalvm.polyglot.Value
import org.graalvm.polyglot.proxy.ProxyObject

/**
* ## Read-only Proxy Object
*
* Interop base which defines a [ProxyObject] that forbids writes and deletes.
*/
public interface ReadOnlyProxyObject : SealedProxyObject {
override fun putMember(key: String?, value: Value?): Unit = Unit
override fun removeMember(key: String?): Boolean = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2024-2025 Elide Technologies, Inc.
*
* Licensed under the MIT license (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://opensource.org/license/mit/
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under the License.
*/
package elide.runtime.interop

import org.graalvm.polyglot.proxy.ProxyObject

/**
* ## Sealed Proxy Object
*
* Describes a [ProxyObject] which has a known suite of properties ahead of time.
*/
public interface SealedProxyObject : InteropProxyObject {
override fun getMemberKeys(): Array<String>
override fun hasMember(key: String): Boolean = key in memberKeys
}
2 changes: 2 additions & 0 deletions packages/graalvm-js/api/graalvm-js.api
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ public final class elide/runtime/lang/javascript/NodeModuleName {
public static final field CONSTANTS Ljava/lang/String;
public static final field CRYPTO Ljava/lang/String;
public static final field DGRAM Ljava/lang/String;
public static final field DIAGNOSTICS_CHANNEL Ljava/lang/String;
public static final field DNS Ljava/lang/String;
public static final field DNS_PROMISES Ljava/lang/String;
public static final field DOMAIN Ljava/lang/String;
public static final field EVENTS Ljava/lang/String;
public static final field FS Ljava/lang/String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ private val allNodeModules = sortedSetOf(
public const val CONSOLE: String = "console"
public const val CONSTANTS: String = "constants"
public const val CRYPTO: String = "crypto"
public const val DIAGNOSTICS_CHANNEL: String = "diagnostics_channel"
public const val DGRAM: String = "dgram"
public const val DNS: String = "dns"
public const val DNS_PROMISES: String = "dns_promises"
public const val DOMAIN: String = "domain"
public const val EVENTS: String = "events"
public const val FS: String = "fs"
Expand Down Expand Up @@ -264,16 +266,25 @@ internal class ElideUniversalJsModuleLoader private constructor(realm: JSRealm)

private fun setSyntheticModuleExport(module: JSModuleRecord) {
module.environment.setObject(defaultExportSlot.index, surface)
val mountPropsFromProxy = { it: ProxyObject ->
for ((slotName, slot) in mappedSlots) {
// module.namespace.X
val member = it.getMember(slotName)
module.environment.setObject(slot.index, realm.env.asGuestValue(member))
}
}
when (surface) {
is ProxyObject -> {
for ((slotName, slot) in mappedSlots) {
// module.namespace.X
val member = surface.getMember(slotName)
module.environment.setObject(slot.index, realm.env.asGuestValue(member))
}
is ProxyObject -> mountPropsFromProxy(surface)
is SyntheticJSModule<*> -> {
val prox = surface.provide()
if (prox is ProxyObject) {
mountPropsFromProxy(prox)
} else error(
"Provided synthetic module from `SyntheticJSModule.provide` is not a `ProxyObject`: $prox"
)
}

else -> error("Object is usable synthetic module: $surface")
else -> error("Object is unusable synthetic module: $surface")
}
}
}
Expand Down
Binary file not shown.
Loading

0 comments on commit 1119660

Please sign in to comment.