@@ -3,8 +3,7 @@ import {API_URLS} from '../config';
33import { showJsException } from '../view/output-view' ;
44import { processingHtmlBrackets } from '../utils' ;
55import { isWasmRelated , TargetPlatforms } from '../utils/platforms' ;
6- import { executeJs , executeWasmCode , executeWasmCodeWithSkiko , executeWasmCodeWithStdlib } from './execute-es-module' ;
7- import { fetch } from "whatwg-fetch" ;
6+ import { executeWasmCode } from './execute-es-module' ;
87
98const INIT_SCRIPT =
109 'if(kotlin.BufferedOutput!==undefined){kotlin.out = new kotlin.BufferedOutput()}' +
@@ -26,7 +25,6 @@ const normalizeJsVersion = (version) => {
2625export default class JsExecutor {
2726 constructor ( kotlinVersion ) {
2827 this . kotlinVersion = kotlinVersion ;
29- this . stdlibExports = undefined ;
3028 }
3129
3230 async executeJsCode (
@@ -37,7 +35,6 @@ export default class JsExecutor {
3735 outputHeight ,
3836 theme ,
3937 onError ,
40- additionalRequestsResults ,
4138 ) {
4239 if ( platform === TargetPlatforms . SWIFT_EXPORT ) {
4340 return `<span class="standard-output ${ theme } "><div class="result-code">${ jsCode } </span>` ;
@@ -69,15 +66,12 @@ export default class JsExecutor {
6966 // for some reason resize function in Compose does not work in Firefox in invisible block
7067 this . iframe . style . display = 'block' ;
7168
72- const additionalRequestsResult = additionalRequestsResults [ 0 ] ;
7369 const result = await this . executeWasm (
7470 jsCode ,
7571 wasm ,
76- executeWasmCodeWithStdlib ,
72+ executeWasmCode ,
7773 theme ,
78- processError ,
79- additionalRequestsResult . stdlib ,
80- additionalRequestsResult . output ,
74+ processError
8175 ) ;
8276
8377 if ( exception ) {
@@ -123,15 +117,15 @@ export default class JsExecutor {
123117 return await this . execute ( jsCode , jsLibs , theme , onError , platform ) ;
124118 }
125119
126- async executeWasm ( jsCode , wasmCode , executor , theme , onError , imports , output ) {
120+ async executeWasm ( jsCode , wasmCode , executor , theme , onError ) {
127121 try {
128122 const exports = await executor (
129123 this . iframe . contentWindow ,
130124 jsCode ,
131125 wasmCode ,
132126 ) ;
133- await exports . instantiate ( { "playground.master" : imports } ) ;
134- const bufferedOutput = output ?? exports . bufferedOutput ;
127+ await exports . instantiate ( ) ;
128+ const bufferedOutput = this . iframe . contentWindow . bufferedOutput ?? exports . bufferedOutput ;
135129 const outputString = bufferedOutput . buffer ;
136130 bufferedOutput . buffer = '' ;
137131 return outputString
@@ -182,107 +176,10 @@ export default class JsExecutor {
182176 }
183177 }
184178 if ( targetPlatform === TargetPlatforms . COMPOSE_WASM ) {
185-
186- const skikoStdlib = fetch ( API_URLS . RESOURCE_VERSIONS ( ) , {
187- method : 'GET'
188- } ) . then ( response => response . json ( ) )
189- . then ( versions => {
190- const skikoVersion = versions [ "skiko" ] ;
191-
192- const skikoExports = fetch ( API_URLS . SKIKO_MJS ( skikoVersion ) , {
193- method : 'GET' ,
194- headers : {
195- 'Content-Type' : 'text/javascript' ,
196- }
197- } ) . then ( script => script . text ( ) )
198- . then ( script => script . replace (
199- "new URL(\"skiko.wasm\",import.meta.url).href" ,
200- `'${ API_URLS . SKIKO_WASM ( skikoVersion ) } '`
201- ) )
202- . then ( skikoCode =>
203- executeJs (
204- this . iframe . contentWindow ,
205- skikoCode ,
206- ) )
207- . then ( skikoExports => fixedSkikoExports ( skikoExports ) )
208-
209- const stdlibVersion = versions [ "stdlib" ] ;
210-
211- const stdlibExports = fetch ( API_URLS . STDLIB_MJS ( stdlibVersion ) , {
212- method : 'GET' ,
213- headers : {
214- 'Content-Type' : 'text/javascript' ,
215- }
216- } ) . then ( script => script . text ( ) )
217- . then ( script =>
218- // necessary to load stdlib.wasm before its initialization to parallelize
219- // language=JavaScript
220- ( `const stdlibWasm = fetch('${ API_URLS . STDLIB_WASM ( stdlibVersion ) } ');\n` + script ) . replace (
221- "fetch(new URL('./stdlib_master.wasm',import.meta.url).href)" ,
222- "stdlibWasm"
223- ) . replace (
224- "(extends) => { return { extends }; }" ,
225- "(extends_) => { return { extends_ }; }"
226- ) )
227- . then ( stdlibCode =>
228- executeWasmCodeWithSkiko (
229- this . iframe . contentWindow ,
230- stdlibCode ,
231- )
232- )
233-
234- return Promise . all ( [ skikoExports , stdlibExports ] )
235- } )
236-
237- this . stdlibExports = skikoStdlib
238- . then ( async ( [ skikoExportsResult , stdlibExportsResult ] ) => {
239- return [
240- await stdlibExportsResult . instantiate ( {
241- "./skiko.mjs" : skikoExportsResult
242- } ) ,
243- stdlibExportsResult
244- ]
245- }
246- )
247- . then ( ( [ stdlibResult , outputResult ] ) => {
248- return {
249- "stdlib" : stdlibResult . exports ,
250- "output" : outputResult . bufferedOutput
251- }
252- }
253- )
254-
255179 this . iframe . height = "1000"
256180 iframeDoc . write ( `<canvas height="1000" id="ComposeTarget"></canvas>` ) ;
257181 }
258182 iframeDoc . write ( '<body style="margin: 0; overflow: hidden;"></body>' ) ;
259183 iframeDoc . close ( ) ;
260184 }
261185}
262-
263- function fixedSkikoExports ( skikoExports ) {
264- return {
265- ...skikoExports ,
266- org_jetbrains_skia_Bitmap__1nGetPixmap : function ( ) {
267- console . log ( "org_jetbrains_skia_TextBlobBuilderRunHandler__1nGetFinalizer" )
268- } ,
269- org_jetbrains_skia_Bitmap__1nIsVolatile : function ( ) {
270- console . log ( "org_jetbrains_skia_TextBlobBuilderRunHandler__1nGetFinalizer" )
271- } ,
272- org_jetbrains_skia_Bitmap__1nSetVolatile : function ( ) {
273- console . log ( "org_jetbrains_skia_TextBlobBuilderRunHandler__1nGetFinalizer" )
274- } ,
275- org_jetbrains_skia_TextBlobBuilderRunHandler__1nGetFinalizer : function ( ) {
276- console . log ( "org_jetbrains_skia_TextBlobBuilderRunHandler__1nGetFinalizer" )
277- } ,
278- org_jetbrains_skia_TextBlobBuilderRunHandler__1nMake : function ( ) {
279- console . log ( "org_jetbrains_skia_TextBlobBuilderRunHandler__1nGetFinalizer" )
280- } ,
281- org_jetbrains_skia_TextBlobBuilderRunHandler__1nMakeBlob : function ( ) {
282- console . log ( "org_jetbrains_skia_TextBlobBuilderRunHandler__1nGetFinalizer" )
283- } ,
284- org_jetbrains_skia_svg_SVGCanvasKt__1nMake : function ( ) {
285- console . log ( "org_jetbrains_skia_TextBlobBuilderRunHandler__1nGetFinalizer" )
286- }
287- }
288- }
0 commit comments