错误:无法访问词汇声明

Non*_*ron 6 javascript nss firefox-addon jsctypes

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

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

Noi*_*art 0

我无法重现您收到的参考错误,但我认为需要更改

let textBytes = ctypes.uint8_t("hello"); 
Run Code Online (Sandbox Code Playgroud)

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

let textBytes = ctypes.uint8_t.array()("hello"); 
Run Code Online (Sandbox Code Playgroud)

这将为您提供一个长度为 6 的以 null 结尾的字符串。如果您希望它的长度为 5,则不以 null 结尾let textBytes = ctypes.uint8_t.array(5)("hello");

正如我所想,改变

let a = new SECItem;
Run Code Online (Sandbox Code Playgroud)

let a = SECItem();
Run Code Online (Sandbox Code Playgroud)

或者let a = new SECItem();它们都是相同的。

如果这不能解决问题,请分享 的结构SECItem和内容siBuffer