Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
core: Don't show source of native module in error
Browse files Browse the repository at this point in the history
  • Loading branch information
Shigeki Ohtsu committed May 9, 2012
1 parent 84e6b32 commit 267c31f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/node.cc
Expand Up @@ -1168,12 +1168,21 @@ void DisplayExceptionLine (TryCatch &try_catch) {
}
}

bool is_native_module(const char* filename) {
const char* native_module_postfix = "_native";
int pos = strlen(filename) - strlen(native_module_postfix);
if(pos > 0 && strcmp(filename+pos, native_module_postfix) == 0) {
return true;
} else {
return false;
}
}

static void ReportException(TryCatch &try_catch, bool show_line) {
HandleScope scope;
Handle<Message> message = try_catch.Message();

if (show_line) DisplayExceptionLine(try_catch);
String::Utf8Value filename(message->GetScriptResourceName());
if (show_line && !is_native_module(*filename)) DisplayExceptionLine(try_catch);

String::Utf8Value trace(try_catch.StackTrace());

Expand Down
5 changes: 3 additions & 2 deletions src/node.js
Expand Up @@ -477,6 +477,7 @@

function NativeModule(id) {
this.filename = id + '.js';
this.nativename = id + '_native';
this.id = id;
this.exports = {};
this.loaded = false;
Expand Down Expand Up @@ -534,8 +535,8 @@
var source = NativeModule.getSource(this.id);
source = NativeModule.wrap(source);

var fn = runInThisContext(source, this.filename, true);
fn(this.exports, NativeModule.require, this, this.filename);
var fn = runInThisContext(source, this.nativename, true);
fn(this.exports, NativeModule.require, this, this.nativename);

this.loaded = true;
};
Expand Down

0 comments on commit 267c31f

Please sign in to comment.