sptc 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/engine/index.js +9 -2
- package/engine/interpreter.js +24 -19
- package/package.json +1 -1
- package/tests/www/dd.s +2 -0
- package/tests/www/index.s +4 -0
- package/tests/www/stream.s +4 -0
package/engine/index.js
CHANGED
|
@@ -28,14 +28,21 @@ function executeSptcFile(filename, payload, option={}) {
|
|
|
28
28
|
|
|
29
29
|
function executeSptcFileEx(...x) {
|
|
30
30
|
const e=new Promise((resolve, reject)=>{
|
|
31
|
-
const {end, onError
|
|
31
|
+
const {end, onError}=(x[2]=x[2] || {})
|
|
32
32
|
const buf=[]
|
|
33
33
|
x[2].write=(...x)=>{
|
|
34
34
|
buf.push(...x)
|
|
35
35
|
}
|
|
36
36
|
x[2].end=_=>{
|
|
37
37
|
end && end()
|
|
38
|
-
|
|
38
|
+
const xbuf=[]
|
|
39
|
+
const is_str=typeof buf[0]==='string'
|
|
40
|
+
for(let x of buf) {
|
|
41
|
+
if(is_str && typeof x!=='string') x=x.toString('utf8')
|
|
42
|
+
if(!is_str && typeof x==='string') x=Buffer.concat(x)
|
|
43
|
+
xbuf.push(x)
|
|
44
|
+
}
|
|
45
|
+
resolve(xbuf)
|
|
39
46
|
}
|
|
40
47
|
x[2].onError=e=>{
|
|
41
48
|
onError && onError(e)
|
package/engine/interpreter.js
CHANGED
|
@@ -132,7 +132,6 @@ function buildContext(ctx0, option) {
|
|
|
132
132
|
end=NOOP,
|
|
133
133
|
onError=NOOP,
|
|
134
134
|
masterPriv=null,
|
|
135
|
-
readAsBinary=false,
|
|
136
135
|
isEntry=false,
|
|
137
136
|
}=option
|
|
138
137
|
|
|
@@ -174,7 +173,7 @@ function buildContext(ctx0, option) {
|
|
|
174
173
|
ctx.flush=_=>{
|
|
175
174
|
if(priv.isEnd) return;
|
|
176
175
|
const {echos}=priv
|
|
177
|
-
echos.splice(0).map(x=>write(toWritable(x
|
|
176
|
+
echos.splice(0).map(x=>write(toWritable(x)))
|
|
178
177
|
}
|
|
179
178
|
|
|
180
179
|
ctx.var_dump=(...x)=>{
|
|
@@ -235,11 +234,21 @@ function buildContext(ctx0, option) {
|
|
|
235
234
|
write: option.write,
|
|
236
235
|
onError: option.onError,
|
|
237
236
|
masterPriv: priv,
|
|
238
|
-
readAsBinary,
|
|
239
237
|
isEntry: false,
|
|
240
238
|
})
|
|
241
239
|
const ret=executeVm(_vm, _ctx, priv)
|
|
242
|
-
return
|
|
240
|
+
return new Proxy(_ctx._exports, {
|
|
241
|
+
get: (target, prop, receiver)=>{
|
|
242
|
+
if(false===prop in target) {
|
|
243
|
+
try{
|
|
244
|
+
return ret.constructor('return '+prop)()
|
|
245
|
+
}catch(e) {
|
|
246
|
+
return undefined
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return target[prop]
|
|
250
|
+
},
|
|
251
|
+
})
|
|
243
252
|
}
|
|
244
253
|
|
|
245
254
|
ctx.__autoload=fn=>{
|
|
@@ -259,8 +268,7 @@ function buildContext(ctx0, option) {
|
|
|
259
268
|
if(priv.__autoload_func) {
|
|
260
269
|
let inc_fn=priv.__autoload_func(prop)
|
|
261
270
|
if(inc_fn) {
|
|
262
|
-
|
|
263
|
-
return priv.__autoload_vars[prop]=e.default || e.__getter__(prop)
|
|
271
|
+
return priv.__autoload_vars[prop]=ctx.include(inc_fn)[prop]
|
|
264
272
|
}
|
|
265
273
|
}
|
|
266
274
|
}
|
|
@@ -271,21 +279,18 @@ function buildContext(ctx0, option) {
|
|
|
271
279
|
return [pctx, priv]
|
|
272
280
|
}
|
|
273
281
|
|
|
274
|
-
function toWritable(x
|
|
282
|
+
function toWritable(x) {
|
|
275
283
|
if(x && [Uint8Array, Buffer].includes(x.constructor)) {
|
|
276
|
-
return
|
|
284
|
+
return x
|
|
277
285
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
if(
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
return JSON.stringify(x)+''
|
|
287
|
-
})()
|
|
288
|
-
return asBinary? Buffer.from(str): str
|
|
286
|
+
if(typeof x==='string') return x
|
|
287
|
+
if(typeof x==='undefined') return 'undefined'
|
|
288
|
+
if(typeof x==='number') {
|
|
289
|
+
if(isNaN(x))return 'NaN'
|
|
290
|
+
if(x===Infinity) return 'Infinity'
|
|
291
|
+
if(x===-Infinity) return '-Infinity'
|
|
292
|
+
}
|
|
293
|
+
return JSON.stringify(x)+''
|
|
289
294
|
}
|
|
290
295
|
|
|
291
296
|
function executeVm(vm, ctx, priv) {
|
package/package.json
CHANGED
package/tests/www/dd.s
ADDED
package/tests/www/index.s
CHANGED