sys-shim icon indicating copy to clipboard operation
sys-shim copied to clipboard

不能正常处理稀疏数组

Open wll8 opened this issue 1 year ago • 2 comments

同样是中间有 null 的两个数组,为什么第一个数组出现了数据丢失?

起因

await native.unpack([1, null, 2]) // 错误
// 实例输出 [undefined, 1]
// 预期输出 [undefined, 1, null, 2]

await native.table.unpack([1, 2, null, 3]) // 正确
// 实例输出 [undefined, 1, 2, null, 3]
// 预期输出 [undefined, 1, 2, null, 3]

排查

在原生代码中 使用 thread 可以重现此问题:

import console; 
import thread.command
console.open()

var listener = thread.command.instance();
listener.publish = function(...){
  var data = {...}
  console.writeText(web.json.stringify(data), '---\r\n')
}
thread.command.publish({null, 1, 3}) // 输出 [{}] -- 数据丢失
thread.command.publish({1, null, 3}) // 输出 [[1]] -- 数据丢失
thread.command.publish({1, 2, null, 3}) // 输出 [[1,2,null,3]] -- 数据没有丢失

import win
win.loopMessage()

在原生代码中 不使用 thread 没有重现此问题:

import console

fn = function(...){
  var data = {...}
  return table.unpack(data); 
}

console.dumpJson(fn({1, null, 3})) // 输出 [1, null, 3]

import web.json
console.writeText(web.json.stringify({1, null, 3}), '---\r\n') // 输出 [1, null, 3]

import win
win.loopMessage()

环境

  • sys-shim v0.0.1-15
  • aardio v36.19.1

wll8 avatar Jun 27 '24 04:06 wll8

aardio 作者回复:

image

aardio 文档:

image

数组含 null 实例输出:

代码:

import console
var array = { "值:1", null, "值:2", "值:4" } 

console.dump(array)
import win
win.loopMessage()

输出:

{
[1]="值:1";
[3]="值:2";
[4]="值:4"
}table: 029F4860

wll8 avatar Jun 27 '24 06:06 wll8

Deleted.

wll8 avatar Jun 28 '24 10:06 wll8