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 17 matching lines...) Expand all Loading... | |
| 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 |
| 30 #include "config.h" | 30 #include "config.h" |
| 31 #include "bindings/dart/DartUtilities.h" | 31 #include "bindings/dart/DartUtilities.h" |
| 32 | 32 |
| 33 #include "DartBlob.h" | 33 #include "DartBlob.h" |
| 34 #include "DartHTMLElement.h" | 34 #include "DartHTMLElement.h" |
| 35 #include "DartIDBKeyRange.h" | 35 #include "DartIDBKeyRange.h" |
| 36 #include "DartImageData.h" | 36 #include "DartImageData.h" |
| 37 #include "DartMessagePort.h" | 37 #include "DartMessagePort.h" |
| 38 #include "DartScriptState.h" | |
|
vsm
2013/10/22 00:32:02
Use the full include path for non-generated files
| |
| 38 #include "bindings/dart/DartDOMData.h" | 39 #include "bindings/dart/DartDOMData.h" |
| 39 #include "bindings/dart/DartHandleProxy.h" | 40 #include "bindings/dart/DartHandleProxy.h" |
| 40 #include "bindings/dart/V8Converter.h" | 41 #include "bindings/dart/V8Converter.h" |
| 41 #include "bindings/v8/ScriptController.h" | 42 #include "bindings/v8/ScriptController.h" |
| 42 #include "bindings/v8/SerializedScriptValue.h" | 43 #include "bindings/v8/SerializedScriptValue.h" |
| 43 #include "bindings/v8/V8Binding.h" | 44 #include "bindings/v8/V8Binding.h" |
| 44 #include "bindings/v8/V8PerIsolateData.h" | 45 #include "bindings/v8/V8PerIsolateData.h" |
| 45 #include "core/dom/Document.h" | 46 #include "core/dom/Document.h" |
| 46 #include "core/html/canvas/DataView.h" | 47 #include "core/html/canvas/DataView.h" |
| 47 #include "core/inspector/ScriptArguments.h" | 48 #include "core/inspector/ScriptArguments.h" |
| (...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 888 return DartDOMData::current()->scriptExecutionContext(); | 889 return DartDOMData::current()->scriptExecutionContext(); |
| 889 return 0; | 890 return 0; |
| 890 } | 891 } |
| 891 | 892 |
| 892 bool DartUtilities::processingUserGesture() | 893 bool DartUtilities::processingUserGesture() |
| 893 { | 894 { |
| 894 // FIXME: implement this. | 895 // FIXME: implement this. |
| 895 return false; | 896 return false; |
| 896 } | 897 } |
| 897 | 898 |
| 899 // FIXME(dartbug.com/14291): this should be implemented directly by the DartVM. | |
| 900 intptr_t DartUtilities::libraryHandleToLibraryId(Dart_Handle library) | |
| 901 { | |
| 902 Dart_Handle libraries = Dart_GetLibraryIds(); | |
| 903 ASSERT(Dart_IsList(libraries)); | |
| 904 | |
| 905 intptr_t librariesLength = 0; | |
| 906 Dart_Handle result = Dart_ListLength(libraries, &librariesLength); | |
| 907 ASSERT(!Dart_IsError(result)); | |
| 908 UNUSED_PARAM(result); | |
| 909 for (intptr_t i = 0; i < librariesLength; ++i) { | |
| 910 Dart_Handle libraryIdHandle = Dart_ListGetAt(libraries, i); | |
| 911 ASSERT(!Dart_IsError(libraryIdHandle)); | |
| 912 Dart_Handle exception = 0; | |
| 913 intptr_t libraryId = DartUtilities::toInteger(libraryIdHandle, exception ); | |
| 914 ASSERT(!exception); | |
| 915 if (Dart_IdentityEquals(Dart_GetLibraryFromId(libraryId), library)) | |
| 916 return libraryId; | |
| 917 } | |
| 918 ASSERT_NOT_REACHED(); | |
| 919 return 0; | |
| 920 } | |
| 921 | |
| 922 DartScriptState* DartUtilities::currentScriptState() | |
| 923 { | |
| 924 DartDOMData* dartDOMData = DartDOMData::current(); | |
| 925 if (!dartDOMData->rootScriptState()) { | |
| 926 DartController* controller = DartController::retrieve(dartDOMData->scrip tExecutionContext()); | |
| 927 intptr_t libraryId = DartUtilities::libraryHandleToLibraryId(Dart_RootLi brary()); | |
| 928 DartScriptState* scriptState = controller->lookupScriptState(Dart_Curren tIsolate(), currentV8Context(), libraryId); | |
| 929 dartDOMData->setRootScriptState(scriptState); | |
| 930 return scriptState; | |
| 931 } | |
| 932 return dartDOMData->rootScriptState(); | |
| 933 } | |
| 934 | |
| 898 PassRefPtr<ScriptArguments> DartUtilities::createScriptArguments(Dart_Handle arg ument, Dart_Handle& exception) | 935 PassRefPtr<ScriptArguments> DartUtilities::createScriptArguments(Dart_Handle arg ument, Dart_Handle& exception) |
| 899 { | 936 { |
| 900 v8::Handle<v8::Value> v8Argument = DartHandleProxy::create(argument); | 937 v8::Handle<v8::Value> v8Argument = DartHandleProxy::create(argument); |
| 901 Vector<ScriptValue> arguments; | 938 Vector<ScriptValue> arguments; |
| 902 arguments.append(v8Argument); | 939 arguments.append(v8Argument); |
| 903 ScriptState* scriptState = ScriptState::forContext(currentV8Context()); | 940 return ScriptArguments::create(DartUtilities::currentScriptState(), argument s); |
| 904 return ScriptArguments::create(scriptState, arguments); | 941 } |
| 942 | |
| 943 static PassRefPtr<ScriptCallStack> createScriptCallStackFromParsedStackTrace(Dar t_Handle parsedStackTrace, Dart_Handle exception) | |
| 944 { | |
| 945 Vector<Dart_Handle> callFrames; | |
| 946 DartUtilities::extractListElements(parsedStackTrace, exception, callFrames); | |
| 947 if (exception) | |
| 948 return 0; | |
| 949 | |
| 950 size_t frameCount = callFrames.size(); | |
| 951 if (frameCount > ScriptCallStack::maxCallStackSizeToCapture) | |
| 952 frameCount = ScriptCallStack::maxCallStackSizeToCapture; | |
| 953 | |
| 954 Vector<ScriptCallFrame> scriptCallStackFrames; | |
| 955 for (size_t i = 0; i < frameCount; i++) { | |
| 956 Dart_Handle callFrame = callFrames[i]; | |
| 957 Vector<Dart_Handle> fields; | |
| 958 DartUtilities::extractListElements(callFrame, exception, fields); | |
| 959 if (exception) | |
| 960 return 0; | |
| 961 ASSERT(fields.size() == 4); | |
| 962 String functionName = DartUtilities::toString(fields[0]); | |
| 963 String sourceName = DartUtilities::toString(fields[1]); | |
| 964 int lineNumber = DartUtilities::toInteger(fields[2], exception); | |
| 965 if (exception) | |
| 966 return 0; | |
| 967 int columnNumber = DartUtilities::toInteger(fields[3], exception); | |
| 968 if (exception) | |
| 969 return 0; | |
| 970 scriptCallStackFrames.append(ScriptCallFrame(functionName, sourceName, l ineNumber, columnNumber)); | |
| 971 } | |
| 972 if (!frameCount) | |
| 973 scriptCallStackFrames.append(ScriptCallFrame("undefined", "undefined", 0 , 0)); | |
| 974 | |
| 975 return ScriptCallStack::create(scriptCallStackFrames); | |
| 976 } | |
| 977 | |
| 978 static PassRefPtr<ScriptCallStack> createScriptCallStackFromStackTrace(Dart_Hand le stackTrace, Dart_Handle& exception) | |
| 979 { | |
| 980 Dart_Handle parsedStackTrace = DartUtilities::invokeUtilsMethod("parseStackT race", 1, &stackTrace); | |
| 981 if (!DartUtilities::checkResult(parsedStackTrace, exception)) | |
| 982 return 0; | |
| 983 | |
| 984 return createScriptCallStackFromParsedStackTrace(parsedStackTrace, exception ); | |
| 905 } | 985 } |
| 906 | 986 |
| 907 PassRefPtr<ScriptCallStack> DartUtilities::createScriptCallStack() | 987 PassRefPtr<ScriptCallStack> DartUtilities::createScriptCallStack() |
| 908 { | 988 { |
| 909 // FIXME: wrap current dart call stack as ScriptCallStack. | 989 Dart_ExceptionPauseInfo previousPauseInfo = Dart_GetExceptionPauseInfo(); |
| 910 Vector<ScriptCallFrame> wrappedCallFrames; | 990 if (previousPauseInfo != kNoPauseOnExceptions) |
| 911 wrappedCallFrames.append(ScriptCallFrame("undefined", "undefined", 0)); | 991 Dart_SetExceptionPauseInfo(kNoPauseOnExceptions); |
| 912 return ScriptCallStack::create(wrappedCallFrames); | 992 Dart_Handle exception = 0; |
| 993 Dart_Handle parsedStackTrace = DartUtilities::invokeUtilsMethod("capturePars edStackTrace", 0, 0); | |
| 994 | |
| 995 if (previousPauseInfo != kNoPauseOnExceptions) | |
| 996 Dart_SetExceptionPauseInfo(previousPauseInfo); | |
| 997 | |
| 998 if (!DartUtilities::checkResult(parsedStackTrace, exception)) | |
| 999 return 0; | |
| 1000 | |
| 1001 return createScriptCallStackFromParsedStackTrace(parsedStackTrace, exception ); | |
| 913 } | 1002 } |
| 914 | 1003 |
| 915 Dart_WeakPersistentHandle DartUtilities::createPrologueWeakPersistentHandle(Dart _Handle object, void* peer, Dart_WeakPersistentHandleFinalizer weakCallback) | 1004 Dart_WeakPersistentHandle DartUtilities::createPrologueWeakPersistentHandle(Dart _Handle object, void* peer, Dart_WeakPersistentHandleFinalizer weakCallback) |
| 916 { | 1005 { |
| 917 DartWeakCallback* callback = new DartWeakCallback(peer, weakCallback); | 1006 DartWeakCallback* callback = new DartWeakCallback(peer, weakCallback); |
| 918 callback->m_object = Dart_NewPrologueWeakPersistentHandle(object, callback, &weakCallbackWrapper); | 1007 callback->m_object = Dart_NewPrologueWeakPersistentHandle(object, callback, &weakCallbackWrapper); |
| 919 DartDOMData::current()->weakCallbacks()->add(callback); | 1008 DartDOMData::current()->weakCallbacks()->add(callback); |
| 920 return callback->m_object; | 1009 return callback->m_object; |
| 921 } | 1010 } |
| 922 | 1011 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1001 } | 1090 } |
| 1002 } | 1091 } |
| 1003 | 1092 |
| 1004 void DartUtilities::reportProblem(ScriptExecutionContext* context, Dart_Handle r esult) | 1093 void DartUtilities::reportProblem(ScriptExecutionContext* context, Dart_Handle r esult) |
| 1005 { | 1094 { |
| 1006 // FIXME: provide sourceURL. | 1095 // FIXME: provide sourceURL. |
| 1007 String sourceURL = "FIXME"; | 1096 String sourceURL = "FIXME"; |
| 1008 reportProblem(context, result, sourceURL); | 1097 reportProblem(context, result, sourceURL); |
| 1009 } | 1098 } |
| 1010 | 1099 |
| 1011 static PassRefPtr<ScriptCallStack> createScriptCallStackFromStackTrace(Dart_Hand le stackTrace, Dart_Handle& exception) { | |
| 1012 Dart_Handle parsedStackTrace = DartUtilities::invokeUtilsMethod("parseStackT race", 1, &stackTrace); | |
| 1013 if (!DartUtilities::checkResult(parsedStackTrace, exception)) | |
| 1014 return 0; | |
| 1015 | |
| 1016 Vector<Dart_Handle> callFrames; | |
| 1017 DartUtilities::extractListElements(parsedStackTrace, exception, callFrames); | |
| 1018 if (exception) | |
| 1019 return 0; | |
| 1020 | |
| 1021 size_t frameCount = callFrames.size(); | |
| 1022 if (frameCount > ScriptCallStack::maxCallStackSizeToCapture) | |
| 1023 frameCount = ScriptCallStack::maxCallStackSizeToCapture; | |
| 1024 | |
| 1025 Vector<ScriptCallFrame> scriptCallStackFrames; | |
| 1026 for (size_t i = 0; i < frameCount; i++) { | |
| 1027 Dart_Handle callFrame = callFrames[i]; | |
| 1028 Vector<Dart_Handle> fields; | |
| 1029 DartUtilities::extractListElements(callFrame, exception, fields); | |
| 1030 if (exception) | |
| 1031 return 0; | |
| 1032 ASSERT(fields.size() == 4); | |
| 1033 String functionName = DartUtilities::toString(fields[0]); | |
| 1034 String sourceName = DartUtilities::toString(fields[1]); | |
| 1035 int lineNumber = DartUtilities::toInteger(fields[2], exception); | |
| 1036 if (exception) | |
| 1037 return 0; | |
| 1038 int columnNumber = DartUtilities::toInteger(fields[3], exception); | |
| 1039 if (exception) | |
| 1040 return 0; | |
| 1041 scriptCallStackFrames.append(ScriptCallFrame(functionName, sourceName, l ineNumber, columnNumber)); | |
| 1042 } | |
| 1043 if (!frameCount) | |
| 1044 scriptCallStackFrames.append(ScriptCallFrame("undefined", "undefined", 0 , 0)); | |
| 1045 | |
| 1046 return ScriptCallStack::create(scriptCallStackFrames); | |
| 1047 } | |
| 1048 | |
| 1049 void DartUtilities::reportProblem(ScriptExecutionContext* context, Dart_Handle r esult, const String& sourceURL) | 1100 void DartUtilities::reportProblem(ScriptExecutionContext* context, Dart_Handle r esult, const String& sourceURL) |
| 1050 { | 1101 { |
| 1051 ASSERT(Dart_IsError(result)); | 1102 ASSERT(Dart_IsError(result)); |
| 1052 ASSERT(!sourceURL.isEmpty()); | 1103 ASSERT(!sourceURL.isEmpty()); |
| 1053 | 1104 |
| 1054 const String internalErrorPrefix("Internal error: "); | 1105 const String internalErrorPrefix("Internal error: "); |
| 1055 | 1106 |
| 1056 String errorMessage; | 1107 String errorMessage; |
| 1057 // FIXME: line number info. | 1108 // FIXME: line number info. |
| 1058 int lineNumber = 0; | 1109 int lineNumber = 0; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1101 Dart_PersistentHandle library = domData->htmlLibrary(); | 1152 Dart_PersistentHandle library = domData->htmlLibrary(); |
| 1102 ASSERT(!Dart_IsError(library)); | 1153 ASSERT(!Dart_IsError(library)); |
| 1103 | 1154 |
| 1104 Dart_Handle utilsClass = Dart_GetType(library, Dart_NewStringFromCString("_U tils"), 0, 0); | 1155 Dart_Handle utilsClass = Dart_GetType(library, Dart_NewStringFromCString("_U tils"), 0, 0); |
| 1105 ASSERT(!Dart_IsError(utilsClass)); | 1156 ASSERT(!Dart_IsError(utilsClass)); |
| 1106 | 1157 |
| 1107 return Dart_Invoke(utilsClass, Dart_NewStringFromCString(methodName), argCou nt, args); | 1158 return Dart_Invoke(utilsClass, Dart_NewStringFromCString(methodName), argCou nt, args); |
| 1108 } | 1159 } |
| 1109 | 1160 |
| 1110 } | 1161 } |
| OLD | NEW |