OLD | NEW |
1 // Copyright (c) 2009, Google Inc. | 1 // Copyright (c) 2009, 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 23 matching lines...) Expand all Loading... |
34 #include "DartWindow.h" | 34 #include "DartWindow.h" |
35 #include "HTMLNames.h" | 35 #include "HTMLNames.h" |
36 #include "V8Navigator.h" | 36 #include "V8Navigator.h" |
37 #include "bindings/dart/DartApplicationLoader.h" | 37 #include "bindings/dart/DartApplicationLoader.h" |
38 #include "bindings/dart/DartDOMData.h" | 38 #include "bindings/dart/DartDOMData.h" |
39 #include "bindings/dart/DartDOMWrapper.h" | 39 #include "bindings/dart/DartDOMWrapper.h" |
40 #include "bindings/dart/DartDebugServer.h" | 40 #include "bindings/dart/DartDebugServer.h" |
41 #include "bindings/dart/DartGCController.h" | 41 #include "bindings/dart/DartGCController.h" |
42 #include "bindings/dart/DartIsolateDestructionObserver.h" | 42 #include "bindings/dart/DartIsolateDestructionObserver.h" |
43 #include "bindings/dart/DartNativeUtilities.h" | 43 #include "bindings/dart/DartNativeUtilities.h" |
| 44 #include "bindings/dart/DartScriptState.h" |
44 #include "bindings/dart/DartTimeline.h" | 45 #include "bindings/dart/DartTimeline.h" |
45 #include "bindings/dart/DartUtilities.h" | 46 #include "bindings/dart/DartUtilities.h" |
46 #include "bindings/dart/ThreadSafeDartIsolateWrapper.h" | 47 #include "bindings/dart/ThreadSafeDartIsolateWrapper.h" |
47 #include "bindings/v8/ScheduledAction.h" | 48 #include "bindings/v8/ScheduledAction.h" |
48 #include "bindings/v8/ScriptController.h" | 49 #include "bindings/v8/ScriptController.h" |
49 #include "bindings/v8/npruntime_impl.h" | 50 #include "bindings/v8/npruntime_impl.h" |
50 #include "core/dom/Document.h" | 51 #include "core/dom/Document.h" |
51 #include "core/dom/MutationObserver.h" | 52 #include "core/dom/MutationObserver.h" |
52 #include "core/dom/NodeList.h" | 53 #include "core/dom/NodeList.h" |
53 #include "core/dom/ScriptExecutionContext.h" | 54 #include "core/dom/ScriptExecutionContext.h" |
54 #include "core/dom/ScriptLoader.h" | 55 #include "core/dom/ScriptLoader.h" |
55 #include "core/html/HTMLScriptElement.h" | 56 #include "core/html/HTMLScriptElement.h" |
56 #include "core/page/DOMTimer.h" | 57 #include "core/page/DOMTimer.h" |
57 #include "core/page/DOMWindow.h" | 58 #include "core/page/DOMWindow.h" |
58 #include "core/page/Frame.h" | 59 #include "core/page/Frame.h" |
59 #include "core/page/Page.h" | 60 #include "core/page/Page.h" |
60 #include "core/page/PageGroup.h" | 61 #include "core/page/PageGroup.h" |
61 #include "core/page/Settings.h" | 62 #include "core/page/Settings.h" |
62 #include "core/storage/StorageNamespace.h" | 63 #include "core/storage/StorageNamespace.h" |
63 #include "core/svg/SVGScriptElement.h" | 64 #include "core/svg/SVGScriptElement.h" |
64 #include "modules/indexeddb/IDBPendingTransactionMonitor.h" | 65 #include "modules/indexeddb/IDBPendingTransactionMonitor.h" |
65 | 66 |
66 #include <ctype.h> | 67 #include <ctype.h> |
67 | 68 |
| 69 #include <dart_api.h> |
| 70 #include <dart_debugger_api.h> |
| 71 |
68 namespace WebCore { | 72 namespace WebCore { |
69 | 73 |
70 static void copyValue(Dart_Handle source, const char* fieldName, | 74 static void copyValue(Dart_Handle source, const char* fieldName, |
71 const char* targetLibrary, const char* targetClass, const char* targetField) | 75 const char* targetLibrary, const char* targetClass, const char* targetField) |
72 { | 76 { |
73 Dart_Handle value = Dart_GetField(source, Dart_NewStringFromCString(fieldNam
e)); | 77 Dart_Handle value = Dart_GetField(source, Dart_NewStringFromCString(fieldNam
e)); |
74 ASSERT(!Dart_IsError(value)); | 78 ASSERT(!Dart_IsError(value)); |
75 | 79 |
76 Dart_Handle library = Dart_LookupLibrary(Dart_NewStringFromCString(targetLib
rary)); | 80 Dart_Handle library = Dart_LookupLibrary(Dart_NewStringFromCString(targetLib
rary)); |
77 ASSERT(!Dart_IsError(library)); | 81 ASSERT(!Dart_IsError(library)); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 | 240 |
237 Dart_Isolate currentIsolate = Dart_CurrentIsolate(); | 241 Dart_Isolate currentIsolate = Dart_CurrentIsolate(); |
238 if (currentIsolate) | 242 if (currentIsolate) |
239 Dart_ExitIsolate(); | 243 Dart_ExitIsolate(); |
240 for (size_t i = 0; i < m_isolates.size(); ++i) | 244 for (size_t i = 0; i < m_isolates.size(); ++i) |
241 shutdownIsolate(m_isolates[i]); | 245 shutdownIsolate(m_isolates[i]); |
242 if (currentIsolate) | 246 if (currentIsolate) |
243 Dart_EnterIsolate(currentIsolate); | 247 Dart_EnterIsolate(currentIsolate); |
244 | 248 |
245 m_isolates.clear(); | 249 m_isolates.clear(); |
| 250 |
| 251 for (ScriptStatesMap::iterator it = m_scriptStates.begin(); it != m_scriptSt
ates.end(); ++it) { |
| 252 LibraryIdMap* libraryIdMap = it->value; |
| 253 for (LibraryIdMap::iterator scriptStateIt = libraryIdMap->begin(); scrip
tStateIt != libraryIdMap->end(); ++scriptStateIt) { |
| 254 delete scriptStateIt->value; |
| 255 } |
| 256 delete libraryIdMap; |
| 257 } |
| 258 m_scriptStates.clear(); |
246 } | 259 } |
247 | 260 |
248 static void cleanupAfterCall() | 261 static void cleanupAfterCall() |
249 { | 262 { |
250 // FIXME: Instrument any work that takes place when script exits to c++ (e.g
. Mutation Observers). | 263 // FIXME: Instrument any work that takes place when script exits to c++ (e.g
. Mutation Observers). |
251 | 264 |
252 IDBPendingTransactionMonitor::deactivateNewTransactions(); | 265 IDBPendingTransactionMonitor::deactivateNewTransactions(); |
253 | 266 |
254 MutationObserver::deliverAllMutations(); | 267 MutationObserver::deliverAllMutations(); |
255 } | 268 } |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 | 720 |
708 void DartController::loadScripts() | 721 void DartController::loadScripts() |
709 { | 722 { |
710 if (m_scriptsLoaded) | 723 if (m_scriptsLoaded) |
711 return; | 724 return; |
712 | 725 |
713 Timeline timeline(frame(), "DC::loadScripts"); | 726 Timeline timeline(frame(), "DC::loadScripts"); |
714 initVMIfNeeded(); | 727 initVMIfNeeded(); |
715 | 728 |
716 Document* document = frame()->document(); | 729 Document* document = frame()->document(); |
717 | |
718 RefPtr<NodeList> scripts = document->getElementsByTagName("script"); | 730 RefPtr<NodeList> scripts = document->getElementsByTagName("script"); |
719 Vector< RefPtr<Node> > scriptsCopy(scripts->length()); | 731 Vector< RefPtr<Node> > scriptsCopy(scripts->length()); |
720 for (unsigned i = 0; i < scripts->length(); ++i) | 732 for (unsigned i = 0; i < scripts->length(); ++i) |
721 scriptsCopy[i] = scripts->item(i); | 733 scriptsCopy[i] = scripts->item(i); |
722 for (unsigned i = 0; i < scriptsCopy.size(); ++i) { | 734 for (unsigned i = 0; i < scriptsCopy.size(); ++i) { |
723 RefPtr<ScriptElementProxy> scriptElementProxy; | 735 RefPtr<ScriptElementProxy> scriptElementProxy; |
724 if (document->isHTMLDocument()) | 736 if (document->isHTMLDocument()) |
725 scriptElementProxy = HTMLScriptElementProxy::create(scriptsCopy[i].g
et()); | 737 scriptElementProxy = HTMLScriptElementProxy::create(scriptsCopy[i].g
et()); |
726 else if (document->isSVGDocument()) | 738 else if (document->isSVGDocument()) |
727 scriptElementProxy = SVGScriptElementProxy::create(scriptsCopy[i].ge
t()); | 739 scriptElementProxy = SVGScriptElementProxy::create(scriptsCopy[i].ge
t()); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 return frame->script()->scriptControllerDelegate(); | 880 return frame->script()->scriptControllerDelegate(); |
869 } | 881 } |
870 | 882 |
871 DartController* DartController::retrieve(ScriptExecutionContext* context) | 883 DartController* DartController::retrieve(ScriptExecutionContext* context) |
872 { | 884 { |
873 if (!context || !context->isDocument()) | 885 if (!context || !context->isDocument()) |
874 return 0; | 886 return 0; |
875 return retrieve(static_cast<Document*>(context)->frame()); | 887 return retrieve(static_cast<Document*>(context)->frame()); |
876 } | 888 } |
877 | 889 |
| 890 void DartController::collectScriptStates(ScriptState* v8ScriptState, Vector<Scri
ptState*>& result) |
| 891 { |
| 892 v8::HandleScope handleScope; |
| 893 v8::Handle<v8::Context> v8Context = v8ScriptState->context(); |
| 894 |
| 895 for (Vector<Dart_Isolate>::iterator it = m_isolates.begin(); it != m_isolate
s.end(); ++it) |
| 896 collectScriptStatesForIsolate(*it, v8Context, result); |
878 } | 897 } |
| 898 |
| 899 void DartController::collectScriptStatesForIsolate(Dart_Isolate isolate, v8::Han
dle<v8::Context> v8Context, Vector<ScriptState*>& result) |
| 900 { |
| 901 DartIsolateScope scope(isolate); |
| 902 DartApiScope apiScope; |
| 903 ScriptStatesMap::iterator it = m_scriptStates.find(isolate); |
| 904 LibraryIdMap* libraryIdMap; |
| 905 if (it == m_scriptStates.end()) { |
| 906 libraryIdMap = new LibraryIdMap(); |
| 907 m_scriptStates.add(isolate, libraryIdMap); |
| 908 } else { |
| 909 libraryIdMap = it->value; |
| 910 } |
| 911 Dart_Handle libraryIdList = Dart_GetLibraryIds(); |
| 912 |
| 913 intptr_t length = 0; |
| 914 Dart_Handle res = Dart_ListLength(libraryIdList, &length); |
| 915 |
| 916 for (intptr_t i = 0; i < length; i++) { |
| 917 Dart_Handle libraryIdHandle = Dart_ListGetAt(libraryIdList, i); |
| 918 Dart_Handle exception = 0; |
| 919 intptr_t libraryId = DartUtilities::toInteger(libraryIdHandle, exception
); |
| 920 ASSERT(!exception); |
| 921 LibraryIdMap::iterator libraryIter = libraryIdMap->find(libraryId); |
| 922 DartScriptState* scriptState; |
| 923 if (libraryIter == libraryIdMap->end()) { |
| 924 scriptState = new DartScriptState(isolate, libraryId, v8Context); |
| 925 libraryIdMap->add(libraryId, scriptState); |
| 926 } else { |
| 927 scriptState = libraryIter->value; |
| 928 } |
| 929 result.append(scriptState); |
| 930 } |
| 931 } |
| 932 |
| 933 } |
OLD | NEW |