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 { | |
1538 DCHECK(0 < line && line <= line_count); | |
1539 const int pos = Smi::cast(line_ends_array->get(line - 1))->value() + 1; | |
1540 return Smi::FromInt(pos); | |
1541 } | |
1542 } | |
1543 | |
1544 RUNTIME_FUNCTION(Runtime_ScriptLineEndPosition) { | |
1545 HandleScope scope(isolate); | |
1546 DCHECK(args.length() == 2); | |
1547 CONVERT_ARG_CHECKED(JSValue, script, 0); | |
1548 CONVERT_NUMBER_CHECKED(int32_t, line, Int32, args[1]); | |
1549 | |
1550 RUNTIME_ASSERT(script->value()->IsScript()); | |
1551 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value())); | |
1552 | |
1553 Script::InitLineEnds(script_handle); | |
1554 | |
1555 FixedArray* line_ends_array = FixedArray::cast(script_handle->line_ends()); | |
1556 const int line_count = line_ends_array->length(); | |
1557 | |
1558 if (line < 0 || line >= line_count) { | |
1559 return Smi::FromInt(-1); | |
1560 } else { | |
1561 return Smi::cast(line_ends_array->get(line)); | |
1562 } | |
1563 } | |
1564 | |
1565 RUNTIME_FUNCTION(Runtime_ScriptPositionInfo) { | |
1566 HandleScope scope(isolate); | |
1567 DCHECK(args.length() == 3); | |
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; | |
1576 const Script::OffsetFlag offset_flag = | |
1577 with_offset ? Script::kWithOffset : Script::kNoOffset; | |
1578 if (!script_handle->GetPositionInfo(position, &info, offset_flag)) { | |
1579 return isolate->heap()->null_value(); | |
1580 } | |
1581 | |
1582 Handle<String> source = | |
1583 handle(String::cast(script_handle->source()), isolate); | |
1584 Handle<String> sourceText = | |
1585 isolate->factory()->NewSubString(source, info.line_start, info.line_end); | |
1586 | |
1587 Handle<JSObject> jsinfo = | |
1588 isolate->factory()->NewJSObject(isolate->object_function()); | |
1589 | |
1590 JSObject::AddProperty(jsinfo, isolate->factory()->script_string(), | |
1591 script_handle, NONE); | |
1592 JSObject::AddProperty(jsinfo, isolate->factory()->position_string(), | |
1593 handle(Smi::FromInt(position), isolate), NONE); | |
1594 JSObject::AddProperty(jsinfo, isolate->factory()->line_string(), | |
1595 handle(Smi::FromInt(info.line), isolate), NONE); | |
1596 JSObject::AddProperty(jsinfo, isolate->factory()->column_string(), | |
1597 handle(Smi::FromInt(info.column), isolate), NONE); | |
1598 JSObject::AddProperty(jsinfo, isolate->factory()->sourceText_string(), | |
1599 sourceText, NONE); | |
1600 | |
1601 return *jsinfo; | |
1602 } | |
1603 | 1504 |
1604 // Set one shot breakpoints for the callback function that is passed to a | 1505 // 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, | 1506 // 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. | 1507 // if we are indeed stepping and the callback is subject to debugging. |
1607 RUNTIME_FUNCTION(Runtime_DebugPrepareStepInIfStepping) { | 1508 RUNTIME_FUNCTION(Runtime_DebugPrepareStepInIfStepping) { |
1608 HandleScope scope(isolate); | 1509 HandleScope scope(isolate); |
1609 DCHECK_EQ(1, args.length()); | 1510 DCHECK_EQ(1, args.length()); |
1610 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0); | 1511 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0); |
1611 isolate->debug()->PrepareStepIn(fun); | 1512 isolate->debug()->PrepareStepIn(fun); |
1612 return isolate->heap()->undefined_value(); | 1513 return isolate->heap()->undefined_value(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1647 return Smi::FromInt(isolate->debug()->is_active()); | 1548 return Smi::FromInt(isolate->debug()->is_active()); |
1648 } | 1549 } |
1649 | 1550 |
1650 | 1551 |
1651 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { | 1552 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { |
1652 UNIMPLEMENTED(); | 1553 UNIMPLEMENTED(); |
1653 return NULL; | 1554 return NULL; |
1654 } | 1555 } |
1655 } // namespace internal | 1556 } // namespace internal |
1656 } // namespace v8 | 1557 } // namespace v8 |
OLD | NEW |