From f19423d53a2bed2ad95cdaafa8c023834656d08d Mon Sep 17 00:00:00 2001 From: Volker Berlin Date: Sun, 15 Sep 2019 15:38:32 +0200 Subject: [PATCH] evaluate the JavaScript lazy for more dynamic JavaScript (non GC polyfill) --- .../javascript/JavaScriptWriter.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/de/inetsoftware/jwebassembly/javascript/JavaScriptWriter.java b/src/de/inetsoftware/jwebassembly/javascript/JavaScriptWriter.java index 3b3186c..dfece38 100644 --- a/src/de/inetsoftware/jwebassembly/javascript/JavaScriptWriter.java +++ b/src/de/inetsoftware/jwebassembly/javascript/JavaScriptWriter.java @@ -36,7 +36,7 @@ public class JavaScriptWriter { /** annotation attribute for the JavaScript content */ static final String JAVA_SCRIPT_CONTENT = "js"; - private Map> modules = new HashMap<>(); + private Map>> modules = new HashMap<>(); /** * Create a new instance @@ -59,13 +59,12 @@ public class JavaScriptWriter { * the other values of the annotation */ public void addImport( String module, String name, Function annotationValues ) { - String content = (String)annotationValues.apply( JAVA_SCRIPT_CONTENT ); - Map moduleEntries = modules.get( module ); + Map> moduleEntries = modules.get( module ); if( moduleEntries == null ) { modules.put( module, moduleEntries = new HashMap<>() ); } - String old = moduleEntries.put( name, content ); + Function old = moduleEntries.put( name, annotationValues ); if( old != null ) { System.err.println( "Redefine JavaScript function: " + module + "." + name ); } @@ -96,15 +95,16 @@ public class JavaScriptWriter { void finish( Appendable out ) throws IOException { out.append( "'use strict';var wasmImports = {\n" ); boolean isFirst = true; - for( Entry> module : modules.entrySet() ) { + for( Entry>> module : modules.entrySet() ) { if( !isFirst ) { out.append( ",\n" ); } out.append( module.getKey() ).append( ':' ); - Map functions = module.getValue(); + Map> functions = module.getValue(); boolean hasContent = false; - for( String content : functions.values() ) { + for( Function annotationValues : functions.values() ) { + String content = (String)annotationValues.apply( JAVA_SCRIPT_CONTENT ); if( content != null && !content.isEmpty() ) { hasContent = true; break; @@ -116,11 +116,12 @@ public class JavaScriptWriter { // write the function boolean isFirstFunc = true; - for( Entry func : functions.entrySet() ) { + for( Entry> func : functions.entrySet() ) { if( !isFirstFunc ) { out.append( ",\n" ); } - out.append( func.getKey() ).append( ':' ).append( func.getValue() ); + String content = (String)func.getValue().apply( JAVA_SCRIPT_CONTENT ); + out.append( func.getKey() ).append( ':' ).append( content ); isFirstFunc = false; }