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 = |
| 89 new window.MediaSource().sourceBuffers.constructor; |
| 90 } |
| 91 if (typeof window.SpeechRecognition == "undefined") { |
| 92 window.SpeechRecognition = window.webkitSpeechRecognition; |
| 93 window.SpeechRecognitionError = window.webkitSpeechRecognitionError; |
| 94 window.SpeechRecognitionEvent = window.webkitSpeechRecognitionEvent; |
| 95 } |
| 96 } |
| 97 } |
| 98 '''); |
| 99 |
39 @JSExportName('global') | 100 @JSExportName('global') |
40 final global_ = JS( | 101 final global_ = JS( |
41 '', | 102 '', |
42 ''' | 103 ''' |
43 function () { | 104 function () { |
44 if (typeof NodeList !== "undefined") { | 105 // 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 | 106 var globalState = (typeof window != "undefined") ? window |
99 : (typeof global != "undefined") ? global | 107 : (typeof global != "undefined") ? global |
100 : (typeof self != "undefined") ? self : {}; | 108 : (typeof self != "undefined") ? self : {}; |
101 | 109 |
| 110 $polyfill(globalState); |
| 111 |
102 // These settings must be configured before the application starts so that | 112 // These settings must be configured before the application starts so that |
103 // user code runs with the correct configuration. | 113 // user code runs with the correct configuration. |
104 let settings = 'ddcSettings' in globalState ? globalState.ddcSettings : {}; | 114 let settings = 'ddcSettings' in globalState ? globalState.ddcSettings : {}; |
105 $trapRuntimeErrors( | 115 $trapRuntimeErrors( |
106 'trapRuntimeErrors' in settings ? settings.trapRuntimeErrors : true); | 116 'trapRuntimeErrors' in settings ? settings.trapRuntimeErrors : true); |
107 $ignoreWhitelistedErrors( | 117 $ignoreWhitelistedErrors( |
108 'ignoreWhitelistedErrors' in settings ? | 118 'ignoreWhitelistedErrors' in settings ? |
109 settings.ignoreWhitelistedErrors : true); | 119 settings.ignoreWhitelistedErrors : true); |
110 | 120 |
111 $ignoreAllErrors( | 121 $ignoreAllErrors( |
112 'ignoreAllErrors' in settings ?settings.ignoreAllErrors : false); | 122 'ignoreAllErrors' in settings ?settings.ignoreAllErrors : false); |
113 | 123 |
114 $failForWeakModeIsChecks( | 124 $failForWeakModeIsChecks( |
115 'failForWeakModeIsChecks' in settings ? | 125 'failForWeakModeIsChecks' in settings ? |
116 settings.failForWeakModeIsChecks : true); | 126 settings.failForWeakModeIsChecks : true); |
117 $trackProfile( | 127 $trackProfile( |
118 'trackProfile' in settings ? settings.trackProfile : false); | 128 'trackProfile' in settings ? settings.trackProfile : false); |
119 | 129 |
120 return globalState; | 130 return globalState; |
121 }() | 131 }() |
122 '''); | 132 '''); |
123 | 133 |
124 final JsSymbol = JS('', 'Symbol'); | 134 final JsSymbol = JS('', 'Symbol'); |
OLD | NEW |