
com.tangosol.internal.util.graal.js.Module Maven / Gradle / Ivy
/*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
package com.tangosol.internal.util.graal.js;
import com.tangosol.internal.util.graal.ScriptDescriptor;
import com.tangosol.util.ScriptException;
import java.util.HashMap;
import java.util.Map;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.PolyglotException;
import org.graalvm.polyglot.Source;
import org.graalvm.polyglot.Value;
/**
* Module object wraps a JavaScript file and provides a {@link #load} method
* that performs the necessary steps to load a JavaScript file.
*
* For pre ES6 modules, each module is loaded by first wrapping the JavaScript
* file in a function and then executing it.
*
* @author mk 2019.07.26
* @since 14.1.1.0
*/
public class Module
{
// ------ constructor ----------------------------------------------------
/**
* Create a new {@link Module} from the specified {@link ScriptDescriptor}.
*
* @param descriptor the {@link ScriptDescriptor} that represents the
* JavaScript to be loaded
*/
public Module(ScriptDescriptor descriptor)
{
m_sName = descriptor.getScriptUrl().toString();
m_descriptor = descriptor;
}
// ------ Module methods -------------------------------------------------
/**
* Returns the name of this {@link Module}. This is typically the url (in
* String form) of the JavaScript file.
*
* @return the name of this {@link Module}
*/
public String getName()
{
return m_sName;
}
/**
* Get the exported values.
*
* @return the {@link Map} of exported objects
*/
public Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy