Revision: 2700 Author: [email protected] Date: Mon Aug 17 07:26:48 2009 Log: Added API for getting object mirrors Added Debug::GetMirror call to get a mirror for a given object.
Review URL: http://codereview.chromium.org/172045 http://code.google.com/p/v8/source/detail?r=2700 Modified: /branches/bleeding_edge/include/v8-debug.h /branches/bleeding_edge/src/api.cc /branches/bleeding_edge/test/cctest/test-debug.cc ======================================= --- /branches/bleeding_edge/include/v8-debug.h Wed Aug 5 00:59:46 2009 +++ /branches/bleeding_edge/include/v8-debug.h Mon Aug 17 07:26:48 2009 @@ -228,9 +228,14 @@ * } * \endcode */ - static Handle<Value> Call(v8::Handle<v8::Function> fun, + static Local<Value> Call(v8::Handle<v8::Function> fun, Handle<Value> data = Handle<Value>()); + /** + * Returns a mirror object for the given object. + */ + static Local<Value> GetMirror(v8::Handle<v8::Value> obj); + /** * Enable the V8 builtin debug agent. The debugger agent will listen on the * supplied TCP/IP port for remote debugger connection. ======================================= --- /branches/bleeding_edge/src/api.cc Mon Aug 17 06:34:41 2009 +++ /branches/bleeding_edge/src/api.cc Mon Aug 17 07:26:48 2009 @@ -3595,10 +3595,10 @@ } -Handle<Value> Debug::Call(v8::Handle<v8::Function> fun, - v8::Handle<v8::Value> data) { - if (!i::V8::IsRunning()) return Handle<Value>(); - ON_BAILOUT("v8::Debug::Call()", return Handle<Value>()); +Local<Value> Debug::Call(v8::Handle<v8::Function> fun, + v8::Handle<v8::Value> data) { + if (!i::V8::IsRunning()) return Local<Value>(); + ON_BAILOUT("v8::Debug::Call()", return Local<Value>()); ENTER_V8; i::Handle<i::Object> result; EXCEPTION_PREAMBLE(); @@ -3614,6 +3614,28 @@ EXCEPTION_BAILOUT_CHECK(Local<Value>()); return Utils::ToLocal(result); } + + +Local<Value> Debug::GetMirror(v8::Handle<v8::Value> obj) { + if (!i::V8::IsRunning()) return Local<Value>(); + ON_BAILOUT("v8::Debug::GetMirror()", return Local<Value>()); + ENTER_V8; + v8::HandleScope scope; + i::Debug::Load(); + i::Handle<i::JSObject> debug(i::Debug::debug_context()->global()); + i::Handle<i::String> name = i::Factory::LookupAsciiSymbol("MakeMirror"); + i::Handle<i::Object> fun_obj = i::GetProperty(debug, name); + i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(fun_obj); + v8::Handle<v8::Function> v8_fun = Utils::ToLocal(fun); + const int kArgc = 1; + v8::Handle<v8::Value> argv[kArgc] = { obj }; + EXCEPTION_PREAMBLE(); + v8::Handle<v8::Value> result = v8_fun->Call(Utils::ToLocal(debug), + kArgc, + argv); + EXCEPTION_BAILOUT_CHECK(Local<Value>()); + return scope.Close(result); +} bool Debug::EnableAgent(const char* name, int port) { ======================================= --- /branches/bleeding_edge/test/cctest/test-debug.cc Fri Jul 24 00:39:53 2009 +++ /branches/bleeding_edge/test/cctest/test-debug.cc Mon Aug 17 07:26:48 2009 @@ -5357,3 +5357,20 @@ v8::Debug::SetMessageHandler2(NULL); CheckDebuggerUnloaded(); } + + +TEST(GetMirror) { + v8::HandleScope scope; + DebugLocalContext env; + v8::Handle<v8::Value> obj = v8::Debug::GetMirror(v8::String::New("hodja")); + v8::Handle<v8::Function> run_test = v8::Handle<v8::Function>::Cast( + v8::Script::New( + v8::String::New( + "function runTest(mirror) {" + " return mirror.isString() && (mirror.length() == 5);" + "}" + "" + "runTest;"))->Run()); + v8::Handle<v8::Value> result = run_test->Call(env->Global(), 1, &obj); + CHECK(result->IsTrue()); +} --~--~---------~--~----~------------~-------~--~----~ v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev -~----------~----~----~----~------~----~------~--~---
