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

Unified Diff: Source/bindings/core/dart/DartController.cpp

Issue 1663753002: Apply all blink changes between @202695 and tip of trunk (Closed) Base URL: svn://svn.chromium.org/blink/branches/dart/2454_1
Patch Set: Created 4 years, 11 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/core/dart/DartController.h ('k') | Source/bindings/core/dart/DartDOMData.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/core/dart/DartController.cpp
diff --git a/Source/bindings/core/dart/DartController.cpp b/Source/bindings/core/dart/DartController.cpp
index a422acf1d06823a2167449778d0c60201bfb1d41..ed1f28fe83b044ee071752b0251d8539cbcd790d 100644
--- a/Source/bindings/core/dart/DartController.cpp
+++ b/Source/bindings/core/dart/DartController.cpp
@@ -74,12 +74,15 @@
namespace dart {
namespace bin {
extern unsigned int observatory_assets_archive_len; // NOLINT
-extern const char* observatory_assets_archive; // NOLINT
+extern const uint8_t* observatory_assets_archive; // NOLINT
} // namespace bin
} // namespace dart
namespace blink {
+static bool s_checkedMode = false;
+static bool s_vmHasBeenInitialized = false;
+
static void copyValue(Dart_Handle source, const char* fieldName,
Dart_Handle targetLibrary, const char* targetClass, const char* targetField)
{
@@ -115,7 +118,7 @@ const uint8_t* pureIsolateSymbolizer(Dart_NativeFunction nf)
}
Dart_Isolate DartController::createIsolate(const char* scriptURL, const char* entryPoint, const char* packageRoot, Dart_IsolateFlags* flags,
- Document* document, bool isDOMEnabled, bool isDebuggerEnabled, char** errorMessage)
+ Document* document, bool isDOMEnabled, char** errorMessage)
{
DART_START_TIMER();
const uint8_t* snapshot = DartUtilities::isolateSnapshot();
@@ -192,12 +195,6 @@ Dart_Isolate DartController::createIsolate(const char* scriptURL, const char* en
if (isDOMEnabled) {
Dart_SetMessageNotifyCallback(&messageNotifyCallback);
-
- if (isDebuggerEnabled) {
- DART_RECORD_TIMER(" createIsolate before debug setup");
- DartScriptDebugServer::shared().registerIsolate(isolate, document->page());
- DART_RECORD_TIMER(" createIsolate after debug setup");
- }
}
DART_RECORD_TIMER(" createIsolate done %.3f ms");
@@ -211,7 +208,7 @@ Dart_Isolate DartController::createDOMEnabledIsolate(const String& scriptURL, co
// FIXME: proper error reporting.
char* errorMessage = 0;
- Dart_Isolate newIsolate = createIsolate(scriptURL.utf8().data(), entryPoint.utf8().data(), packageRoot, 0, document, true, true, &errorMessage);
+ Dart_Isolate newIsolate = createIsolate(scriptURL.utf8().data(), entryPoint.utf8().data(), packageRoot, 0, document, true, &errorMessage);
ASSERT(newIsolate);
m_isolates.append(newIsolate);
DART_RECORD_TIMER(" createDOMEnabledIsolate took");
@@ -227,9 +224,13 @@ void DartController::spawnHelperDomIsolate(const String& libraryUrl, const Strin
{
DartApiScope apiScope;
+ V8Scope v8scope(DartDOMData::current());
+
Dart_Handle dummyUrl = DartUtilities::stringToDartString(*new String("dummy"));
Dart_Handle dummySource = DartUtilities::stringToDartString(
*new String("library dummy; main() {}"));
+
+ DartApplicationLoader::initializePlaceholderInteropClasses();
Dart_Handle loadResult = Dart_LoadScript(dummyUrl, dummySource, 0, 0);
if (Dart_IsError(loadResult)) {
DartUtilities::reportProblem(m_frame->document(), loadResult);
@@ -242,7 +243,6 @@ void DartController::spawnHelperDomIsolate(const String& libraryUrl, const Strin
return;
}
- V8Scope v8scope(DartDOMData::current());
Dart_Handle sendPort = Dart_NewSendPort(replyTo);
if (Dart_IsError(sendPort)) {
DartUtilities::reportProblem(m_frame->document(), sendPort);
@@ -317,13 +317,20 @@ DartController::~DartController()
void DartController::clearWindowShell()
{
DART_START_TIMER();
- initVMIfNeeded();
- DART_RECORD_TIMER("clearWindowShell::initVM took");
m_loaders.clear();
m_usedNames.clear();
m_isolateNames.clear();
m_mainLoader.clear();
+ DART_RECORD_TIMER("clearWindowShell::initVM took");
+ if (!s_vmHasBeenInitialized) {
+ // No point in doing anything if the vm hasn't even been initialized.
+ // just to be paranoid we clear all our data anyway.
+ m_isolates.clear();
+ m_scriptStates.clear();
+ return;
+ }
+
// Due to synchronous dispatch, we may be in an isolate corresponding to another frame.
// If so, exit here but re-enter before returning.
Dart_Isolate currentIsolate = Dart_CurrentIsolate();
@@ -485,7 +492,7 @@ Dart_Isolate DartController::createPureIsolateCallback(const char* scriptURL, co
ASSERT(context->isDocument());
Document* document = static_cast<Document*>(context);
- Dart_Isolate isolate = createIsolate(scriptURL, entryPoint, packageRoot, flags, document, false, true, errorMsg);
+ Dart_Isolate isolate = createIsolate(scriptURL, entryPoint, packageRoot, flags, document, false, errorMsg);
if (!isolate) {
// This triggers an exception in the caller.
@@ -517,11 +524,10 @@ static char* skipBlackSpace(char* p)
return p;
}
-static void setDartFlags(const char* str)
+static void setDartFlags(const char* str, bool checked)
{
if (!str) {
- Dart_SetVMFlags(0, 0);
- return;
+ str = "";
}
size_t length = strlen(str);
@@ -538,6 +544,15 @@ static void setDartFlags(const char* str)
p = skipBlackSpace(p);
p = skipWhiteSpace(p);
}
+ // Make room for
+ // --ignore_patch_signature_mismatch and
+ // --i_like_slow_isolate_spawn flags.
+ argc += 2;
+
+ if (checked) {
+ argc++;
+ }
+
// Allocate argument array.
const char** argv = new const char*[argc];
@@ -552,6 +567,13 @@ static void setDartFlags(const char* str)
p = skipWhiteSpace(p);
}
+ // We need to force this flag to be on so that Typed JS Interop works.
+ argv[argc++] = "--ignore_patch_signature_mismatch";
+ argv[argc++] = "--i_like_slow_isolate_spawn";
+ if (checked) {
+ argv[argc++] = "--checked";
+ }
+
// Set the flags.
Dart_SetVMFlags(argc, argv);
@@ -640,28 +662,42 @@ static Dart_Handle MakeUint8Array(const uint8_t* buffer, intptr_t len)
static Dart_Handle GetVMServiceAssetsArchiveCallback()
{
- return MakeUint8Array(reinterpret_cast<const uint8_t*>(&dart::bin::observatory_assets_archive[0]), dart::bin::observatory_assets_archive_len);
+ uint8_t* decompressed = 0;
+ unsigned decompressedLen = 0;
+ DartService::DecompressAssets(reinterpret_cast<const uint8_t*>(&dart::bin::observatory_assets_archive[0]), dart::bin::observatory_assets_archive_len, &decompressed, &decompressedLen);
+ return MakeUint8Array(decompressed, decompressedLen);
}
-void DartController::initVMIfNeeded()
+void DartController::initVMIfNeeded(bool checked, Document* document)
{
- static bool hasBeenInitialized = false;
- if (hasBeenInitialized)
+
+ if (s_vmHasBeenInitialized) {
+ if (checked != s_checkedMode) {
+ // We are in trouble... the requested checked mode doesn't match the mode we are already in.
+ // We could be smart about restarting the VM but that could be risky as the existing Dart
+ // binding code and nobody else is exercising that VM functionality.
+ const char* message = checked ? "Unable to run script in checked mode as DartVM is already running. Please open the page in a new tab or restart your browser." :
+ "Unable to run script in unchecked mode as DartVM is already running. Please open the page in a new tab or restart your browser.";
+ document->domWindow()->alert(message);
+ DartUtilities::reportProblem(document, message);
+ }
return;
+ }
+ s_checkedMode = checked;
+ s_vmHasBeenInitialized = true;
char flagsProp[DartUtilities::PROP_VALUE_MAX_LEN];
int propLen = DartUtilities::getProp(
"DART_FLAGS", flagsProp, DartUtilities::PROP_VALUE_MAX_LEN);
if (propLen > 0) {
- setDartFlags(flagsProp);
+ setDartFlags(flagsProp, checked);
} else {
- setDartFlags(0);
+ setDartFlags(0, checked);
}
DartService::Bootstrap();
// FIXME(antonm): implement proper unhandled exception callback.
Dart_Initialize(DartUtilities::vmIsolateSnapshot(), 0, &createPureIsolateCallback, 0, 0, 0, openFileCallback, readFileCallback, writeFileCallback, closeFileCallback, generateEntropy, GetVMServiceAssetsArchiveCallback);
- hasBeenInitialized = true;
}
static bool checkForExpiration()
@@ -791,10 +827,10 @@ void DartController::evaluate(const ScriptSourceCode& sourceCode, ScriptLoader*
}
DART_START_TIMER();
- initVMIfNeeded();
- DART_RECORD_TIMER("evaluate::initVM took");
RefPtr<Element> element(loader->element());
-
+ bool checked = element->hasAttribute("checked") || document->documentElement()->hasAttribute("checked");
+ initVMIfNeeded(checked, document);
+ DART_RECORD_TIMER("evaluate::initVM took");
RefPtr<DartScriptInfo> scriptInfo = DartScriptInfo::create(element);
if (!scriptInfo) {
DartUtilities::reportProblem(document, "Dart script must be in HTML or SVG document.");
« no previous file with comments | « Source/bindings/core/dart/DartController.h ('k') | Source/bindings/core/dart/DartDOMData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698