Index: Source/bindings/dart/DartDebugServer.cpp |
diff --git a/Source/bindings/dart/DartDebugServer.cpp b/Source/bindings/dart/DartDebugServer.cpp |
index 67500c6b6b94b64c7902e90bbb23625d00c033e6..df6894c694ab1245d0560e71b71a292cc459529c 100644 |
--- a/Source/bindings/dart/DartDebugServer.cpp |
+++ b/Source/bindings/dart/DartDebugServer.cpp |
@@ -44,11 +44,13 @@ |
#include "core/inspector/InstrumentingAgents.h" |
#include "core/page/DOMWindow.h" |
#include "core/page/Page.h" |
+#include "core/platform/Logging.h" |
#include <v8-debug.h> |
#include <wtf/HashMap.h> |
#include <wtf/Vector.h> |
+ |
namespace WebCore { |
class V8EventDetails : public v8::Debug::EventDetails { |
@@ -190,13 +192,6 @@ void DartDebugServer::disable() |
disable->Call(m_dartDebugObject.get(), 0, 0); |
} |
-v8::Handle<v8::Value> DartDebugServer::convertInspectedValue(Dart_Handle object) |
-{ |
- v8::Handle<v8::Function> wrapValue = v8::Handle<v8::Function>::Cast(shared().m_dartDebugObject.get()->Get(v8::String::New("wrapValue"))); |
- v8::Handle<v8::Value> args[] = { DartHandleProxy::create(object) }; |
- return wrapValue->Call(shared().m_dartDebugObject.get(), 1, args); |
-} |
- |
v8::Handle<v8::Object> DartDebugServer::createExecutionState(Dart_StackTrace trace) |
{ |
intptr_t length = 0; |
@@ -204,6 +199,9 @@ v8::Handle<v8::Object> DartDebugServer::createExecutionState(Dart_StackTrace tra |
ASSERT(!Dart_IsError(result)); |
UNUSED_PARAM(result); |
ASSERT(length); |
+ ASSERT(Dart_CurrentIsolate()); |
+ int isolateHandle = isolateMap().getByValue(Dart_CurrentIsolate()); |
+ |
v8::Local<v8::Array> callFrames = v8::Array::New(length); |
for (int i = length - 1; i >=0; --i) { |
Dart_ActivationFrame frame = 0; |
@@ -213,15 +211,21 @@ v8::Handle<v8::Object> DartDebugServer::createExecutionState(Dart_StackTrace tra |
Dart_Handle scriptURL = 0; |
intptr_t lineNumber = 0; |
intptr_t libraryId = 0; |
+ |
result = Dart_ActivationFrameInfo(frame, &functionName, &scriptURL, &lineNumber, &libraryId); |
ASSERT(!Dart_IsError(result)); |
+ Dart_Handle libraryURL = Dart_GetLibraryURL(libraryId); |
+ ASSERT(!Dart_IsError(libraryURL)); |
+ Dart_Handle library = Dart_LookupLibrary(libraryURL); |
v8::Local<v8::Object> callFrame = v8::Object::New(); |
callFrame->Set(v8::String::New("functionName"), V8Converter::stringToV8(functionName)); |
callFrame->Set(v8::String::New("scriptURL"), V8Converter::stringToV8(scriptURL)); |
callFrame->Set(v8::String::New("lineNumber"), v8::Number::New(lineNumber - 1)); |
- callFrame->Set(v8::String::New("libraryProxy"), DartHandleProxy::createForLibrary(libraryId)); |
- callFrame->Set(v8::String::New("localVariables"), convertInspectedValue(Dart_GetLocalVariables(frame))); |
+ callFrame->Set(v8::String::New("libraryProxy"), DartHandleProxy::createLibraryProxy(library, libraryId, Dart_Null())); |
+ callFrame->Set(v8::String::New("localScopeProxy"), DartHandleProxy::createLocalScopeProxy( |
+ Dart_GetLocalVariables(frame))); |
+ callFrame->Set(v8::String::New("isolateHandle"), v8::Number::New(isolateHandle)); |
callFrames->Set(i, callFrame); |
} |
@@ -253,7 +257,7 @@ void DartDebugServer::handleException(Dart_Handle exception, Dart_StackTrace tra |
V8Scope v8Scope(v8::Debug::GetDebugContext()); |
V8Scope v8WorldScope(DartUtilities::currentV8Context()); |
v8::Handle<v8::Function> eventDataConstructor = v8::Local<v8::Function>::Cast(m_dartDebugObject.get()->Get(v8::String::New("EventData"))); |
- v8::Handle<v8::Value> args[] = { convertInspectedValue(exception) }; |
+ v8::Handle<v8::Value> args[] = { DartHandleProxy::create(exception) }; |
v8::Handle<v8::Object> eventData = v8::Local<v8::Object>::Cast(eventDataConstructor->CallAsConstructor(1, args)); |
V8EventDetails eventDetails(v8::Exception, createExecutionState(trace), eventData); |
PageScriptDebugServer::shared().handleV8DebugEvent(eventDetails); |
@@ -408,87 +412,23 @@ static v8::Handle<v8::Value> evaluateInScope(const v8::Arguments& args) |
{ |
v8::Handle<v8::String> expression = args[0]->ToString(); |
v8::Handle<v8::Object> receiver = args[1].As<v8::Object>(); |
- v8::Handle<v8::Value> scopeObject = args[2]; |
- |
- expression = v8::String::Concat(v8::String::New("(function(scopeObject) { with(scopeObject) { return "), expression); |
+ v8::Handle<v8::Value> scopeObjectGlobal = args[2]; |
+ v8::Handle<v8::Value> scopeObjectLocal = args[3]; |
+ v8::Handle<v8::Value> scopes[] = { scopeObjectGlobal, scopeObjectLocal }; |
+ |
+ expression = v8::String::Concat(v8::String::New( |
+ "(function($$scopeObjectGlobal, $$scopeObjectLocal) { " |
+ "var $$scopeObjectLocalThis = $$scopeObjectLocal.this;" |
+ "with ($$scopeObjectGlobal) with ($$scopeObjectLocalThis || {}) with($$scopeObjectLocal) { " |
+ "return "), |
+ expression); |
expression = v8::String::Concat(expression, v8::String::New("} })")); |
v8::Handle<v8::Script> script = v8::Script::Compile(expression); |
if (script.IsEmpty()) // Return immediately in case of exception to let the caller handle it. |
return v8::Handle<v8::Value>(); |
v8::Handle<v8::Function> function = script->Run().As<v8::Function>(); |
- return function->Call(receiver, 1, &scopeObject); |
-} |
- |
-static v8::Handle<v8::Value> accessorGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) |
-{ |
- v8::Handle<v8::Value> getter = info.Data()->ToObject()->Get(v8::String::New("getter")); |
- return v8::Handle<v8::Function>::Cast(getter)->Call(v8::Object::New(), 0, 0); |
-} |
- |
-static void accessorSetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info) |
-{ |
- v8::Handle<v8::Value> setter = info.Data()->ToObject()->Get(v8::String::New("setter")); |
- if (!setter->IsUndefined()) |
- v8::Handle<v8::Function>::Cast(setter)->Call(v8::Object::New(), 1, &value); |
-} |
- |
-static v8::Handle<v8::Value> setAccessor(const v8::Arguments& args) |
-{ |
- v8::Handle<v8::Object> descriptor = v8::Object::New(); |
- descriptor->Set(v8::String::New("getter"), args[2]); |
- descriptor->Set(v8::String::New("setter"), args[3]); |
- args[0]->ToObject()->SetAccessor(args[1]->ToString(), accessorGetter, accessorSetter, descriptor); |
- return v8::Undefined(); |
-} |
- |
-static v8::Handle<v8::Value> indexedGetter(uint32_t index, const v8::AccessorInfo& info) |
-{ |
- v8::Handle<v8::Function> getter = v8::Handle<v8::Function>::Cast(info.Holder()->GetHiddenValue(v8::String::New("getter"))); |
- v8::Handle<v8::Value> args[] = { v8::Integer::New(index) }; |
- return getter->Call(info.Holder(), 1, args); |
-} |
- |
-static v8::Handle<v8::Value> indexedSetter(uint32_t index, v8::Local<v8::Value> value, const v8::AccessorInfo& info) |
-{ |
- v8::Handle<v8::Function> setter = v8::Handle<v8::Function>::Cast(info.Holder()->GetHiddenValue(v8::String::New("setter"))); |
- v8::Handle<v8::Value> args[] = { v8::Integer::New(index), value }; |
- return setter->Call(info.Holder(), 2, args); |
-} |
- |
-static v8::Handle<v8::Array> indexedEnumerator(const v8::AccessorInfo& info) |
-{ |
- v8::Handle<v8::Function> enumerator = v8::Handle<v8::Function>::Cast(info.Holder()->GetHiddenValue(v8::String::New("enumerator"))); |
- return enumerator->Call(info.Holder(), 0, 0).As<v8::Array>(); |
-} |
- |
-static v8::Handle<v8::Value> createArrayWithIndexedPropertyHandler(const v8::Arguments& args) |
-{ |
- static v8::Persistent<v8::FunctionTemplate> arrayTemplate; |
- if (arrayTemplate.IsEmpty()) { |
- arrayTemplate = v8::Persistent<v8::FunctionTemplate>::New(args.GetIsolate(), v8::FunctionTemplate::New()); |
- v8::Local<v8::ObjectTemplate> instanceTemplate = arrayTemplate->InstanceTemplate(); |
- instanceTemplate->SetIndexedPropertyHandler(&indexedGetter, &indexedSetter, 0, 0, &indexedEnumerator); |
- } |
- |
- v8::Local<v8::Object> array = arrayTemplate->InstanceTemplate()->NewInstance(); |
- v8::Handle<v8::Value> arrayConstructor = v8::Context::GetCurrent()->Global()->Get(v8::String::New("Array")); |
- v8::Handle<v8::Value> arrayPrototype = arrayConstructor.As<v8::Object>()->Get(v8::String::New("prototype")); |
- array->Set(v8::String::New("__proto__"), arrayPrototype); |
- array->SetHiddenValue(v8::String::New("getter"), args[0]); |
- array->SetHiddenValue(v8::String::New("setter"), args[1]); |
- array->SetHiddenValue(v8::String::New("enumerator"), args[2]); |
- return array; |
-} |
- |
-static v8::Handle<v8::Value> setHiddenValue(const v8::Arguments& args) |
-{ |
- return v8::Boolean::New(args[0]->ToObject()->SetHiddenValue(args[1]->ToString(), args[2])); |
-} |
- |
-static v8::Handle<v8::Value> getHiddenValue(const v8::Arguments& args) |
-{ |
- return args[0]->ToObject()->GetHiddenValue(args[1]->ToString()); |
+ return function->Call(receiver, 2, scopes); |
} |
void DartDebugServer::ensureHooksInstalled() |
@@ -519,25 +459,7 @@ void DartDebugServer::ensureHooksInstalled() |
nativeCallbacks->Set(v8::String::New("stepOver"), v8::FunctionTemplate::New(&stepOver)->GetFunction()); |
nativeCallbacks->Set(v8::String::New("stepOut"), v8::FunctionTemplate::New(&stepOut)->GetFunction()); |
nativeCallbacks->Set(v8::String::New("evaluateInScope"), v8::FunctionTemplate::New(&evaluateInScope)->GetFunction()); |
- nativeCallbacks->Set(v8::String::New("createArrayWithIndexedPropertyHandler"), v8::FunctionTemplate::New(&createArrayWithIndexedPropertyHandler)->GetFunction()); |
- nativeCallbacks->Set(v8::String::New("setAccessor"), v8::FunctionTemplate::New(&setAccessor)->GetFunction()); |
- nativeCallbacks->Set(v8::String::New("setHiddenValue"), v8::FunctionTemplate::New(&setHiddenValue)->GetFunction()); |
- nativeCallbacks->Set(v8::String::New("getHiddenValue"), v8::FunctionTemplate::New(&getHiddenValue)->GetFunction()); |
- { |
- // Trampoline script is required to properly set calling context before |
- // invoking Dart code because of security checks in console.log |
- // implementation (see InjectedScriptManager::canAccessInspectedWindow). |
- V8Scope v8scope; |
- v8::Handle<v8::String> trampolineScript = v8::String::New("(function (func, args) { return func.apply(this, args); })"); |
- v8::Local<v8::Function> trampoline = v8::Local<v8::Function>::Cast(v8::Script::Compile(trampolineScript)->Run()); |
- nativeCallbacks->Set(v8::String::New("invocationTrampoline"), trampoline); |
- } |
m_dartDebugObject.get()->Set(v8::String::New("nativeCallbacks"), nativeCallbacks); |
- |
- v8::Local<v8::Object> mirrorAPI = v8::Object::New(); |
- DartHandleProxy::getMirrorAPI(mirrorAPI); |
- m_dartDebugObject.get()->Set(v8::String::New("mirrorAPI"), mirrorAPI); |
- |
} |
} |