Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: Source/bindings/dart/DartUtilities.cpp

Issue 55433007: Dartium: do not call back into Dart code to parse or generate a stack trace. (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: . Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 if (Dart_IsError(result))
961 return 0; 961 return 0;
962 962
963 size_t frameCount = callFrames.size();
964 if (frameCount > ScriptCallStack::maxCallStackSizeToCapture) 963 if (frameCount > ScriptCallStack::maxCallStackSizeToCapture)
965 frameCount = ScriptCallStack::maxCallStackSizeToCapture; 964 frameCount = ScriptCallStack::maxCallStackSizeToCapture;
966 965
967 Vector<ScriptCallFrame> scriptCallStackFrames; 966 Vector<ScriptCallFrame> scriptCallStackFrames;
968 for (size_t i = 0; i < frameCount; i++) { 967 for (intptr_t frameIndex = 0; frameIndex < frameCount; frameIndex++) {
969 Dart_Handle callFrame = callFrames[i]; 968 Dart_ActivationFrame frame = 0;
970 Vector<Dart_Handle> fields; 969 result = Dart_GetActivationFrame(stackTrace, frameIndex, &frame);
971 DartUtilities::extractListElements(callFrame, exception, fields); 970 if (Dart_IsError(result)) {
972 if (exception)
973 return 0; 971 return 0;
974 ASSERT(fields.size() == 4); 972 }
975 String functionName = DartUtilities::toString(fields[0]); 973 ASSERT(frame);
976 String sourceName = DartUtilities::toString(fields[1]); 974
977 int lineNumber = DartUtilities::toInteger(fields[2], exception); 975 Dart_Handle dartFunctionName;
978 if (exception) 976 Dart_Handle dartScriptUrl;
977 intptr_t lineNumber = 0;
978 intptr_t columnNumber = 0;
979 result = Dart_ActivationFrameInfo(frame, &dartFunctionName, &dartScriptU rl, &lineNumber, &columnNumber);
980 if (Dart_IsError(result)) {
979 return 0; 981 return 0;
980 int columnNumber = DartUtilities::toInteger(fields[3], exception); 982 }
981 if (exception) 983
982 return 0; 984 // This skips frames where source is unavailable. WebKit code for the
983 scriptCallStackFrames.append(ScriptCallFrame(functionName, "undefined", sourceName, lineNumber, columnNumber)); 985 // console assumes that console.log et al. are implemented directly
986 // as natives, i.e. that the top-of-stack will be the caller of
987 // console.log. The Dart implementation involves intermediate Dart
988 // calls, which are skipped by this clause.
989 if (columnNumber == -1)
990 continue;
991
992 String functionName = DartUtilities::toString(dartFunctionName);
993 String scriptUrl = DartUtilities::toString(dartScriptUrl);
994
995 // FIXME: Cause of sources tab sometimes interpreting line/column inform ation relative to the page instead of the script tag body?
vsm 2013/11/12 23:07:27 Are we seeing the wrong offset for inline scripts?
rmacnak 2013/11/15 23:48:26 Filed http://dartbug.com/15106
996 const char* scriptName = "undefined";
997 scriptCallStackFrames.append(ScriptCallFrame(functionName, scriptName, s criptUrl, lineNumber, columnNumber));
984 } 998 }
985 if (!frameCount) 999 if (scriptCallStackFrames.isEmpty())
986 scriptCallStackFrames.append(ScriptCallFrame("undefined", "undefined", " undefined", 0, 0)); 1000 scriptCallStackFrames.append(ScriptCallFrame("undefined", "undefined", " undefined", 0, 0));
987 1001
988 return ScriptCallStack::create(scriptCallStackFrames); 1002 return ScriptCallStack::create(scriptCallStackFrames);
989 } 1003 }
990 1004
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() 1005 PassRefPtr<ScriptCallStack> DartUtilities::createScriptCallStack()
1001 { 1006 {
1002 Dart_ExceptionPauseInfo previousPauseInfo = Dart_GetExceptionPauseInfo(); 1007 Dart_StackTrace trace = 0;
1003 if (previousPauseInfo != kNoPauseOnExceptions) 1008 Dart_Handle result = Dart_GetStackTrace(&trace);
1004 Dart_SetExceptionPauseInfo(kNoPauseOnExceptions); 1009 ASSERT(!Dart_IsError(result));
1005 Dart_Handle exception = 0; 1010 ASSERT(!Dart_IsNull(result));
1006 Dart_Handle parsedStackTrace = DartUtilities::invokeUtilsMethod("capturePars edStackTrace", 0, 0); 1011 ASSERT(trace);
1007 1012 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 } 1013 }
1016 1014
1017 Dart_WeakPersistentHandle DartUtilities::createPrologueWeakPersistentHandle(Dart _Handle object, void* peer, Dart_WeakPersistentHandleFinalizer weakCallback) 1015 Dart_WeakPersistentHandle DartUtilities::createPrologueWeakPersistentHandle(Dart _Handle object, void* peer, Dart_WeakPersistentHandleFinalizer weakCallback)
1018 { 1016 {
1019 DartWeakCallback* callback = new DartWeakCallback(peer, weakCallback); 1017 DartWeakCallback* callback = new DartWeakCallback(peer, weakCallback);
1020 callback->m_object = Dart_NewPrologueWeakPersistentHandle(object, callback, &weakCallbackWrapper); 1018 callback->m_object = Dart_NewPrologueWeakPersistentHandle(object, callback, &weakCallbackWrapper);
1021 DartDOMData::current()->weakCallbacks()->add(callback); 1019 DartDOMData::current()->weakCallbacks()->add(callback);
1022 return callback->m_object; 1020 return callback->m_object;
1023 } 1021 }
1024 1022
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 Dart_Handle exception = Dart_ErrorGetException(result); 1127 Dart_Handle exception = Dart_ErrorGetException(result);
1130 ASSERT(!Dart_IsError(exception)); 1128 ASSERT(!Dart_IsError(exception));
1131 1129
1132 exception = Dart_ToString(exception); 1130 exception = Dart_ToString(exception);
1133 if (Dart_IsError(exception)) 1131 if (Dart_IsError(exception))
1134 errorMessage = String("Error converting exception to a string: ") + Dart_GetError(exception); 1132 errorMessage = String("Error converting exception to a string: ") + Dart_GetError(exception);
1135 else 1133 else
1136 errorMessage = String("Exception: ") + DartUtilities::toString(excep tion); 1134 errorMessage = String("Exception: ") + DartUtilities::toString(excep tion);
1137 1135
1138 // Print the stack trace. 1136 // Print the stack trace.
1139 Dart_Handle stacktrace = Dart_ErrorGetStacktrace(result); 1137 Dart_StackTrace stacktrace;
1140 ASSERT(!Dart_IsError(stacktrace)); 1138 Dart_Handle traceResult = Dart_GetStackTraceFromError(result, &stacktrac e);
1141 Dart_Handle stackTraceConversionException = 0; 1139 ASSERT(!Dart_IsError(traceResult));
1142 callStack = createScriptCallStackFromStackTrace(stacktrace, stackTraceCo nversionException); 1140 callStack = createScriptCallStackFromStackTrace(stacktrace);
1143 if (stackTraceConversionException)
1144 errorMessage.append(String("\nError converting stack trace to a stri ng: ") + DartUtilities::toString(stackTraceConversionException));
1145 } 1141 }
1146 1142
1147 if (context && context->isDocument()) { 1143 if (context && context->isDocument()) {
1148 static_cast<Document*>(context)->reportException(ErrorEvent::create(erro rMessage, sourceURL, lineNumber, 0, 0), callStack, NotSharableCrossOrigin); 1144 static_cast<Document*>(context)->reportException(ErrorEvent::create(erro rMessage, sourceURL, lineNumber, 0, 0), callStack, NotSharableCrossOrigin);
1149 } 1145 }
1150 } 1146 }
1151 1147
1152 Dart_Handle DartUtilities::notImplementedException(const char* fileName, int lin eNumber) 1148 Dart_Handle DartUtilities::notImplementedException(const char* fileName, int lin eNumber)
1153 { 1149 {
1154 Dart_Handle args[2] = { Dart_NewStringFromCString(fileName), Dart_NewInteger (lineNumber) }; 1150 Dart_Handle args[2] = { Dart_NewStringFromCString(fileName), Dart_NewInteger (lineNumber) };
(...skipping 25 matching lines...) Expand all
1180 if (!v) { 1176 if (!v) {
1181 return 0; 1177 return 0;
1182 } 1178 }
1183 ASSERT(valueLen > 0 && static_cast<size_t>(valueLen) > strlen(v)); 1179 ASSERT(valueLen > 0 && static_cast<size_t>(valueLen) > strlen(v));
1184 strncpy(value, v, valueLen); 1180 strncpy(value, v, valueLen);
1185 value[valueLen - 1] = '\0'; 1181 value[valueLen - 1] = '\0';
1186 return strlen(value); 1182 return strlen(value);
1187 #endif 1183 #endif
1188 } 1184 }
1189 } 1185 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698