Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011, Google Inc. | 1 // Copyright 2011, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 946 } | 946 } |
| 947 | 947 |
| 948 PassRefPtr<ScriptArguments> DartUtilities::createScriptArguments(Dart_Handle arg ument, Dart_Handle& exception) | 948 PassRefPtr<ScriptArguments> DartUtilities::createScriptArguments(Dart_Handle arg ument, Dart_Handle& exception) |
| 949 { | 949 { |
| 950 v8::Handle<v8::Value> v8Argument = DartHandleProxy::create(argument); | 950 v8::Handle<v8::Value> v8Argument = DartHandleProxy::create(argument); |
| 951 Vector<ScriptValue> arguments; | 951 Vector<ScriptValue> arguments; |
| 952 arguments.append(ScriptValue(v8Argument, v8::Isolate::GetCurrent())); | 952 arguments.append(ScriptValue(v8Argument, v8::Isolate::GetCurrent())); |
| 953 return ScriptArguments::create(DartUtilities::currentScriptState(), argument s); | 953 return ScriptArguments::create(DartUtilities::currentScriptState(), argument s); |
| 954 } | 954 } |
| 955 | 955 |
| 956 static PassRefPtr<ScriptCallStack> createScriptCallStackFromParsedStackTrace(Dar t_Handle parsedStackTrace, Dart_Handle exception) | 956 static PassRefPtr<ScriptCallStack> createScriptCallStackFromStackTrace(Dart_Stac kTrace stackTrace) |
| 957 { | 957 { |
| 958 Vector<Dart_Handle> callFrames; | 958 intptr_t frameCount = 0; |
| 959 DartUtilities::extractListElements(parsedStackTrace, exception, callFrames); | 959 Dart_Handle result = Dart_StackTraceLength(stackTrace, &frameCount); |
| 960 if (exception) | 960 fprintf(stderr, "-- %d \n", frameCount); |
|
siva
2013/11/12 00:37:45
fprintf is temporary debug code to be removed?
rmacnak
2013/11/12 22:32:45
Woops. Removed.
| |
| 961 if (Dart_IsError(result)) | |
| 961 return 0; | 962 return 0; |
| 962 | 963 |
| 963 size_t frameCount = callFrames.size(); | |
| 964 if (frameCount > ScriptCallStack::maxCallStackSizeToCapture) | 964 if (frameCount > ScriptCallStack::maxCallStackSizeToCapture) |
| 965 frameCount = ScriptCallStack::maxCallStackSizeToCapture; | 965 frameCount = ScriptCallStack::maxCallStackSizeToCapture; |
| 966 | 966 |
| 967 Vector<ScriptCallFrame> scriptCallStackFrames; | 967 Vector<ScriptCallFrame> scriptCallStackFrames; |
| 968 for (size_t i = 0; i < frameCount; i++) { | 968 for (intptr_t frameIndex = 0; frameIndex < frameCount; frameIndex++) { |
| 969 Dart_Handle callFrame = callFrames[i]; | 969 Dart_ActivationFrame frame = 0; |
| 970 Vector<Dart_Handle> fields; | 970 result = Dart_GetActivationFrame(stackTrace, frameIndex, &frame); |
| 971 DartUtilities::extractListElements(callFrame, exception, fields); | 971 if (Dart_IsError(result)) { |
| 972 if (exception) | 972 fprintf(stderr, "GetFrame failed\n"); |
| 973 return 0; | 973 return 0; |
| 974 ASSERT(fields.size() == 4); | 974 } |
| 975 String functionName = DartUtilities::toString(fields[0]); | 975 ASSERT(frame); |
| 976 String sourceName = DartUtilities::toString(fields[1]); | 976 |
| 977 int lineNumber = DartUtilities::toInteger(fields[2], exception); | 977 Dart_Handle dartFunctionName; |
| 978 if (exception) | 978 Dart_Handle dartScriptUrl; |
| 979 intptr_t lineNumber = 0; | |
| 980 intptr_t columnNumber = 0; | |
| 981 result = Dart_ActivationFrameInfoWithColumn(frame, &dartFunctionName, &d artScriptUrl, &lineNumber, &columnNumber); | |
| 982 if (Dart_IsError(result)) { | |
| 983 fprintf(stderr, "GetFrameInfo failed\n"); | |
|
siva
2013/11/12 00:37:45
Ditto comment about fprintf?
| |
| 979 return 0; | 984 return 0; |
| 980 int columnNumber = DartUtilities::toInteger(fields[3], exception); | 985 } |
| 981 if (exception) | 986 |
| 982 return 0; | 987 // FIXME: This skips frames where source is unavailable. WebKit code for |
| 983 scriptCallStackFrames.append(ScriptCallFrame(functionName, "undefined", sourceName, lineNumber, columnNumber)); | 988 // the console assumes that console.log et al. are implemented directly |
| 989 // as natives, i.e. that the top-of-stack will be the caller of console. log. | |
| 990 // The Dart implementation involves intermediate Dart calls, which are | |
| 991 // skipped by this clause. | |
|
siva
2013/11/12 00:37:45
The comment says FIXME, is there anything to be fi
rmacnak
2013/11/12 22:32:45
Removed the "FIXME" part. The problem really lies
| |
| 992 if (columnNumber == -1) | |
| 993 continue; | |
| 994 | |
| 995 String functionName = DartUtilities::toString(dartFunctionName); | |
| 996 String scriptUrl = DartUtilities::toString(dartScriptUrl); | |
| 997 | |
| 998 // FIXME: Cause of sources tab sometimes interpreting line/column inform ation relative to the page instead of the script tag body? | |
| 999 const char* scriptName = "undefined"; | |
| 1000 scriptCallStackFrames.append(ScriptCallFrame(functionName, scriptName, s criptUrl, lineNumber, columnNumber)); | |
| 984 } | 1001 } |
| 985 if (!frameCount) | 1002 if (scriptCallStackFrames.isEmpty()) |
| 986 scriptCallStackFrames.append(ScriptCallFrame("undefined", "undefined", " undefined", 0, 0)); | 1003 scriptCallStackFrames.append(ScriptCallFrame("undefined", "undefined", " undefined", 0, 0)); |
| 987 | 1004 |
| 988 return ScriptCallStack::create(scriptCallStackFrames); | 1005 return ScriptCallStack::create(scriptCallStackFrames); |
| 989 } | 1006 } |
| 990 | 1007 |
| 991 static PassRefPtr<ScriptCallStack> createScriptCallStackFromStackTrace(Dart_Hand le stackTrace, Dart_Handle& exception) | |
| 992 { | |
| 993 Dart_Handle parsedStackTrace = DartUtilities::invokeUtilsMethod("parseStackT race", 1, &stackTrace); | |
| 994 if (!DartUtilities::checkResult(parsedStackTrace, exception)) | |
| 995 return 0; | |
| 996 | |
| 997 return createScriptCallStackFromParsedStackTrace(parsedStackTrace, exception ); | |
| 998 } | |
| 999 | |
| 1000 PassRefPtr<ScriptCallStack> DartUtilities::createScriptCallStack() | 1008 PassRefPtr<ScriptCallStack> DartUtilities::createScriptCallStack() |
| 1001 { | 1009 { |
| 1002 Dart_ExceptionPauseInfo previousPauseInfo = Dart_GetExceptionPauseInfo(); | 1010 Dart_StackTrace trace = 0; |
| 1003 if (previousPauseInfo != kNoPauseOnExceptions) | 1011 Dart_Handle result = Dart_GetStackTrace(&trace); |
| 1004 Dart_SetExceptionPauseInfo(kNoPauseOnExceptions); | 1012 ASSERT(!Dart_IsError(result)); |
| 1005 Dart_Handle exception = 0; | 1013 ASSERT(!Dart_IsNull(result)); |
| 1006 Dart_Handle parsedStackTrace = DartUtilities::invokeUtilsMethod("capturePars edStackTrace", 0, 0); | 1014 ASSERT(trace); |
| 1007 | 1015 return createScriptCallStackFromStackTrace(trace); |
| 1008 if (previousPauseInfo != kNoPauseOnExceptions) | |
| 1009 Dart_SetExceptionPauseInfo(previousPauseInfo); | |
| 1010 | |
| 1011 if (!DartUtilities::checkResult(parsedStackTrace, exception)) | |
| 1012 return 0; | |
| 1013 | |
| 1014 return createScriptCallStackFromParsedStackTrace(parsedStackTrace, exception ); | |
| 1015 } | 1016 } |
| 1016 | 1017 |
| 1017 Dart_WeakPersistentHandle DartUtilities::createPrologueWeakPersistentHandle(Dart _Handle object, void* peer, Dart_WeakPersistentHandleFinalizer weakCallback) | 1018 Dart_WeakPersistentHandle DartUtilities::createPrologueWeakPersistentHandle(Dart _Handle object, void* peer, Dart_WeakPersistentHandleFinalizer weakCallback) |
| 1018 { | 1019 { |
| 1019 DartWeakCallback* callback = new DartWeakCallback(peer, weakCallback); | 1020 DartWeakCallback* callback = new DartWeakCallback(peer, weakCallback); |
| 1020 callback->m_object = Dart_NewPrologueWeakPersistentHandle(object, callback, &weakCallbackWrapper); | 1021 callback->m_object = Dart_NewPrologueWeakPersistentHandle(object, callback, &weakCallbackWrapper); |
| 1021 DartDOMData::current()->weakCallbacks()->add(callback); | 1022 DartDOMData::current()->weakCallbacks()->add(callback); |
| 1022 return callback->m_object; | 1023 return callback->m_object; |
| 1023 } | 1024 } |
| 1024 | 1025 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1129 Dart_Handle exception = Dart_ErrorGetException(result); | 1130 Dart_Handle exception = Dart_ErrorGetException(result); |
| 1130 ASSERT(!Dart_IsError(exception)); | 1131 ASSERT(!Dart_IsError(exception)); |
| 1131 | 1132 |
| 1132 exception = Dart_ToString(exception); | 1133 exception = Dart_ToString(exception); |
| 1133 if (Dart_IsError(exception)) | 1134 if (Dart_IsError(exception)) |
| 1134 errorMessage = String("Error converting exception to a string: ") + Dart_GetError(exception); | 1135 errorMessage = String("Error converting exception to a string: ") + Dart_GetError(exception); |
| 1135 else | 1136 else |
| 1136 errorMessage = String("Exception: ") + DartUtilities::toString(excep tion); | 1137 errorMessage = String("Exception: ") + DartUtilities::toString(excep tion); |
| 1137 | 1138 |
| 1138 // Print the stack trace. | 1139 // Print the stack trace. |
| 1139 Dart_Handle stacktrace = Dart_ErrorGetStacktrace(result); | 1140 Dart_StackTrace stacktrace; |
| 1140 ASSERT(!Dart_IsError(stacktrace)); | 1141 Dart_Handle traceResult = Dart_GetStackTraceFromError(result, &stacktrac e); |
| 1141 Dart_Handle stackTraceConversionException = 0; | 1142 ASSERT(!Dart_IsError(traceResult)); |
| 1142 callStack = createScriptCallStackFromStackTrace(stacktrace, stackTraceCo nversionException); | 1143 callStack = createScriptCallStackFromStackTrace(stacktrace); |
| 1143 if (stackTraceConversionException) | |
| 1144 errorMessage.append(String("\nError converting stack trace to a stri ng: ") + DartUtilities::toString(stackTraceConversionException)); | |
| 1145 } | 1144 } |
| 1146 | 1145 |
| 1147 if (context && context->isDocument()) { | 1146 if (context && context->isDocument()) { |
| 1148 static_cast<Document*>(context)->reportException(ErrorEvent::create(erro rMessage, sourceURL, lineNumber, 0, 0), callStack, NotSharableCrossOrigin); | 1147 static_cast<Document*>(context)->reportException(ErrorEvent::create(erro rMessage, sourceURL, lineNumber, 0, 0), callStack, NotSharableCrossOrigin); |
| 1149 } | 1148 } |
| 1150 } | 1149 } |
| 1151 | 1150 |
| 1152 Dart_Handle DartUtilities::notImplementedException(const char* fileName, int lin eNumber) | 1151 Dart_Handle DartUtilities::notImplementedException(const char* fileName, int lin eNumber) |
| 1153 { | 1152 { |
| 1154 Dart_Handle args[2] = { Dart_NewStringFromCString(fileName), Dart_NewInteger (lineNumber) }; | 1153 Dart_Handle args[2] = { Dart_NewStringFromCString(fileName), Dart_NewInteger (lineNumber) }; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1180 if (!v) { | 1179 if (!v) { |
| 1181 return 0; | 1180 return 0; |
| 1182 } | 1181 } |
| 1183 ASSERT(valueLen > 0 && static_cast<size_t>(valueLen) > strlen(v)); | 1182 ASSERT(valueLen > 0 && static_cast<size_t>(valueLen) > strlen(v)); |
| 1184 strncpy(value, v, valueLen); | 1183 strncpy(value, v, valueLen); |
| 1185 value[valueLen - 1] = '\0'; | 1184 value[valueLen - 1] = '\0'; |
| 1186 return strlen(value); | 1185 return strlen(value); |
| 1187 #endif | 1186 #endif |
| 1188 } | 1187 } |
| 1189 } | 1188 } |
| OLD | NEW |