Skip to content

Commit

Permalink
reload test
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Feb 7, 2011
1 parent 2b03ba5 commit ca4ab71
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
20 changes: 17 additions & 3 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ var runInThisContext = Script.runInThisContext;
var runInNewContext = Script.runInNewContext;
var assert = require('assert').ok;

if (process.reloadMode) {
var Debug = v8debug.Debug;
}

function Module(id, parent) {
this.id = id;
this.exports = {};
Expand Down Expand Up @@ -200,6 +204,7 @@ Module._load = function(request, parent, isMain) {

Module._cache[filename] = module;
module.load(filename);

return module.exports;
};

Expand Down Expand Up @@ -298,11 +303,20 @@ Module.prototype._compile = function(content, filename) {
var wrapper = Module.wrap(content);

var compiledWrapper = runInThisContext(wrapper, filename, true);
if (filename === process.argv[1] && global.v8debug) {
global.v8debug.Debug.setBreakPoint(compiledWrapper, 0, 0);
if (filename === process.argv[1] && Debug) {
Debug.setBreakPoint(compiledWrapper, 0, 0);
}
var args = [self.exports, require, self, filename, dirname];
return compiledWrapper.apply(self.exports, args);
var rv = compiledWrapper.apply(self.exports, args);

if (process.reloadMode) {
console.log("hello world");
console.log(Debug);
var script = Debug.findScript(compiledWrapper);
console.log(script.source);
}

return rv;
};

// Native extension for .js
Expand Down
31 changes: 26 additions & 5 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ static Persistent<String> listeners_symbol;
static Persistent<String> uncaught_exception_symbol;
static Persistent<String> emit_symbol;

static bool reload_mode = false;
static bool debug_object = false;

static char *eval_string = NULL;
static int option_end_index = 0;
Expand Down Expand Up @@ -1983,6 +1985,10 @@ static void Load(int argc, char *argv[]) {
NODE_SET_METHOD(process, "chdir", Chdir);
NODE_SET_METHOD(process, "cwd", Cwd);

if (reload_mode) {
process->Set(String::New("reloadMode"), True());
}

#ifdef __POSIX__
NODE_SET_METHOD(process, "getuid", GetUid);
NODE_SET_METHOD(process, "setuid", SetUid);
Expand Down Expand Up @@ -2099,9 +2105,15 @@ static void ParseArgs(int *argc, char **argv) {
// TODO use parse opts
for (i = 1; i < *argc; i++) {
const char *arg = argv[i];
if (strstr(arg, "--debug") == arg) {
if (strcmp(arg, "--debug") == 0 || strcmp(arg, "--debug-brk") == 0) {
ParseDebugOpt(arg);
argv[i] = const_cast<char*>("");

} else if (strcmp(arg, "--reload") == 0) {
reload_mode = true;
debug_object = true;
argv[i] = const_cast<char*>("--expose_gc");

} else if (strcmp(arg, "--version") == 0 || strcmp(arg, "-v") == 0) {
printf("%s\n", NODE_VERSION);
exit(0);
Expand Down Expand Up @@ -2205,15 +2217,24 @@ int Start(int argc, char *argv[]) {
int v8argc = node::option_end_index;
char **v8argv = argv;

if (node::debug_wait_connect) {
if (debug_wait_connect) debug_object = true;

if (debug_object) {
// v8argv is a copy of argv up to the script file argument +2 if --debug-brk
// to expose the v8 debugger js object so that node.js can set
// a breakpoint on the first line of the startup script
v8argc += 2;
v8argv = new char*[v8argc];
memcpy(v8argv, argv, sizeof(argv) * node::option_end_index);
v8argv[node::option_end_index] = const_cast<char*>("--expose_debug_as");
v8argv[node::option_end_index + 1] = const_cast<char*>("v8debug");

for (int i = 0; i < option_end_index; i++) {
v8argv[i] = argv[i];
}

v8argv[option_end_index] = const_cast<char*>("--expose_debug_as=v8debug");

for (int i = option_end_index; i < argc; i++) {
v8argv[i + 1] = argv[i];
}
}

// For the normal stack which moves from high to low addresses when frames
Expand Down
9 changes: 7 additions & 2 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@
this.loaded = false;
}

NativeModule.functionid = 0;

NativeModule._source = process.binding('natives');
NativeModule._cache = {};

Expand Down Expand Up @@ -408,11 +410,14 @@
}

NativeModule.wrap = function(script) {
return NativeModule.wrapper[0] + script + NativeModule.wrapper[1];
this.functionid = ++NativeModule.functionid;
return NativeModule.wrapper[0] +
script +
NativeModule.wrapper[1];
};

NativeModule.wrapper = [
'(function (exports, require, module, __filename, __dirname) { ',
'(function __f(exports, require, module, __filename, __dirname) { ',
'\n});'
];

Expand Down

0 comments on commit ca4ab71

Please sign in to comment.