我不确定这段代码有什么问题。src 是Uint8Array
一个长度大于 0 的对象。
function makeImageFromChannel(src) {
var image = new Uint8Array(src.length * 4),
i = 0,
index = 0,
value = 0;
console.log(src.BYTES_PER_ELEMENT)
console.log(src.map)
for (i=0; i<src.length; i++) {
value = src[i]|0;
image[index] = value;
image[index + 1] = value;
image[index + 2] = value;
image[index + 3] = 255;
index += 4;
}
return image;
}
var vars = new Uint8Array(23034);
for(var i=0; i<23034; i++) {
vars[i] = (i % 254) + 1
}
makeImageFromChannel(vars);
这是我在运行此命令时可以在终端中多次读取的内容node --trace_deopt --allow-natives-syntax script.js
。
[deoptimizing: begin 0x36125ec63a21 makeImageFromChannel @13]
translating makeImageFromChannel => node=59, height=24
0x7fff5fbfe798: [top + 64] <- 0x3feb15c04121 ; r8 0x3feb15c04121 <undefined>
0x7fff5fbfe790: [top + 56] <- 0x2bc986d9ffc1 ; rdi 0x2bc986d9ffc1 <an Uint8Array>
0x7fff5fbfe788: [top + 48] <- 0x2ea32af21c29 ; caller's pc
0x7fff5fbfe780: [top + 40] <- 0x7fff5fbfe808 ; caller's fp
0x7fff5fbfe778: [top + 32] <- 0x3feb15c414b1; context
0x7fff5fbfe770: [top + 24] <- 0x36125ec63a21; function
0x7fff5fbfe768: [top + 16] <- 0x2bc986c218d1 ; rdx 0x2bc986c218d1 <an Uint8Array>
0x7fff5fbfe760: [top + 8] <- 135448 ; rbx (smi)
0x7fff5fbfe758: [top + 0] <- 541792 ; rax (smi)
[deoptimizing: end 0x36125ec63a21 makeImageFromChannel => node=59, pc=0x2ea32af27c70, state=NO_REGISTERS, alignment=no padding, took 0.033 ms]
[removing optimized code for: makeImageFromChannel]
我不确定它是如何在其中找到未定义的值的。