Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Debugging Tips

This article needs a technical review. How you can help.

Fast Testing

The scratchpad is an excellent tool for running js-ctypes without having to zip up any add-on source files and install them. Code can be run from scratchpad and tested very fast. Here is a screencast demonstrating how to set it up:

https://www.youtube.com/watch?v=oo4STWceGTM

Printing CData and CType

Currently console.log doesn't show type information of CData. Running  the following code shows only partial value information.

let { ctypes } = Components.utils.import("resource://gre/modules/ctypes.jsm", {});
let i = ctypes.int32_t(10);
console.log(i);
let Point = ctypes.StructType("Point", [{ x: ctypes.int32_t }, { y: ctypes.int32_t }])
let p = Point(10, 20);
console.log(p);
let pp = p.address();
console.log(pp);

The result will be as following:

CData { value: 10 }
CData { x: 10, y: 20 }
CData { contents: CData }

To see more descriptive information, you can use .toSource().

let { ctypes } = Components.utils.import("resource://gre/modules/ctypes.jsm", {});
let i = ctypes.int32_t(10);
console.log(i.toSource());
let Point = ctypes.StructType("Point", [{ x: ctypes.int32_t }, { y: ctypes.int32_t }])
let p = Point(10, 20);
console.log(p.toSource());
let pp = p.address();
console.log(pp.toSource());

The result will be :

ctypes.int32_t(10)
Point(10, 20)
Point.ptr(ctypes.UInt64("0x15fdafb08"))

To see the complete type information, you can use .constructor.toSource(), to print the source of CType.

let { ctypes } = Components.utils.import("resource://gre/modules/ctypes.jsm", {});
let i = ctypes.int32_t(10);
console.log(i.constructor.toSource());
let Point = ctypes.StructType("Point", [{ x: ctypes.int32_t }, { y: ctypes.int32_t }])
let p = Point(10, 20);
console.log(p.constructor.toSource());
let pp = p.address();
console.log(pp.constructor.toSource());

The result will be as per the following:

ctypes.int32_t
ctypes.StructType("Point", [{ "x": ctypes.int32_t }, { "y": ctypes.int32_t }])
ctypes.StructType("Point", [{ "x": ctypes.int32_t }, { "y": ctypes.int32_t }]).ptr

Document Tags and Contributors

 Contributors to this page: PushpitaPikuDey, arai, Noitidart
 Last updated by: PushpitaPikuDey,