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

Unified Diff: pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/runtime.dart

Issue 2649613003: Fix for Animation and other polyfills (Closed)
Patch Set: Created 3 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
Index: pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/runtime.dart
diff --git a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/runtime.dart b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/runtime.dart
index b23aa6369d749e7295308f95827b0848e37f854d..a6c3ce44bc6890fe392d58bfbfc824e982fc629b 100644
--- a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/runtime.dart
+++ b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/runtime.dart
@@ -30,6 +30,59 @@ part 'generators.dart';
part 'operations.dart';
part 'utils.dart';
+// TODO(vsm): Move polyfill code to dart:html.
+// Note, native extensions are registered onto types in dart.global.
+// This polyfill needs to run before the corresponding dart:html code is run.
@JSExportName('global')
-final global_ = JS('', 'typeof window == "undefined" ? global : window');
+final global_ = JS('', '''
+ function () {
+ if (typeof NodeList !== "undefined") {
+ // TODO(vsm): Do we still need these?
+ NodeList.prototype.get = function(i) { return this[i]; };
+ NamedNodeMap.prototype.get = function(i) { return this[i]; };
+ DOMTokenList.prototype.get = function(i) { return this[i]; };
+ HTMLCollection.prototype.get = function(i) { return this[i]; };
+
+ // Expose constructors for DOM types dart:html needs to assume are
+ // available on window.
+ if (typeof PannerNode == "undefined") {
+ let audioContext;
+ if (typeof AudioContext == "undefined" &&
+ (typeof webkitAudioContext != "undefined")) {
+ audioContext = new webkitAudioContext();
+ } else {
+ audioContext = new AudioContext();
+ window.StereoPannerNode =
+ audioContext.createStereoPanner().constructor;
+ }
+ window.PannerNode = audioContext.createPanner().constructor;
+ }
+ if (typeof AudioSourceNode == "undefined") {
+ window.AudioSourceNode = MediaElementAudioSourceNode.__proto__;
+ }
+ if (typeof FontFaceSet == "undefined") {
+ window.FontFaceSet = document.fonts.__proto__.constructor;
+ }
+ if (typeof MemoryInfo == "undefined") {
+ if (typeof window.performance.memory != "undefined") {
+ window.MemoryInfo = window.performance.memory.constructor;
+ }
+ }
+ if (typeof Geolocation == "undefined") {
+ navigator.geolocation.constructor;
+ }
+ if (typeof Animation == "undefined") {
+ let d = document.createElement('div');
+ if (typeof d.animate != "undefined") {
+ window.Animation = d.animate(d).constructor;
+ }
+ }
+ if (typeof SourceBufferList == "undefined") {
+ window.SourceBufferList = new MediaSource().sourceBuffers.constructor;
+ }
+ }
+ return typeof window == "undefined" ? global : window;
+ }()
+''');
+
final JsSymbol = JS('', 'Symbol');

Powered by Google App Engine
This is Rietveld 408576698