错误:无法访问词法声明

时间:2015-06-26 08:41:04

标签: javascript firefox-addon jsctypes nss

let textBytes = ctypes.uint8_t("hello"); 
let a = new SECItem;
a.type = siBuffer;
a.data = textBytes.address();
a.len = textBytes.length;

我得到了ReferenceError:在初始化之前无法访问词法声明textBytes。

1 个答案:

答案 0 :(得分:0)

我无法重现您所获得的参考错误,但我认为更改

let textBytes = ctypes.uint8_t("hello"); 

因为这会将TypeError: expected type uint8_t, got "hello"抛给

let textBytes = ctypes.uint8_t.array()("hello"); 

这将为您提供一个以空值终止的字符串,长度为6.如果您希望它的长度为5,则不会出现空终止,然后执行let textBytes = ctypes.uint8_t.array(5)("hello");

正如我所想,改变

let a = new SECItem;

let a = SECItem();

let a = new SECItem();他们都是一样的。

如果不能解决问题,请分享SECItem的结构以及siBuffer的内容。