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 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, readAsBinary}=(x[2]=x[2] || {})
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
- resolve(readAsBinary? Buffer.concat(buf): buf.join(''))
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)
@@ -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, readAsBinary)))
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 Object.assign({}, _ctx._exports, {__getter__: (...x)=>ret.constructor('return '+(x.length>1? '['+x.join(',')+']': x))()})
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
- const e=ctx.include(inc_fn)
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, asBinary=false) {
282
+ function toWritable(x) {
275
283
  if(x && [Uint8Array, Buffer].includes(x.constructor)) {
276
- return asBinary? x: Buffer.from(x).toString('utf8')
284
+ return x
277
285
  }
278
- const str=(_=>{
279
- if(typeof x==='string') return x
280
- if(typeof x==='undefined') return 'undefined'
281
- if(typeof x==='number') {
282
- if(isNaN(x))return 'NaN'
283
- if(x===Infinity) return 'Infinity'
284
- if(x===-Infinity) return '-Infinity'
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sptc",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "Simple Pretreat Toolkit CLI",
5
5
  "main": "index.js",
6
6
  "engines": {
package/tests/www/dd.s ADDED
@@ -0,0 +1,2 @@
1
+ <?js
2
+ const aaa='LLL'
package/tests/www/index.s CHANGED
@@ -9,6 +9,10 @@ echo($_REQUEST_FILE)
9
9
  define('DDD', 2)
10
10
  include(__dirname+'/cc.s')
11
11
 
12
+
13
+ const p=include(__dirname+'/dd.s')
14
+ console.log('p.aaa=', p.aaa)
15
+
12
16
  echo('oaawecR=>'+RRR, Math.random())
13
17
 
14
18
  /*
@@ -0,0 +1,4 @@
1
+ <?js
2
+
3
+ echo(Buffer.from([1, 65]))
4
+ echo('bbbbb')