flutter_flutter/engine/core/app/AbstractModule.h
Eric Seidel c78cea7e54 Allow multiple dart <script> tags in .sky files
This does several things:
1.  Teaches sky about asynchronous script execution. Previously once all imports
were loaded and the script text was available, we executed a script and assumed
it completed synchronously.  We left the parser loop to do so, but that was fine
as the next chunk from the background thread would resume the parser.  In this
change scripts now load and execute separately.  The "load" step may trigger
further dart import loads which may cause the execution to happen asynchronously
which required teaching both the DartController and the HTMLScriptRunner to
take callbacks to allow HTMLDocumentParser to know to continue parsing after
the Dart script has resolved its imports and executed.

This required re-working some of how the parser executes scripts and I
re-purposed isWaitingForScripts to include "is the parser blocked" where
as before it was limited only to "does the treebuilder have a script", even
though the imports system may have had pending scripts as well.

I made HTMLScriptRunner live only as long as the script it was executing
since it only contained per-script state at this point.

2.  Fixed an error reporting bug whereby we would not show errors when "init"
failed to execute, only "main".  This required using the dart_mirrors_api.h
which required adding an include path to the core build. :(

3.  Made it possible for a single sky file to contain multiple dart <script>
tags.  Each <script> is a separate library and executes as
soon as </script> is seen.  main or init is called for each.  This required
mangling "urls" for these script blocks since Dart unique's libraries by urls.
Before this change it may have been possible to do <import 'foo.sky'> and then
<script>import 'foo.sky'</script> and have it work!?

R=abarth@chromium.org
BUG=

Review URL: https://codereview.chromium.org/938623005
2015-02-20 11:08:28 -08:00

62 lines
1.8 KiB
C++

// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_ENGINE_CORE_APP_ABSTRACTMODULE_H_
#define SKY_ENGINE_CORE_APP_ABSTRACTMODULE_H_
#include "sky/engine/core/dom/ContextLifecycleObserver.h"
#include "sky/engine/core/dom/Document.h"
#include "sky/engine/core/events/EventTarget.h"
#include "sky/engine/wtf/RefCounted.h"
namespace blink {
class Application;
class LibraryEntry {
public:
LibraryEntry(PassRefPtr<DartValue> library, TextPosition position)
: dart_library_(library), text_position_(position) {}
DartValue* library() const { return dart_library_.get(); }
const TextPosition& position() const { return text_position_; }
private:
RefPtr<DartValue> dart_library_;
TextPosition text_position_;
};
class AbstractModule : public RefCounted<AbstractModule>,
public EventTargetWithInlineData,
public ContextLifecycleObserver {
REFCOUNTED_EVENT_TARGET(AbstractModule);
public:
virtual ~AbstractModule();
Document* document() const { return document_.get(); }
const String& url() const { return url_; }
virtual bool isApplication() const { return false; }
String UrlForLibraryAt(TextPosition);
void AddLibrary(RefPtr<DartValue> library, TextPosition position);
const Vector<LibraryEntry>& libraries() const { return libraries_; }
protected:
AbstractModule(ExecutionContext*, PassRefPtr<Document>, const String& url);
virtual Application* GetApplication() = 0;
private:
ExecutionContext* executionContext() const override;
RefPtr<Document> document_;
String url_;
Vector<LibraryEntry> libraries_;
};
} // namespace blink
#endif // SKY_ENGINE_CORE_APP_ABSTRACTMODULE_H_