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

Side by Side Diff: test/cctest/test-debug.cc

Issue 398002: Skip debugger frames when looking for calling context (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « src/top.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. 1 // Copyright 2007-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 5587 matching lines...) Expand 10 before | Expand all | Expand 10 after
5598 break_point_hit_count = 0; 5598 break_point_hit_count = 0;
5599 max_break_point_hit_count = 10000; // 10000 => infinite loop. 5599 max_break_point_hit_count = 10000; // 10000 => infinite loop.
5600 foo->Call(env->Global(), 0, NULL); 5600 foo->Call(env->Global(), 0, NULL);
5601 5601
5602 // When keeping the debug break several break will happen. 5602 // When keeping the debug break several break will happen.
5603 CHECK_EQ(3, break_point_hit_count); 5603 CHECK_EQ(3, break_point_hit_count);
5604 5604
5605 v8::Debug::SetDebugEventListener(NULL); 5605 v8::Debug::SetDebugEventListener(NULL);
5606 CheckDebuggerUnloaded(); 5606 CheckDebuggerUnloaded();
5607 } 5607 }
5608
5609
5610 v8::Handle<v8::Context> debugee_context;
5611 v8::Handle<v8::Context> debugger_context;
5612
5613
5614 // Property getter that checks that current and calling contexts
5615 // are both the debugee contexts.
5616 static v8::Handle<v8::Value> NamedGetterWithCallingContextCheck(
5617 v8::Local<v8::String> name,
5618 const v8::AccessorInfo& info) {
5619 CHECK(strcmp(*v8::String::AsciiValue(name), "a") == 0);
5620 v8::Handle<v8::Context> current = v8::Context::GetCurrent();
5621 CHECK(current == debugee_context);
5622 CHECK(current != debugger_context);
5623 v8::Handle<v8::Context> calling = v8::Context::GetCalling();
5624 CHECK(calling == debugee_context);
5625 CHECK(calling != debugger_context);
5626 return v8::Int32::New(1);
5627 }
5628
5629
5630 // Debug event listener that checks if the first argument of a function is
5631 // an object with property 'a' == 1. If the property has custom accessor
5632 // this handler will eventually invoke it.
5633 static void DebugEventGetAtgumentPropertyValue(
5634 v8::DebugEvent event,
5635 v8::Handle<v8::Object> exec_state,
5636 v8::Handle<v8::Object> event_data,
5637 v8::Handle<v8::Value> data) {
5638 if (event == v8::Break) {
5639 break_point_hit_count++;
5640 CHECK(debugger_context == v8::Context::GetCurrent());
5641 v8::Handle<v8::Function> func(v8::Function::Cast(*CompileRun(
5642 "(function(exec_state) {\n"
5643 " return (exec_state.frame(0).argumentValue(0).property('a').\n"
5644 " value().value() == 1);\n"
5645 "})")));
5646 const int argc = 1;
5647 v8::Handle<v8::Value> argv[argc] = { exec_state };
5648 v8::Handle<v8::Value> result = func->Call(exec_state, argc, argv);
5649 CHECK(result->IsTrue());
5650 }
5651 }
5652
5653
5654 TEST(CallingContextIsNotDebugContext) {
5655 // Create and enter a debugee context.
5656 v8::HandleScope scope;
5657 DebugLocalContext env;
5658 env.ExposeDebug();
5659
5660 // Save handles to the debugger and debugee contexts to be used in
5661 // NamedGetterWithCallingContextCheck.
5662 debugee_context = v8::Local<v8::Context>(*env);
5663 debugger_context = v8::Utils::ToLocal(Debug::debug_context());
5664
5665 // Create object with 'a' property accessor.
5666 v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New();
5667 named->SetAccessor(v8::String::New("a"),
5668 NamedGetterWithCallingContextCheck);
5669 env->Global()->Set(v8::String::New("obj"),
5670 named->NewInstance());
5671
5672 // Register the debug event listener
5673 v8::Debug::SetDebugEventListener(DebugEventGetAtgumentPropertyValue);
5674
5675 // Create a function that invokes debugger.
5676 v8::Local<v8::Function> foo = CompileFunction(
5677 &env,
5678 "function bar(x) { debugger; }"
5679 "function foo(){ bar(obj); }",
5680 "foo");
5681
5682 break_point_hit_count = 0;
5683 foo->Call(env->Global(), 0, NULL);
5684 CHECK_EQ(1, break_point_hit_count);
5685
5686 v8::Debug::SetDebugEventListener(NULL);
5687 debugee_context = v8::Handle<v8::Context>();
5688 debugger_context = v8::Handle<v8::Context>();
5689 CheckDebuggerUnloaded();
5690 }
OLDNEW
« no previous file with comments | « src/top.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698