Skip to content
This repository

Support startup of embedded node better #733

Closed
wants to merge 1 commit into from

4 participants

Aria Stewart Dean McNamee Trevor Norris Ben Noordhuis
Aria Stewart

This patch adds a callback to the node::Start and node::Load function to allow an embedding module to add things to the global scope.

Node's great to attach libraries to, where the node binary is the entry point -- not quite so smooth embedding libnode into an existing app. This helps.

Aria Stewart Add a startup callback in C
Allows a startup callback to be called to set up an embedded environment
with additional bindings.
a185953
Dean McNamee
deanm commented

I have a similar patch out, would it solve your use case? Basically you would write your own Start() with the new exported functions:

deanm@3542650

Trevor Norris
Collaborator

Non-relevant. Load function has changed too much since submission of this pull request.

Ben Noordhuis bnoordhuis closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Feb 28, 2011
Aria Stewart Add a startup callback in C
Allows a startup callback to be called to set up an embedded environment
with additional bindings.
a185953
This page is out of date. Refresh to see the latest.
8  src/node.cc
@@ -1901,7 +1901,7 @@ static Handle<Array> EnvEnumerator(const AccessorInfo& info) {
1901 1901
 }
1902 1902
 
1903 1903
 
1904  
-static void Load(int argc, char *argv[]) {
  1904
+static void Load(int argc, char *argv[], void (startup_callback)(Local<Object>)) {
1905 1905
   HandleScope scope;
1906 1906
 
1907 1907
   int i, j;
@@ -2064,6 +2064,8 @@ static void Load(int argc, char *argv[]) {
2064 2064
   InitDTrace(global);
2065 2065
 #endif
2066 2066
 
  2067
+  if(startup_callback) startup_callback(global);
  2068
+
2067 2069
   f->Call(global, 1, args);
2068 2070
 
2069 2071
   if (try_catch.HasCaught())  {
@@ -2224,7 +2226,7 @@ static int RegisterSignalHandler(int signal, void (*handler)(int)) {
2224 2226
 #endif // __POSIX__
2225 2227
 
2226 2228
 
2227  
-int Start(int argc, char *argv[]) {
  2229
+int Start(int argc, char *argv[], void (startup_callback)(Local<Object>)) {
2228 2230
   // Hack aroung with the argv pointer. Used for process.title = "blah".
2229 2231
   argv = node::Platform::SetupArgs(argc, argv);
2230 2232
 
@@ -2358,7 +2360,7 @@ int Start(int argc, char *argv[]) {
2358 2360
 
2359 2361
   // Create all the objects, load modules, do everything.
2360 2362
   // so your next reading stop should be node::Load()!
2361  
-  node::Load(argc, argv);
  2363
+  node::Load(argc, argv, startup_callback);
2362 2364
 
2363 2365
   // TODO Probably don't need to start this each time.
2364 2366
   // Avoids failing on test/simple/test-eio-race3.js though
2  src/node.h
@@ -17,7 +17,7 @@
17 17
 
18 18
 namespace node {
19 19
 
20  
-int Start (int argc, char *argv[]);
  20
+int Start (int argc, char *argv[], void(startup_callback)(v8::Local<v8::Object>));
21 21
 
22 22
 #define NODE_PSYMBOL(s) Persistent<String>::New(String::NewSymbol(s))
23 23
 
2  src/node_main.cc
@@ -3,5 +3,5 @@
3 3
 #include <node.h>
4 4
 
5 5
 int main(int argc, char *argv[]) {
6  
-  return node::Start(argc, argv);
  6
+  return node::Start(argc, argv, NULL);
7 7
 }
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.