@@ -6,7 +6,7 @@ import $xworker from './worker/class.js';
6
6
import workerURL from './worker/url.js' ;
7
7
import { getRuntime , getRuntimeID } from './loader.js' ;
8
8
import { registry } from './interpreters.js' ;
9
- import { JSModules , all , dispatch , resolve , defineProperty , nodeInfo , registerJSModules } from './utils.js' ;
9
+ import { JSModules , isSync , all , dispatch , resolve , defineProperty , nodeInfo , registerJSModules } from './utils.js' ;
10
10
11
11
const getRoot = ( script ) => {
12
12
let parent = script ;
@@ -55,12 +55,6 @@ const execute = async (currentScript, source, XWorker, isAsync) => {
55
55
source ,
56
56
] ) ;
57
57
try {
58
- // temporarily override inherited document.currentScript in a non writable way
59
- // but it deletes it right after to preserve native behavior (as it's sync: no trouble)
60
- defineProperty ( document , 'currentScript' , {
61
- configurable : true ,
62
- get : ( ) => currentScript ,
63
- } ) ;
64
58
registerJSModules ( type , module , interpreter , JSModules ) ;
65
59
module . registerJSModule ( interpreter , 'polyscript' , {
66
60
XWorker,
@@ -69,10 +63,16 @@ const execute = async (currentScript, source, XWorker, isAsync) => {
69
63
workers : workersHandler ,
70
64
} ) ;
71
65
dispatch ( currentScript , type , 'ready' ) ;
72
- const result = module [ isAsync ? 'runAsync' : 'run' ] ( interpreter , content ) ;
66
+ // temporarily override inherited document.currentScript in a non writable way
67
+ // but it deletes it right after to preserve native behavior (as it's sync: no trouble)
68
+ defineProperty ( document , 'currentScript' , {
69
+ configurable : true ,
70
+ get : ( ) => currentScript ,
71
+ } ) ;
73
72
const done = dispatch . bind ( null , currentScript , type , 'done' ) ;
74
- if ( isAsync ) result . then ( done ) ;
75
- else done ( ) ;
73
+ let result = module [ isAsync ? 'runAsync' : 'run' ] ( interpreter , content ) ;
74
+ if ( isAsync ) result = await result ;
75
+ done ( ) ;
76
76
return result ;
77
77
} finally {
78
78
delete document . currentScript ;
@@ -125,7 +125,6 @@ export const handle = async (script) => {
125
125
// and/or source code with different config or interpreter
126
126
const {
127
127
attributes : {
128
- async : asyncAttribute ,
129
128
config,
130
129
env,
131
130
name : wn ,
@@ -138,7 +137,7 @@ export const handle = async (script) => {
138
137
} = script ;
139
138
140
139
/* c8 ignore start */
141
- const isAsync = asyncAttribute ?. value !== 'false' ;
140
+ const isAsync = ! isSync ( script ) ;
142
141
143
142
const versionValue = version ?. value ;
144
143
const name = getRuntimeID ( type , versionValue ) ;
0 commit comments