@@ -3,7 +3,8 @@ import { API_URLS } from '../config';
33import { showJsException } from '../view/output-view' ;
44import { processingHtmlBrackets } from '../utils' ;
55import { isWasmRelated , TargetPlatforms } from '../utils/platforms' ;
6- import { executeWasmCode , executeWasmCodeWithSkiko } from './execute-es-module' ;
6+ import { executeJs , executeWasmCode , executeWasmCodeWithSkiko } from './execute-es-module' ;
7+ import { fetch } from "whatwg-fetch" ;
78
89const INIT_SCRIPT =
910 'if(kotlin.BufferedOutput!==undefined){kotlin.out = new kotlin.BufferedOutput()}' +
@@ -25,7 +26,7 @@ const normalizeJsVersion = (version) => {
2526export default class JsExecutor {
2627 constructor ( kotlinVersion ) {
2728 this . kotlinVersion = kotlinVersion ;
28- this . skikoImports = undefined ;
29+ this . skikoImport = undefined ;
2930 }
3031
3132 async executeJsCode (
@@ -138,7 +139,7 @@ export default class JsExecutor {
138139 return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
139140 }
140141
141- reloadIframeScripts ( jsLibs , node , targetPlatform ) {
142+ reloadIframeScripts ( jsLibs , node , targetPlatform , compilerVersion ) {
142143 if ( this . iframe !== undefined ) {
143144 node . removeChild ( this . iframe ) ;
144145 }
@@ -170,10 +171,29 @@ export default class JsExecutor {
170171 }
171172 }
172173 if ( targetPlatform === TargetPlatforms . COMPOSE_WASM ) {
173- if ( this . skikoImports ) {
174- this . iframe . contentWindow . skikoImports = this . skikoImports ;
175- }
176- this . iframe . height = '1000' ;
174+ this . skikoImport = fetch ( API_URLS . SKIKO_MJS ( compilerVersion ) , {
175+ method : 'GET' ,
176+ headers : {
177+ 'Content-Type' : 'text/javascript' ,
178+ }
179+ } )
180+ . then ( script => script . text ( ) )
181+ . then ( script => script . replace (
182+ "new URL(\"skiko.wasm\",import.meta.url).href" ,
183+ `'${ API_URLS . SKIKO_WASM ( compilerVersion ) } '`
184+ ) )
185+ . then ( async skikoCode => {
186+ return await executeJs (
187+ this . iframe . contentWindow ,
188+ skikoCode ,
189+ ) ;
190+ }
191+ )
192+ . then ( skikoImports => {
193+ this . iframe . contentWindow . skikoImports = skikoImports ;
194+ } ) ;
195+
196+ this . iframe . height = "1000"
177197 iframeDoc . write ( `<canvas height="1000" id="ComposeTarget"></canvas>` ) ;
178198 }
179199 iframeDoc . write ( '<body style="margin: 0; overflow: hidden;"></body>' ) ;
0 commit comments