Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library dart._runtime; | 5 library dart._runtime; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'dart:_debugger' show stackTraceMapper; | 10 import 'dart:_debugger' show stackTraceMapper; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 part 'types.dart'; | 29 part 'types.dart'; |
| 30 part 'errors.dart'; | 30 part 'errors.dart'; |
| 31 part 'generators.dart'; | 31 part 'generators.dart'; |
| 32 part 'operations.dart'; | 32 part 'operations.dart'; |
| 33 part 'profile.dart'; | 33 part 'profile.dart'; |
| 34 part 'utils.dart'; | 34 part 'utils.dart'; |
| 35 | 35 |
| 36 // TODO(vsm): Move polyfill code to dart:html. | 36 // TODO(vsm): Move polyfill code to dart:html. |
| 37 // Note, native extensions are registered onto types in dart.global. | 37 // Note, native extensions are registered onto types in dart.global. |
| 38 // This polyfill needs to run before the corresponding dart:html code is run. | 38 // This polyfill needs to run before the corresponding dart:html code is run. |
| 39 final polyfill = JS( | |
| 40 '', | |
| 41 ''' | |
| 42 function (window) { | |
| 43 if (typeof window.NodeList !== "undefined") { | |
| 44 // TODO(vsm): Do we still need these? | |
| 45 window.NodeList.prototype.get = function(i) { return this[i]; }; | |
| 46 window.NamedNodeMap.prototype.get = function(i) { return this[i]; }; | |
| 47 window.DOMTokenList.prototype.get = function(i) { return this[i]; }; | |
| 48 window.HTMLCollection.prototype.get = function(i) { return this[i]; }; | |
| 49 | |
| 50 // Expose constructors for DOM types dart:html needs to assume are | |
| 51 // available on window. | |
| 52 if (typeof window.PannerNode == "undefined") { | |
| 53 let audioContext; | |
| 54 if (typeof window.AudioContext == "undefined" && | |
| 55 (typeof window.webkitAudioContext != "undefined")) { | |
| 56 audioContext = new window.webkitAudioContext(); | |
| 57 } else { | |
| 58 audioContext = new window.AudioContext(); | |
| 59 window.StereoPannerNode = | |
| 60 audioContext.createStereoPanner().constructor; | |
| 61 } | |
| 62 window.PannerNode = audioContext.createPanner().constructor; | |
| 63 } | |
| 64 if (typeof window.AudioSourceNode == "undefined") { | |
| 65 window.AudioSourceNode = MediaElementAudioSourceNode.__proto__; | |
| 66 } | |
| 67 if (typeof window.FontFaceSet == "undefined") { | |
| 68 // CSS Font Loading is not supported on Edge. | |
| 69 if (typeof window.document.fonts != "undefined") { | |
| 70 window.FontFaceSet = window.document.fonts.__proto__.constructor; | |
| 71 } | |
| 72 } | |
| 73 if (typeof window.MemoryInfo == "undefined") { | |
| 74 if (typeof window.performance.memory != "undefined") { | |
| 75 window.MemoryInfo = window.performance.memory.constructor; | |
| 76 } | |
| 77 } | |
| 78 if (typeof window.Geolocation == "undefined") { | |
| 79 window.Geolocation == window.navigator.geolocation.constructor; | |
| 80 } | |
| 81 if (typeof window.Animation == "undefined") { | |
| 82 let d = window.document.createElement('div'); | |
| 83 if (typeof d.animate != "undefined") { | |
| 84 window.Animation = d.animate(d).constructor; | |
| 85 } | |
| 86 } | |
| 87 if (typeof window.SourceBufferList == "undefined") { | |
| 88 window.SourceBufferList = new window.MediaSource().sourceBuffers.construct or; | |
|
Jennifer Messerly
2017/07/14 19:38:08
long line
vsm
2017/07/19 15:59:01
Done.
| |
| 89 } | |
| 90 if (typeof window.SpeechRecognition == "undefined") { | |
| 91 window.SpeechRecognition = window.webkitSpeechRecognition; | |
| 92 window.SpeechRecognitionError = window.webkitSpeechRecognitionError; | |
| 93 window.SpeechRecognitionEvent = window.webkitSpeechRecognitionEvent; | |
| 94 } | |
| 95 } | |
| 96 } | |
| 97 '''); | |
| 98 | |
| 39 @JSExportName('global') | 99 @JSExportName('global') |
| 40 final global_ = JS( | 100 final global_ = JS( |
| 41 '', | 101 '', |
| 42 ''' | 102 ''' |
| 43 function () { | 103 function () { |
| 44 if (typeof NodeList !== "undefined") { | 104 // Find global object. |
| 45 // TODO(vsm): Do we still need these? | |
| 46 NodeList.prototype.get = function(i) { return this[i]; }; | |
| 47 NamedNodeMap.prototype.get = function(i) { return this[i]; }; | |
| 48 DOMTokenList.prototype.get = function(i) { return this[i]; }; | |
| 49 HTMLCollection.prototype.get = function(i) { return this[i]; }; | |
| 50 | |
| 51 // Expose constructors for DOM types dart:html needs to assume are | |
| 52 // available on window. | |
| 53 if (typeof PannerNode == "undefined") { | |
| 54 let audioContext; | |
| 55 if (typeof AudioContext == "undefined" && | |
| 56 (typeof webkitAudioContext != "undefined")) { | |
| 57 audioContext = new webkitAudioContext(); | |
| 58 } else { | |
| 59 audioContext = new AudioContext(); | |
| 60 window.StereoPannerNode = | |
| 61 audioContext.createStereoPanner().constructor; | |
| 62 } | |
| 63 window.PannerNode = audioContext.createPanner().constructor; | |
| 64 } | |
| 65 if (typeof AudioSourceNode == "undefined") { | |
| 66 window.AudioSourceNode = MediaElementAudioSourceNode.__proto__; | |
| 67 } | |
| 68 if (typeof FontFaceSet == "undefined") { | |
| 69 // CSS Font Loading is not supported on Edge. | |
| 70 if (typeof document.fonts != "undefined") { | |
| 71 window.FontFaceSet = document.fonts.__proto__.constructor; | |
| 72 } | |
| 73 } | |
| 74 if (typeof MemoryInfo == "undefined") { | |
| 75 if (typeof window.performance.memory != "undefined") { | |
| 76 window.MemoryInfo = window.performance.memory.constructor; | |
| 77 } | |
| 78 } | |
| 79 if (typeof Geolocation == "undefined") { | |
| 80 navigator.geolocation.constructor; | |
| 81 } | |
| 82 if (typeof Animation == "undefined") { | |
| 83 let d = document.createElement('div'); | |
| 84 if (typeof d.animate != "undefined") { | |
| 85 window.Animation = d.animate(d).constructor; | |
| 86 } | |
| 87 } | |
| 88 if (typeof SourceBufferList == "undefined") { | |
| 89 window.SourceBufferList = new MediaSource().sourceBuffers.constructor; | |
| 90 } | |
| 91 if (typeof SpeechRecognition == "undefined") { | |
| 92 window.SpeechRecognition = window.webkitSpeechRecognition; | |
| 93 window.SpeechRecognitionError = window.webkitSpeechRecognitionError; | |
| 94 window.SpeechRecognitionEvent = window.webkitSpeechRecognitionEvent; | |
| 95 } | |
| 96 } | |
| 97 | |
| 98 var globalState = (typeof window != "undefined") ? window | 105 var globalState = (typeof window != "undefined") ? window |
| 99 : (typeof global != "undefined") ? global | 106 : (typeof global != "undefined") ? global |
| 100 : (typeof self != "undefined") ? self : {}; | 107 : (typeof self != "undefined") ? self : {}; |
| 101 | 108 |
| 109 $polyfill(globalState); | |
| 110 | |
| 102 // These settings must be configured before the application starts so that | 111 // These settings must be configured before the application starts so that |
| 103 // user code runs with the correct configuration. | 112 // user code runs with the correct configuration. |
| 104 let settings = 'ddcSettings' in globalState ? globalState.ddcSettings : {}; | 113 let settings = 'ddcSettings' in globalState ? globalState.ddcSettings : {}; |
| 105 $trapRuntimeErrors( | 114 $trapRuntimeErrors( |
| 106 'trapRuntimeErrors' in settings ? settings.trapRuntimeErrors : true); | 115 'trapRuntimeErrors' in settings ? settings.trapRuntimeErrors : true); |
| 107 $ignoreWhitelistedErrors( | 116 $ignoreWhitelistedErrors( |
| 108 'ignoreWhitelistedErrors' in settings ? | 117 'ignoreWhitelistedErrors' in settings ? |
| 109 settings.ignoreWhitelistedErrors : true); | 118 settings.ignoreWhitelistedErrors : true); |
| 110 | 119 |
| 111 $ignoreAllErrors( | 120 $ignoreAllErrors( |
| 112 'ignoreAllErrors' in settings ?settings.ignoreAllErrors : false); | 121 'ignoreAllErrors' in settings ?settings.ignoreAllErrors : false); |
| 113 | 122 |
| 114 $failForWeakModeIsChecks( | 123 $failForWeakModeIsChecks( |
| 115 'failForWeakModeIsChecks' in settings ? | 124 'failForWeakModeIsChecks' in settings ? |
| 116 settings.failForWeakModeIsChecks : true); | 125 settings.failForWeakModeIsChecks : true); |
| 117 $trackProfile( | 126 $trackProfile( |
| 118 'trackProfile' in settings ? settings.trackProfile : false); | 127 'trackProfile' in settings ? settings.trackProfile : false); |
| 119 | 128 |
| 120 return globalState; | 129 return globalState; |
| 121 }() | 130 }() |
| 122 '''); | 131 '''); |
| 123 | 132 |
| 124 final JsSymbol = JS('', 'Symbol'); | 133 final JsSymbol = JS('', 'Symbol'); |
| OLD | NEW |