mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 11:31:57 +00:00
Polyfill only once
Avoid dcall on polyfill. R=jmesserly@google.com Review-Url: https://codereview.chromium.org/2983903002 .
This commit is contained in:
parent
c98989f0d7
commit
87ee6cc0d6
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
|
@ -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(
|
||||
|
|
|
@ -910,6 +910,7 @@ class BooleanConversionAssertionError extends AssertionError {
|
|||
// Hook to register new global object. This is invoked from dart:html
|
||||
// whenever a new window is accessed for the first time.
|
||||
void registerGlobalObject(object) {
|
||||
dart.polyfill(object);
|
||||
dart.applyAllExtensions(object);
|
||||
if (dart.polyfill(object)) {
|
||||
dart.applyAllExtensions(object);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue