GraalExtension
com.jsmacrosce.jsmacros.graal.GraalExtension
Provides Graal language support and the JavaWrapper library through the extension loader; it is not a script global.
js
const extension = context.getCtx().runner.extensions.getExtensionForName("graal");
if (extension !== null) {
Chat.log(extension.getExtensionName() + ": " + extension.defaultFileExtension());
}Constructors
new GraalExtension
new GraalExtension()#Methods
defaultFileExtension
extensionMatch
extensionMatch(File fname): LanguageExtension.ExtMatch#Tests a file using the initialized runner's Graal engine and language detection; a detected language gets a name-preferred match when its basename contains
"graal". An IOException from language detection is printed and results in NOT_MATCH.Parameters:
fname: candidate file to test
Returns:
MATCH_WITH_NAME for a detected language with "graal" in its basename, MATCH for another detected language, or NOT_MATCH when the engine lacks the detected language or detection throws IOExceptiongetExtensionName
getLanguage
getLanguage(Core<?, ?> runner): BaseLanguage<?, ?>#Returns the cached Graal language definition, creating it on the first call. The definition is stored statically across extension instances and uses the core supplied when it is created; a call finding the cache populated ignores its core argument. Creation is unsynchronized, so concurrent calls can construct competing definitions. During creation, the calling thread's context class loader is changed to this extension's loader and restored on the normal path, not in a failure-protected block.
Parameters:
runner: core used if the shared definition has not yet been created
Returns: the cached Graal language definition
getLibraries
getLibraries(): Set<Class<? extends BaseLibrary>>#Returns this extension's library classes for loader registration. Each call returns a fresh mutable set containing
FWrapper.class.Returns: fresh set of contributed library classes
getPriority
getPriority(): int#Returns this language extension's selection priority.
Returns: priority value
1000; higher priorities are normally preferred, but this does not guarantee selectioninit
Stores the core and registers this extension's
graal configuration options. The runner is stored before registration; a registration failure is wrapped in RuntimeException and does not undo that assignment.Parameters:
runner: core to store and use for configuration registration
isGuestObject
wrapException
wrapException(Throwable ex): BaseWrappedException<?>#Builds a diagnostic wrapper for a Graal polyglot exception; other throwable types are not recognized. Host exceptions use their host class name and optional message; other polyglot exceptions use
GuestExceptionSimplifier, falling back to "UnknownGuestException" if its message is null. The wrapper retains the original throwable and may include a source position and linked guest/host frames; the frame chain stops at the first host org.graalvm.polyglot.Context.eval frame.Parameters:
ex: throwable to inspect
Returns: diagnostic wrapper for a
PolyglotException, or null otherwise