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
This commit is contained in:
@@ -0,0 +1 @@
|
||||
PASS
|
||||
@@ -0,0 +1,12 @@
|
||||
<import src='resources/with-dart-import.sky' as='test'></import>
|
||||
<script>
|
||||
import "dart:sky.internals" as internals;
|
||||
|
||||
void main() {
|
||||
// The HTMLImportsLoader used to think with-dart-import load completed
|
||||
// and did not know about with-dart-import having dart import statements
|
||||
// which had made the load/execution of the script asynchronous.
|
||||
String result = test.didInit ? "PASS" : "FAIL";
|
||||
internals.notifyTestComplete(result);
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1 @@
|
||||
PASS
|
||||
@@ -0,0 +1,8 @@
|
||||
CONSOLE: unittest-suite-wait-for-done
|
||||
CONSOLE: PASS: multiple libraries should combine using "as"
|
||||
CONSOLE: PASS: multiple libraries should each init
|
||||
CONSOLE: PASS: conflicting names should be ignored
|
||||
CONSOLE:
|
||||
CONSOLE: All 3 tests passed.
|
||||
CONSOLE: unittest-suite-success
|
||||
DONE
|
||||
28
engine/src/flutter/tests/modules/multiple-scripts-import.sky
Normal file
28
engine/src/flutter/tests/modules/multiple-scripts-import.sky
Normal file
@@ -0,0 +1,28 @@
|
||||
<sky>
|
||||
<import src='resources/multiple-scripts-child.sky' as='child'></import>
|
||||
<script>
|
||||
import "../resources/third_party/unittest/unittest.dart";
|
||||
import "../resources/unit.dart";
|
||||
|
||||
import "dart:sky";
|
||||
import "dart:sky.internals";
|
||||
|
||||
void main () {
|
||||
initUnit();
|
||||
|
||||
test('multiple libraries should combine using "as"', () {
|
||||
expect(child.one, 'one');
|
||||
expect(child.two, 'two');
|
||||
});
|
||||
|
||||
test('multiple libraries should each init', () {
|
||||
expect(child.oneInit, true);
|
||||
expect(child.twoInit, true);
|
||||
});
|
||||
|
||||
test('conflicting names should be ignored', () {
|
||||
expect(() => child.conflict, throwsNoSuchMethodError);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</sky>
|
||||
19
engine/src/flutter/tests/modules/multiple-scripts.sky
Normal file
19
engine/src/flutter/tests/modules/multiple-scripts.sky
Normal file
@@ -0,0 +1,19 @@
|
||||
<sky>
|
||||
<div id='test'>FAIL</div>
|
||||
<script>
|
||||
import "dart:sky" as sky;
|
||||
|
||||
void main () {
|
||||
sky.document.getElementById('test').textContent = 'PASS';
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
// Each script is a separate dart library.
|
||||
import "dart:sky" as sky;
|
||||
import "dart:sky.internals" as internals;
|
||||
|
||||
void main () {
|
||||
internals.notifyTestComplete(sky.document.getElementById('test').textContent);
|
||||
}
|
||||
</script>
|
||||
</sky>
|
||||
@@ -0,0 +1,2 @@
|
||||
class BaseClass {
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<sky>
|
||||
<script>
|
||||
final String one = 'one';
|
||||
bool oneInit = false;
|
||||
void init() {
|
||||
oneInit = true;
|
||||
}
|
||||
final conflict = 'one';
|
||||
</script>
|
||||
<script>
|
||||
final String two = 'two';
|
||||
bool twoInit = false;
|
||||
void init() {
|
||||
twoInit = true;
|
||||
}
|
||||
final conflict = 'two';
|
||||
</script>
|
||||
</sky>
|
||||
@@ -0,0 +1,12 @@
|
||||
<script>
|
||||
import 'dart-import.dart' as base;
|
||||
// Use the dart import so it doesn't ignore it.
|
||||
class TestClass extends base.BaseClass {
|
||||
}
|
||||
|
||||
bool didInit = false;
|
||||
|
||||
void init() {
|
||||
didInit = (new TestClass() != null);
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user