Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/runtime/runtime-debug.cc

Issue 2003303002: Remove inessential functions from the JS Script class (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/debug/debug-evaluate.h" 8 #include "src/debug/debug-evaluate.h"
9 #include "src/debug/debug-frames.h" 9 #include "src/debug/debug-frames.h"
10 #include "src/debug/debug-scopes.h" 10 #include "src/debug/debug-scopes.h"
(...skipping 1544 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 FixedArray* line_ends_array = FixedArray::cast(script_handle->line_ends()); 1555 FixedArray* line_ends_array = FixedArray::cast(script_handle->line_ends());
1556 const int line_count = line_ends_array->length(); 1556 const int line_count = line_ends_array->length();
1557 1557
1558 if (line < 0 || line >= line_count) { 1558 if (line < 0 || line >= line_count) {
1559 return Smi::FromInt(-1); 1559 return Smi::FromInt(-1);
1560 } else { 1560 } else {
1561 return Smi::cast(line_ends_array->get(line)); 1561 return Smi::cast(line_ends_array->get(line));
1562 } 1562 }
1563 } 1563 }
1564 1564
1565 RUNTIME_FUNCTION(Runtime_ScriptPositionInfo) { 1565 static Object* GetJSPositionInfo(Handle<Script> script, int position,
Yang 2016/05/24 07:54:31 Let's return a handle and let the call site derefe
jgruber 2016/05/24 10:52:55 Done.
1566 HandleScope scope(isolate); 1566 Script::OffsetFlag offset_flag,
1567 DCHECK(args.length() == 3); 1567 Isolate* isolate) {
1568 CONVERT_ARG_CHECKED(JSValue, script, 0);
1569 CONVERT_NUMBER_CHECKED(int32_t, position, Int32, args[1]);
1570 CONVERT_BOOLEAN_ARG_CHECKED(with_offset, 2);
1571
1572 RUNTIME_ASSERT(script->value()->IsScript());
1573 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value()));
1574
1575 Script::PositionInfo info; 1568 Script::PositionInfo info;
1576 const Script::OffsetFlag offset_flag = 1569 if (!script->GetPositionInfo(position, &info, offset_flag)) {
1577 with_offset ? Script::WITH_OFFSET : Script::NO_OFFSET;
1578 if (!script_handle->GetPositionInfo(position, &info, offset_flag)) {
1579 return isolate->heap()->null_value(); 1570 return isolate->heap()->null_value();
1580 } 1571 }
1581 1572
1582 Handle<String> source = 1573 Handle<String> source = handle(String::cast(script->source()), isolate);
1583 handle(String::cast(script_handle->source()), isolate);
1584 Handle<String> sourceText = 1574 Handle<String> sourceText =
1585 isolate->factory()->NewSubString(source, info.line_start, info.line_end); 1575 isolate->factory()->NewSubString(source, info.line_start, info.line_end);
1586 1576
1587 Handle<JSObject> jsinfo = 1577 Handle<JSObject> jsinfo =
1588 isolate->factory()->NewJSObject(isolate->object_function()); 1578 isolate->factory()->NewJSObject(isolate->object_function());
1589 1579
1590 JSObject::AddProperty(jsinfo, isolate->factory()->script_string(), 1580 JSObject::AddProperty(jsinfo, isolate->factory()->script_string(), script,
1591 script_handle, NONE); 1581 NONE);
1592 JSObject::AddProperty(jsinfo, isolate->factory()->position_string(), 1582 JSObject::AddProperty(jsinfo, isolate->factory()->position_string(),
1593 handle(Smi::FromInt(position), isolate), NONE); 1583 handle(Smi::FromInt(position), isolate), NONE);
1594 JSObject::AddProperty(jsinfo, isolate->factory()->line_string(), 1584 JSObject::AddProperty(jsinfo, isolate->factory()->line_string(),
1595 handle(Smi::FromInt(info.line), isolate), NONE); 1585 handle(Smi::FromInt(info.line), isolate), NONE);
1596 JSObject::AddProperty(jsinfo, isolate->factory()->column_string(), 1586 JSObject::AddProperty(jsinfo, isolate->factory()->column_string(),
1597 handle(Smi::FromInt(info.column), isolate), NONE); 1587 handle(Smi::FromInt(info.column), isolate), NONE);
1598 JSObject::AddProperty(jsinfo, isolate->factory()->sourceText_string(), 1588 JSObject::AddProperty(jsinfo, isolate->factory()->sourceText_string(),
1599 sourceText, NONE); 1589 sourceText, NONE);
1600 1590
1601 return *jsinfo; 1591 return *jsinfo;
1602 } 1592 }
1603 1593
1594 // Get information on a specific source line and column possibly offset by a
1595 // fixed source position. This function is used to find a source position from
1596 // a line and column position. The fixed source position offset is typically
1597 // used to find a source position in a function based on a line and column in
1598 // the source for the function alone. The offset passed will then be the
1599 // start position of the source for the function within the full script source.
1600 // Note that incoming line and column parameters are assumed to be passed *with*
1601 // offsets.
1602 RUNTIME_FUNCTION(Runtime_ScriptLocationFromLine) {
1603 HandleScope scope(isolate);
1604 DCHECK(args.length() == 4);
1605 CONVERT_ARG_CHECKED(JSValue, script, 0);
1606 CONVERT_NUMBER_CHECKED(int32_t, line, Int32, args[1]);
1607 CONVERT_NUMBER_CHECKED(int32_t, column, Int32, args[2]);
1608 CONVERT_NUMBER_CHECKED(int32_t, offset_position, Int32, args[3]);
1609
1610 RUNTIME_ASSERT(script->value()->IsScript());
1611 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value()));
1612
1613 // Subtract any offsets from line and column.
1614 line -= script_handle->line_offset();
1615 if (line == 0) column -= script_handle->column_offset();
1616
1617 if (line < 0 || column < 0 || offset_position < 0) {
1618 return isolate->heap()->null_value();
1619 }
1620
1621 Script::InitLineEnds(script_handle);
1622
1623 FixedArray* line_ends_array = FixedArray::cast(script_handle->line_ends());
1624 const int line_count = line_ends_array->length();
1625
1626 int position;
1627 if (line == 0) {
1628 position = offset_position + column;
1629 } else {
1630 Script::PositionInfo info;
1631 if (!script_handle->GetPositionInfo(offset_position, &info,
1632 Script::NO_OFFSET) ||
1633 info.line + line >= line_count) {
1634 return isolate->heap()->null_value();
1635 }
1636
1637 const int offset_line = info.line + line;
1638 const int offset_line_position =
1639 (offset_line == 0)
1640 ? 0
1641 : Smi::cast(line_ends_array->get(offset_line - 1))->value() + 1;
1642 position = offset_line_position + column;
1643 }
1644
1645 return GetJSPositionInfo(script_handle, position, Script::NO_OFFSET, isolate);
1646 }
1647
1648 RUNTIME_FUNCTION(Runtime_ScriptPositionInfo) {
1649 HandleScope scope(isolate);
1650 DCHECK(args.length() == 3);
1651 CONVERT_ARG_CHECKED(JSValue, script, 0);
1652 CONVERT_NUMBER_CHECKED(int32_t, position, Int32, args[1]);
1653 CONVERT_BOOLEAN_ARG_CHECKED(with_offset, 2);
1654
1655 RUNTIME_ASSERT(script->value()->IsScript());
1656 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value()));
1657
1658 const Script::OffsetFlag offset_flag =
1659 with_offset ? Script::WITH_OFFSET : Script::NO_OFFSET;
1660 return GetJSPositionInfo(script_handle, position, offset_flag, isolate);
1661 }
1662
1663 // Returns the given line as a string, or null if line is out of bounds.
1664 // The parameter line is expected to include the script's line offset.
1665 RUNTIME_FUNCTION(Runtime_ScriptSourceLine) {
1666 HandleScope scope(isolate);
1667 DCHECK(args.length() == 2);
1668 CONVERT_ARG_CHECKED(JSValue, script, 0);
1669 CONVERT_NUMBER_CHECKED(int32_t, line, Int32, args[1]);
1670
1671 RUNTIME_ASSERT(script->value()->IsScript());
1672 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value()));
1673
1674 Script::InitLineEnds(script_handle);
1675
1676 FixedArray* line_ends_array = FixedArray::cast(script_handle->line_ends());
1677 const int line_count = line_ends_array->length();
1678
1679 line -= script_handle->line_offset();
1680 if (line < 0 || line_count <= line) {
1681 return isolate->heap()->null_value();
1682 }
1683
1684 const int start =
1685 (line == 0) ? 0 : Smi::cast(line_ends_array->get(line - 1))->value() + 1;
1686 const int end = Smi::cast(line_ends_array->get(line))->value();
1687
1688 Handle<String> source =
1689 handle(String::cast(script_handle->source()), isolate);
1690 Handle<String> str = isolate->factory()->NewSubString(source, start, end);
1691
1692 return *str;
1693 }
1694
1604 // Set one shot breakpoints for the callback function that is passed to a 1695 // Set one shot breakpoints for the callback function that is passed to a
1605 // built-in function such as Array.forEach to enable stepping into the callback, 1696 // built-in function such as Array.forEach to enable stepping into the callback,
1606 // if we are indeed stepping and the callback is subject to debugging. 1697 // if we are indeed stepping and the callback is subject to debugging.
1607 RUNTIME_FUNCTION(Runtime_DebugPrepareStepInIfStepping) { 1698 RUNTIME_FUNCTION(Runtime_DebugPrepareStepInIfStepping) {
1608 HandleScope scope(isolate); 1699 HandleScope scope(isolate);
1609 DCHECK_EQ(1, args.length()); 1700 DCHECK_EQ(1, args.length());
1610 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0); 1701 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0);
1611 isolate->debug()->PrepareStepIn(fun); 1702 isolate->debug()->PrepareStepIn(fun);
1612 return isolate->heap()->undefined_value(); 1703 return isolate->heap()->undefined_value();
1613 } 1704 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1647 return Smi::FromInt(isolate->debug()->is_active()); 1738 return Smi::FromInt(isolate->debug()->is_active());
1648 } 1739 }
1649 1740
1650 1741
1651 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { 1742 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) {
1652 UNIMPLEMENTED(); 1743 UNIMPLEMENTED();
1653 return NULL; 1744 return NULL;
1654 } 1745 }
1655 } // namespace internal 1746 } // namespace internal
1656 } // namespace v8 1747 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698