| Index: sky/engine/core/html/parser/HTMLScriptRunner.h
|
| diff --git a/sky/engine/core/html/parser/HTMLScriptRunner.h b/sky/engine/core/html/parser/HTMLScriptRunner.h
|
| index e3c4c880cc0e250d82b1374f26d239daea95a0f7..368b9d60c116942a45b12bd326d210186ea84716 100644
|
| --- a/sky/engine/core/html/parser/HTMLScriptRunner.h
|
| +++ b/sky/engine/core/html/parser/HTMLScriptRunner.h
|
| @@ -5,26 +5,65 @@
|
| #ifndef SKY_ENGINE_CORE_HTML_PARSER_HTMLSCRIPTRUNNER_H_
|
| #define SKY_ENGINE_CORE_HTML_PARSER_HTMLSCRIPTRUNNER_H_
|
|
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "sky/engine/core/app/AbstractModule.h"
|
| #include "sky/engine/core/html/HTMLElement.h"
|
| #include "sky/engine/wtf/Vector.h"
|
| #include "sky/engine/wtf/text/TextPosition.h"
|
|
|
| namespace blink {
|
|
|
| +class HTMLScriptRunnerHost {
|
| + public:
|
| + virtual void scriptExecutionCompleted() = 0;
|
| +};
|
| +
|
| +// Dart script blocks can include 'import' statements which can introduce
|
| +// additional dependencies which need to be resolved before the script can
|
| +// be executed. The job of this class is to insulate the rest of the system
|
| +// from this complexity and take in a script and always produce a callback
|
| +// to continue parsing when that script completes/errors out, etc.
|
| +
|
| class HTMLScriptRunner {
|
| public:
|
| - HTMLScriptRunner();
|
| + static PassOwnPtr<HTMLScriptRunner> createForScript(
|
| + PassRefPtr<HTMLScriptElement>,
|
| + TextPosition,
|
| + HTMLScriptRunnerHost*);
|
| ~HTMLScriptRunner();
|
|
|
| - bool isExecutingScript() const { return m_isExecutingScript; }
|
| + void start();
|
|
|
| - void runScript(PassRefPtr<HTMLScriptElement>, TextPosition);
|
| + bool isExecutingScript() const;
|
|
|
| private:
|
| - void executeScript(PassRefPtr<HTMLScriptElement>, TextPosition);
|
| + HTMLScriptRunner(PassRefPtr<HTMLScriptElement>,
|
| + TextPosition,
|
| + HTMLScriptRunnerHost*);
|
| +
|
| + enum State {
|
| + StateInitial, // No script.
|
| + StateLoading, // Waiting on imports to load.
|
| + StateExecuting, // Actually running the script.
|
| + StateCompleted, // Done, always hit this state regardless of success.
|
| + };
|
| +
|
| + enum AdvanceType {
|
| + ExecutionNormal,
|
| + ExecutionFailure,
|
| + };
|
| +
|
| + // Advancing to StateCompleted may cause the host to delete us.
|
| + void advanceTo(State, AdvanceType = ExecutionNormal);
|
| +
|
| + void executeLibrary(RefPtr<AbstractModule> module, RefPtr<DartValue> library);
|
| + void scriptFailed();
|
|
|
| - bool m_isExecutingScript;
|
| - TextPosition m_textPosition;
|
| + HTMLScriptRunnerHost* m_host;
|
| + RefPtr<HTMLScriptElement> m_element;
|
| + TextPosition m_position;
|
| + State m_state;
|
| + base::WeakPtrFactory<HTMLScriptRunner> m_weakFactory;
|
| };
|
|
|
| } // namespace blink
|
|
|