Chromium Code Reviews| Index: Source/bindings/dart/DartUtilities.cpp |
| diff --git a/Source/bindings/dart/DartUtilities.cpp b/Source/bindings/dart/DartUtilities.cpp |
| index 7c5610339f1c52c4e0745f4fe8a1cb0c175d6192..2fe6b0b57ca075ce9fedc9290971db4e4b7606c0 100644 |
| --- a/Source/bindings/dart/DartUtilities.cpp |
| +++ b/Source/bindings/dart/DartUtilities.cpp |
| @@ -35,6 +35,7 @@ |
| #include "DartIDBKeyRange.h" |
| #include "DartImageData.h" |
| #include "DartMessagePort.h" |
| +#include "DartScriptState.h" |
|
vsm
2013/10/22 00:32:02
Use the full include path for non-generated files
|
| #include "bindings/dart/DartDOMData.h" |
| #include "bindings/dart/DartHandleProxy.h" |
| #include "bindings/dart/V8Converter.h" |
| @@ -895,21 +896,109 @@ bool DartUtilities::processingUserGesture() |
| return false; |
| } |
| +// FIXME(dartbug.com/14291): this should be implemented directly by the DartVM. |
| +intptr_t DartUtilities::libraryHandleToLibraryId(Dart_Handle library) |
| +{ |
| + Dart_Handle libraries = Dart_GetLibraryIds(); |
| + ASSERT(Dart_IsList(libraries)); |
| + |
| + intptr_t librariesLength = 0; |
| + Dart_Handle result = Dart_ListLength(libraries, &librariesLength); |
| + ASSERT(!Dart_IsError(result)); |
| + UNUSED_PARAM(result); |
| + for (intptr_t i = 0; i < librariesLength; ++i) { |
| + Dart_Handle libraryIdHandle = Dart_ListGetAt(libraries, i); |
| + ASSERT(!Dart_IsError(libraryIdHandle)); |
| + Dart_Handle exception = 0; |
| + intptr_t libraryId = DartUtilities::toInteger(libraryIdHandle, exception); |
| + ASSERT(!exception); |
| + if (Dart_IdentityEquals(Dart_GetLibraryFromId(libraryId), library)) |
| + return libraryId; |
| + } |
| + ASSERT_NOT_REACHED(); |
| + return 0; |
| +} |
| + |
| +DartScriptState* DartUtilities::currentScriptState() |
| +{ |
| + DartDOMData* dartDOMData = DartDOMData::current(); |
| + if (!dartDOMData->rootScriptState()) { |
| + DartController* controller = DartController::retrieve(dartDOMData->scriptExecutionContext()); |
| + intptr_t libraryId = DartUtilities::libraryHandleToLibraryId(Dart_RootLibrary()); |
| + DartScriptState* scriptState = controller->lookupScriptState(Dart_CurrentIsolate(), currentV8Context(), libraryId); |
| + dartDOMData->setRootScriptState(scriptState); |
| + return scriptState; |
| + } |
| + return dartDOMData->rootScriptState(); |
| +} |
| + |
| PassRefPtr<ScriptArguments> DartUtilities::createScriptArguments(Dart_Handle argument, Dart_Handle& exception) |
| { |
| v8::Handle<v8::Value> v8Argument = DartHandleProxy::create(argument); |
| Vector<ScriptValue> arguments; |
| arguments.append(v8Argument); |
| - ScriptState* scriptState = ScriptState::forContext(currentV8Context()); |
| - return ScriptArguments::create(scriptState, arguments); |
| + return ScriptArguments::create(DartUtilities::currentScriptState(), arguments); |
| +} |
| + |
| +static PassRefPtr<ScriptCallStack> createScriptCallStackFromParsedStackTrace(Dart_Handle parsedStackTrace, Dart_Handle exception) |
| +{ |
| + Vector<Dart_Handle> callFrames; |
| + DartUtilities::extractListElements(parsedStackTrace, exception, callFrames); |
| + if (exception) |
| + return 0; |
| + |
| + size_t frameCount = callFrames.size(); |
| + if (frameCount > ScriptCallStack::maxCallStackSizeToCapture) |
| + frameCount = ScriptCallStack::maxCallStackSizeToCapture; |
| + |
| + Vector<ScriptCallFrame> scriptCallStackFrames; |
| + for (size_t i = 0; i < frameCount; i++) { |
| + Dart_Handle callFrame = callFrames[i]; |
| + Vector<Dart_Handle> fields; |
| + DartUtilities::extractListElements(callFrame, exception, fields); |
| + if (exception) |
| + return 0; |
| + ASSERT(fields.size() == 4); |
| + String functionName = DartUtilities::toString(fields[0]); |
| + String sourceName = DartUtilities::toString(fields[1]); |
| + int lineNumber = DartUtilities::toInteger(fields[2], exception); |
| + if (exception) |
| + return 0; |
| + int columnNumber = DartUtilities::toInteger(fields[3], exception); |
| + if (exception) |
| + return 0; |
| + scriptCallStackFrames.append(ScriptCallFrame(functionName, sourceName, lineNumber, columnNumber)); |
| + } |
| + if (!frameCount) |
| + scriptCallStackFrames.append(ScriptCallFrame("undefined", "undefined", 0, 0)); |
| + |
| + return ScriptCallStack::create(scriptCallStackFrames); |
| +} |
| + |
| +static PassRefPtr<ScriptCallStack> createScriptCallStackFromStackTrace(Dart_Handle stackTrace, Dart_Handle& exception) |
| +{ |
| + Dart_Handle parsedStackTrace = DartUtilities::invokeUtilsMethod("parseStackTrace", 1, &stackTrace); |
| + if (!DartUtilities::checkResult(parsedStackTrace, exception)) |
| + return 0; |
| + |
| + return createScriptCallStackFromParsedStackTrace(parsedStackTrace, exception); |
| } |
| PassRefPtr<ScriptCallStack> DartUtilities::createScriptCallStack() |
| { |
| - // FIXME: wrap current dart call stack as ScriptCallStack. |
| - Vector<ScriptCallFrame> wrappedCallFrames; |
| - wrappedCallFrames.append(ScriptCallFrame("undefined", "undefined", 0)); |
| - return ScriptCallStack::create(wrappedCallFrames); |
| + Dart_ExceptionPauseInfo previousPauseInfo = Dart_GetExceptionPauseInfo(); |
| + if (previousPauseInfo != kNoPauseOnExceptions) |
| + Dart_SetExceptionPauseInfo(kNoPauseOnExceptions); |
| + Dart_Handle exception = 0; |
| + Dart_Handle parsedStackTrace = DartUtilities::invokeUtilsMethod("captureParsedStackTrace", 0, 0); |
| + |
| + if (previousPauseInfo != kNoPauseOnExceptions) |
| + Dart_SetExceptionPauseInfo(previousPauseInfo); |
| + |
| + if (!DartUtilities::checkResult(parsedStackTrace, exception)) |
| + return 0; |
| + |
| + return createScriptCallStackFromParsedStackTrace(parsedStackTrace, exception); |
| } |
| Dart_WeakPersistentHandle DartUtilities::createPrologueWeakPersistentHandle(Dart_Handle object, void* peer, Dart_WeakPersistentHandleFinalizer weakCallback) |
| @@ -1008,44 +1097,6 @@ void DartUtilities::reportProblem(ScriptExecutionContext* context, Dart_Handle r |
| reportProblem(context, result, sourceURL); |
| } |
| -static PassRefPtr<ScriptCallStack> createScriptCallStackFromStackTrace(Dart_Handle stackTrace, Dart_Handle& exception) { |
| - Dart_Handle parsedStackTrace = DartUtilities::invokeUtilsMethod("parseStackTrace", 1, &stackTrace); |
| - if (!DartUtilities::checkResult(parsedStackTrace, exception)) |
| - return 0; |
| - |
| - Vector<Dart_Handle> callFrames; |
| - DartUtilities::extractListElements(parsedStackTrace, exception, callFrames); |
| - if (exception) |
| - return 0; |
| - |
| - size_t frameCount = callFrames.size(); |
| - if (frameCount > ScriptCallStack::maxCallStackSizeToCapture) |
| - frameCount = ScriptCallStack::maxCallStackSizeToCapture; |
| - |
| - Vector<ScriptCallFrame> scriptCallStackFrames; |
| - for (size_t i = 0; i < frameCount; i++) { |
| - Dart_Handle callFrame = callFrames[i]; |
| - Vector<Dart_Handle> fields; |
| - DartUtilities::extractListElements(callFrame, exception, fields); |
| - if (exception) |
| - return 0; |
| - ASSERT(fields.size() == 4); |
| - String functionName = DartUtilities::toString(fields[0]); |
| - String sourceName = DartUtilities::toString(fields[1]); |
| - int lineNumber = DartUtilities::toInteger(fields[2], exception); |
| - if (exception) |
| - return 0; |
| - int columnNumber = DartUtilities::toInteger(fields[3], exception); |
| - if (exception) |
| - return 0; |
| - scriptCallStackFrames.append(ScriptCallFrame(functionName, sourceName, lineNumber, columnNumber)); |
| - } |
| - if (!frameCount) |
| - scriptCallStackFrames.append(ScriptCallFrame("undefined", "undefined", 0, 0)); |
| - |
| - return ScriptCallStack::create(scriptCallStackFrames); |
| -} |
| - |
| void DartUtilities::reportProblem(ScriptExecutionContext* context, Dart_Handle result, const String& sourceURL) |
| { |
| ASSERT(Dart_IsError(result)); |