}
void
-ReportException(v8::TryCatch* try_catch)
+ReportException(TryCatch* try_catch)
{
- v8::HandleScope handle_scope;
- v8::String::Utf8Value exception(try_catch->Exception());
+ HandleScope handle_scope;
+ String::Utf8Value exception(try_catch->Exception());
const char* exception_string = ToCString(exception);
- v8::Handle<v8::Message> message = try_catch->Message();
+ Handle<Message> message = try_catch->Message();
if (message.IsEmpty()) {
// V8 didn't provide any extra information about this error; just
// print the exception.
- printf("%s\n", exception_string);
+ fprintf(stderr, "%s\n", exception_string);
} else {
- message->PrintCurrentStackTrace(stdout);
-
// Print (filename):(line number): (message).
- v8::String::Utf8Value filename(message->GetScriptResourceName());
+ String::Utf8Value filename(message->GetScriptResourceName());
const char* filename_string = ToCString(filename);
int linenum = message->GetLineNumber();
- printf("%s:%i: %s\n", filename_string, linenum, exception_string);
+ fprintf(stderr, "%s:%i: %s\n", filename_string, linenum, exception_string);
// Print line of source code.
- v8::String::Utf8Value sourceline(message->GetSourceLine());
+ String::Utf8Value sourceline(message->GetSourceLine());
const char* sourceline_string = ToCString(sourceline);
- printf("%s\n", sourceline_string);
+ fprintf(stderr, "%s\n", sourceline_string);
// Print wavy underline (GetUnderline is deprecated).
int start = message->GetStartColumn();
for (int i = 0; i < start; i++) {
- printf(" ");
+ fprintf(stderr, " ");
}
int end = message->GetEndColumn();
for (int i = start; i < end; i++) {
- printf("^");
+ fprintf(stderr, "^");
}
- printf("\n");
+ fprintf(stderr, "\n");
+
+ message->PrintCurrentStackTrace(stderr);
}
}
Handle<Value>
node_dlopen (const v8::Arguments& args)
{
- if (args.Length() < 2) return Undefined();
-
HandleScope scope;
+ if (args.Length() < 2) return Undefined();
+
String::Utf8Value filename(args[0]->ToString());
Local<Object> target = args[1]->ToObject();
void *handle = dlopen(*filename, RTLD_LAZY);
if (handle == NULL) {
- ThrowException(String::New("dlopen() failed."));
- return Undefined();
+ return ThrowException(String::New("dlopen() failed."));
}
void *init_handle = dlsym(handle, "init");
{
printf("Usage: node [switches] script.js [arguments] \n"
" -v, --version print node's version\n"
+ " --libs print linker flags for modules\n"
+ " --cflags print pre-processor and compiler flags\n"
" --v8-options print v8 command line options\n");
}
};
node.Module.prototype.load = function (callback) {
+ if (this.filename.match(/\.node$/)) {
+ return this.loadObject(callback);
+ } else {
+ return this.loadScript(callback);
+ }
+};
+
+node.Module.prototype.loadObject = function (callback) {
+ var self = this;
+ var loadPromise = new node.Promise();
+ self.loadPromise = loadPromise;
+ // XXX Not yet supporting loading from HTTP. would need to download the
+ // file, store it to tmp then run dlopen on it.
+ node.fs.exists(self.filename, function (does_exist) {
+ if (does_exist) {
+ node.dlopen(self.filename, self.target); // FIXME synchronus
+ loadPromise.emitSuccess([self.target]);
+ } else {
+ node.stdio.writeError("Error reading " + self.filename + "\n");
+ loadPromise.emitError();
+ }
+ });
+ return loadPromise;
+};
+
+node.Module.prototype.loadScript = function (callback) {
var self = this;
if (self.loaded) {
throw "Module '" + self.filename + "' is already loaded.";
if (child.loaded) {
nloaded++;
} else {
- child.addCallback(function () {
+ child.loadPromise.addCallback(function () {
nloaded++;
if (children.length == nloaded && callback) callback();
});
libdir=${prefix}/lib
includedir=${prefix}/include/node
-Name: node@DEBUG_EXT@
+Name: node
Description: v8 powered non-browser javascript
Version: @VERSION@
-Libs: @LIBFLAGS@ -L${libdir} -lnode@DEBUG_EXT@
+Libs: @LIBFLAGS@ -R${libdir}
Cflags: @CCFLAGS@ @CPPFLAGS@ -I${includedir}
-#define NODE_VERSION "@VERSION@"
-#define NODE_CFLAGS "@CCFLAGS@ @CPPFLAGS@ -I@PREFIX@/include"
-#define NODE_LIBFLAGS "@LIBFLAGS@ -L@PREFIX@/lib -lnode@DEBUG_EXT@"
+#ifndef node_version_h
+#define node_version_h
+
+#ifdef NDEBUG
+# define NODE_VERSION "@VERSION@"
+#else
+# define NODE_VERSION "@VERSION@ (debug)"
+#endif
+#define NODE_CFLAGS "@CCFLAGS@ @CPPFLAGS@ -I@PREFIX@/include/node"
+#define NODE_LIBFLAGS "@LIBFLAGS@ -R@PREFIX@/lib"
+
+#endif /* node_version_h */
conf.env["USE_DEBUG"] = Options.options.debug
conf.check(lib='dl', uselib_store='DL')
+ conf.env.append_value("LINKFLAGS_DL", "-rdynamic")
+
if Options.options.debug:
conf.check(lib='profiler', uselib_store='PROFILER')
libnode.uselib_local = "evcom ev eio http_parser coupling"
libnode.uselib = "UDNS V8 EXECINFO PROFILER EFENCE DL"
libnode.install_path = '${PREFIX}/lib'
- bld.install_files('${PREFIX}/include/node/', 'config.h src/node.h src/node_version.h src/object_wrap.h');
+
+
+ libnode_static = bld.new_task_gen("cxx", "staticlib")
+ libnode_static.name = "node-static"
+ libnode_static.target = libnode.target
+ libnode_static.source = libnode.source
+ libnode_static.includes = libnode.includes
+ libnode_static.uselib_local = libnode.uselib_local
+ libnode_static.uselib = libnode.uselib
### node
node = bld.new_task_gen("cxx", "program")
node.target = 'node'
node.source = "src/main.cc"
node.includes = libnode.includes
- node.uselib_local = "node"
+ node.uselib_local = "node-static"
node.install_path = '${PREFIX}/bin'
node.chmod = 0755
-
def subflags(program):
- debug_ext = ""
- if program.target == "node_g": debug_ext = "_g"
x = { 'CCFLAGS' : " ".join(program.env["CCFLAGS"])
, 'CPPFLAGS' : " ".join(program.env["CPPFLAGS"])
, 'LIBFLAGS' : " ".join(program.env["LIBFLAGS"])
, 'VERSION' : VERSION
, 'PREFIX' : program.env["PREFIX"]
- , 'DEBUG_EXT' : debug_ext
}
return x;
-
# process file.pc.in -> file.pc
pkgconfig = bld.new_task_gen('subst', before="cxx")
pkgconfig.source = 'src/node.pc.in'
node_version.source = 'src/node_version.h.in'
node_version.target = 'src/node_version.h'
node_version.dict = subflags(node)
+ node_version.install_path = '${PREFIX}/include/node'
if bld.env["USE_DEBUG"]:
node_g = node.clone("debug")
libnode_g = libnode.clone("debug")
libnode_g.target = "node_g"
- pkgconfig_g = pkgconfig.clone("debug")
- pkgconfig_g.dict = subflags(node_g)
- pkgconfig_g.target = 'node_g.pc'
+ libnode_static_g = libnode_static.clone("debug")
+ libnode_static_g.target = "node_g"
node_version_g = node_version.clone("debug")
node_version_g.dict = subflags(node_g)
+ node_version_g.install_path = None
+
+ bld.install_files('${PREFIX}/include/node/', """
+ config.h
+ src/node.h
+ src/object_wrap.h
+ src/events.h
+ src/net.h
+ """);