OLD | NEW |
---|---|
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 1483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1494 found = Handle<Script>(script, isolate); | 1494 found = Handle<Script>(script, isolate); |
1495 break; | 1495 break; |
1496 } | 1496 } |
1497 } | 1497 } |
1498 } | 1498 } |
1499 | 1499 |
1500 if (found.is_null()) return isolate->heap()->undefined_value(); | 1500 if (found.is_null()) return isolate->heap()->undefined_value(); |
1501 return *Script::GetWrapper(found); | 1501 return *Script::GetWrapper(found); |
1502 } | 1502 } |
1503 | 1503 |
1504 RUNTIME_FUNCTION(Runtime_ScriptLineCount) { | |
1505 HandleScope scope(isolate); | |
1506 DCHECK(args.length() == 1); | |
1507 CONVERT_ARG_CHECKED(JSValue, script, 0); | |
1508 | |
1509 RUNTIME_ASSERT(script->value()->IsScript()); | |
1510 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value())); | |
1511 | |
1512 Script::InitLineEnds(script_handle); | |
1513 | |
1514 FixedArray* line_ends_array = FixedArray::cast(script_handle->line_ends()); | |
1515 return Smi::FromInt(line_ends_array->length()); | |
1516 } | |
1517 | |
1518 RUNTIME_FUNCTION(Runtime_ScriptLineStartPosition) { | |
1519 HandleScope scope(isolate); | |
1520 DCHECK(args.length() == 2); | |
1521 CONVERT_ARG_CHECKED(JSValue, script, 0); | |
1522 CONVERT_NUMBER_CHECKED(int32_t, line, Int32, args[1]); | |
1523 | |
1524 RUNTIME_ASSERT(script->value()->IsScript()); | |
1525 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value())); | |
1526 | |
1527 Script::InitLineEnds(script_handle); | |
1528 | |
1529 FixedArray* line_ends_array = FixedArray::cast(script_handle->line_ends()); | |
1530 const int line_count = line_ends_array->length(); | |
1531 | |
1532 // If line == line_count, we return the first position beyond the last line. | |
1533 if (line < 0 || line > line_count) { | |
1534 return Smi::FromInt(-1); | |
1535 } else if (line == 0) { | |
1536 return Smi::FromInt(0); | |
1537 } 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.
| |
1538 const int pos = Smi::cast(line_ends_array->get(line - 1))->value() + 1; | |
1539 return Smi::FromInt(pos); | |
1540 } | |
1541 } | |
1542 | |
1543 RUNTIME_FUNCTION(Runtime_ScriptLineEndPosition) { | |
1544 HandleScope scope(isolate); | |
1545 DCHECK(args.length() == 2); | |
1546 CONVERT_ARG_CHECKED(JSValue, script, 0); | |
1547 CONVERT_NUMBER_CHECKED(int32_t, line, Int32, args[1]); | |
1548 | |
1549 RUNTIME_ASSERT(script->value()->IsScript()); | |
1550 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value())); | |
1551 | |
1552 Script::InitLineEnds(script_handle); | |
1553 | |
1554 FixedArray* line_ends_array = FixedArray::cast(script_handle->line_ends()); | |
1555 const int line_count = line_ends_array->length(); | |
1556 | |
1557 if (line < 0 || line >= line_count) { | |
1558 return Smi::FromInt(-1); | |
1559 } else { | |
1560 return Smi::cast(line_ends_array->get(line)); | |
1561 } | |
1562 } | |
1563 | |
1564 RUNTIME_FUNCTION(Runtime_ScriptPositionInfo) { | |
1565 HandleScope scope(isolate); | |
1566 DCHECK(args.length() == 3); | |
1567 CONVERT_ARG_CHECKED(JSValue, script, 0); | |
1568 CONVERT_NUMBER_CHECKED(int32_t, position, Int32, args[1]); | |
1569 CONVERT_BOOLEAN_ARG_CHECKED(with_offset, 2); | |
1570 | |
1571 RUNTIME_ASSERT(script->value()->IsScript()); | |
1572 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value())); | |
1573 | |
1574 Script::PositionInfo info; | |
1575 if (!Script::GetPositionInfo(script_handle, position, &info, with_offset)) { | |
1576 return isolate->heap()->null_value(); | |
1577 } | |
1578 | |
1579 Handle<JSObject> jsinfo = | |
1580 isolate->factory()->NewJSObject(isolate->object_function()); | |
1581 | |
1582 JSObject::AddProperty(jsinfo, isolate->factory()->line_string(), | |
1583 handle(Smi::FromInt(info.line), isolate), NONE); | |
1584 JSObject::AddProperty(jsinfo, isolate->factory()->column_string(), | |
1585 handle(Smi::FromInt(info.column), isolate), NONE); | |
1586 JSObject::AddProperty(jsinfo, isolate->factory()->line_start_string(), | |
1587 handle(Smi::FromInt(info.line_start), isolate), NONE); | |
1588 JSObject::AddProperty(jsinfo, isolate->factory()->line_end_string(), | |
1589 handle(Smi::FromInt(info.line_end), isolate), NONE); | |
1590 | |
1591 return *jsinfo; | |
1592 } | |
1504 | 1593 |
1505 // Set one shot breakpoints for the callback function that is passed to a | 1594 // Set one shot breakpoints for the callback function that is passed to a |
1506 // built-in function such as Array.forEach to enable stepping into the callback, | 1595 // built-in function such as Array.forEach to enable stepping into the callback, |
1507 // if we are indeed stepping and the callback is subject to debugging. | 1596 // if we are indeed stepping and the callback is subject to debugging. |
1508 RUNTIME_FUNCTION(Runtime_DebugPrepareStepInIfStepping) { | 1597 RUNTIME_FUNCTION(Runtime_DebugPrepareStepInIfStepping) { |
1509 HandleScope scope(isolate); | 1598 HandleScope scope(isolate); |
1510 DCHECK_EQ(1, args.length()); | 1599 DCHECK_EQ(1, args.length()); |
1511 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0); | 1600 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0); |
1512 isolate->debug()->PrepareStepIn(fun); | 1601 isolate->debug()->PrepareStepIn(fun); |
1513 return isolate->heap()->undefined_value(); | 1602 return isolate->heap()->undefined_value(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1548 return Smi::FromInt(isolate->debug()->is_active()); | 1637 return Smi::FromInt(isolate->debug()->is_active()); |
1549 } | 1638 } |
1550 | 1639 |
1551 | 1640 |
1552 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { | 1641 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { |
1553 UNIMPLEMENTED(); | 1642 UNIMPLEMENTED(); |
1554 return NULL; | 1643 return NULL; |
1555 } | 1644 } |
1556 } // namespace internal | 1645 } // namespace internal |
1557 } // namespace v8 | 1646 } // namespace v8 |
OLD | NEW |