This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a template for the global object and set the built-in global functions | |
Local<ObjectTemplate> global = ObjectTemplate::New(isolate); | |
global->Set( | |
String::NewFromUtf8(isolate, "log"), | |
FunctionTemplate::New(isolate, LogCallback) | |
); | |
// Each processor gets its own context so different processors do not affect each other | |
Persistent<Context> context = Context::New(isolate, NULL, global); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a new context. | |
Local<Context> context = Context::New(isolate); | |
// Enter the context for compiling and running the hello world script. | |
Context::Scope context_scope(context); | |
// Create a string containing the JavaScript source code. | |
Local<String> source = String::NewFromUtf8(isolate, "'Hello' + ', World!'"); | |
// Compile the source code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct node_module { | |
int nm_version; | |
unsigned int nm_flags; | |
void* nm_dso_handle; | |
const char* nm_filename; | |
node::addon_register_func nm_register_func; | |
node::addon_context_register_func nm_context_register_func; | |
const char* nm_modname; | |
void* nm_priv; | |
struct node_module* nm_link; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void node_module_register(void* m) { | |
struct node_module* mp = reinterpret_cast<struct node_module*>(m); | |
if (mp->nm_flags & NM_F_BUILTIN) { | |
mp->nm_link = modlist_builtin; | |
modlist_builtin = mp; | |
} else if (!node_is_initialized) { | |
// "Linked" modules are included as part of the node project. | |
// Like builtins they are registered *before* node::Init runs. | |
mp->nm_flags = NM_F_LINKED; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct node_module* get_builtin_module(const char* name) { | |
struct node_module* mp; | |
for (mp = modlist_builtin; mp != nullptr; mp = mp->nm_link) { | |
if (strcmp(mp->nm_modname, name) == 0) | |
break; | |
} | |
CHECK(mp == nullptr || (mp->nm_flags & NM_F_BUILTIN) != 0); | |
return (mp); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Binding(const FunctionCallbackInfo<Value>& args) { | |
Environment* env = Environment::GetCurrent(args); | |
Local<String> module = args[0]->ToString(env->isolate()); | |
node::Utf8Value module_v(env->isolate(), module); | |
Local<Object> cache = env->binding_cache_object(); | |
Local<Object> exports; | |
if (cache->Has(module)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, priv, flags) \ | |
extern "C" { \ | |
static node::node_module _module = \ | |
{ \ | |
NODE_MODULE_VERSION, \ | |
flags, \ | |
NULL, \ | |
__FILE__, \ | |
NULL, \ | |
(node::addon_context_register_func) (regfunc), \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Include header files here | |
namespace node { | |
// Using namespaces | |
// Define useful macros | |
// And a lot other stuff here in C++ | |
void UpdateHeapStatisticsArrayBuffer(const FunctionCallbackInfo<Value>& args) { | |
// Some logic here... | |
} | |
void SetFlagsFromString(const FunctionCallbackInfo<Value>& args) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function NativeModule(id) { | |
this.filename = id + '.js'; | |
this.id = id; | |
this.exports = {}; | |
this.loaded = false; | |
} | |
NativeModule._source = process.binding('natives'); | |
NativeModule._cache = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void DefineJavaScript(Environment* env, Handle<Object> target) { | |
HandleScope scope(env->isolate()); | |
for (int i = 0; natives[i].name; i++) { | |
if (natives[i].source != node_native) { | |
Local<String> name = String::NewFromUtf8(env->isolate(), natives[i].name); | |
Handle<String> source = String::NewFromUtf8(env->isolate(), natives[i].source, String::kNormalString, natives[i].source_len); | |
target->Set(name, source); | |
} | |
} |
OlderNewer