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 1239033002: Debugger: use FrameInspector in ScopeIterator to find context. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-4309.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/arguments.h" 8 #include "src/arguments.h"
9 #include "src/compiler.h" 9 #include "src/compiler.h"
10 #include "src/debug.h" 10 #include "src/debug.h"
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 : frame_->LookupCode()->SourcePosition(frame_->pc()); 522 : frame_->LookupCode()->SourcePosition(frame_->pc());
523 } 523 }
524 bool IsConstructor() { 524 bool IsConstructor() {
525 return is_optimized_ && !is_bottommost_ 525 return is_optimized_ && !is_bottommost_
526 ? deoptimized_frame_->HasConstructStub() 526 ? deoptimized_frame_->HasConstructStub()
527 : frame_->IsConstructor(); 527 : frame_->IsConstructor();
528 } 528 }
529 Object* GetContext() { 529 Object* GetContext() {
530 return is_optimized_ ? deoptimized_frame_->GetContext() : frame_->context(); 530 return is_optimized_ ? deoptimized_frame_->GetContext() : frame_->context();
531 } 531 }
532 JavaScriptFrame* GetArgumentsFrame() { return frame_; }
532 533
533 // To inspect all the provided arguments the frame might need to be 534 // To inspect all the provided arguments the frame might need to be
534 // replaced with the arguments frame. 535 // replaced with the arguments frame.
535 void SetArgumentsFrame(JavaScriptFrame* frame) { 536 void SetArgumentsFrame(JavaScriptFrame* frame) {
536 DCHECK(has_adapted_arguments_); 537 DCHECK(has_adapted_arguments_);
537 frame_ = frame; 538 frame_ = frame;
538 is_optimized_ = frame_->is_optimized(); 539 is_optimized_ = frame_->is_optimized();
539 DCHECK(!is_optimized_); 540 DCHECK(!is_optimized_);
540 } 541 }
541 542
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 ScriptContextTable::GetContext(script_contexts, context_index); 1052 ScriptContextTable::GetContext(script_contexts, context_index);
1052 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension())); 1053 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension()));
1053 ScopeInfo::CopyContextLocalsToScopeObject(scope_info, context, 1054 ScopeInfo::CopyContextLocalsToScopeObject(scope_info, context,
1054 script_scope); 1055 script_scope);
1055 } 1056 }
1056 return script_scope; 1057 return script_scope;
1057 } 1058 }
1058 1059
1059 1060
1060 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeLocalScope( 1061 MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeLocalScope(
1061 Isolate* isolate, JavaScriptFrame* frame, int inlined_jsframe_index) { 1062 Isolate* isolate, FrameInspector* frame_inspector) {
1062 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); 1063 Handle<JSFunction> function(JSFunction::cast(frame_inspector->GetFunction()));
1063 Handle<JSFunction> function(JSFunction::cast(frame_inspector.GetFunction()));
1064 1064
1065 Handle<JSObject> local_scope = 1065 Handle<JSObject> local_scope =
1066 isolate->factory()->NewJSObject(isolate->object_function()); 1066 isolate->factory()->NewJSObject(isolate->object_function());
1067 MaterializeStackLocalsWithFrameInspector(isolate, local_scope, function, 1067 MaterializeStackLocalsWithFrameInspector(isolate, local_scope, function,
1068 &frame_inspector); 1068 frame_inspector);
1069
1070 JavaScriptFrame* frame = frame_inspector->GetArgumentsFrame();
1069 1071
1070 return MaterializeLocalContext(isolate, local_scope, function, frame); 1072 return MaterializeLocalContext(isolate, local_scope, function, frame);
1071 } 1073 }
1072 1074
1073 1075
1074 // Set the context local variable value. 1076 // Set the context local variable value.
1075 static bool SetContextLocalValue(Isolate* isolate, Handle<ScopeInfo> scope_info, 1077 static bool SetContextLocalValue(Isolate* isolate, Handle<ScopeInfo> scope_info,
1076 Handle<Context> context, 1078 Handle<Context> context,
1077 Handle<String> variable_name, 1079 Handle<String> variable_name,
1078 Handle<Object> new_value) { 1080 Handle<Object> new_value) {
(...skipping 10 matching lines...) Expand all
1089 context->set(context_index, *new_value); 1091 context->set(context_index, *new_value);
1090 return true; 1092 return true;
1091 } 1093 }
1092 } 1094 }
1093 1095
1094 return false; 1096 return false;
1095 } 1097 }
1096 1098
1097 1099
1098 static bool SetLocalVariableValue(Isolate* isolate, JavaScriptFrame* frame, 1100 static bool SetLocalVariableValue(Isolate* isolate, JavaScriptFrame* frame,
1099 int inlined_jsframe_index,
1100 Handle<String> variable_name, 1101 Handle<String> variable_name,
1101 Handle<Object> new_value) { 1102 Handle<Object> new_value) {
1102 if (inlined_jsframe_index != 0 || frame->is_optimized()) { 1103 // Optimized frames are not supported.
1103 // Optimized frames are not supported. 1104 if (frame->is_optimized()) return false;
1104 return false;
1105 }
1106 1105
1107 Handle<JSFunction> function(frame->function()); 1106 Handle<JSFunction> function(frame->function());
1108 Handle<SharedFunctionInfo> shared(function->shared()); 1107 Handle<SharedFunctionInfo> shared(function->shared());
1109 Handle<ScopeInfo> scope_info(shared->scope_info()); 1108 Handle<ScopeInfo> scope_info(shared->scope_info());
1110 1109
1111 bool default_result = false; 1110 bool default_result = false;
1112 1111
1113 // Parameters. 1112 // Parameters.
1114 for (int i = 0; i < scope_info->ParameterCount(); ++i) { 1113 for (int i = 0; i < scope_info->ParameterCount(); ++i) {
1115 HandleScope scope(isolate); 1114 HandleScope scope(isolate);
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 context->set(Context::THROWN_OBJECT_INDEX, *new_value); 1303 context->set(Context::THROWN_OBJECT_INDEX, *new_value);
1305 return true; 1304 return true;
1306 } 1305 }
1307 1306
1308 1307
1309 // Create a plain JSObject which materializes the block scope for the specified 1308 // Create a plain JSObject which materializes the block scope for the specified
1310 // block context. 1309 // block context.
1311 static Handle<JSObject> MaterializeBlockScope(Isolate* isolate, 1310 static Handle<JSObject> MaterializeBlockScope(Isolate* isolate,
1312 Handle<ScopeInfo> scope_info, 1311 Handle<ScopeInfo> scope_info,
1313 Handle<Context> context, 1312 Handle<Context> context,
1314 JavaScriptFrame* frame, 1313 FrameInspector* frame_inspector) {
1315 int inlined_jsframe_index) {
1316 Handle<JSObject> block_scope = 1314 Handle<JSObject> block_scope =
1317 isolate->factory()->NewJSObject(isolate->object_function()); 1315 isolate->factory()->NewJSObject(isolate->object_function());
1318 1316
1319 if (frame != nullptr) { 1317 if (frame_inspector != nullptr) {
1320 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate);
1321 MaterializeStackLocalsWithFrameInspector(isolate, block_scope, scope_info, 1318 MaterializeStackLocalsWithFrameInspector(isolate, block_scope, scope_info,
1322 &frame_inspector); 1319 frame_inspector);
1323 } 1320 }
1324 1321
1325 if (!context.is_null()) { 1322 if (!context.is_null()) {
1326 Handle<ScopeInfo> scope_info_from_context( 1323 Handle<ScopeInfo> scope_info_from_context(
1327 ScopeInfo::cast(context->extension())); 1324 ScopeInfo::cast(context->extension()));
1328 // Fill all context locals. 1325 // Fill all context locals.
1329 ScopeInfo::CopyContextLocalsToScopeObject(scope_info_from_context, context, 1326 ScopeInfo::CopyContextLocalsToScopeObject(scope_info_from_context, context,
1330 block_scope); 1327 block_scope);
1331 } 1328 }
1332 1329
(...skipping 30 matching lines...) Expand all
1363 ScopeTypeGlobal = 0, 1360 ScopeTypeGlobal = 0,
1364 ScopeTypeLocal, 1361 ScopeTypeLocal,
1365 ScopeTypeWith, 1362 ScopeTypeWith,
1366 ScopeTypeClosure, 1363 ScopeTypeClosure,
1367 ScopeTypeCatch, 1364 ScopeTypeCatch,
1368 ScopeTypeBlock, 1365 ScopeTypeBlock,
1369 ScopeTypeScript, 1366 ScopeTypeScript,
1370 ScopeTypeModule 1367 ScopeTypeModule
1371 }; 1368 };
1372 1369
1373 ScopeIterator(Isolate* isolate, JavaScriptFrame* frame, 1370 ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector,
1374 int inlined_jsframe_index, bool ignore_nested_scopes = false) 1371 bool ignore_nested_scopes = false)
1375 : isolate_(isolate), 1372 : isolate_(isolate),
1376 frame_(frame), 1373 frame_inspector_(frame_inspector),
1377 inlined_jsframe_index_(inlined_jsframe_index), 1374 context_(Context::cast(frame_inspector->GetContext())),
1378 function_(frame->function()),
1379 context_(Context::cast(frame->context())),
1380 nested_scope_chain_(4), 1375 nested_scope_chain_(4),
1381 seen_script_scope_(false), 1376 seen_script_scope_(false),
1382 failed_(false) { 1377 failed_(false) {
1383 // Catch the case when the debugger stops in an internal function. 1378 // Catch the case when the debugger stops in an internal function.
1384 Handle<SharedFunctionInfo> shared_info(function_->shared()); 1379 Handle<SharedFunctionInfo> shared_info(function()->shared());
1385 Handle<ScopeInfo> scope_info(shared_info->scope_info()); 1380 Handle<ScopeInfo> scope_info(shared_info->scope_info());
1386 if (shared_info->script() == isolate->heap()->undefined_value()) { 1381 if (shared_info->script() == isolate->heap()->undefined_value()) {
1387 while (context_->closure() == *function_) { 1382 while (context_->closure() == function()) {
1388 context_ = Handle<Context>(context_->previous(), isolate_); 1383 context_ = Handle<Context>(context_->previous(), isolate_);
1389 } 1384 }
1390 return; 1385 return;
1391 } 1386 }
1392 1387
1393 // Currently it takes too much time to find nested scopes due to script 1388 // Currently it takes too much time to find nested scopes due to script
1394 // parsing. Sometimes we want to run the ScopeIterator as fast as possible 1389 // parsing. Sometimes we want to run the ScopeIterator as fast as possible
1395 // (for example, while collecting async call stacks on every 1390 // (for example, while collecting async call stacks on every
1396 // addEventListener call), even if we drop some nested scopes. 1391 // addEventListener call), even if we drop some nested scopes.
1397 // Later we may optimize getting the nested scopes (cache the result?) 1392 // Later we may optimize getting the nested scopes (cache the result?)
1398 // and include nested scopes into the "fast" iteration case as well. 1393 // and include nested scopes into the "fast" iteration case as well.
1399 1394
1400 if (!ignore_nested_scopes && !shared_info->debug_info()->IsUndefined()) { 1395 if (!ignore_nested_scopes && !shared_info->debug_info()->IsUndefined()) {
1401 // The source position at return is always the end of the function, 1396 // The source position at return is always the end of the function,
1402 // which is not consistent with the current scope chain. Therefore all 1397 // which is not consistent with the current scope chain. Therefore all
1403 // nested with, catch and block contexts are skipped, and we can only 1398 // nested with, catch and block contexts are skipped, and we can only
1404 // inspect the function scope. 1399 // inspect the function scope.
1405 // This can only happen if we set a break point inside right before the 1400 // This can only happen if we set a break point inside right before the
1406 // return, which requires a debug info to be available. 1401 // return, which requires a debug info to be available.
1407 Handle<DebugInfo> debug_info = Debug::GetDebugInfo(shared_info); 1402 Handle<DebugInfo> debug_info = Debug::GetDebugInfo(shared_info);
1408 1403
1409 // PC points to the instruction after the current one, possibly a break 1404 // PC points to the instruction after the current one, possibly a break
1410 // location as well. So the "- 1" to exclude it from the search. 1405 // location as well. So the "- 1" to exclude it from the search.
1411 Address call_pc = frame->pc() - 1; 1406 Address call_pc = frame()->pc() - 1;
1412 1407
1413 // Find the break point where execution has stopped. 1408 // Find the break point where execution has stopped.
1414 BreakLocation location = 1409 BreakLocation location =
1415 BreakLocation::FromAddress(debug_info, ALL_BREAK_LOCATIONS, call_pc); 1410 BreakLocation::FromAddress(debug_info, ALL_BREAK_LOCATIONS, call_pc);
1416 1411
1417 ignore_nested_scopes = location.IsReturn(); 1412 ignore_nested_scopes = location.IsReturn();
1418 } 1413 }
1419 1414
1420 if (ignore_nested_scopes) { 1415 if (ignore_nested_scopes) {
1421 if (scope_info->HasContext()) { 1416 if (scope_info->HasContext()) {
1422 context_ = Handle<Context>(context_->declaration_context(), isolate_); 1417 context_ = Handle<Context>(context_->declaration_context(), isolate_);
1423 } else { 1418 } else {
1424 while (context_->closure() == *function_) { 1419 while (context_->closure() == function()) {
1425 context_ = Handle<Context>(context_->previous(), isolate_); 1420 context_ = Handle<Context>(context_->previous(), isolate_);
1426 } 1421 }
1427 } 1422 }
1428 if (scope_info->scope_type() == FUNCTION_SCOPE || 1423 if (scope_info->scope_type() == FUNCTION_SCOPE ||
1429 scope_info->scope_type() == ARROW_SCOPE) { 1424 scope_info->scope_type() == ARROW_SCOPE) {
1430 nested_scope_chain_.Add(scope_info); 1425 nested_scope_chain_.Add(scope_info);
1431 } 1426 }
1432 } else { 1427 } else {
1433 // Reparse the code and analyze the scopes. 1428 // Reparse the code and analyze the scopes.
1434 Handle<Script> script(Script::cast(shared_info->script())); 1429 Handle<Script> script(Script::cast(shared_info->script()));
1435 Scope* scope = NULL; 1430 Scope* scope = NULL;
1436 1431
1437 // Check whether we are in global, eval or function code. 1432 // Check whether we are in global, eval or function code.
1438 Handle<ScopeInfo> scope_info(shared_info->scope_info()); 1433 Handle<ScopeInfo> scope_info(shared_info->scope_info());
1439 Zone zone; 1434 Zone zone;
1440 if (scope_info->scope_type() != FUNCTION_SCOPE && 1435 if (scope_info->scope_type() != FUNCTION_SCOPE &&
1441 scope_info->scope_type() != ARROW_SCOPE) { 1436 scope_info->scope_type() != ARROW_SCOPE) {
1442 // Global or eval code. 1437 // Global or eval code.
1443 ParseInfo info(&zone, script); 1438 ParseInfo info(&zone, script);
1444 if (scope_info->scope_type() == SCRIPT_SCOPE) { 1439 if (scope_info->scope_type() == SCRIPT_SCOPE) {
1445 info.set_global(); 1440 info.set_global();
1446 } else { 1441 } else {
1447 DCHECK(scope_info->scope_type() == EVAL_SCOPE); 1442 DCHECK(scope_info->scope_type() == EVAL_SCOPE);
1448 info.set_eval(); 1443 info.set_eval();
1449 info.set_context(Handle<Context>(function_->context())); 1444 info.set_context(Handle<Context>(function()->context()));
1450 } 1445 }
1451 if (Parser::ParseStatic(&info) && Scope::Analyze(&info)) { 1446 if (Parser::ParseStatic(&info) && Scope::Analyze(&info)) {
1452 scope = info.function()->scope(); 1447 scope = info.function()->scope();
1453 } 1448 }
1454 RetrieveScopeChain(scope, shared_info); 1449 RetrieveScopeChain(scope, shared_info);
1455 } else { 1450 } else {
1456 // Function code 1451 // Function code
1457 ParseInfo info(&zone, function_); 1452 ParseInfo info(&zone, Handle<JSFunction>(function()));
1458 if (Parser::ParseStatic(&info) && Scope::Analyze(&info)) { 1453 if (Parser::ParseStatic(&info) && Scope::Analyze(&info)) {
1459 scope = info.function()->scope(); 1454 scope = info.function()->scope();
1460 } 1455 }
1461 RetrieveScopeChain(scope, shared_info); 1456 RetrieveScopeChain(scope, shared_info);
1462 } 1457 }
1463 } 1458 }
1464 } 1459 }
1465 1460
1466 ScopeIterator(Isolate* isolate, Handle<JSFunction> function) 1461 ScopeIterator(Isolate* isolate, Handle<JSFunction> function)
1467 : isolate_(isolate), 1462 : isolate_(isolate),
1468 frame_(NULL), 1463 frame_inspector_(NULL),
1469 inlined_jsframe_index_(0),
1470 function_(function),
1471 context_(function->context()), 1464 context_(function->context()),
1472 seen_script_scope_(false), 1465 seen_script_scope_(false),
1473 failed_(false) { 1466 failed_(false) {
1474 if (function->IsBuiltin()) { 1467 if (function->IsBuiltin()) context_ = Handle<Context>();
1475 context_ = Handle<Context>();
1476 }
1477 } 1468 }
1478 1469
1479 // More scopes? 1470 // More scopes?
1480 bool Done() { 1471 bool Done() {
1481 DCHECK(!failed_); 1472 DCHECK(!failed_);
1482 return context_.is_null(); 1473 return context_.is_null();
1483 } 1474 }
1484 1475
1485 bool Failed() { return failed_; } 1476 bool Failed() { return failed_; }
1486 1477
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 DCHECK(!failed_); 1568 DCHECK(!failed_);
1578 switch (Type()) { 1569 switch (Type()) {
1579 case ScopeIterator::ScopeTypeGlobal: 1570 case ScopeIterator::ScopeTypeGlobal:
1580 return Handle<JSObject>(CurrentContext()->global_object()); 1571 return Handle<JSObject>(CurrentContext()->global_object());
1581 case ScopeIterator::ScopeTypeScript: 1572 case ScopeIterator::ScopeTypeScript:
1582 return MaterializeScriptScope( 1573 return MaterializeScriptScope(
1583 Handle<GlobalObject>(CurrentContext()->global_object())); 1574 Handle<GlobalObject>(CurrentContext()->global_object()));
1584 case ScopeIterator::ScopeTypeLocal: 1575 case ScopeIterator::ScopeTypeLocal:
1585 // Materialize the content of the local scope into a JSObject. 1576 // Materialize the content of the local scope into a JSObject.
1586 DCHECK(nested_scope_chain_.length() == 1); 1577 DCHECK(nested_scope_chain_.length() == 1);
1587 return MaterializeLocalScope(isolate_, frame_, inlined_jsframe_index_); 1578 return MaterializeLocalScope(isolate_, frame_inspector_);
1588 case ScopeIterator::ScopeTypeWith: 1579 case ScopeIterator::ScopeTypeWith:
1589 // Return the with object. 1580 // Return the with object.
1590 return Handle<JSObject>(JSObject::cast(CurrentContext()->extension())); 1581 return Handle<JSObject>(JSObject::cast(CurrentContext()->extension()));
1591 case ScopeIterator::ScopeTypeCatch: 1582 case ScopeIterator::ScopeTypeCatch:
1592 return MaterializeCatchScope(isolate_, CurrentContext()); 1583 return MaterializeCatchScope(isolate_, CurrentContext());
1593 case ScopeIterator::ScopeTypeClosure: 1584 case ScopeIterator::ScopeTypeClosure:
1594 // Materialize the content of the closure scope into a JSObject. 1585 // Materialize the content of the closure scope into a JSObject.
1595 return MaterializeClosure(isolate_, CurrentContext()); 1586 return MaterializeClosure(isolate_, CurrentContext());
1596 case ScopeIterator::ScopeTypeBlock: { 1587 case ScopeIterator::ScopeTypeBlock: {
1597 if (!nested_scope_chain_.is_empty()) { 1588 if (!nested_scope_chain_.is_empty()) {
1598 // this is a block scope on the stack. 1589 // this is a block scope on the stack.
1599 Handle<ScopeInfo> scope_info = nested_scope_chain_.last(); 1590 Handle<ScopeInfo> scope_info = nested_scope_chain_.last();
1600 Handle<Context> context = scope_info->HasContext() 1591 Handle<Context> context = scope_info->HasContext()
1601 ? CurrentContext() 1592 ? CurrentContext()
1602 : Handle<Context>::null(); 1593 : Handle<Context>::null();
1603 return MaterializeBlockScope(isolate_, scope_info, context, frame_, 1594 return MaterializeBlockScope(isolate_, scope_info, context,
1604 inlined_jsframe_index_); 1595 frame_inspector_);
1605 } else { 1596 } else {
1606 return MaterializeBlockScope(isolate_, Handle<ScopeInfo>::null(), 1597 return MaterializeBlockScope(isolate_, Handle<ScopeInfo>::null(),
1607 CurrentContext(), nullptr, 0); 1598 CurrentContext(), nullptr);
1608 } 1599 }
1609 } 1600 }
1610 case ScopeIterator::ScopeTypeModule: 1601 case ScopeIterator::ScopeTypeModule:
1611 return MaterializeModuleScope(isolate_, CurrentContext()); 1602 return MaterializeModuleScope(isolate_, CurrentContext());
1612 } 1603 }
1613 UNREACHABLE(); 1604 UNREACHABLE();
1614 return Handle<JSObject>(); 1605 return Handle<JSObject>();
1615 } 1606 }
1616 1607
1617 bool HasContext() { 1608 bool HasContext() {
1618 ScopeType type = Type(); 1609 ScopeType type = Type();
1619 if (type == ScopeTypeBlock || type == ScopeTypeLocal) { 1610 if (type == ScopeTypeBlock || type == ScopeTypeLocal) {
1620 if (!nested_scope_chain_.is_empty()) { 1611 if (!nested_scope_chain_.is_empty()) {
1621 return nested_scope_chain_.last()->HasContext(); 1612 return nested_scope_chain_.last()->HasContext();
1622 } 1613 }
1623 } 1614 }
1624 return true; 1615 return true;
1625 } 1616 }
1626 1617
1627 bool SetVariableValue(Handle<String> variable_name, 1618 bool SetVariableValue(Handle<String> variable_name,
1628 Handle<Object> new_value) { 1619 Handle<Object> new_value) {
1629 DCHECK(!failed_); 1620 DCHECK(!failed_);
1630 switch (Type()) { 1621 switch (Type()) {
1631 case ScopeIterator::ScopeTypeGlobal: 1622 case ScopeIterator::ScopeTypeGlobal:
1632 break; 1623 break;
1633 case ScopeIterator::ScopeTypeLocal: 1624 case ScopeIterator::ScopeTypeLocal:
1634 return SetLocalVariableValue(isolate_, frame_, inlined_jsframe_index_, 1625 return SetLocalVariableValue(isolate_, frame(), variable_name,
1635 variable_name, new_value); 1626 new_value);
1636 case ScopeIterator::ScopeTypeWith: 1627 case ScopeIterator::ScopeTypeWith:
1637 break; 1628 break;
1638 case ScopeIterator::ScopeTypeCatch: 1629 case ScopeIterator::ScopeTypeCatch:
1639 return SetCatchVariableValue(isolate_, CurrentContext(), variable_name, 1630 return SetCatchVariableValue(isolate_, CurrentContext(), variable_name,
1640 new_value); 1631 new_value);
1641 case ScopeIterator::ScopeTypeClosure: 1632 case ScopeIterator::ScopeTypeClosure:
1642 return SetClosureVariableValue(isolate_, CurrentContext(), 1633 return SetClosureVariableValue(isolate_, CurrentContext(),
1643 variable_name, new_value); 1634 variable_name, new_value);
1644 case ScopeIterator::ScopeTypeScript: 1635 case ScopeIterator::ScopeTypeScript:
1645 return SetScriptVariableValue(CurrentContext(), variable_name, 1636 return SetScriptVariableValue(CurrentContext(), variable_name,
1646 new_value); 1637 new_value);
1647 case ScopeIterator::ScopeTypeBlock: 1638 case ScopeIterator::ScopeTypeBlock:
1648 return SetBlockVariableValue( 1639 return SetBlockVariableValue(
1649 isolate_, HasContext() ? CurrentContext() : Handle<Context>::null(), 1640 isolate_, HasContext() ? CurrentContext() : Handle<Context>::null(),
1650 CurrentScopeInfo(), frame_, variable_name, new_value); 1641 CurrentScopeInfo(), frame(), variable_name, new_value);
1651 case ScopeIterator::ScopeTypeModule: 1642 case ScopeIterator::ScopeTypeModule:
1652 // TODO(2399): should we implement it? 1643 // TODO(2399): should we implement it?
1653 break; 1644 break;
1654 } 1645 }
1655 return false; 1646 return false;
1656 } 1647 }
1657 1648
1658 Handle<ScopeInfo> CurrentScopeInfo() { 1649 Handle<ScopeInfo> CurrentScopeInfo() {
1659 DCHECK(!failed_); 1650 DCHECK(!failed_);
1660 if (!nested_scope_chain_.is_empty()) { 1651 if (!nested_scope_chain_.is_empty()) {
(...skipping 26 matching lines...) Expand all
1687 OFStream os(stdout); 1678 OFStream os(stdout);
1688 DCHECK(!failed_); 1679 DCHECK(!failed_);
1689 switch (Type()) { 1680 switch (Type()) {
1690 case ScopeIterator::ScopeTypeGlobal: 1681 case ScopeIterator::ScopeTypeGlobal:
1691 os << "Global:\n"; 1682 os << "Global:\n";
1692 CurrentContext()->Print(os); 1683 CurrentContext()->Print(os);
1693 break; 1684 break;
1694 1685
1695 case ScopeIterator::ScopeTypeLocal: { 1686 case ScopeIterator::ScopeTypeLocal: {
1696 os << "Local:\n"; 1687 os << "Local:\n";
1697 function_->shared()->scope_info()->Print(); 1688 function()->shared()->scope_info()->Print();
1698 if (!CurrentContext().is_null()) { 1689 if (!CurrentContext().is_null()) {
1699 CurrentContext()->Print(os); 1690 CurrentContext()->Print(os);
1700 if (CurrentContext()->has_extension()) { 1691 if (CurrentContext()->has_extension()) {
1701 Handle<Object> extension(CurrentContext()->extension(), isolate_); 1692 Handle<Object> extension(CurrentContext()->extension(), isolate_);
1702 if (extension->IsJSContextExtensionObject()) { 1693 if (extension->IsJSContextExtensionObject()) {
1703 extension->Print(os); 1694 extension->Print(os);
1704 } 1695 }
1705 } 1696 }
1706 } 1697 }
1707 break; 1698 break;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1740 1731
1741 default: 1732 default:
1742 UNREACHABLE(); 1733 UNREACHABLE();
1743 } 1734 }
1744 PrintF("\n"); 1735 PrintF("\n");
1745 } 1736 }
1746 #endif 1737 #endif
1747 1738
1748 private: 1739 private:
1749 Isolate* isolate_; 1740 Isolate* isolate_;
1750 JavaScriptFrame* frame_; 1741 FrameInspector* frame_inspector_;
Benedikt Meurer 2015/07/16 07:33:40 Nit: Make this const, i.e. FrameInspector* const f
1751 int inlined_jsframe_index_;
1752 Handle<JSFunction> function_;
1753 Handle<Context> context_; 1742 Handle<Context> context_;
1754 List<Handle<ScopeInfo> > nested_scope_chain_; 1743 List<Handle<ScopeInfo> > nested_scope_chain_;
1755 bool seen_script_scope_; 1744 bool seen_script_scope_;
1756 bool failed_; 1745 bool failed_;
1757 1746
1747 inline JavaScriptFrame* frame() {
1748 return frame_inspector_->GetArgumentsFrame();
1749 }
1750
1751 inline JSFunction* function() {
1752 return JSFunction::cast(frame_inspector_->GetFunction());
1753 }
1754
1758 void RetrieveScopeChain(Scope* scope, 1755 void RetrieveScopeChain(Scope* scope,
1759 Handle<SharedFunctionInfo> shared_info) { 1756 Handle<SharedFunctionInfo> shared_info) {
1760 if (scope != NULL) { 1757 if (scope != NULL) {
1761 int source_position = shared_info->code()->SourcePosition(frame_->pc()); 1758 int source_position = shared_info->code()->SourcePosition(frame()->pc());
1762 scope->GetNestedScopeChain(isolate_, &nested_scope_chain_, 1759 scope->GetNestedScopeChain(isolate_, &nested_scope_chain_,
1763 source_position); 1760 source_position);
1764 } else { 1761 } else {
1765 // A failed reparse indicates that the preparser has diverged from the 1762 // A failed reparse indicates that the preparser has diverged from the
1766 // parser or that the preparse data given to the initial parse has been 1763 // parser or that the preparse data given to the initial parse has been
1767 // faulty. We fail in debug mode but in release mode we only provide the 1764 // faulty. We fail in debug mode but in release mode we only provide the
1768 // information we get from the context chain but nothing about 1765 // information we get from the context chain but nothing about
1769 // completely stack allocated scopes or stack allocated locals. 1766 // completely stack allocated scopes or stack allocated locals.
1770 // Or it could be due to stack overflow. 1767 // Or it could be due to stack overflow.
1771 DCHECK(isolate_->has_pending_exception()); 1768 DCHECK(isolate_->has_pending_exception());
(...skipping 10 matching lines...) Expand all
1782 DCHECK(args.length() == 2); 1779 DCHECK(args.length() == 2);
1783 CONVERT_NUMBER_CHECKED(int, break_id, Int32, args[0]); 1780 CONVERT_NUMBER_CHECKED(int, break_id, Int32, args[0]);
1784 RUNTIME_ASSERT(isolate->debug()->CheckExecutionState(break_id)); 1781 RUNTIME_ASSERT(isolate->debug()->CheckExecutionState(break_id));
1785 1782
1786 CONVERT_SMI_ARG_CHECKED(wrapped_id, 1); 1783 CONVERT_SMI_ARG_CHECKED(wrapped_id, 1);
1787 1784
1788 // Get the frame where the debugging is performed. 1785 // Get the frame where the debugging is performed.
1789 StackFrame::Id id = UnwrapFrameId(wrapped_id); 1786 StackFrame::Id id = UnwrapFrameId(wrapped_id);
1790 JavaScriptFrameIterator it(isolate, id); 1787 JavaScriptFrameIterator it(isolate, id);
1791 JavaScriptFrame* frame = it.frame(); 1788 JavaScriptFrame* frame = it.frame();
1789 FrameInspector frame_inspector(frame, 0, isolate);
1792 1790
1793 // Count the visible scopes. 1791 // Count the visible scopes.
1794 int n = 0; 1792 int n = 0;
1795 for (ScopeIterator it(isolate, frame, 0); !it.Done(); it.Next()) { 1793 for (ScopeIterator it(isolate, &frame_inspector); !it.Done(); it.Next()) {
1796 n++; 1794 n++;
1797 } 1795 }
1798 1796
1799 return Smi::FromInt(n); 1797 return Smi::FromInt(n);
1800 } 1798 }
1801 1799
1802 1800
1803 // Returns the list of step-in positions (text offset) in a function of the 1801 // Returns the list of step-in positions (text offset) in a function of the
1804 // stack frame in a range from the current debug break position to the end 1802 // stack frame in a range from the current debug break position to the end
1805 // of the corresponding statement. 1803 // of the corresponding statement.
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1910 RUNTIME_ASSERT(isolate->debug()->CheckExecutionState(break_id)); 1908 RUNTIME_ASSERT(isolate->debug()->CheckExecutionState(break_id));
1911 1909
1912 CONVERT_SMI_ARG_CHECKED(wrapped_id, 1); 1910 CONVERT_SMI_ARG_CHECKED(wrapped_id, 1);
1913 CONVERT_NUMBER_CHECKED(int, inlined_jsframe_index, Int32, args[2]); 1911 CONVERT_NUMBER_CHECKED(int, inlined_jsframe_index, Int32, args[2]);
1914 CONVERT_NUMBER_CHECKED(int, index, Int32, args[3]); 1912 CONVERT_NUMBER_CHECKED(int, index, Int32, args[3]);
1915 1913
1916 // Get the frame where the debugging is performed. 1914 // Get the frame where the debugging is performed.
1917 StackFrame::Id id = UnwrapFrameId(wrapped_id); 1915 StackFrame::Id id = UnwrapFrameId(wrapped_id);
1918 JavaScriptFrameIterator frame_it(isolate, id); 1916 JavaScriptFrameIterator frame_it(isolate, id);
1919 JavaScriptFrame* frame = frame_it.frame(); 1917 JavaScriptFrame* frame = frame_it.frame();
1918 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate);
1920 1919
1921 // Find the requested scope. 1920 // Find the requested scope.
1922 int n = 0; 1921 int n = 0;
1923 ScopeIterator it(isolate, frame, inlined_jsframe_index); 1922 ScopeIterator it(isolate, &frame_inspector);
1924 for (; !it.Done() && n < index; it.Next()) { 1923 for (; !it.Done() && n < index; it.Next()) {
1925 n++; 1924 n++;
1926 } 1925 }
1927 if (it.Done()) { 1926 if (it.Done()) {
1928 return isolate->heap()->undefined_value(); 1927 return isolate->heap()->undefined_value();
1929 } 1928 }
1930 Handle<JSObject> details; 1929 Handle<JSObject> details;
1931 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, details, 1930 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, details,
1932 MaterializeScopeDetails(isolate, &it)); 1931 MaterializeScopeDetails(isolate, &it));
1933 return *details; 1932 return *details;
(...skipping 21 matching lines...) Expand all
1955 bool ignore_nested_scopes = false; 1954 bool ignore_nested_scopes = false;
1956 if (args.length() == 4) { 1955 if (args.length() == 4) {
1957 CONVERT_BOOLEAN_ARG_CHECKED(flag, 3); 1956 CONVERT_BOOLEAN_ARG_CHECKED(flag, 3);
1958 ignore_nested_scopes = flag; 1957 ignore_nested_scopes = flag;
1959 } 1958 }
1960 1959
1961 // Get the frame where the debugging is performed. 1960 // Get the frame where the debugging is performed.
1962 StackFrame::Id id = UnwrapFrameId(wrapped_id); 1961 StackFrame::Id id = UnwrapFrameId(wrapped_id);
1963 JavaScriptFrameIterator frame_it(isolate, id); 1962 JavaScriptFrameIterator frame_it(isolate, id);
1964 JavaScriptFrame* frame = frame_it.frame(); 1963 JavaScriptFrame* frame = frame_it.frame();
1964 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate);
1965 1965
1966 List<Handle<JSObject> > result(4); 1966 List<Handle<JSObject> > result(4);
1967 ScopeIterator it(isolate, frame, inlined_jsframe_index, ignore_nested_scopes); 1967 ScopeIterator it(isolate, &frame_inspector, ignore_nested_scopes);
1968 for (; !it.Done(); it.Next()) { 1968 for (; !it.Done(); it.Next()) {
1969 Handle<JSObject> details; 1969 Handle<JSObject> details;
1970 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, details, 1970 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, details,
1971 MaterializeScopeDetails(isolate, &it)); 1971 MaterializeScopeDetails(isolate, &it));
1972 result.Add(details); 1972 result.Add(details);
1973 } 1973 }
1974 1974
1975 Handle<FixedArray> array = isolate->factory()->NewFixedArray(result.length()); 1975 Handle<FixedArray> array = isolate->factory()->NewFixedArray(result.length());
1976 for (int i = 0; i < result.length(); ++i) { 1976 for (int i = 0; i < result.length(); ++i) {
1977 array->set(i, *result[i]); 1977 array->set(i, *result[i]);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 CONVERT_NUMBER_CHECKED(int, break_id, Int32, args[0]); 2058 CONVERT_NUMBER_CHECKED(int, break_id, Int32, args[0]);
2059 RUNTIME_ASSERT(isolate->debug()->CheckExecutionState(break_id)); 2059 RUNTIME_ASSERT(isolate->debug()->CheckExecutionState(break_id));
2060 2060
2061 CONVERT_SMI_ARG_CHECKED(wrapped_id, 1); 2061 CONVERT_SMI_ARG_CHECKED(wrapped_id, 1);
2062 CONVERT_NUMBER_CHECKED(int, inlined_jsframe_index, Int32, args[2]); 2062 CONVERT_NUMBER_CHECKED(int, inlined_jsframe_index, Int32, args[2]);
2063 2063
2064 // Get the frame where the debugging is performed. 2064 // Get the frame where the debugging is performed.
2065 StackFrame::Id id = UnwrapFrameId(wrapped_id); 2065 StackFrame::Id id = UnwrapFrameId(wrapped_id);
2066 JavaScriptFrameIterator frame_it(isolate, id); 2066 JavaScriptFrameIterator frame_it(isolate, id);
2067 JavaScriptFrame* frame = frame_it.frame(); 2067 JavaScriptFrame* frame = frame_it.frame();
2068 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate);
2068 2069
2069 ScopeIterator it(isolate, frame, inlined_jsframe_index); 2070 ScopeIterator it(isolate, &frame_inspector);
2070 res = SetScopeVariableValue(&it, index, variable_name, new_value); 2071 res = SetScopeVariableValue(&it, index, variable_name, new_value);
2071 } else { 2072 } else {
2072 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0); 2073 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0);
2073 ScopeIterator it(isolate, fun); 2074 ScopeIterator it(isolate, fun);
2074 res = SetScopeVariableValue(&it, index, variable_name, new_value); 2075 res = SetScopeVariableValue(&it, index, variable_name, new_value);
2075 } 2076 }
2076 2077
2077 return isolate->heap()->ToBoolean(res); 2078 return isolate->heap()->ToBoolean(res);
2078 } 2079 }
2079 2080
2080 2081
2081 RUNTIME_FUNCTION(Runtime_DebugPrintScopes) { 2082 RUNTIME_FUNCTION(Runtime_DebugPrintScopes) {
2082 HandleScope scope(isolate); 2083 HandleScope scope(isolate);
2083 DCHECK(args.length() == 0); 2084 DCHECK(args.length() == 0);
2084 2085
2085 #ifdef DEBUG 2086 #ifdef DEBUG
2086 // Print the scopes for the top frame. 2087 // Print the scopes for the top frame.
2087 StackFrameLocator locator(isolate); 2088 StackFrameLocator locator(isolate);
2088 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0); 2089 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0);
2089 for (ScopeIterator it(isolate, frame, 0); !it.Done(); it.Next()) { 2090 FrameInspector frame_inspector(frame, 0, isolate);
2091
2092 for (ScopeIterator it(isolate, &frame_inspector); !it.Done(); it.Next()) {
2090 it.DebugPrint(); 2093 it.DebugPrint();
2091 } 2094 }
2092 #endif 2095 #endif
2093 return isolate->heap()->undefined_value(); 2096 return isolate->heap()->undefined_value();
2094 } 2097 }
2095 2098
2096 2099
2097 RUNTIME_FUNCTION(Runtime_GetThreadCount) { 2100 RUNTIME_FUNCTION(Runtime_GetThreadCount) {
2098 HandleScope scope(isolate); 2101 HandleScope scope(isolate);
2099 DCHECK(args.length() == 1); 2102 DCHECK(args.length() == 1);
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
2472 frame_(frame), 2475 frame_(frame),
2473 inlined_jsframe_index_(inlined_jsframe_index) { 2476 inlined_jsframe_index_(inlined_jsframe_index) {
2474 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); 2477 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate);
2475 Handle<JSFunction> function = 2478 Handle<JSFunction> function =
2476 handle(JSFunction::cast(frame_inspector.GetFunction())); 2479 handle(JSFunction::cast(frame_inspector.GetFunction()));
2477 Handle<Context> outer_context = handle(function->context(), isolate); 2480 Handle<Context> outer_context = handle(function->context(), isolate);
2478 outer_info_ = handle(function->shared()); 2481 outer_info_ = handle(function->shared());
2479 Handle<Context> inner_context; 2482 Handle<Context> inner_context;
2480 2483
2481 bool stop = false; 2484 bool stop = false;
2482 for (ScopeIterator it(isolate, frame, inlined_jsframe_index); 2485 for (ScopeIterator it(isolate, &frame_inspector);
2483 !it.Failed() && !it.Done() && !stop; it.Next()) { 2486 !it.Failed() && !it.Done() && !stop; it.Next()) {
2484 ScopeIterator::ScopeType scope_type = it.Type(); 2487 ScopeIterator::ScopeType scope_type = it.Type();
2485 2488
2486 if (scope_type == ScopeIterator::ScopeTypeLocal) { 2489 if (scope_type == ScopeIterator::ScopeTypeLocal) {
2487 Handle<Context> parent_context = 2490 Handle<Context> parent_context =
2488 it.HasContext() ? it.CurrentContext() : outer_context; 2491 it.HasContext() ? it.CurrentContext() : outer_context;
2489 2492
2490 // The "this" binding, if any, can't be bound via "with". If we need 2493 // The "this" binding, if any, can't be bound via "with". If we need
2491 // to, add another node onto the outer context to bind "this". 2494 // to, add another node onto the outer context to bind "this".
2492 parent_context = 2495 parent_context =
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
3218 return *isolate->factory()->undefined_value(); 3221 return *isolate->factory()->undefined_value();
3219 } 3222 }
3220 3223
3221 3224
3222 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { 3225 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) {
3223 UNIMPLEMENTED(); 3226 UNIMPLEMENTED();
3224 return NULL; 3227 return NULL;
3225 } 3228 }
3226 } // namespace internal 3229 } // namespace internal
3227 } // namespace v8 3230 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-4309.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698