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 8dff67c6617d9bbf947197c69c2aa1fbdf17b33d..ea935073b2c47092ab0848fdb6998d70e584662f 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 |
@@ -36,66 +36,70 @@ 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. |
-final polyfill = JS( |
+final _polyfilled = JS('', 'Symbol("_polyfilled")'); |
+ |
+bool polyfill(window) => JS( |
'', |
- ''' |
-function (window) { |
- if (typeof window.NodeList !== "undefined") { |
+ '''(() => { |
+ if ($window[$_polyfilled]) return false; |
+ $window[$_polyfilled] = true; |
+ |
+ if (typeof $window.NodeList !== "undefined") { |
// TODO(vsm): Do we still need these? |
- window.NodeList.prototype.get = function(i) { return this[i]; }; |
- window.NamedNodeMap.prototype.get = function(i) { return this[i]; }; |
- window.DOMTokenList.prototype.get = function(i) { return this[i]; }; |
- window.HTMLCollection.prototype.get = function(i) { return this[i]; }; |
+ $window.NodeList.prototype.get = function(i) { return this[i]; }; |
+ $window.NamedNodeMap.prototype.get = function(i) { return this[i]; }; |
+ $window.DOMTokenList.prototype.get = function(i) { return this[i]; }; |
+ $window.HTMLCollection.prototype.get = function(i) { return this[i]; }; |
// Expose constructors for DOM types dart:html needs to assume are |
// available on window. |
- if (typeof window.PannerNode == "undefined") { |
+ if (typeof $window.PannerNode == "undefined") { |
let audioContext; |
- if (typeof window.AudioContext == "undefined" && |
- (typeof window.webkitAudioContext != "undefined")) { |
- audioContext = new window.webkitAudioContext(); |
+ if (typeof $window.AudioContext == "undefined" && |
+ (typeof $window.webkitAudioContext != "undefined")) { |
+ audioContext = new $window.webkitAudioContext(); |
} else { |
- audioContext = new window.AudioContext(); |
- window.StereoPannerNode = |
+ audioContext = new $window.AudioContext(); |
+ $window.StereoPannerNode = |
audioContext.createStereoPanner().constructor; |
} |
- window.PannerNode = audioContext.createPanner().constructor; |
+ $window.PannerNode = audioContext.createPanner().constructor; |
} |
- if (typeof window.AudioSourceNode == "undefined") { |
- window.AudioSourceNode = MediaElementAudioSourceNode.__proto__; |
+ if (typeof $window.AudioSourceNode == "undefined") { |
+ $window.AudioSourceNode = MediaElementAudioSourceNode.__proto__; |
} |
- if (typeof window.FontFaceSet == "undefined") { |
+ if (typeof $window.FontFaceSet == "undefined") { |
// CSS Font Loading is not supported on Edge. |
- if (typeof window.document.fonts != "undefined") { |
- window.FontFaceSet = window.document.fonts.__proto__.constructor; |
+ if (typeof $window.document.fonts != "undefined") { |
+ $window.FontFaceSet = $window.document.fonts.__proto__.constructor; |
} |
} |
- if (typeof window.MemoryInfo == "undefined") { |
- if (typeof window.performance.memory != "undefined") { |
- window.MemoryInfo = window.performance.memory.constructor; |
+ if (typeof $window.MemoryInfo == "undefined") { |
+ if (typeof $window.performance.memory != "undefined") { |
+ $window.MemoryInfo = $window.performance.memory.constructor; |
} |
} |
- if (typeof window.Geolocation == "undefined") { |
- window.Geolocation == window.navigator.geolocation.constructor; |
+ if (typeof $window.Geolocation == "undefined") { |
+ $window.Geolocation == $window.navigator.geolocation.constructor; |
} |
- if (typeof window.Animation == "undefined") { |
- let d = window.document.createElement('div'); |
+ if (typeof $window.Animation == "undefined") { |
+ let d = $window.document.createElement('div'); |
if (typeof d.animate != "undefined") { |
- window.Animation = d.animate(d).constructor; |
+ $window.Animation = d.animate(d).constructor; |
} |
} |
- if (typeof window.SourceBufferList == "undefined") { |
- window.SourceBufferList = |
- new window.MediaSource().sourceBuffers.constructor; |
+ if (typeof $window.SourceBufferList == "undefined") { |
+ $window.SourceBufferList = |
+ new $window.MediaSource().sourceBuffers.constructor; |
} |
- if (typeof window.SpeechRecognition == "undefined") { |
- window.SpeechRecognition = window.webkitSpeechRecognition; |
- window.SpeechRecognitionError = window.webkitSpeechRecognitionError; |
- window.SpeechRecognitionEvent = window.webkitSpeechRecognitionEvent; |
+ if (typeof $window.SpeechRecognition == "undefined") { |
+ $window.SpeechRecognition = $window.webkitSpeechRecognition; |
+ $window.SpeechRecognitionError = $window.webkitSpeechRecognitionError; |
+ $window.SpeechRecognitionEvent = $window.webkitSpeechRecognitionEvent; |
} |
} |
-} |
-'''); |
+ return true; |
+})()'''); |
@JSExportName('global') |
final global_ = JS( |