Permalink
Browse files

Move global context to singleton so other modules can get at it

  • Loading branch information...
1 parent 074b022 commit 1dec5ea90aa093110204852802f07a771c26307d @creationix creationix committed Mar 23, 2012
Showing with 12 additions and 12 deletions.
  1. +1 −1 deps/candor
  2. +1 −1 deps/libuv
  3. +6 −1 src/cio.cc
  4. +1 −3 src/cio.h
  5. +3 −6 src/main.cc
View
@@ -161,9 +161,14 @@ static Value* LoadBuiltin(uint32_t argc, Value* argv[]) {
return Nil::New();
}
-void cio_init(Object* global) {
+static Handle<Object> global;
+Object* cio_global_context() {
+ if (!global.IsEmpty()) return *global;
+ global.Wrap(Object::New());
global->Set("print", Function::New(Print));
global->Set("prettyPrint", Function::New(PrettyPrint));
global->Set("exit", Function::New(Exit));
global->Set("require", Function::New(LoadBuiltin));
+ return *global;
}
+
View
@@ -3,8 +3,6 @@
#include "candor.h"
-using namespace candor;
-
-void cio_init(Object* global);
+candor::Object* cio_global_context();
#endif
View
@@ -3,7 +3,7 @@
#include "candor.h"
#include "uv.h"
-#include "cio.h" // cio_init
+#include "cio.h" // cio_global_context
#include <stdio.h> // fprintf
#include <stdlib.h> // abort
@@ -61,11 +61,8 @@ int main(int argc, char** argv) {
}
- // Create a global context
- Handle<Object> global(Object::New());
- cio_init(*global);
-
- code->SetContext(*global);
+ Object* global = cio_global_context();
+ code->SetContext(global);
code->Call(0, NULL);
// Start the libuv event loop

0 comments on commit 1dec5ea

Please sign in to comment.