Chromium Code Reviews| Index: src/runtime/runtime-debug.cc |
| diff --git a/src/runtime/runtime-debug.cc b/src/runtime/runtime-debug.cc |
| index e3f3beb6976da53443707168c427ff0247e525ed..f340990af626be6e6e27836e62e46b15203feafa 100644 |
| --- a/src/runtime/runtime-debug.cc |
| +++ b/src/runtime/runtime-debug.cc |
| @@ -1501,6 +1501,95 @@ RUNTIME_FUNCTION(Runtime_GetScript) { |
| return *Script::GetWrapper(found); |
| } |
| +RUNTIME_FUNCTION(Runtime_ScriptLineCount) { |
| + HandleScope scope(isolate); |
| + DCHECK(args.length() == 1); |
| + CONVERT_ARG_CHECKED(JSValue, script, 0); |
| + |
| + 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()); |
| + return Smi::FromInt(line_ends_array->length()); |
| +} |
| + |
| +RUNTIME_FUNCTION(Runtime_ScriptLineStartPosition) { |
| + 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(); |
| + |
| + // If line == line_count, we return the first position beyond the last line. |
| + if (line < 0 || line > line_count) { |
| + return Smi::FromInt(-1); |
| + } else if (line == 0) { |
| + return Smi::FromInt(0); |
| + } else { // 0 < line <= line_count |
|
Yang
2016/05/18 13:23:09
Let's simply make this a DCHECK.
jgruber1
2016/05/19 08:05:24
Done.
|
| + const int pos = Smi::cast(line_ends_array->get(line - 1))->value() + 1; |
| + return Smi::FromInt(pos); |
| + } |
| +} |
| + |
| +RUNTIME_FUNCTION(Runtime_ScriptLineEndPosition) { |
| + 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(); |
| + |
| + if (line < 0 || line >= line_count) { |
| + return Smi::FromInt(-1); |
| + } else { |
| + return Smi::cast(line_ends_array->get(line)); |
| + } |
| +} |
| + |
| +RUNTIME_FUNCTION(Runtime_ScriptPositionInfo) { |
| + HandleScope scope(isolate); |
| + DCHECK(args.length() == 3); |
| + CONVERT_ARG_CHECKED(JSValue, script, 0); |
| + CONVERT_NUMBER_CHECKED(int32_t, position, Int32, args[1]); |
| + CONVERT_BOOLEAN_ARG_CHECKED(with_offset, 2); |
| + |
| + RUNTIME_ASSERT(script->value()->IsScript()); |
| + Handle<Script> script_handle = Handle<Script>(Script::cast(script->value())); |
| + |
| + Script::PositionInfo info; |
| + if (!Script::GetPositionInfo(script_handle, position, &info, with_offset)) { |
| + return isolate->heap()->null_value(); |
| + } |
| + |
| + Handle<JSObject> jsinfo = |
| + isolate->factory()->NewJSObject(isolate->object_function()); |
| + |
| + 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()->line_start_string(), |
| + handle(Smi::FromInt(info.line_start), isolate), NONE); |
| + JSObject::AddProperty(jsinfo, isolate->factory()->line_end_string(), |
| + handle(Smi::FromInt(info.line_end), isolate), NONE); |
| + |
| + return *jsinfo; |
| +} |
| // Set one shot breakpoints for the callback function that is passed to a |
| // built-in function such as Array.forEach to enable stepping into the callback, |