ProfilingNode(ListenerImpl config, EventContext context) { super(config, context); PolyglotLanguage languageToUse = null; if (location != null) { languageToUse = config.engine.idToLanguage.get(location.getSource().getLanguage()); } if (languageToUse == null) { // should not happen but just in case fallback to host language assert false; languageToUse = config.engine.hostLanguage; } this.language = languageToUse; }
/** * Evaluates a source by using the {@linkplain Source#getLanguage() language} specified in the * source. The result is accessible as {@link Value value} and never <code>null</code>. The * first time a source is evaluated it will be parsed, consecutive invocations of eval with the * same source will only execute the already parsed code. * <p> * <b>Basic Example:</b> * * <pre> * Context context = Context.create(); * Source source = Source.newBuilder("js", "42").name("mysource.js").build(); * Value result = context.eval(source); * assert result.asInt() == 42; * context.close(); * </pre> * * @param source a source object to evaluate * @throws PolyglotException in case parsing or evaluation of the guest language code failed. * @throws IllegalStateException if the context is already closed, the current thread is not * allowed to access this context or if the language of the given source is not * installed. * @return result of the evaluation. The returned instance is is never <code>null</code>, but * the result might represent a {@link Value#isNull() null} value. * @since 1.0 */ public Value eval(Source source) { return impl.eval(source.getLanguage(), source.impl); }
/** * Evaluates a source object by using the {@linkplain Source#getLanguage() language} specified * in the source. The result is accessible as {@link Value value} and never returns * <code>null</code>. The first time a source is evaluated, it will be parsed. Consecutive * invocations of eval with the same source will only execute the already parsed code. * <p> * <b>Basic Example:</b> * * <pre> * Context context = Context.create(); * Source source = Source.newBuilder("js", "42").name("mysource.js").build(); * Value result = context.eval(source); * assert result.asInt() == 42; * context.close(); * </pre> * * @param source a source object to evaluate * @throws PolyglotException in case the guest language code parsing or evaluation failed. * @throws IllegalStateException if the context is already closed and the current thread is not * allowed to access it. * @throws IllegalArgumentException if the language of the given source is not installed or the * {@link Source#getMimeType() MIME type} is not supported with the language. * @return the evaluation result. The returned instance is never <code>null</code>, but the * result might represent a {@link Value#isNull() null} value. * @since 1.0 */ public Value eval(Source source) { return impl.eval(source.getLanguage(), source.impl); }