| 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 22 matching lines...) Expand all Loading... |
| 33 #include "CachedMetadata.h" | 33 #include "CachedMetadata.h" |
| 34 #include "CachedResourceClient.h" | 34 #include "CachedResourceClient.h" |
| 35 #include "CachedResourceLoader.h" | 35 #include "CachedResourceLoader.h" |
| 36 #include "DOMWindow.h" | 36 #include "DOMWindow.h" |
| 37 #include "DartDebugServer.h" | 37 #include "DartDebugServer.h" |
| 38 #include "DartDOMWrapper.h" | 38 #include "DartDOMWrapper.h" |
| 39 #include "DartIsolateState.h" | 39 #include "DartIsolateState.h" |
| 40 #include "DartUtilities.h" | 40 #include "DartUtilities.h" |
| 41 #include "Document.h" | 41 #include "Document.h" |
| 42 #include "Frame.h" | 42 #include "Frame.h" |
| 43 #include "InspectorInstrumentation.h" |
| 43 #include "ScriptCallStack.h" | 44 #include "ScriptCallStack.h" |
| 44 #include "ScriptSourceCode.h" | 45 #include "ScriptSourceCode.h" |
| 45 | 46 |
| 46 #include <dart_api.h> | 47 #include <dart_api.h> |
| 47 | 48 |
| 48 namespace WebCore { | 49 namespace WebCore { |
| 49 | 50 |
| 51 class Timeline { |
| 52 public: |
| 53 Timeline(DartApplicationLoader* loader, String tag) |
| 54 { |
| 55 m_cookie = InspectorInstrumentation::willEvaluateScript(loader->m_docume
nt->frame(), tag + "@"+ loader->m_libraryUrl, 0); |
| 56 } |
| 57 |
| 58 ~Timeline() |
| 59 { |
| 60 InspectorInstrumentation::didEvaluateScript(m_cookie); |
| 61 } |
| 62 |
| 63 private: |
| 64 InspectorInstrumentationCookie m_cookie; |
| 65 }; |
| 66 |
| 50 DartApplicationLoader::DartApplicationLoader(Document* document) | 67 DartApplicationLoader::DartApplicationLoader(Document* document) |
| 51 : m_document(document) | 68 : m_document(document) |
| 52 , m_libraryUrl() | 69 , m_libraryUrl() |
| 53 , m_importedLibraries() | 70 , m_importedLibraries() |
| 54 , m_importersForSource() | 71 , m_importersForSource() |
| 55 , m_sources() | 72 , m_sources() |
| 56 , m_mainScriptHasBeenLoaded(false) | 73 , m_mainScriptHasBeenLoaded(false) |
| 57 { | 74 { |
| 58 } | 75 } |
| 59 | 76 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 77 } | 94 } |
| 78 } | 95 } |
| 79 | 96 |
| 80 m_sources.add(url, source); | 97 m_sources.add(url, source); |
| 81 DartDebugServer::shared().scriptParsed(url, source); | 98 DartDebugServer::shared().scriptParsed(url, source); |
| 82 | 99 |
| 83 if (m_importedLibraries.isEmpty() && m_importersForSource.isEmpty() && m_mai
nScriptHasBeenLoaded) { | 100 if (m_importedLibraries.isEmpty() && m_importersForSource.isEmpty() && m_mai
nScriptHasBeenLoaded) { |
| 84 CachedResourceLoader* loader = m_document->cachedResourceLoader(); | 101 CachedResourceLoader* loader = m_document->cachedResourceLoader(); |
| 85 ResourceRequest request(m_document->completeURL(mainLibraryURL())); | 102 ResourceRequest request(m_document->completeURL(mainLibraryURL())); |
| 86 CachedScript* cachedScript = loader->requestScript(request, "utf-8"); | 103 CachedScript* cachedScript = loader->requestScript(request, "utf-8"); |
| 87 if (cachedScript && !cachedScript->cachedMetadata(dartTypeID)) { | 104 if (true && cachedScript && !cachedScript->cachedMetadata(dartTypeID)) { |
| 88 uint8_t* buffer; | 105 uint8_t* buffer; |
| 89 intptr_t size; | 106 intptr_t size; |
| 90 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); | 107 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); |
| 91 if (Dart_IsError(result)) { | 108 if (Dart_IsError(result)) { |
| 92 DartUtilities::reportProblem(m_document, result); | 109 DartUtilities::reportProblem(m_document, result); |
| 93 // FIXME: exiting early might be not the best option if error is
due to snapshot | 110 // FIXME: exiting early might be not the best option if error is
due to snapshot |
| 94 // creation proper (and not due to compilation), even though it'
s unlikely. | 111 // creation proper (and not due to compilation), even though it'
s unlikely. |
| 95 // Consider other options like Dart_CompileAll. | 112 // Consider other options like Dart_CompileAll. |
| 96 return; | 113 return; |
| 97 } | 114 } |
| 115 printf("*** Creating a snapshot of size %d\n", size); |
| 98 cachedScript->setCachedMetadata(dartTypeID, reinterpret_cast<const c
har*>(buffer), size); | 116 cachedScript->setCachedMetadata(dartTypeID, reinterpret_cast<const c
har*>(buffer), size); |
| 99 } | 117 } |
| 100 | 118 |
| 101 callEntryPoint(); | 119 callEntryPoint(); |
| 102 } | 120 } |
| 103 } | 121 } |
| 104 | 122 |
| 105 void DartApplicationLoader::importBuiltinLibrary(const String& url, const String
& source) | 123 void DartApplicationLoader::importBuiltinLibrary(const String& url, const String
& source) |
| 106 { | 124 { |
| 107 Dart_Handle result = Dart_LoadLibrary(DartUtilities::stringToDartString(url)
, DartUtilities::stringToDartString(source)); | 125 Dart_Handle result = Dart_LoadLibrary(DartUtilities::stringToDartString(url)
, DartUtilities::stringToDartString(source)); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 { | 188 { |
| 171 ASSERT(m_importedLibraries.isEmpty()); | 189 ASSERT(m_importedLibraries.isEmpty()); |
| 172 ASSERT(m_importersForSource.isEmpty()); | 190 ASSERT(m_importersForSource.isEmpty()); |
| 173 m_libraryUrl = url; | 191 m_libraryUrl = url; |
| 174 ScriptLoader<InitialLoader>::loadScript(url, source, m_document); | 192 ScriptLoader<InitialLoader>::loadScript(url, source, m_document); |
| 175 m_mainScriptHasBeenLoaded = true; | 193 m_mainScriptHasBeenLoaded = true; |
| 176 } | 194 } |
| 177 | 195 |
| 178 void DartApplicationLoader::loadScriptFromSnapshot(const String& url, const uint
8_t* snapshot) | 196 void DartApplicationLoader::loadScriptFromSnapshot(const String& url, const uint
8_t* snapshot) |
| 179 { | 197 { |
| 198 Timeline timeline(this, "loadSnapshot"); |
| 180 ASSERT(m_importedLibraries.isEmpty()); | 199 ASSERT(m_importedLibraries.isEmpty()); |
| 181 ASSERT(m_importersForSource.isEmpty()); | 200 ASSERT(m_importersForSource.isEmpty()); |
| 182 m_libraryUrl = url; | 201 m_libraryUrl = url; |
| 183 DartApiScope apiScope; | 202 DartApiScope apiScope; |
| 184 Dart_Handle result = Dart_LoadScriptFromSnapshot(snapshot); | 203 Dart_Handle result = Dart_LoadScriptFromSnapshot(snapshot); |
| 185 if (Dart_IsError(result)) { | 204 if (Dart_IsError(result)) { |
| 186 DartUtilities::reportProblem(m_document, result); | 205 DartUtilities::reportProblem(m_document, result); |
| 187 return; | 206 return; |
| 188 } | 207 } |
| 189 m_mainScriptHasBeenLoaded = true; | 208 m_mainScriptHasBeenLoaded = true; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 213 void DartApplicationLoader::loadLibrary(const String& url, const String& source) | 232 void DartApplicationLoader::loadLibrary(const String& url, const String& source) |
| 214 { | 233 { |
| 215 ASSERT(m_importedLibraries.contains(url)); | 234 ASSERT(m_importedLibraries.contains(url)); |
| 216 Dart_Handle result = Dart_LoadLibrary(DartUtilities::stringToDartString(url)
, DartUtilities::stringToDartString(source)); | 235 Dart_Handle result = Dart_LoadLibrary(DartUtilities::stringToDartString(url)
, DartUtilities::stringToDartString(source)); |
| 217 if (Dart_IsError(result)) | 236 if (Dart_IsError(result)) |
| 218 DartUtilities::reportProblem(m_document, result); | 237 DartUtilities::reportProblem(m_document, result); |
| 219 } | 238 } |
| 220 | 239 |
| 221 void DartApplicationLoader::callEntryPoint() | 240 void DartApplicationLoader::callEntryPoint() |
| 222 { | 241 { |
| 242 Timeline timeline(this, "callEntryPoint"); |
| 223 ASSERT(m_document->readyState() != "loading"); | 243 ASSERT(m_document->readyState() != "loading"); |
| 224 Dart_Handle result = Dart_InvokeStatic(topLevelLibrary(), Dart_NewString("")
, Dart_NewString("main"), 0, 0); | 244 Dart_Handle result = Dart_InvokeStatic(topLevelLibrary(), Dart_NewString("")
, Dart_NewString("main"), 0, 0); |
| 225 if (Dart_IsError(result)) | 245 if (Dart_IsError(result)) |
| 226 DartUtilities::reportProblem(m_document, result); | 246 DartUtilities::reportProblem(m_document, result); |
| 227 } | 247 } |
| 228 | 248 |
| 229 Dart_Handle DartApplicationLoader::topLevelLibrary() | 249 Dart_Handle DartApplicationLoader::topLevelLibrary() |
| 230 { | 250 { |
| 231 Dart_Handle library = Dart_LookupLibrary(DartUtilities::stringToDartString(m
_libraryUrl)); | 251 Dart_Handle library = Dart_LookupLibrary(DartUtilities::stringToDartString(m
_libraryUrl)); |
| 232 ASSERT(!Dart_IsError(library)); | 252 ASSERT(!Dart_IsError(library)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 257 | 277 |
| 258 if (cachedResource->errorOccurred()) | 278 if (cachedResource->errorOccurred()) |
| 259 m_loader->scriptLoadError(cachedResource->url()); | 279 m_loader->scriptLoadError(cachedResource->url()); |
| 260 else if (cachedResource->wasCanceled()) { | 280 else if (cachedResource->wasCanceled()) { |
| 261 // FIXME: shall we let VM know, so it can inform application some of
its | 281 // FIXME: shall we let VM know, so it can inform application some of
its |
| 262 // resources cannot be loaded? | 282 // resources cannot be loaded? |
| 263 } else { | 283 } else { |
| 264 ScriptSourceCode sourceCode(m_cachedScript.get()); | 284 ScriptSourceCode sourceCode(m_cachedScript.get()); |
| 265 DartIsolateState::Scope scope(m_isolate); | 285 DartIsolateState::Scope scope(m_isolate); |
| 266 CachedMetadata* cachedMetadata = m_cachedScript->cachedMetadata(dart
TypeID); | 286 CachedMetadata* cachedMetadata = m_cachedScript->cachedMetadata(dart
TypeID); |
| 287 printf("*** cachedMetadata: %p for %s\n", cachedMetadata, sourceCode
.url().string().ascii().data()); |
| 267 if (cachedMetadata) | 288 if (cachedMetadata) |
| 268 m_loader->loadScriptFromSnapshot(sourceCode.url(), reinterpret_c
ast<const uint8_t*>(cachedMetadata->data())); | 289 m_loader->loadScriptFromSnapshot(sourceCode.url(), reinterpret_c
ast<const uint8_t*>(cachedMetadata->data())); |
| 269 else | 290 else |
| 270 // FIXME: we can get rid of imported libs and sources map. | 291 // FIXME: we can get rid of imported libs and sources map. |
| 271 m_loader->load(sourceCode.url(), sourceCode.source()); | 292 m_loader->load(sourceCode.url(), sourceCode.source()); |
| 272 } | 293 } |
| 273 | 294 |
| 274 m_cachedScript->removeClient(this); | 295 m_cachedScript->removeClient(this); |
| 275 delete this; | 296 delete this; |
| 276 } | 297 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 // FIXME: propagate flags as well. | 392 // FIXME: propagate flags as well. |
| 372 | 393 |
| 373 // Set proper dart loader for child isolate. | 394 // Set proper dart loader for child isolate. |
| 374 isolateToDartApplicationLoaderMap().set(Dart_CurrentIsolate(), this); | 395 isolateToDartApplicationLoaderMap().set(Dart_CurrentIsolate(), this); |
| 375 | 396 |
| 376 ASSERT(m_sources.contains(m_libraryUrl)); | 397 ASSERT(m_sources.contains(m_libraryUrl)); |
| 377 ScriptLoader<ReinjectLoader>::loadScript(m_libraryUrl, m_sources.get(m_libra
ryUrl), m_document); | 398 ScriptLoader<ReinjectLoader>::loadScript(m_libraryUrl, m_sources.get(m_libra
ryUrl), m_document); |
| 378 } | 399 } |
| 379 | 400 |
| 380 } | 401 } |
| OLD | NEW |