From 500f5cb3242a0ff96eff7c5acb220e50f5357b28 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 18 Jul 2017 13:13:44 -0700 Subject: [PATCH] 2nd try: SDK dep cleanup Retry https://github.com/dart-lang/sdk/commit/7a9cc03c09 Which was reverted at https://github.com/dart-lang/sdk/commit/b6d15d87bc R=devoncarew@google.com Review-Url: https://codereview.chromium.org/2978233002 . --- .packages | 8 ++--- DEPS | 20 ------------ tests/html/utils.dart | 52 +++++++++++++++++++++++++++++++- tests/lib_strong/html/utils.dart | 52 +++++++++++++++++++++++++++++++- 4 files changed, 104 insertions(+), 28 deletions(-) diff --git a/.packages b/.packages index bea37ceca412..8efe34369de7 100644 --- a/.packages +++ b/.packages @@ -20,7 +20,6 @@ browser:pkg/browser/lib charcode:third_party/pkg/charcode/lib charted:third_party/observatory_pub_packages/packages/charted/lib cli_util:third_party/pkg/cli_util/lib -code_transformers:third_party/pkg/code_transformers/lib collection:third_party/pkg/collection/lib compiler:pkg/compiler/lib # Compiler is imported as compiler_unsupported so it can work outside the SDK. @@ -44,7 +43,6 @@ http:third_party/pkg/http/lib http_multi_server:third_party/pkg/http_multi_server/lib http_parser:third_party/pkg/http_parser/lib http_throttle:third_party/pkg/http_throttle/lib -initialize:third_party/pkg/initialize/lib intl:third_party/pkg/intl/lib isolate:third_party/pkg/isolate/lib js:pkg/js/lib @@ -62,9 +60,9 @@ microlytics:pkg/microlytics/lib mime:third_party/pkg/mime/lib mustache4dart:third_party/pkg/mustache4dart/lib oauth2:third_party/pkg/oauth2/lib -observable:third_party/pkg/observable/lib observatory:runtime/observatory/lib -observe:third_party/pkg/observe/lib +# Note: this is pointing to the observatory_pub_packages version of pkg/observe +observe:third_party/observatory_pub_packages/packages/observe/lib package_config:third_party/pkg_tested/package_config/lib package_resolver:third_party/pkg_tested/package_resolver/lib path:third_party/pkg/path/lib @@ -83,7 +81,6 @@ shelf:third_party/pkg/shelf/lib shelf_packages_handler:third_party/pkg/shelf_packages_handler/lib shelf_static:third_party/pkg/shelf_static/lib shelf_web_socket:third_party/pkg/shelf_web_socket/lib -smoke:third_party/pkg/smoke/lib source_map_stack_trace:third_party/pkg/source_map_stack_trace/lib source_maps:third_party/pkg/source_maps/lib source_span:third_party/pkg/source_span/lib @@ -102,6 +99,5 @@ unittest:third_party/pkg/unittest/lib usage:third_party/pkg/usage/lib utf:third_party/pkg/utf/lib watcher:third_party/pkg/watcher/lib -web_components:third_party/pkg/web_components/lib web_socket_channel:third_party/pkg/web_socket_channel/lib yaml:third_party/pkg/yaml/lib diff --git a/DEPS b/DEPS index bbe226dd5e7d..c5102c99be9d 100644 --- a/DEPS +++ b/DEPS @@ -58,7 +58,6 @@ vars = { "charcode_tag": "@v1.1.1", "chrome_rev" : "@19997", "cli_util_tag" : "@0.1.0", - "code_transformers_tag": "@v0.5.1", "collection_tag": "@1.13.0", "convert_tag": "@2.0.1", "crypto_tag" : "@2.0.1", @@ -90,7 +89,6 @@ vars = { "http_tag" : "@0.11.3+13", "http_throttle_tag" : "@1.0.1", "idl_parser_rev": "@7fbe68cab90c38147dee4f48c30ad0d496c17915", - "initialize_tag": "@v0.6.2+5", "intl_tag": "@0.14.0", "isolate_tag": "@1.0.0", "jinja2_rev": "@2222b31554f03e62600cd7e383376a7c187967a1", @@ -102,9 +100,7 @@ vars = { "mime_rev": "@75890811d4af5af080351ba8a2853ad4c8df98dd", "mustache4dart_tag" : "@v1.1.0", "oauth2_tag": "@1.0.2", - "observable_tag": "@0.17.0", "observatory_pub_packages_rev": "@26aad88f1c1915d39bbcbff3cad589e2402fdcf1", - "observe_tag": "@0.15.0", "package_config_tag": "@1.0.0", "package_resolver_tag": "@1.0.2+1", "path_tag": "@1.4.1", @@ -122,7 +118,6 @@ vars = { "shelf_packages_handler_tag": "@1.0.0", "shelf_tag": "@0.6.7+2", "shelf_web_socket_tag": "@0.2.1", - "smoke_tag" : "@v0.3.6+2", "source_map_stack_trace_tag": "@1.1.4", "source_maps-0.9.4_rev": "@38524", "source_maps_tag": "@0.10.4", @@ -138,7 +133,6 @@ vars = { "usage_tag": "@3.3.0", "utf_tag": "@0.9.0+3", "watcher_tag": "@0.9.7+3", - "web_components_rev": "@6349e09f9118dce7ae1b309af5763745e25a9d61", "web_socket_channel_tag": "@1.0.4", "WebCore_rev": "@3c45690813c112373757bbef53de1602a62af609", "yaml_tag": "@2.1.12", @@ -216,9 +210,6 @@ deps = { (Var("github_mirror") % "crypto") + Var("crypto_tag"), Var("dart_root") + "/third_party/pkg/csslib": (Var("github_mirror") % "csslib") + Var("csslib_tag"), - Var("dart_root") + "/third_party/pkg/code_transformers": - (Var("github_mirror") % "code_transformers") + - Var("code_transformers_tag"), Var("dart_root") + "/third_party/dart-services": (Var("github_mirror") % "dart-services") + Var("dart_services_rev"), @@ -246,8 +237,6 @@ deps = { Var("dart_root") + "/third_party/pkg/http_throttle": (Var("github_mirror") % "http_throttle") + Var("http_throttle_tag"), - Var("dart_root") + "/third_party/pkg/initialize": - (Var("github_mirror") % "initialize") + Var("initialize_tag"), Var("dart_root") + "/third_party/pkg/intl": (Var("github_mirror") % "intl") + Var("intl_tag"), Var("dart_root") + "/third_party/pkg/isolate": @@ -270,10 +259,6 @@ deps = { + Var("mustache4dart_tag"), Var("dart_root") + "/third_party/pkg/oauth2": (Var("github_mirror") % "oauth2") + Var("oauth2_tag"), - Var("dart_root") + "/third_party/pkg/observable": - (Var("github_mirror") % "observable") + Var("observable_tag"), - Var("dart_root") + "/third_party/pkg/observe": - (Var("github_mirror") % "observe") + Var("observe_tag"), Var("dart_root") + "/third_party/observatory_pub_packages": (Var("github_mirror") % "observatory_pub_packages") + Var("observatory_pub_packages_rev"), @@ -312,8 +297,6 @@ deps = { Var("dart_root") + "/third_party/pkg/shelf_web_socket": (Var("github_mirror") % "shelf_web_socket") + Var("shelf_web_socket_tag"), - Var("dart_root") + "/third_party/pkg/smoke": - (Var("github_mirror") % "smoke") + Var("smoke_tag"), Var("dart_root") + "/third_party/pkg/source_maps": (Var("github_mirror") % "source_maps") + Var("source_maps_tag"), Var("dart_root") + "/third_party/pkg/source_span": @@ -347,9 +330,6 @@ deps = { (Var("github_mirror") % "utf") + Var("utf_tag"), Var("dart_root") + "/third_party/pkg/watcher": (Var("github_mirror") % "watcher") + Var("watcher_tag"), - Var("dart_root") + "/third_party/pkg/web_components": - (Var("github_mirror") % "web-components") + - Var("web_components_rev"), Var("dart_root") + "/third_party/pkg/web_socket_channel": (Var("github_mirror") % "web_socket_channel") + Var("web_socket_channel_tag"), diff --git a/tests/html/utils.dart b/tests/html/utils.dart index 8d941d7b3ad1..4209f9bd3ea1 100644 --- a/tests/html/utils.dart +++ b/tests/html/utils.dart @@ -5,7 +5,6 @@ import 'dart:html'; import 'dart:js' as js; import 'dart:typed_data'; import 'package:unittest/unittest.dart'; -export 'package:web_components/polyfill.dart'; /** * Verifies that [actual] has the same graph structure as [expected]. @@ -167,3 +166,54 @@ void upgradeCustomElements(Node node) { js.context['CustomElements'].callMethod('upgradeAll', [node]); } } + +/** + * A future that completes once all custom elements in the initial HTML page + * have been upgraded. + * + * This is needed because the native implementation can update the elements + * while parsing the HTML document, but the custom element polyfill cannot, + * so it completes this future once all elements are upgraded. + */ +// TODO(jmesserly): rename to webComponentsReady to match the event? +Future customElementsReady = () { + if (_isReady) return new Future.value(); + + // Not upgraded. Wait for the polyfill to fire the WebComponentsReady event. + // Note: we listen on document (not on document.body) to allow this polyfill + // to be loaded in the HEAD element. + return document.on['WebComponentsReady'].first; +}(); + +// Return true if we are using the polyfill and upgrade is complete, or if we +// have native document.register and therefore the browser took care of it. +// Otherwise return false, including the case where we can't find the polyfill. +bool get _isReady { + // If we don't have dart:js, assume things are ready + if (js.context == null) return true; + + var customElements = js.context['CustomElements']; + if (customElements == null) { + // Return true if native document.register, otherwise false. + // (Maybe the polyfill isn't loaded yet. Wait for it.) + return document.supportsRegisterElement; + } + + return customElements['ready'] == true; +} + +/** + * *Note* this API is primarily intended for tests. In other code it is better + * to write it in a style that works with or without the polyfill, rather than + * using this method. + * + * Synchronously trigger evaluation of pending lifecycle events, which otherwise + * need to wait for a [MutationObserver] to signal the changes in the polyfill. + * This method can be used to resolve differences in timing between native and + * polyfilled custom elements. + */ +void customElementsTakeRecords([Node node]) { + var customElements = js.context['CustomElements']; + if (customElements == null) return; + customElements.callMethod('takeRecords', [node]); +} diff --git a/tests/lib_strong/html/utils.dart b/tests/lib_strong/html/utils.dart index 8d941d7b3ad1..4209f9bd3ea1 100644 --- a/tests/lib_strong/html/utils.dart +++ b/tests/lib_strong/html/utils.dart @@ -5,7 +5,6 @@ import 'dart:html'; import 'dart:js' as js; import 'dart:typed_data'; import 'package:unittest/unittest.dart'; -export 'package:web_components/polyfill.dart'; /** * Verifies that [actual] has the same graph structure as [expected]. @@ -167,3 +166,54 @@ void upgradeCustomElements(Node node) { js.context['CustomElements'].callMethod('upgradeAll', [node]); } } + +/** + * A future that completes once all custom elements in the initial HTML page + * have been upgraded. + * + * This is needed because the native implementation can update the elements + * while parsing the HTML document, but the custom element polyfill cannot, + * so it completes this future once all elements are upgraded. + */ +// TODO(jmesserly): rename to webComponentsReady to match the event? +Future customElementsReady = () { + if (_isReady) return new Future.value(); + + // Not upgraded. Wait for the polyfill to fire the WebComponentsReady event. + // Note: we listen on document (not on document.body) to allow this polyfill + // to be loaded in the HEAD element. + return document.on['WebComponentsReady'].first; +}(); + +// Return true if we are using the polyfill and upgrade is complete, or if we +// have native document.register and therefore the browser took care of it. +// Otherwise return false, including the case where we can't find the polyfill. +bool get _isReady { + // If we don't have dart:js, assume things are ready + if (js.context == null) return true; + + var customElements = js.context['CustomElements']; + if (customElements == null) { + // Return true if native document.register, otherwise false. + // (Maybe the polyfill isn't loaded yet. Wait for it.) + return document.supportsRegisterElement; + } + + return customElements['ready'] == true; +} + +/** + * *Note* this API is primarily intended for tests. In other code it is better + * to write it in a style that works with or without the polyfill, rather than + * using this method. + * + * Synchronously trigger evaluation of pending lifecycle events, which otherwise + * need to wait for a [MutationObserver] to signal the changes in the polyfill. + * This method can be used to resolve differences in timing between native and + * polyfilled custom elements. + */ +void customElementsTakeRecords([Node node]) { + var customElements = js.context['CustomElements']; + if (customElements == null) return; + customElements.callMethod('takeRecords', [node]); +}