Remove inessential functions from the JS Script class
Moved functionality of Script.{lineCount, lineFromPosition, sourceLine, locationFromLine, and sourceSlice} into runtime functions. R=yangguo@chromium.org BUG= Review-Url: https://codereview.chromium.org/2003303002 Cr-Commit-Position: refs/heads/master@{#36469}
This commit is contained in:
parent
2abe5cd275
commit
9ffedb50d5
@ -361,7 +361,7 @@ ScriptBreakPoint.prototype.matchesScript = function(script) {
|
||||
} else {
|
||||
// We might want to account columns here as well.
|
||||
if (!(script.line_offset <= this.line_ &&
|
||||
this.line_ < script.line_offset + script.lineCount())) {
|
||||
this.line_ < script.line_offset + %ScriptLineCount(script))) {
|
||||
return false;
|
||||
}
|
||||
if (this.type_ == Debug.ScriptBreakPointType.ScriptName) {
|
||||
@ -383,11 +383,11 @@ ScriptBreakPoint.prototype.set = function (script) {
|
||||
// first piece of breakable code on the line try to find the column on the
|
||||
// line which contains some source.
|
||||
if (IS_UNDEFINED(column)) {
|
||||
var source_line = script.sourceLine(this.line());
|
||||
var source_line = %ScriptSourceLine(script, line || script.line_offset);
|
||||
|
||||
// Allocate array for caching the columns where the actual source starts.
|
||||
if (!script.sourceColumnStart_) {
|
||||
script.sourceColumnStart_ = new GlobalArray(script.lineCount());
|
||||
script.sourceColumnStart_ = new GlobalArray(%ScriptLineCount(script));
|
||||
}
|
||||
|
||||
// Fill cache if needed and get column where the actual source starts.
|
||||
@ -536,14 +536,14 @@ Debug.sourcePosition = function(f) {
|
||||
Debug.findFunctionSourceLocation = function(func, opt_line, opt_column) {
|
||||
var script = %FunctionGetScript(func);
|
||||
var script_offset = %FunctionGetScriptSourcePosition(func);
|
||||
return script.locationFromLine(opt_line, opt_column, script_offset);
|
||||
return %ScriptLocationFromLine(script, opt_line, opt_column, script_offset);
|
||||
};
|
||||
|
||||
|
||||
// Returns the character position in a script based on a line number and an
|
||||
// optional position within that line.
|
||||
Debug.findScriptSourcePosition = function(script, opt_line, opt_column) {
|
||||
var location = script.locationFromLine(opt_line, opt_column);
|
||||
var location = %ScriptLocationFromLine(script, opt_line, opt_column, 0);
|
||||
return location ? location.position : null;
|
||||
};
|
||||
|
||||
@ -2085,18 +2085,34 @@ DebugCommandProcessor.prototype.sourceRequest_ = function(request, response) {
|
||||
return response.failed('No source');
|
||||
}
|
||||
|
||||
// Get the source slice and fill it into the response.
|
||||
var slice = script.sourceSlice(from_line, to_line);
|
||||
if (!slice) {
|
||||
var raw_script = script.value();
|
||||
|
||||
// Sanitize arguments and remove line offset.
|
||||
var line_offset = raw_script.line_offset;
|
||||
var line_count = %ScriptLineCount(raw_script);
|
||||
from_line = IS_UNDEFINED(from_line) ? 0 : from_line - line_offset;
|
||||
to_line = IS_UNDEFINED(to_line) ? line_count : to_line - line_offset;
|
||||
|
||||
if (from_line < 0) from_line = 0;
|
||||
if (to_line > line_count) to_line = line_count;
|
||||
|
||||
if (from_line >= line_count || to_line < 0 || from_line > to_line) {
|
||||
return response.failed('Invalid line interval');
|
||||
}
|
||||
|
||||
// Fill in the response.
|
||||
|
||||
response.body = {};
|
||||
response.body.source = slice.sourceText();
|
||||
response.body.fromLine = slice.from_line;
|
||||
response.body.toLine = slice.to_line;
|
||||
response.body.fromPosition = slice.from_position;
|
||||
response.body.toPosition = slice.to_position;
|
||||
response.body.totalLines = script.lineCount();
|
||||
response.body.fromLine = from_line + line_offset;
|
||||
response.body.toLine = to_line + line_offset;
|
||||
response.body.fromPosition = %ScriptLineStartPosition(raw_script, from_line);
|
||||
response.body.toPosition =
|
||||
(to_line == 0) ? 0 : %ScriptLineEndPosition(raw_script, to_line - 1);
|
||||
response.body.totalLines = %ScriptLineCount(raw_script);
|
||||
|
||||
response.body.source = %_SubString(raw_script.source,
|
||||
response.body.fromPosition,
|
||||
response.body.toPosition);
|
||||
};
|
||||
|
||||
|
||||
|
@ -2356,7 +2356,7 @@ ScriptMirror.prototype.compilationType = function() {
|
||||
|
||||
|
||||
ScriptMirror.prototype.lineCount = function() {
|
||||
return this.script_.lineCount();
|
||||
return %ScriptLineCount(this.script_);
|
||||
};
|
||||
|
||||
|
||||
@ -2366,11 +2366,6 @@ ScriptMirror.prototype.locationFromPosition = function(
|
||||
};
|
||||
|
||||
|
||||
ScriptMirror.prototype.sourceSlice = function (opt_from_line, opt_to_line) {
|
||||
return this.script_.sourceSlice(opt_from_line, opt_to_line);
|
||||
};
|
||||
|
||||
|
||||
ScriptMirror.prototype.context = function() {
|
||||
return this.context_;
|
||||
};
|
||||
|
@ -41,7 +41,6 @@ var ObjectToString = utils.ImportNow("object_to_string");
|
||||
var Script = utils.ImportNow("Script");
|
||||
var stackTraceSymbol = utils.ImportNow("stack_trace_symbol");
|
||||
var StringIndexOf;
|
||||
var StringSubstring;
|
||||
var SymbolToString;
|
||||
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
|
||||
var Uint16x8ToString;
|
||||
@ -59,7 +58,6 @@ utils.Import(function(from) {
|
||||
Int8x16ToString = from.Int8x16ToString;
|
||||
ObjectHasOwnProperty = from.ObjectHasOwnProperty;
|
||||
StringIndexOf = from.StringIndexOf;
|
||||
StringSubstring = from.StringSubstring;
|
||||
SymbolToString = from.SymbolToString;
|
||||
Uint16x8ToString = from.Uint16x8ToString;
|
||||
Uint32x4ToString = from.Uint32x4ToString;
|
||||
@ -218,18 +216,6 @@ function GetSourceLine(message) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find a line number given a specific source position.
|
||||
* @param {number} position The source position.
|
||||
* @return {number} 0 if input too small, -1 if input too large,
|
||||
else the line number.
|
||||
*/
|
||||
function ScriptLineFromPosition(position) {
|
||||
var info = %ScriptPositionInfo(this, position, false);
|
||||
return (info == null) ? -1 : info.line;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get information on a specific source position.
|
||||
* Returns an object with the following following properties:
|
||||
@ -249,124 +235,6 @@ function ScriptLocationFromPosition(position,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get information on a specific source line and column possibly offset by a
|
||||
* fixed source position. This function is used to find a source position from
|
||||
* a line and column position. The fixed source position offset is typically
|
||||
* used to find a source position in a function based on a line and column in
|
||||
* the source for the function alone. The offset passed will then be the
|
||||
* start position of the source for the function within the full script source.
|
||||
* @param {number} opt_line The line within the source. Default value is 0
|
||||
* @param {number} opt_column The column in within the line. Default value is 0
|
||||
* @param {number} opt_offset_position The offset from the begining of the
|
||||
* source from where the line and column calculation starts.
|
||||
* Default value is 0
|
||||
* @return If line is negative or not in the source null is returned.
|
||||
*/
|
||||
function ScriptLocationFromLine(opt_line, opt_column, opt_offset_position) {
|
||||
// Default is the first line in the script. Lines in the script is relative
|
||||
// to the offset within the resource.
|
||||
var line = 0;
|
||||
if (!IS_UNDEFINED(opt_line)) {
|
||||
line = opt_line - this.line_offset;
|
||||
}
|
||||
|
||||
// Default is first column. If on the first line add the offset within the
|
||||
// resource.
|
||||
var column = opt_column || 0;
|
||||
if (line == 0) {
|
||||
column -= this.column_offset;
|
||||
}
|
||||
|
||||
var offset_position = opt_offset_position || 0;
|
||||
if (line < 0 || column < 0 || offset_position < 0) return null;
|
||||
if (line == 0) {
|
||||
return this.locationFromPosition(offset_position + column, false);
|
||||
} else {
|
||||
// Find the line where the offset position is located.
|
||||
var offset_line = this.lineFromPosition(offset_position);
|
||||
|
||||
if (offset_line == -1 || offset_line + line >= this.lineCount()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.locationFromPosition(
|
||||
%ScriptLineStartPosition(this, offset_line + line) + column);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a slice of source code from the script. The boundaries for the slice is
|
||||
* specified in lines.
|
||||
* @param {number} opt_from_line The first line (zero bound) in the slice.
|
||||
* Default is 0
|
||||
* @param {number} opt_to_column The last line (zero bound) in the slice (non
|
||||
* inclusive). Default is the number of lines in the script
|
||||
* @return {SourceSlice} The source slice or null of the parameters where
|
||||
* invalid
|
||||
*/
|
||||
function ScriptSourceSlice(opt_from_line, opt_to_line) {
|
||||
var from_line = IS_UNDEFINED(opt_from_line) ? this.line_offset
|
||||
: opt_from_line;
|
||||
var to_line = IS_UNDEFINED(opt_to_line) ? this.line_offset + this.lineCount()
|
||||
: opt_to_line;
|
||||
|
||||
// Adjust according to the offset within the resource.
|
||||
from_line -= this.line_offset;
|
||||
to_line -= this.line_offset;
|
||||
if (from_line < 0) from_line = 0;
|
||||
if (to_line > this.lineCount()) to_line = this.lineCount();
|
||||
|
||||
// Check parameters.
|
||||
if (from_line >= this.lineCount() ||
|
||||
to_line < 0 ||
|
||||
from_line > to_line) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var from_position = %ScriptLineStartPosition(this, from_line);
|
||||
var to_position = %ScriptLineStartPosition(this, to_line);
|
||||
|
||||
// Return a source slice with line numbers re-adjusted to the resource.
|
||||
return new SourceSlice(this,
|
||||
from_line + this.line_offset,
|
||||
to_line + this.line_offset,
|
||||
from_position, to_position);
|
||||
}
|
||||
|
||||
|
||||
function ScriptSourceLine(opt_line) {
|
||||
// Default is the first line in the script. Lines in the script are relative
|
||||
// to the offset within the resource.
|
||||
var line = 0;
|
||||
if (!IS_UNDEFINED(opt_line)) {
|
||||
line = opt_line - this.line_offset;
|
||||
}
|
||||
|
||||
// Check parameter.
|
||||
if (line < 0 || this.lineCount() <= line) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return the source line.
|
||||
var start = %ScriptLineStartPosition(this, line);
|
||||
var end = %ScriptLineEndPosition(this, line);
|
||||
return %_Call(StringSubstring, this.source, start, end);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of source lines.
|
||||
* @return {number}
|
||||
* Number of source lines.
|
||||
*/
|
||||
function ScriptLineCount() {
|
||||
// Return number of source lines.
|
||||
return %ScriptLineCount(this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* If sourceURL comment is available returns sourceURL comment contents.
|
||||
* Otherwise, script name is returned. See
|
||||
@ -391,61 +259,12 @@ utils.SetUpLockedPrototype(Script, [
|
||||
"line_offset",
|
||||
"column_offset"
|
||||
], [
|
||||
"lineFromPosition", ScriptLineFromPosition,
|
||||
"locationFromPosition", ScriptLocationFromPosition,
|
||||
"locationFromLine", ScriptLocationFromLine,
|
||||
"sourceSlice", ScriptSourceSlice,
|
||||
"sourceLine", ScriptSourceLine,
|
||||
"lineCount", ScriptLineCount,
|
||||
"nameOrSourceURL", ScriptNameOrSourceURL,
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Class for a source slice. A source slice is a part of a script source with
|
||||
* the following properties:
|
||||
* script : script object for the source
|
||||
* from_line : line number for the first line in the slice
|
||||
* to_line : source line number for the last line in the slice
|
||||
* from_position : position of the first character in the slice
|
||||
* to_position : position of the last character in the slice
|
||||
* The to_line and to_position are not included in the slice, that is the lines
|
||||
* in the slice are [from_line, to_line[. Likewise the characters in the slice
|
||||
* are [from_position, to_position[.
|
||||
* @param {Script} script The Script object for the source slice
|
||||
* @param {number} from_line
|
||||
* @param {number} to_line
|
||||
* @param {number} from_position
|
||||
* @param {number} to_position
|
||||
* @constructor
|
||||
*/
|
||||
function SourceSlice(script, from_line, to_line, from_position, to_position) {
|
||||
this.script = script;
|
||||
this.from_line = from_line;
|
||||
this.to_line = to_line;
|
||||
this.from_position = from_position;
|
||||
this.to_position = to_position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the source text for a SourceSlice
|
||||
* @return {String} Source text for this slice. The last line will include
|
||||
* the line terminating characters (if any)
|
||||
*/
|
||||
function SourceSliceSourceText() {
|
||||
return %_Call(StringSubstring,
|
||||
this.script.source,
|
||||
this.from_position,
|
||||
this.to_position);
|
||||
}
|
||||
|
||||
utils.SetUpLockedPrototype(SourceSlice,
|
||||
["script", "from_line", "to_line", "from_position", "to_position"],
|
||||
["sourceText", SourceSliceSourceText]
|
||||
);
|
||||
|
||||
|
||||
function GetStackTraceLine(recv, fun, pos, isGlobal) {
|
||||
return new CallSite(recv, fun, pos, false).toString();
|
||||
}
|
||||
|
@ -1562,6 +1562,105 @@ RUNTIME_FUNCTION(Runtime_ScriptLineEndPosition) {
|
||||
}
|
||||
}
|
||||
|
||||
static Handle<Object> GetJSPositionInfo(Handle<Script> script, int position,
|
||||
Script::OffsetFlag offset_flag,
|
||||
Isolate* isolate) {
|
||||
Script::PositionInfo info;
|
||||
if (!script->GetPositionInfo(position, &info, offset_flag)) {
|
||||
return handle(isolate->heap()->null_value(), isolate);
|
||||
}
|
||||
|
||||
Handle<String> source = handle(String::cast(script->source()), isolate);
|
||||
Handle<String> sourceText =
|
||||
isolate->factory()->NewSubString(source, info.line_start, info.line_end);
|
||||
|
||||
Handle<JSObject> jsinfo =
|
||||
isolate->factory()->NewJSObject(isolate->object_function());
|
||||
|
||||
JSObject::AddProperty(jsinfo, isolate->factory()->script_string(), script,
|
||||
NONE);
|
||||
JSObject::AddProperty(jsinfo, isolate->factory()->position_string(),
|
||||
handle(Smi::FromInt(position), isolate), NONE);
|
||||
JSObject::AddProperty(jsinfo, isolate->factory()->line_string(),
|
||||
handle(Smi::FromInt(info.line), isolate), NONE);
|
||||
JSObject::AddProperty(jsinfo, isolate->factory()->column_string(),
|
||||
handle(Smi::FromInt(info.column), isolate), NONE);
|
||||
JSObject::AddProperty(jsinfo, isolate->factory()->sourceText_string(),
|
||||
sourceText, NONE);
|
||||
|
||||
return jsinfo;
|
||||
}
|
||||
|
||||
// Get information on a specific source line and column possibly offset by a
|
||||
// fixed source position. This function is used to find a source position from
|
||||
// a line and column position. The fixed source position offset is typically
|
||||
// used to find a source position in a function based on a line and column in
|
||||
// the source for the function alone. The offset passed will then be the
|
||||
// start position of the source for the function within the full script source.
|
||||
// Note that incoming line and column parameters may be undefined, and are
|
||||
// assumed to be passed *with* offsets.
|
||||
RUNTIME_FUNCTION(Runtime_ScriptLocationFromLine) {
|
||||
HandleScope scope(isolate);
|
||||
DCHECK(args.length() == 4);
|
||||
CONVERT_ARG_CHECKED(JSValue, script, 0);
|
||||
|
||||
RUNTIME_ASSERT(script->value()->IsScript());
|
||||
Handle<Script> script_handle = Handle<Script>(Script::cast(script->value()));
|
||||
|
||||
// Line and column are possibly undefined and we need to handle these cases,
|
||||
// additionally subtracting corresponding offsets.
|
||||
|
||||
int32_t line;
|
||||
if (args[1]->IsNull() || args[1]->IsUndefined()) {
|
||||
line = 0;
|
||||
} else {
|
||||
RUNTIME_ASSERT(args[1]->IsNumber());
|
||||
line = NumberToInt32(args[1]) - script_handle->line_offset();
|
||||
}
|
||||
|
||||
int32_t column;
|
||||
if (args[2]->IsNull() || args[2]->IsUndefined()) {
|
||||
column = 0;
|
||||
} else {
|
||||
RUNTIME_ASSERT(args[2]->IsNumber());
|
||||
column = NumberToInt32(args[2]);
|
||||
if (line == 0) column -= script_handle->column_offset();
|
||||
}
|
||||
|
||||
CONVERT_NUMBER_CHECKED(int32_t, offset_position, Int32, args[3]);
|
||||
|
||||
if (line < 0 || column < 0 || offset_position < 0) {
|
||||
return isolate->heap()->null_value();
|
||||
}
|
||||
|
||||
Script::InitLineEnds(script_handle);
|
||||
|
||||
FixedArray* line_ends_array = FixedArray::cast(script_handle->line_ends());
|
||||
const int line_count = line_ends_array->length();
|
||||
|
||||
int position;
|
||||
if (line == 0) {
|
||||
position = offset_position + column;
|
||||
} else {
|
||||
Script::PositionInfo info;
|
||||
if (!script_handle->GetPositionInfo(offset_position, &info,
|
||||
Script::NO_OFFSET) ||
|
||||
info.line + line >= line_count) {
|
||||
return isolate->heap()->null_value();
|
||||
}
|
||||
|
||||
const int offset_line = info.line + line;
|
||||
const int offset_line_position =
|
||||
(offset_line == 0)
|
||||
? 0
|
||||
: Smi::cast(line_ends_array->get(offset_line - 1))->value() + 1;
|
||||
position = offset_line_position + column;
|
||||
}
|
||||
|
||||
return *GetJSPositionInfo(script_handle, position, Script::NO_OFFSET,
|
||||
isolate);
|
||||
}
|
||||
|
||||
RUNTIME_FUNCTION(Runtime_ScriptPositionInfo) {
|
||||
HandleScope scope(isolate);
|
||||
DCHECK(args.length() == 3);
|
||||
@ -1572,33 +1671,41 @@ RUNTIME_FUNCTION(Runtime_ScriptPositionInfo) {
|
||||
RUNTIME_ASSERT(script->value()->IsScript());
|
||||
Handle<Script> script_handle = Handle<Script>(Script::cast(script->value()));
|
||||
|
||||
Script::PositionInfo info;
|
||||
const Script::OffsetFlag offset_flag =
|
||||
with_offset ? Script::WITH_OFFSET : Script::NO_OFFSET;
|
||||
if (!script_handle->GetPositionInfo(position, &info, offset_flag)) {
|
||||
return *GetJSPositionInfo(script_handle, position, offset_flag, isolate);
|
||||
}
|
||||
|
||||
// Returns the given line as a string, or null if line is out of bounds.
|
||||
// The parameter line is expected to include the script's line offset.
|
||||
RUNTIME_FUNCTION(Runtime_ScriptSourceLine) {
|
||||
HandleScope scope(isolate);
|
||||
DCHECK(args.length() == 2);
|
||||
CONVERT_ARG_CHECKED(JSValue, script, 0);
|
||||
CONVERT_NUMBER_CHECKED(int32_t, line, Int32, args[1]);
|
||||
|
||||
RUNTIME_ASSERT(script->value()->IsScript());
|
||||
Handle<Script> script_handle = Handle<Script>(Script::cast(script->value()));
|
||||
|
||||
Script::InitLineEnds(script_handle);
|
||||
|
||||
FixedArray* line_ends_array = FixedArray::cast(script_handle->line_ends());
|
||||
const int line_count = line_ends_array->length();
|
||||
|
||||
line -= script_handle->line_offset();
|
||||
if (line < 0 || line_count <= line) {
|
||||
return isolate->heap()->null_value();
|
||||
}
|
||||
|
||||
const int start =
|
||||
(line == 0) ? 0 : Smi::cast(line_ends_array->get(line - 1))->value() + 1;
|
||||
const int end = Smi::cast(line_ends_array->get(line))->value();
|
||||
|
||||
Handle<String> source =
|
||||
handle(String::cast(script_handle->source()), isolate);
|
||||
Handle<String> sourceText =
|
||||
isolate->factory()->NewSubString(source, info.line_start, info.line_end);
|
||||
Handle<String> str = isolate->factory()->NewSubString(source, start, end);
|
||||
|
||||
Handle<JSObject> jsinfo =
|
||||
isolate->factory()->NewJSObject(isolate->object_function());
|
||||
|
||||
JSObject::AddProperty(jsinfo, isolate->factory()->script_string(),
|
||||
script_handle, NONE);
|
||||
JSObject::AddProperty(jsinfo, isolate->factory()->position_string(),
|
||||
handle(Smi::FromInt(position), isolate), NONE);
|
||||
JSObject::AddProperty(jsinfo, isolate->factory()->line_string(),
|
||||
handle(Smi::FromInt(info.line), isolate), NONE);
|
||||
JSObject::AddProperty(jsinfo, isolate->factory()->column_string(),
|
||||
handle(Smi::FromInt(info.column), isolate), NONE);
|
||||
JSObject::AddProperty(jsinfo, isolate->factory()->sourceText_string(),
|
||||
sourceText, NONE);
|
||||
|
||||
return *jsinfo;
|
||||
return *str;
|
||||
}
|
||||
|
||||
// Set one shot breakpoints for the callback function that is passed to a
|
||||
|
@ -184,7 +184,9 @@ namespace internal {
|
||||
F(ScriptLineCount, 1, 1) \
|
||||
F(ScriptLineStartPosition, 2, 1) \
|
||||
F(ScriptLineEndPosition, 2, 1) \
|
||||
F(ScriptLocationFromLine, 4, 1) \
|
||||
F(ScriptPositionInfo, 3, 1) \
|
||||
F(ScriptSourceLine, 2, 1) \
|
||||
F(DebugPrepareStepInIfStepping, 1, 1) \
|
||||
F(DebugPushPromise, 2, 1) \
|
||||
F(DebugPopPromise, 0, 1) \
|
||||
|
@ -63,12 +63,11 @@ var comment_lines = 28;
|
||||
|
||||
// This is the last position in the entire file (note: this equals
|
||||
// file size of <debug-sourceinfo.js> - 1, since starting at 0).
|
||||
var last_position = 11519;
|
||||
var last_position = 8126;
|
||||
// This is the last line of entire file (note: starting at 0).
|
||||
var last_line = 269;
|
||||
// This is the last column of last line (note: starting at 0 and +1, due
|
||||
// to trailing <LF>).
|
||||
var last_column = 1;
|
||||
var last_line = 200;
|
||||
// This is the last column of last line (note: starting at 0).
|
||||
var last_column = 71;
|
||||
|
||||
// This magic number is the length or the first line comment (actually number
|
||||
// of characters before 'function a(...'.
|
||||
@ -168,66 +167,6 @@ assertEquals(start_d, script.locationFromPosition(start_d).position);
|
||||
assertEquals(11, script.locationFromPosition(start_d).line - comment_lines);
|
||||
assertEquals(10, script.locationFromPosition(start_d).column);
|
||||
|
||||
// Test first line.
|
||||
assertEquals(0, script.locationFromLine().position);
|
||||
assertEquals(0, script.locationFromLine().line);
|
||||
assertEquals(0, script.locationFromLine().column);
|
||||
assertEquals(0, script.locationFromLine(0).position);
|
||||
assertEquals(0, script.locationFromLine(0).line);
|
||||
assertEquals(0, script.locationFromLine(0).column);
|
||||
|
||||
// Test first line column 1.
|
||||
assertEquals(1, script.locationFromLine(0, 1).position);
|
||||
assertEquals(0, script.locationFromLine(0, 1).line);
|
||||
assertEquals(1, script.locationFromLine(0, 1).column);
|
||||
|
||||
// Test first line offset 1.
|
||||
assertEquals(1, script.locationFromLine(0, 0, 1).position);
|
||||
assertEquals(0, script.locationFromLine(0, 0, 1).line);
|
||||
assertEquals(1, script.locationFromLine(0, 0, 1).column);
|
||||
|
||||
// Test offset function a().
|
||||
assertEquals(start_a, script.locationFromLine(void 0, void 0, start_a).position);
|
||||
assertEquals(0, script.locationFromLine(void 0, void 0, start_a).line - comment_lines);
|
||||
assertEquals(10, script.locationFromLine(void 0, void 0, start_a).column);
|
||||
assertEquals(start_a, script.locationFromLine(0, void 0, start_a).position);
|
||||
assertEquals(0, script.locationFromLine(0, void 0, start_a).line - comment_lines);
|
||||
assertEquals(10, script.locationFromLine(0, void 0, start_a).column);
|
||||
assertEquals(start_a, script.locationFromLine(0, 0, start_a).position);
|
||||
assertEquals(0, script.locationFromLine(0, 0, start_a).line - comment_lines);
|
||||
assertEquals(10, script.locationFromLine(0, 0, start_a).column);
|
||||
|
||||
// Test second line offset function a().
|
||||
assertEquals(start_a + 13, script.locationFromLine(1, 0, start_a).position);
|
||||
assertEquals(1, script.locationFromLine(1, 0, start_a).line - comment_lines);
|
||||
assertEquals(0, script.locationFromLine(1, 0, start_a).column);
|
||||
|
||||
// Test second line column 2 offset function a().
|
||||
assertEquals(start_a + 13 + 1, script.locationFromLine(1, 1, start_a).position);
|
||||
assertEquals(1, script.locationFromLine(1, 2, start_a).line - comment_lines);
|
||||
assertEquals(2, script.locationFromLine(1, 2, start_a).column);
|
||||
|
||||
// Test offset function b().
|
||||
assertEquals(start_b, script.locationFromLine(0, 0, start_b).position);
|
||||
assertEquals(1, script.locationFromLine(0, 0, start_b).line - comment_lines);
|
||||
assertEquals(13, script.locationFromLine(0, 0, start_b).column);
|
||||
|
||||
// Test second line offset function b().
|
||||
assertEquals(start_b + 5, script.locationFromLine(1, 0, start_b).position);
|
||||
assertEquals(2, script.locationFromLine(1, 0, start_b).line - comment_lines);
|
||||
assertEquals(0, script.locationFromLine(1, 0, start_b).column);
|
||||
|
||||
// Test second line column 10 offset function b().
|
||||
assertEquals(start_b + 5 + 10, script.locationFromLine(1, 10, start_b).position);
|
||||
assertEquals(2, script.locationFromLine(1, 10, start_b).line - comment_lines);
|
||||
assertEquals(10, script.locationFromLine(1, 10, start_b).column);
|
||||
|
||||
// Test second line column 11 offset function b. Second line in b is 10 long
|
||||
// using column 11 wraps to next line.
|
||||
assertEquals(start_b + 5 + 11, script.locationFromLine(1, 11, start_b).position);
|
||||
assertEquals(3, script.locationFromLine(1, 11, start_b).line - comment_lines);
|
||||
assertEquals(0, script.locationFromLine(1, 11, start_b).column);
|
||||
|
||||
// Test the Debug.findSourcePosition which wraps SourceManager.
|
||||
assertEquals(0 + start_a, Debug.findFunctionSourceLocation(a, 0, 0).position);
|
||||
assertEquals(0 + start_b, Debug.findFunctionSourceLocation(b, 0, 0).position);
|
||||
@ -260,11 +199,3 @@ assertEquals(last_column, script.locationFromPosition(last_position).column);
|
||||
assertEquals(last_line + 1,
|
||||
script.locationFromPosition(last_position + 1).line);
|
||||
assertEquals(0, script.locationFromPosition(last_position + 1).column);
|
||||
|
||||
// Test that script.sourceLine(line) works.
|
||||
var location;
|
||||
|
||||
for (line = 0; line < num_lines_d; line++) {
|
||||
var line_content_regexp = new RegExp(" x = " + (line + 1));
|
||||
assertTrue(line_content_regexp.test(script.sourceLine(start_line_d + line)));
|
||||
}
|
||||
|
@ -1,74 +0,0 @@
|
||||
// Copyright 2008 the V8 project authors. All rights reserved.
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Flags: --expose-debug-as debug
|
||||
// Source lines for test.
|
||||
var lines = [ 'function a() { b(); };\n',
|
||||
'function b() {\n',
|
||||
' c(true);\n',
|
||||
'};\n',
|
||||
' function c(x) {\n',
|
||||
' if (x) {\n',
|
||||
' return 1;\n',
|
||||
' } else {\n',
|
||||
' return 1;\n',
|
||||
' }\n',
|
||||
' };\n' ];
|
||||
|
||||
// Build source by putting all lines together
|
||||
var source = '';
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
source += lines[i];
|
||||
}
|
||||
eval(source);
|
||||
|
||||
// Flags: --expose-debug-as debug
|
||||
// Get the Debug object exposed from the debug context global object.
|
||||
Debug = debug.Debug
|
||||
|
||||
// Get the script object from one of the functions in the source.
|
||||
var script = Debug.findScript(a);
|
||||
|
||||
// Make sure that the source is as expected.
|
||||
assertEquals(source, script.source);
|
||||
assertEquals(source, script.sourceSlice().sourceText());
|
||||
|
||||
// Try all possible line interval slices.
|
||||
for (var slice_size = 0; slice_size < lines.length; slice_size++) {
|
||||
for (var n = 0; n < lines.length - slice_size; n++) {
|
||||
var slice = script.sourceSlice(n, n + slice_size);
|
||||
assertEquals(n, slice.from_line);
|
||||
assertEquals(n + slice_size, slice.to_line);
|
||||
|
||||
var text = slice.sourceText();
|
||||
var expected = '';
|
||||
for (var i = 0; i < slice_size; i++) {
|
||||
expected += lines[n + i];
|
||||
}
|
||||
assertEquals(expected, text);
|
||||
}
|
||||
}
|
@ -83,16 +83,7 @@ function testScriptMirror(f, file_name, file_lines, type, compilation_type,
|
||||
|
||||
|
||||
// Test the script mirror for different functions.
|
||||
testScriptMirror(function(){}, 'mirror-script.js', 99, 2, 0);
|
||||
testScriptMirror(function(){}, 'mirror-script.js', 90, 2, 0);
|
||||
testScriptMirror(Math.abs, 'native math.js', -1, 0, 0);
|
||||
testScriptMirror(eval('(function(){})'), null, 1, 2, 1, '(function(){})', 87);
|
||||
testScriptMirror(eval('(function(){\n })'), null, 2, 2, 1, '(function(){\n })', 88);
|
||||
|
||||
// Test taking slices of source.
|
||||
var mirror = debug.MakeMirror(eval('(function(){\n 1;\n})')).script();
|
||||
assertEquals('(function(){\n', mirror.sourceSlice(0, 1).sourceText());
|
||||
assertEquals(' 1;\n', mirror.sourceSlice(1, 2).sourceText());
|
||||
assertEquals('})', mirror.sourceSlice(2, 3).sourceText());
|
||||
assertEquals('(function(){\n 1;\n', mirror.sourceSlice(0, 2).sourceText());
|
||||
assertEquals(' 1;\n})', mirror.sourceSlice(1, 3).sourceText());
|
||||
assertEquals('(function(){\n 1;\n})', mirror.sourceSlice(0, 3).sourceText());
|
||||
|
Loading…
Reference in New Issue
Block a user