Expose debug context into the native code. This change is doing several things:

1) Exposes Local<Context> v8::Debug::GetDebugContext().
Rationale: We can already get debugger context instance using various workarounds,
so exposing it explicitly in the API only makes things more clear.

2) Removes debugger.HasJavaScriptFrames() requirement for entering debugger context.
Rationale: Sometimes we'd like to call into debugger from the external native code.

3) Makes Debugger v8::Debug::Call execute on debugger context's global object.
Rationale: This is somewhat arguable, but temporary measure. We've agreed that we
should introduce a DebugAPI object that would expose necessary API in the debug-delay.
The problem is that it would take some time to define this API and it is not really
convenient to do that on the v8 land given the difference in v8 / host lifecycle.
The plan is to compose this API as a Debug.* wrapper outside v8 by means of exposing
debugger context's global object here, and once API settles down, upstream it to v8 and
start making Debug::Calls on this new DebugAPI object instead.


git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4251 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
pfeldman@chromium.org 2010-03-24 13:09:02 +00:00
parent 3503ee2ae4
commit 54f0a5b221
4 changed files with 27 additions and 11 deletions

View File

@ -237,9 +237,10 @@ class EXPORT Debug {
* With this call the debugger is entered and the function specified is called
* with the execution state as the first argument. This makes it possible to
* get access to information otherwise not available during normal JavaScript
* execution e.g. details on stack frames. The following example show a
* JavaScript function which when passed to v8::Debug::Call will return the
* current line of JavaScript execution.
* execution e.g. details on stack frames. Receiver of the function call will
* be the debugger context global object, however this is a subject to change.
* The following example show a JavaScript function which when passed to
* v8::Debug::Call will return the current line of JavaScript execution.
*
* \code
* function frame_source_line(exec_state) {
@ -302,6 +303,14 @@ class EXPORT Debug {
* of this method.
*/
static void ProcessDebugMessages();
/**
* Debugger is running in it's own context which is entered while debugger
* messages are being dispatched. This is an explicit getter for this
* debugger context. Note that the content of the debugger context is subject
* to change.
*/
static Local<Context> GetDebugContext();
};

View File

@ -3973,6 +3973,11 @@ void Debug::ProcessDebugMessages() {
i::Execution::ProcessDebugMesssages(true);
}
Local<Context> Debug::GetDebugContext() {
i::EnterDebugger debugger;
return Utils::ToLocal(i::Debug::debug_context());
}
#endif // ENABLE_DEBUGGER_SUPPORT
namespace internal {

View File

@ -2448,7 +2448,7 @@ Handle<Object> Debugger::Call(Handle<JSFunction> fun,
// Enter the debugger.
EnterDebugger debugger;
if (debugger.FailedToEnter() || !debugger.HasJavaScriptFrames()) {
if (debugger.FailedToEnter()) {
return Factory::undefined_value();
}
@ -2461,8 +2461,12 @@ Handle<Object> Debugger::Call(Handle<JSFunction> fun,
static const int kArgc = 2;
Object** argv[kArgc] = { exec_state.location(), data.location() };
Handle<Object> result = Execution::Call(fun, Factory::undefined_value(),
kArgc, argv, pending_exception);
Handle<Object> result = Execution::Call(
fun,
Handle<Object>(Debug::debug_context_->global_proxy()),
kArgc,
argv,
pending_exception);
return result;
}

View File

@ -4655,11 +4655,9 @@ TEST(CallFunctionInDebugger) {
v8::Script::Compile(
v8::String::New(debugger_call_with_closure_source))->Run());
// Calling a function through the debugger returns undefined if there are no
// JavaScript frames.
CHECK(v8::Debug::Call(frame_count)->IsUndefined());
CHECK(v8::Debug::Call(frame_source_line)->IsUndefined());
CHECK(v8::Debug::Call(debugger_call_with_data)->IsUndefined());
// Calling a function through the debugger returns 0 frames if there are
// no JavaScript frames.
CHECK_EQ(v8::Integer::New(0), v8::Debug::Call(frame_count));
// Test that the number of frames can be retrieved.
v8::Script::Compile(v8::String::New("CheckFrameCount(1)"))->Run();