-
Notifications
You must be signed in to change notification settings - Fork 7.3k
module: fix column offset on first line stack trace #25342
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -441,8 +441,10 @@ Module.prototype._compile = function(content, filename) { | |
|
||
// create wrapper function | ||
var wrapper = Module.wrap(content); | ||
var wrapperOffset = Module.wrapper[0].length; | ||
|
||
var compiledWrapper = runInThisContext(wrapper, { filename: filename }); | ||
var compiledWrapper = runInThisContext(wrapper, | ||
{ filename: filename, columnOffset: -wrapperOffset }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this pass |
||
if (global.v8debug) { | ||
if (!resolvedArgv) { | ||
// we enter the repl if we're not given a filename argument. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -485,13 +485,15 @@ class ContextifyScript : public BaseObject { | |
TryCatch try_catch; | ||
Local<String> code = args[0]->ToString(); | ||
Local<String> filename = GetFilenameArg(args, 1); | ||
Local<Integer> lineOffset = GetLineOffsetArg(args, 1); | ||
Local<Integer> columnOffset = GetColumnOffsetArg(args, 1); | ||
bool display_errors = GetDisplayErrorsArg(args, 1); | ||
if (try_catch.HasCaught()) { | ||
try_catch.ReThrow(); | ||
return; | ||
} | ||
|
||
ScriptOrigin origin(filename); | ||
ScriptOrigin origin(filename, lineOffset, columnOffset); | ||
ScriptCompiler::Source source(code, origin); | ||
Local<UnboundScript> v8_script = | ||
ScriptCompiler::CompileUnbound(env->isolate(), &source); | ||
|
@@ -658,6 +660,51 @@ class ContextifyScript : public BaseObject { | |
} | ||
|
||
|
||
static Local<Integer> GetLineOffsetArg( | ||
const FunctionCallbackInfo<Value>& args, | ||
const int i) { | ||
Local<Integer> defaultLineOffset = Integer::New(args.GetIsolate(), 0); | ||
|
||
if (args[i]->IsUndefined()) { | ||
return defaultLineOffset; | ||
} | ||
if (args[i]->IsInt32()) { | ||
return args[i].As<Integer>(); | ||
} | ||
if (!args[i]->IsObject()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is the only check you actually need here. The |
||
return defaultLineOffset; | ||
} | ||
|
||
Local<String> key = FIXED_ONE_BYTE_STRING(args.GetIsolate(), "lineOffset"); | ||
Local<Value> value = args[i].As<Object>()->Get(key); | ||
|
||
return value->IsUndefined() ? defaultLineOffset : value->ToInteger(); | ||
} | ||
|
||
|
||
static Local<Integer> GetColumnOffsetArg( | ||
const FunctionCallbackInfo<Value>& args, | ||
const int i) { | ||
Local<Integer> defaultColumnOffset = Integer::New(args.GetIsolate(), 0); | ||
|
||
if (args[i]->IsUndefined()) { | ||
return defaultColumnOffset; | ||
} | ||
if (args[i]->IsInt32()) { | ||
return args[i].As<Integer>(); | ||
} | ||
if (!args[i]->IsObject()) { | ||
return defaultColumnOffset; | ||
} | ||
|
||
Local<String> key = FIXED_ONE_BYTE_STRING(args.GetIsolate(), | ||
"columnOffset"); | ||
Local<Value> value = args[i].As<Object>()->Get(key); | ||
|
||
return value->IsUndefined() ? defaultColumnOffset : value->ToInteger(); | ||
} | ||
|
||
|
||
static bool EvalMachine(Environment* env, | ||
const int64_t timeout, | ||
const bool display_errors, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
s |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -306,3 +306,18 @@ process.on('exit', function() { | |
// #1440 Loading files with a byte order marker. | ||
assert.equal(42, require('../fixtures/utf8-bom.js')); | ||
assert.equal(42, require('../fixtures/utf8-bom.json')); | ||
|
||
// #9445 Error on first line of a module have the correct column number. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can just be (might need to split this across lines if it's more than 80 characters):
|
||
var gh9445Exception; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you just name this |
||
try { | ||
var err_js = require('../fixtures/module-err.js'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to assign this to a variable since you don't reference it anywhere. |
||
} | ||
catch (e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you move this to the previous line like |
||
gh9445Exception = e; | ||
assert.ok(/module-err.js:1:1/.test(e.stack), | ||
'expected appearance of proper offset in Error stack'); | ||
} | ||
assert.ok(gh9445Exception, | ||
'expected exception from runInContext offset test'); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,22 @@ catch (e) { | |
assert.ok(gh1140Exception, | ||
'expected exception from runInContext signature test'); | ||
|
||
// Issue GH-9445: | ||
console.error('test runInContext offset'); | ||
var gh9445Exception; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just use |
||
try { | ||
vm.runInContext('throw new Error()', context, { filename: 'expected-filename.js', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leave the opening curly brace, |
||
lineOffset: 32, | ||
columnOffset: 123}); | ||
} | ||
catch (e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this up to the previous line. |
||
gh9445Exception = e; | ||
assert.ok(/expected-filename.js:33:130/.test(e.stack), | ||
'expected appearance of proper offset in Error stack'); | ||
} | ||
assert.ok(gh9445Exception, | ||
'expected exception from runInContext offset test'); | ||
|
||
// GH-558, non-context argument segfaults / raises assertion | ||
[undefined, null, 0, 0.0, '', {}, []].forEach(function(e) { | ||
assert.throws(function() { script.runInContext(e); }, TypeError); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be pulled out of the function to avoid calculating every time.