Skip to content
Jamie Davis edited this page Jan 13, 2017 · 2 revisions

Welcome to the guide for new developers on this project.

Source

This module is a Node.js C++ addon. It is a mix of JavaScript (actually, LiveScript) and C++. The module is driven by the C++ code, which loads and registers the JavaScript code (see WebWorkerThreads.cc:Init).

Compiling from source

Since this module is a C++ addon, you have to compile it for your machine. This will produce the build/Release/WebWorkerThreads.node file containing the module.

cd your_clone
npm run js # ensure the latest version of the LiveScript code
node-gyp configure build

Architecture

Initialization

When you require('webworker-threads'), the webworker-threads index.js file loads the WebWorkerThreads(.node) file using the bindings module. When require'd, WebWorkerThreads is initialized by its Init function (see the call to NODE_MODULE in WebWorkerThreads.cc).

New threads

New threads are created by WebWorkerThreads.cc:Create, which creates a typeThread struct and creates a new thread (uv_thread_create) starting in WebWorkerThreads.cc:aThread.

LiveScript -> JavaScript -> minified

The LiveScript files (X.ls) are the "master" versions of the JavaScript portion of the module. The JavaScript files (X.js) are generated automatically from their LiveScript equivalents, and the minified files (X.js.c) are the contents of the js files (each ASCII character is represented in hex). Minification makes it easier to work with the JS code in C++.

To change or extend the "JS-level" code, modify the LiveScript files, then run npm run js to produce updated versions of the .js and .js.c files.

The C++ code uses NAN to reduce dependency on the V8 API.

Tests

See the tests/ subdir. What each test does is not well documented, nor is there a test matrix mapping module features to tests.

I don't know how to run the full test suite other than manually or with a bash script. npm test only executes node test-package.js, which is just a smoke test.