Error: Can't access lexical declaration
Asked Answered
A

1

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

I got ReferenceError: can't access lexical declaration textBytes before initialization.

Ailyn answered 26/6, 2015 at 8:41 Comment(0)
S
0

I can't reproduce the reference error you are getting, but I think change

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

as this throws TypeError: expected type uint8_t, got "hello" to

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

This will give you a null-terminated string, of length 6. If you want it to be length 5, no null termination then do let textBytes = ctypes.uint8_t.array(5)("hello");

as I am thinking, change

let a = new SECItem;

to

let a = SECItem();

or let a = new SECItem(); they are both same.

If that doesn't fix it, please share the structure of SECItem and what is siBuffer.

Slippage answered 27/6, 2015 at 9:11 Comment(5)
on let textBytes = ctypes.uint8_t.array()("hello"); it throws TypeError: expected type array, got "hello". Add info const siBuffer = 0; const SECItem = ctypes.StructType("SECItem", [ { "type": SECItemType }, { "data": ctypes.uint8_t.ptr }, { "len": ctypes.int } ]);Ailyn
Use unsigned_char instead, so like this: let textBytes = ctypes.unsigned_char.array()("hello"); Slippage
Thanks :) Any books or reference you recommend regarding jsctypes?Ailyn
The best source for js-ctypes is looking at how others did it. I share a ton of snippets on my gists.github i link to them from here: developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/… thats a great page to learn from. Or you can search my gists: gist.github.com/search?q=ctypes+%40noitidart and then there are a lots of stuff on github like here are my ctypes repos: github.com/… definitely read up on MDN it has lots of good stuff developer.mozilla.org/en-US/docs/Mozilla/js-ctypesSlippage
I learned best though from others helping me personally, if you need that help join mozilla irc channel for jsctypes: client00.chat.mibbit.com/… thats the mibbit link or if you have a client: irc://moznet/jsctypesSlippage

© 2022 - 2024 — McMap. All rights reserved.