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

Side by Side Diff: test/codegen/expect/convert/convert.js

Issue 949383003: use js_ast instead of strings to generate JS (Closed) Base URL: git@github.com:dart-lang/dart-dev-compiler.git@master
Patch Set: add redirecting ctor test Created 5 years, 9 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 unified diff | Download patch
« no previous file with comments | « test/codegen/expect/constructors/constructors.js ('k') | test/codegen/expect/core/core.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 var convert; 1 var convert;
2 (function (convert) { 2 (function(convert) {
3 'use strict'; 3 'use strict';
4 // Function _convertJsonToDart: (dynamic, (dynamic, dynamic) → dynamic) → dyna mic 4 // Function _convertJsonToDart: (dynamic, (dynamic, dynamic) → dynamic) → dyna mic
5 function _convertJsonToDart(json, reviver) { 5 function _convertJsonToDart(json, reviver) {
6 dart.assert(reviver !== null); 6 dart.assert(reviver !== null);
7 // Function walk: (dynamic) → dynamic 7 // Function walk: (dynamic) → dynamic
8 function walk(e) { 8 function walk(e) {
9 if (dart.dbinary(dart.dinvokef(/* Unimplemented unknown name */JS, 'bool', '# == null', e), "||", dart.dinvokef(/* Unimplemented unknown name */JS, 'bool' , 'typeof # != "object"', e))) { 9 if (dart.dbinary(dart.dinvokef(/* Unimplemented unknown name */JS, 'bool', '# == null', e), '||', dart.dinvokef(/* Unimplemented unknown name */JS, 'bool' , 'typeof # != "object"', e))) {
10 return e; 10 return e;
11 } 11 }
12 if (dart.dinvokef(/* Unimplemented unknown name */JS, 'bool', 'Object.getP rototypeOf(#) === Array.prototype', e)) { 12 if (dart.dinvokef(/* Unimplemented unknown name */JS, 'bool', 'Object.getP rototypeOf(#) === Array.prototype', e)) {
13 for (let i = 0; i['<'](dart.dinvokef(/* Unimplemented unknown name */JS, 'int', '#.length', e)); i++) { 13 for (let i = 0; i['<'](dart.dinvokef(/* Unimplemented unknown name */JS, 'int', '#.length', e)); i++) {
14 let item = dart.dinvokef(/* Unimplemented unknown name */JS, '', '#[#] ', e, i); 14 let item = dart.dinvokef(/* Unimplemented unknown name */JS, '', '#[#] ', e, i);
15 dart.dinvokef(/* Unimplemented unknown name */JS, '', '#[#]=#', e, i, reviver(i, walk(item))); 15 dart.dinvokef(/* Unimplemented unknown name */JS, '', '#[#]=#', e, i, reviver(i, walk(item)));
16 } 16 }
17 return e; 17 return e;
18 } 18 }
19 let map = new _JsonMap(e); 19 let map = new _JsonMap(e);
20 let processed = map._processed; 20 let processed = map._processed;
21 let keys = map._computeKeys(); 21 let keys = map._computeKeys();
22 for (let i = 0; i < keys.length; i++) { 22 for (let i = 0; i < keys.length; i++) {
23 let key = keys.get(i); 23 let key = keys.get(i);
24 let revived = reviver(key, walk(dart.dinvokef(/* Unimplemented unknown n ame */JS, '', '#[#]', e, key))); 24 let revived = reviver(key, walk(dart.dinvokef(/* Unimplemented unknown n ame */JS, '', '#[#]', e, key)));
25 dart.dinvokef(/* Unimplemented unknown name */JS, '', '#[#]=#', processe d, key, revived); 25 dart.dinvokef(/* Unimplemented unknown name */JS, '', '#[#]=#', processe d, key, revived);
26 } 26 }
27 map._original = processed; 27 map._original = processed;
28 return map; 28 return map;
29 } 29 }
30 return reviver(null, walk(json)); 30 return reviver(null, walk(json));
31 } 31 }
32
33 // Function _convertJsonToDartLazy: (dynamic) → dynamic 32 // Function _convertJsonToDartLazy: (dynamic) → dynamic
34 function _convertJsonToDartLazy(object) { 33 function _convertJsonToDartLazy(object) {
35 if (object === null) return null; 34 if (object === null)
35 return null;
36 if (dart.dinvokef(/* Unimplemented unknown name */JS, 'bool', 'typeof # != " object"', object)) { 36 if (dart.dinvokef(/* Unimplemented unknown name */JS, 'bool', 'typeof # != " object"', object)) {
37 return object; 37 return object;
38 } 38 }
39 if (dart.dinvokef(/* Unimplemented unknown name */JS, 'bool', 'Object.getPro totypeOf(#) !== Array.prototype', object)) { 39 if (dart.dinvokef(/* Unimplemented unknown name */JS, 'bool', 'Object.getPro totypeOf(#) !== Array.prototype', object)) {
40 return new _JsonMap(object); 40 return new _JsonMap(object);
41 } 41 }
42 for (let i = 0; i['<'](dart.dinvokef(/* Unimplemented unknown name */JS, 'in t', '#.length', object)); i++) { 42 for (let i = 0; i['<'](dart.dinvokef(/* Unimplemented unknown name */JS, 'in t', '#.length', object)); i++) {
43 let item = dart.dinvokef(/* Unimplemented unknown name */JS, '', '#[#]', o bject, i); 43 let item = dart.dinvokef(/* Unimplemented unknown name */JS, '', '#[#]', o bject, i);
44 dart.dinvokef(/* Unimplemented unknown name */JS, '', '#[#]=#', object, i, _convertJsonToDartLazy(item)); 44 dart.dinvokef(/* Unimplemented unknown name */JS, '', '#[#]=#', object, i, _convertJsonToDartLazy(item));
45 } 45 }
46 return object; 46 return object;
47 } 47 }
48
49 class _JsonMap extends dart.Object { 48 class _JsonMap extends dart.Object {
50 _JsonMap(_original) { 49 _JsonMap(_original) {
51 this._processed = _newJavaScriptObject(); 50 this._processed = _newJavaScriptObject();
52 this._original = _original; 51 this._original = _original;
53 this._data = null; 52 this._data = null;
54 } 53 }
55 get(key) { 54 get(key) {
56 if (this._isUpgraded) { 55 if (this._isUpgraded) {
57 return this._upgradedMap.get(key); 56 return this._upgradedMap.get(key);
58 } else if (!(typeof key == "string")) { 57 } else if (!(typeof key == string)) {
59 return null; 58 return null;
60 } else { 59 } else {
61 let result = _getProperty(this._processed, dart.as(key, core.String)); 60 let result = _getProperty(this._processed, dart.as(key, core.String));
62 if (_isUnprocessed(result)) result = this._process(dart.as(key, core.Str ing)); 61 if (_isUnprocessed(result))
62 result = this._process(dart.as(key, core.String));
63 return result; 63 return result;
64 } 64 }
65 } 65 }
66 get length() { return this._isUpgraded ? this._upgradedMap.length : this._co mputeKeys().length; } 66 get length() {
67 get isEmpty() { return this.length === 0; } 67 return this._isUpgraded ? this._upgradedMap.length : this._computeKeys().l ength;
68 get isNotEmpty() { return this.length > 0; } 68 }
69 get isEmpty() {
70 return this.length === 0;
71 }
72 get isNotEmpty() {
73 return this.length > 0;
74 }
69 get keys() { 75 get keys() {
70 if (this._isUpgraded) return this._upgradedMap.keys; 76 if (this._isUpgraded)
77 return this._upgradedMap.keys;
71 return new _JsonMapKeyIterable(this); 78 return new _JsonMapKeyIterable(this);
72 } 79 }
73 get values() { 80 get values() {
74 if (this._isUpgraded) return this._upgradedMap.values; 81 if (this._isUpgraded)
82 return this._upgradedMap.values;
75 return new _internal.MappedIterable(this._computeKeys(), ((each) => this.g et(each)).bind(this)); 83 return new _internal.MappedIterable(this._computeKeys(), ((each) => this.g et(each)).bind(this));
76 } 84 }
77 set(key, value) { 85 set(key, value) {
78 if (this._isUpgraded) { 86 if (this._isUpgraded) {
79 this._upgradedMap.set(key, value); 87 this._upgradedMap.set(key, value);
80 } else if (this.containsKey(key)) { 88 } else if (this.containsKey(key)) {
81 let processed = this._processed; 89 let processed = this._processed;
82 _setProperty(processed, dart.as(key, core.String), value); 90 _setProperty(processed, dart.as(key, core.String), value);
83 let original = this._original; 91 let original = this._original;
84 if (!dart.notNull(core.identical(original, processed))) { 92 if (!dart.notNull(core.identical(original, processed))) {
85 _setProperty(original, dart.as(key, core.String), null); 93 _setProperty(original, dart.as(key, core.String), null);
86 } 94 }
87 } else { 95 } else {
88 this._upgrade().set(key, value); 96 this._upgrade().set(key, value);
89 } 97 }
90 } 98 }
91 addAll(other) { 99 addAll(other) {
92 other.forEach(((key, value) => { 100 other.forEach(((key, value) => {
93 this.set(key, value); 101 this.set(key, value);
94 }).bind(this)); 102 }).bind(this));
95 } 103 }
96 containsValue(value) { 104 containsValue(value) {
97 if (this._isUpgraded) return this._upgradedMap.containsValue(value); 105 if (this._isUpgraded)
106 return this._upgradedMap.containsValue(value);
98 let keys = this._computeKeys(); 107 let keys = this._computeKeys();
99 for (let i = 0; i < keys.length; i++) { 108 for (let i = 0; i < keys.length; i++) {
100 let key = keys.get(i); 109 let key = keys.get(i);
101 if (dart.equals(this.get(key), value)) return true; 110 if (dart.equals(this.get(key), value))
111 return true;
102 } 112 }
103 return false; 113 return false;
104 } 114 }
105 containsKey(key) { 115 containsKey(key) {
106 if (this._isUpgraded) return this._upgradedMap.containsKey(key); 116 if (this._isUpgraded)
107 if (!(typeof key == "string")) return false; 117 return this._upgradedMap.containsKey(key);
118 if (!(typeof key == string))
119 return false;
108 return _hasProperty(this._original, dart.as(key, core.String)); 120 return _hasProperty(this._original, dart.as(key, core.String));
109 } 121 }
110 putIfAbsent(key, ifAbsent) { 122 putIfAbsent(key, ifAbsent) {
111 if (this.containsKey(key)) return this.get(key); 123 if (this.containsKey(key))
124 return this.get(key);
112 let value = ifAbsent(); 125 let value = ifAbsent();
113 this.set(key, value); 126 this.set(key, value);
114 return value; 127 return value;
115 } 128 }
116 remove(key) { 129 remove(key) {
117 if (dart.notNull(!dart.notNull(this._isUpgraded)) && dart.notNull(!dart.no tNull(this.containsKey(key)))) return null; 130 if (dart.notNull(!dart.notNull(this._isUpgraded)) && dart.notNull(!dart.no tNull(this.containsKey(key))))
131 return null;
118 return this._upgrade().remove(key); 132 return this._upgrade().remove(key);
119 } 133 }
120 clear() { 134 clear() {
121 if (this._isUpgraded) { 135 if (this._isUpgraded) {
122 this._upgradedMap.clear(); 136 this._upgradedMap.clear();
123 } else { 137 } else {
124 if (this._data !== null) { 138 if (this._data !== null) {
125 dart.dinvoke(this._data, "clear"); 139 dart.dinvoke(this._data, 'clear');
126 } 140 }
127 this._original = this._processed = null; 141 this._original = this._processed = null;
128 this._data = dart.map(); 142 this._data = dart.map();
129 } 143 }
130 } 144 }
131 forEach(f) { 145 forEach(f) {
132 if (this._isUpgraded) return this._upgradedMap.forEach(f); 146 if (this._isUpgraded)
147 return this._upgradedMap.forEach(f);
133 let keys = this._computeKeys(); 148 let keys = this._computeKeys();
134 for (let i = 0; i < keys.length; i++) { 149 for (let i = 0; i < keys.length; i++) {
135 let key = keys.get(i); 150 let key = keys.get(i);
136 let value = _getProperty(this._processed, key); 151 let value = _getProperty(this._processed, key);
137 if (_isUnprocessed(value)) { 152 if (_isUnprocessed(value)) {
138 value = _convertJsonToDartLazy(_getProperty(this._original, key)); 153 value = _convertJsonToDartLazy(_getProperty(this._original, key));
139 _setProperty(this._processed, key, value); 154 _setProperty(this._processed, key, value);
140 } 155 }
141 f(key, value); 156 f(key, value);
142 if (!dart.notNull(core.identical(keys, this._data))) { 157 if (!dart.notNull(core.identical(keys, this._data))) {
143 throw new core.ConcurrentModificationError(this); 158 throw new core.ConcurrentModificationError(this);
144 } 159 }
145 } 160 }
146 } 161 }
147 toString() { return collection.Maps.mapToString(this); } 162 toString() {
148 get _isUpgraded() { return this._processed === null; } 163 return collection.Maps.mapToString(this);
164 }
165 get _isUpgraded() {
166 return this._processed === null;
167 }
149 get _upgradedMap() { 168 get _upgradedMap() {
150 dart.assert(this._isUpgraded); 169 dart.assert(this._isUpgraded);
151 return dart.as(dart.dinvokef(/* Unimplemented unknown name */JS, 'LinkedHa shMap', '#', this._data), core.Map); 170 return dart.as(dart.dinvokef(/* Unimplemented unknown name */JS, 'LinkedHa shMap', '#', this._data), core.Map);
152 } 171 }
153 _computeKeys() { 172 _computeKeys() {
154 dart.assert(!dart.notNull(this._isUpgraded)); 173 dart.assert(!dart.notNull(this._isUpgraded));
155 let keys = dart.as(this._data, core.List); 174 let keys = dart.as(this._data, core.List);
156 if (keys === null) { 175 if (keys === null) {
157 keys = this._data = _getPropertyNames(this._original); 176 keys = this._data = _getPropertyNames(this._original);
158 } 177 }
159 return dart.as(dart.dinvokef(/* Unimplemented unknown name */JS, 'JSExtend ableArray', '#', keys), core.List$(core.String)); 178 return dart.as(dart.dinvokef(/* Unimplemented unknown name */JS, 'JSExtend ableArray', '#', keys), core.List$(core.String));
160 } 179 }
161 _upgrade() { 180 _upgrade() {
162 if (this._isUpgraded) return this._upgradedMap; 181 if (this._isUpgraded)
182 return this._upgradedMap;
163 let result = dart.map(); 183 let result = dart.map();
164 let keys = this._computeKeys(); 184 let keys = this._computeKeys();
165 for (let i = 0; i < keys.length; i++) { 185 for (let i = 0; i < keys.length; i++) {
166 let key = keys.get(i); 186 let key = keys.get(i);
167 result.set(key, this.get(key)); 187 result.set(key, this.get(key));
168 } 188 }
169 if (keys.isEmpty) { 189 if (keys.isEmpty) {
170 keys.add(null); 190 keys.add(null);
171 } else { 191 } else {
172 keys.clear(); 192 keys.clear();
173 } 193 }
174 this._original = this._processed = null; 194 this._original = this._processed = null;
175 this._data = result; 195 this._data = result;
176 dart.assert(this._isUpgraded); 196 dart.assert(this._isUpgraded);
177 return result; 197 return result;
178 } 198 }
179 _process(key) { 199 _process(key) {
180 if (!dart.notNull(_hasProperty(this._original, key))) return null; 200 if (!dart.notNull(_hasProperty(this._original, key)))
201 return null;
181 let result = _convertJsonToDartLazy(_getProperty(this._original, key)); 202 let result = _convertJsonToDartLazy(_getProperty(this._original, key));
182 return _setProperty(this._processed, key, result); 203 return _setProperty(this._processed, key, result);
183 } 204 }
184 static _hasProperty(object, key) { return dart.as(dart.dinvokef(/* Unimpleme nted unknown name */JS, 'bool', 'Object.prototype.hasOwnProperty.call(#,#)', obj ect, key), core.bool); } 205 static _hasProperty(object, key) {
185 static _getProperty(object, key) { return dart.dinvokef(/* Unimplemented unk nown name */JS, '', '#[#]', object, key); } 206 return dart.as(dart.dinvokef(/* Unimplemented unknown name */JS, 'bool', ' Object.prototype.hasOwnProperty.call(#,#)', object, key), core.bool);
186 static _setProperty(object, key, value) { return dart.dinvokef(/* Unimplemen ted unknown name */JS, '', '#[#]=#', object, key, value); } 207 }
187 static _getPropertyNames(object) { return dart.as(dart.dinvokef(/* Unimpleme nted unknown name */JS, 'JSExtendableArray', 'Object.keys(#)', object), core.Lis t); } 208 static _getProperty(object, key) {
188 static _isUnprocessed(object) { return dart.as(dart.dinvokef(/* Unimplemente d unknown name */JS, 'bool', 'typeof(#)=="undefined"', object), core.bool); } 209 return dart.dinvokef(/* Unimplemented unknown name */JS, '', '#[#]', objec t, key);
189 static _newJavaScriptObject() { return dart.dinvokef(/* Unimplemented unknow n name */JS, '=Object', 'Object.create(null)'); } 210 }
211 static _setProperty(object, key, value) {
212 return dart.dinvokef(/* Unimplemented unknown name */JS, '', '#[#]=#', obj ect, key, value);
213 }
214 static _getPropertyNames(object) {
215 return dart.as(dart.dinvokef(/* Unimplemented unknown name */JS, 'JSExtend ableArray', 'Object.keys(#)', object), core.List);
216 }
217 static _isUnprocessed(object) {
218 return dart.as(dart.dinvokef(/* Unimplemented unknown name */JS, 'bool', ' typeof(#)=="undefined"', object), core.bool);
219 }
220 static _newJavaScriptObject() {
221 return dart.dinvokef(/* Unimplemented unknown name */JS, '=Object', 'Objec t.create(null)');
222 }
190 } 223 }
191
192 class _JsonMapKeyIterable extends _internal.ListIterable { 224 class _JsonMapKeyIterable extends _internal.ListIterable {
193 _JsonMapKeyIterable(_parent) { 225 _JsonMapKeyIterable(_parent) {
194 this._parent = _parent; 226 this._parent = _parent;
195 super.ListIterable(); 227 super.ListIterable();
196 } 228 }
197 get length() { return this._parent.length; } 229 get length() {
230 return this._parent.length;
231 }
198 elementAt(index) { 232 elementAt(index) {
199 return dart.as(this._parent._isUpgraded ? this._parent.keys.elementAt(inde x) : this._parent._computeKeys().get(index), core.String); 233 return dart.as(this._parent._isUpgraded ? this._parent.keys.elementAt(inde x) : this._parent._computeKeys().get(index), core.String);
200 } 234 }
201 get iterator() { 235 get iterator() {
202 return dart.as(this._parent._isUpgraded ? this._parent.keys.iterator : thi s._parent._computeKeys().iterator, core.Iterator); 236 return dart.as(this._parent._isUpgraded ? this._parent.keys.iterator : thi s._parent._computeKeys().iterator, core.Iterator);
203 } 237 }
204 contains(key) { return this._parent.containsKey(key); } 238 contains(key) {
239 return this._parent.containsKey(key);
240 }
205 } 241 }
206
207 class _JsonDecoderSink extends _StringSinkConversionSink { 242 class _JsonDecoderSink extends _StringSinkConversionSink {
208 _JsonDecoderSink(_reviver, _sink) { 243 _JsonDecoderSink(_reviver, _sink) {
209 this._reviver = _reviver; 244 this._reviver = _reviver;
210 this._sink = _sink; 245 this._sink = _sink;
211 super._StringSinkConversionSink(new core.StringBuffer()); 246 super._StringSinkConversionSink(new core.StringBuffer());
212 } 247 }
213 close() { 248 close() {
214 super.close(); 249 super.close();
215 let buffer = dart.as(this._stringSink, core.StringBuffer); 250 let buffer = dart.as(this._stringSink, core.StringBuffer);
216 let accumulated = buffer.toString(); 251 let accumulated = buffer.toString();
217 buffer.clear(); 252 buffer.clear();
218 let decoded = _parseJson(accumulated, this._reviver); 253 let decoded = _parseJson(accumulated, this._reviver);
219 this._sink.add(decoded); 254 this._sink.add(decoded);
220 this._sink.close(); 255 this._sink.close();
221 } 256 }
222 } 257 }
223
224 let ASCII = new AsciiCodec(); 258 let ASCII = new AsciiCodec();
225 let _ASCII_MASK = 127; 259 let _ASCII_MASK = 127;
226 class AsciiCodec extends Encoding { 260 class AsciiCodec extends Encoding {
227 AsciiCodec(opt$) { 261 AsciiCodec(opt$) {
228 let allowInvalid = opt$.allowInvalid === undefined ? false : opt$.allowInv alid; 262 let allowInvalid = opt$.allowInvalid === void 0 ? false : opt$.allowInvali d;
229 this._allowInvalid = allowInvalid; 263 this._allowInvalid = allowInvalid;
230 super.Encoding(); 264 super.Encoding();
231 } 265 }
232 get name() { return "us-ascii"; } 266 get name() {
267 return "us-ascii";
268 }
233 decode(bytes, opt$) { 269 decode(bytes, opt$) {
234 let allowInvalid = opt$.allowInvalid === undefined ? null : opt$.allowInva lid; 270 let allowInvalid = opt$.allowInvalid === void 0 ? null : opt$.allowInvalid ;
235 if (allowInvalid === null) allowInvalid = this._allowInvalid; 271 if (allowInvalid === null)
272 allowInvalid = this._allowInvalid;
236 if (allowInvalid) { 273 if (allowInvalid) {
237 return new AsciiDecoder({allowInvalid: true}).convert(bytes); 274 return new AsciiDecoder({allowInvalid: true}).convert(bytes);
238 } else { 275 } else {
239 return new AsciiDecoder({allowInvalid: false}).convert(bytes); 276 return new AsciiDecoder({allowInvalid: false}).convert(bytes);
240 } 277 }
241 } 278 }
242 get encoder() { return new AsciiEncoder(); } 279 get encoder() {
243 get decoder() { return this._allowInvalid ? new AsciiDecoder({allowInvalid: true}) : new AsciiDecoder({allowInvalid: false}); } 280 return new AsciiEncoder();
281 }
282 get decoder() {
283 return this._allowInvalid ? new AsciiDecoder({allowInvalid: true}) : new A sciiDecoder({allowInvalid: false});
284 }
244 } 285 }
245
246 class _UnicodeSubsetEncoder extends Converter$(core.String, core.List$(core.in t)) { 286 class _UnicodeSubsetEncoder extends Converter$(core.String, core.List$(core.in t)) {
247 _UnicodeSubsetEncoder(_subsetMask) { 287 _UnicodeSubsetEncoder(_subsetMask) {
248 this._subsetMask = _subsetMask; 288 this._subsetMask = _subsetMask;
249 super.Converter(); 289 super.Converter();
250 } 290 }
251 convert(string, start, end) { 291 convert(string, start, end) {
252 if (start === undefined) start = 0; 292 if (start === void 0)
253 if (end === undefined) end = null; 293 start = 0;
294 if (end === void 0)
295 end = null;
254 let stringLength = string.length; 296 let stringLength = string.length;
255 core.RangeError.checkValidRange(start, end, stringLength); 297 core.RangeError.checkValidRange(start, end, stringLength);
256 if (end === null) end = stringLength; 298 if (end === null)
299 end = stringLength;
257 let length = end - start; 300 let length = end - start;
258 let result = new typed_data.Uint8List(length); 301 let result = new typed_data.Uint8List(length);
259 for (let i = 0; i < length; i++) { 302 for (let i = 0; i < length; i++) {
260 let codeUnit = string.codeUnitAt(start + i); 303 let codeUnit = string.codeUnitAt(start + i);
261 if ((codeUnit & ~this._subsetMask) !== 0) { 304 if ((codeUnit & ~this._subsetMask) !== 0) {
262 throw new core.ArgumentError("String contains invalid characters."); 305 throw new core.ArgumentError("String contains invalid characters.");
263 } 306 }
264 result.set(i, codeUnit); 307 result.set(i, codeUnit);
265 } 308 }
266 return dart.as(result, core.List$(core.int)); 309 return dart.as(result, core.List$(core.int));
267 } 310 }
268 startChunkedConversion(sink) { 311 startChunkedConversion(sink) {
269 if (!dart.is(sink, ByteConversionSink)) { 312 if (!dart.is(sink, ByteConversionSink)) {
270 sink = new ByteConversionSink.from(sink); 313 sink = new ByteConversionSink.from(sink);
271 } 314 }
272 return new _UnicodeSubsetEncoderSink(this._subsetMask, sink); 315 return new _UnicodeSubsetEncoderSink(this._subsetMask, sink);
273 } 316 }
274 bind(stream) { return dart.as(super.bind(stream), async.Stream$(core.List$(c ore.int))); } 317 bind(stream) {
318 return dart.as(super.bind(stream), async.Stream$(core.List$(core.int)));
319 }
275 } 320 }
276
277 class AsciiEncoder extends _UnicodeSubsetEncoder { 321 class AsciiEncoder extends _UnicodeSubsetEncoder {
278 AsciiEncoder() { 322 AsciiEncoder() {
279 super._UnicodeSubsetEncoder(_ASCII_MASK); 323 super._UnicodeSubsetEncoder(_ASCII_MASK);
280 } 324 }
281 } 325 }
282
283 class _UnicodeSubsetEncoderSink extends StringConversionSinkBase { 326 class _UnicodeSubsetEncoderSink extends StringConversionSinkBase {
284 _UnicodeSubsetEncoderSink(_subsetMask, _sink) { 327 _UnicodeSubsetEncoderSink(_subsetMask, _sink) {
285 this._subsetMask = _subsetMask; 328 this._subsetMask = _subsetMask;
286 this._sink = _sink; 329 this._sink = _sink;
287 super.StringConversionSinkBase(); 330 super.StringConversionSinkBase();
288 } 331 }
289 close() { 332 close() {
290 this._sink.close(); 333 this._sink.close();
291 } 334 }
292 addSlice(source, start, end, isLast) { 335 addSlice(source, start, end, isLast) {
293 core.RangeError.checkValidRange(start, end, source.length); 336 core.RangeError.checkValidRange(start, end, source.length);
294 for (let i = start; i < end; i++) { 337 for (let i = start; i < end; i++) {
295 let codeUnit = source.codeUnitAt(i); 338 let codeUnit = source.codeUnitAt(i);
296 if ((codeUnit & ~this._subsetMask) !== 0) { 339 if ((codeUnit & ~this._subsetMask) !== 0) {
297 throw new core.ArgumentError(`Source contains invalid character with c ode point: ${codeUnit}.`); 340 throw new core.ArgumentError(`Source contains invalid character with c ode point: ${codeUnit}.`);
298 } 341 }
299 } 342 }
300 this._sink.add(source.codeUnits.sublist(start, end)); 343 this._sink.add(source.codeUnits.sublist(start, end));
301 if (isLast) { 344 if (isLast) {
302 this.close(); 345 this.close();
303 } 346 }
304 } 347 }
305 } 348 }
306
307 class _UnicodeSubsetDecoder extends Converter$(core.List$(core.int), core.Stri ng) { 349 class _UnicodeSubsetDecoder extends Converter$(core.List$(core.int), core.Stri ng) {
308 _UnicodeSubsetDecoder(_allowInvalid, _subsetMask) { 350 _UnicodeSubsetDecoder(_allowInvalid, _subsetMask) {
309 this._allowInvalid = _allowInvalid; 351 this._allowInvalid = _allowInvalid;
310 this._subsetMask = _subsetMask; 352 this._subsetMask = _subsetMask;
311 super.Converter(); 353 super.Converter();
312 } 354 }
313 convert(bytes, start, end) { 355 convert(bytes, start, end) {
314 if (start === undefined) start = 0; 356 if (start === void 0)
315 if (end === undefined) end = null; 357 start = 0;
358 if (end === void 0)
359 end = null;
316 let byteCount = bytes.length; 360 let byteCount = bytes.length;
317 core.RangeError.checkValidRange(start, end, byteCount); 361 core.RangeError.checkValidRange(start, end, byteCount);
318 if (end === null) end = byteCount; 362 if (end === null)
363 end = byteCount;
319 let length = end - start; 364 let length = end - start;
320 for (let i = start; i < end; i++) { 365 for (let i = start; i < end; i++) {
321 let byte = bytes.get(i); 366 let byte = bytes.get(i);
322 if ((byte & ~this._subsetMask) !== 0) { 367 if ((byte & ~this._subsetMask) !== 0) {
323 if (!dart.notNull(this._allowInvalid)) { 368 if (!dart.notNull(this._allowInvalid)) {
324 throw new core.FormatException(`Invalid value in input: ${byte}`); 369 throw new core.FormatException(`Invalid value in input: ${byte}`);
325 } 370 }
326 return this._convertInvalid(bytes, start, end); 371 return this._convertInvalid(bytes, start, end);
327 } 372 }
328 } 373 }
329 return new core.String.fromCharCodes(bytes, start, end); 374 return new core.String.fromCharCodes(bytes, start, end);
330 } 375 }
331 _convertInvalid(bytes, start, end) { 376 _convertInvalid(bytes, start, end) {
332 let buffer = new core.StringBuffer(); 377 let buffer = new core.StringBuffer();
333 for (let i = start; i < end; i++) { 378 for (let i = start; i < end; i++) {
334 let value = bytes.get(i); 379 let value = bytes.get(i);
335 if ((value & ~this._subsetMask) !== 0) value = 65533; 380 if ((value & ~this._subsetMask) !== 0)
381 value = 65533;
336 buffer.writeCharCode(value); 382 buffer.writeCharCode(value);
337 } 383 }
338 return buffer.toString(); 384 return buffer.toString();
339 } 385 }
340 bind(stream) { return dart.as(super.bind(stream), async.Stream$(core.String) ); } 386 bind(stream) {
387 return dart.as(super.bind(stream), async.Stream$(core.String));
388 }
341 } 389 }
342
343 class AsciiDecoder extends _UnicodeSubsetDecoder { 390 class AsciiDecoder extends _UnicodeSubsetDecoder {
344 AsciiDecoder(opt$) { 391 AsciiDecoder(opt$) {
345 let allowInvalid = opt$.allowInvalid === undefined ? false : opt$.allowInv alid; 392 let allowInvalid = opt$.allowInvalid === void 0 ? false : opt$.allowInvali d;
346 super._UnicodeSubsetDecoder(allowInvalid, _ASCII_MASK); 393 super._UnicodeSubsetDecoder(allowInvalid, _ASCII_MASK);
347 } 394 }
348 startChunkedConversion(sink) { 395 startChunkedConversion(sink) {
349 let stringSink = null; 396 let stringSink = null;
350 if (dart.is(sink, StringConversionSink)) { 397 if (dart.is(sink, StringConversionSink)) {
351 stringSink = sink; 398 stringSink = sink;
352 } else { 399 } else {
353 stringSink = new StringConversionSink.from(sink); 400 stringSink = new StringConversionSink.from(sink);
354 } 401 }
355 if (this._allowInvalid) { 402 if (this._allowInvalid) {
356 return new _ErrorHandlingAsciiDecoderSink(stringSink.asUtf8Sink(false)); 403 return new _ErrorHandlingAsciiDecoderSink(stringSink.asUtf8Sink(false));
357 } else { 404 } else {
358 return new _SimpleAsciiDecoderSink(stringSink); 405 return new _SimpleAsciiDecoderSink(stringSink);
359 } 406 }
360 } 407 }
361 } 408 }
362
363 class _ErrorHandlingAsciiDecoderSink extends ByteConversionSinkBase { 409 class _ErrorHandlingAsciiDecoderSink extends ByteConversionSinkBase {
364 _ErrorHandlingAsciiDecoderSink(_utf8Sink) { 410 _ErrorHandlingAsciiDecoderSink(_utf8Sink) {
365 this._utf8Sink = _utf8Sink; 411 this._utf8Sink = _utf8Sink;
366 super.ByteConversionSinkBase(); 412 super.ByteConversionSinkBase();
367 } 413 }
368 close() { 414 close() {
369 this._utf8Sink.close(); 415 this._utf8Sink.close();
370 } 416 }
371 add(source) { 417 add(source) {
372 this.addSlice(source, 0, source.length, false); 418 this.addSlice(source, 0, source.length, false);
373 } 419 }
374 addSlice(source, start, end, isLast) { 420 addSlice(source, start, end, isLast) {
375 core.RangeError.checkValidRange(start, end, source.length); 421 core.RangeError.checkValidRange(start, end, source.length);
376 for (let i = start; i < end; i++) { 422 for (let i = start; i < end; i++) {
377 if ((source.get(i) & ~_ASCII_MASK) !== 0) { 423 if ((source.get(i) & ~_ASCII_MASK) !== 0) {
378 if (i > start) this._utf8Sink.addSlice(source, start, i, false); 424 if (i > start)
425 this._utf8Sink.addSlice(source, start, i, false);
379 this._utf8Sink.add(/* Unimplemented const */new List.from([239, 191, 1 89])); 426 this._utf8Sink.add(/* Unimplemented const */new List.from([239, 191, 1 89]));
380 start = i + 1; 427 start = i + 1;
381 } 428 }
382 } 429 }
383 if (start < end) { 430 if (start < end) {
384 this._utf8Sink.addSlice(source, start, end, isLast); 431 this._utf8Sink.addSlice(source, start, end, isLast);
385 } else if (isLast) { 432 } else if (isLast) {
386 this.close(); 433 this.close();
387 } 434 }
388 } 435 }
389 } 436 }
390
391 class _SimpleAsciiDecoderSink extends ByteConversionSinkBase { 437 class _SimpleAsciiDecoderSink extends ByteConversionSinkBase {
392 _SimpleAsciiDecoderSink(_sink) { 438 _SimpleAsciiDecoderSink(_sink) {
393 this._sink = _sink; 439 this._sink = _sink;
394 super.ByteConversionSinkBase(); 440 super.ByteConversionSinkBase();
395 } 441 }
396 close() { 442 close() {
397 this._sink.close(); 443 this._sink.close();
398 } 444 }
399 add(source) { 445 add(source) {
400 for (let i = 0; i < source.length; i++) { 446 for (let i = 0; i < source.length; i++) {
401 if ((source.get(i) & ~_ASCII_MASK) !== 0) { 447 if ((source.get(i) & ~_ASCII_MASK) !== 0) {
402 throw new core.FormatException("Source contains non-ASCII bytes."); 448 throw new core.FormatException("Source contains non-ASCII bytes.");
403 } 449 }
404 } 450 }
405 this._sink.add(new core.String.fromCharCodes(source)); 451 this._sink.add(new core.String.fromCharCodes(source));
406 } 452 }
407 addSlice(source, start, end, isLast) { 453 addSlice(source, start, end, isLast) {
408 let length = source.length; 454 let length = source.length;
409 core.RangeError.checkValidRange(start, end, length); 455 core.RangeError.checkValidRange(start, end, length);
410 if (start < end) { 456 if (start < end) {
411 if (dart.notNull(start !== 0) || dart.notNull(end !== length)) { 457 if (dart.notNull(start !== 0) || dart.notNull(end !== length)) {
412 source = source.sublist(start, end); 458 source = source.sublist(start, end);
413 } 459 }
414 this.add(source); 460 this.add(source);
415 } 461 }
416 if (isLast) this.close(); 462 if (isLast)
463 this.close();
417 } 464 }
418 } 465 }
419
420 class ByteConversionSink extends ChunkedConversionSink$(core.List$(core.int)) { 466 class ByteConversionSink extends ChunkedConversionSink$(core.List$(core.int)) {
421 ByteConversionSink() { 467 ByteConversionSink() {
422 super.ChunkedConversionSink(); 468 super.ChunkedConversionSink();
423 } 469 }
424 ByteConversionSink$withCallback(callback) { 470 ByteConversionSink$withCallback(callback) {
425 return new _ByteCallbackSink(callback); 471 return new _ByteCallbackSink(callback);
426 } 472 }
427 ByteConversionSink$from(sink) { 473 ByteConversionSink$from(sink) {
428 return new _ByteAdapterSink(sink); 474 return new _ByteAdapterSink(sink);
429 } 475 }
430 } 476 }
431 dart.defineNamedConstructor(ByteConversionSink, "withCallback"); 477 dart.defineNamedConstructor(ByteConversionSink, 'withCallback');
432 dart.defineNamedConstructor(ByteConversionSink, "from"); 478 dart.defineNamedConstructor(ByteConversionSink, 'from');
433
434 class ByteConversionSinkBase extends ByteConversionSink { 479 class ByteConversionSinkBase extends ByteConversionSink {
435 addSlice(chunk, start, end, isLast) { 480 addSlice(chunk, start, end, isLast) {
436 this.add(chunk.sublist(start, end)); 481 this.add(chunk.sublist(start, end));
437 if (isLast) this.close(); 482 if (isLast)
483 this.close();
438 } 484 }
439 } 485 }
440
441 class _ByteAdapterSink extends ByteConversionSinkBase { 486 class _ByteAdapterSink extends ByteConversionSinkBase {
442 _ByteAdapterSink(_sink) { 487 _ByteAdapterSink(_sink) {
443 this._sink = _sink; 488 this._sink = _sink;
444 super.ByteConversionSinkBase(); 489 super.ByteConversionSinkBase();
445 } 490 }
446 add(chunk) { return this._sink.add(chunk); } 491 add(chunk) {
447 close() { return this._sink.close(); } 492 return this._sink.add(chunk);
493 }
494 close() {
495 return this._sink.close();
496 }
448 } 497 }
449
450 class _ByteCallbackSink extends ByteConversionSinkBase { 498 class _ByteCallbackSink extends ByteConversionSinkBase {
451 _ByteCallbackSink(callback) { 499 _ByteCallbackSink(callback) {
452 this._buffer = new typed_data.Uint8List(_INITIAL_BUFFER_SIZE); 500 this._buffer = new typed_data.Uint8List(_INITIAL_BUFFER_SIZE);
453 this._callback = callback; 501 this._callback = callback;
454 this._bufferIndex = 0; 502 this._bufferIndex = 0;
455 super.ByteConversionSinkBase(); 503 super.ByteConversionSinkBase();
456 } 504 }
457 add(chunk) { 505 add(chunk) {
458 let freeCount = this._buffer.length - this._bufferIndex; 506 let freeCount = this._buffer.length - this._bufferIndex;
459 if (chunk.length > freeCount) { 507 if (chunk.length > freeCount) {
(...skipping 15 matching lines...) Expand all
475 v = v >> 8; 523 v = v >> 8;
476 v = v >> 16; 524 v = v >> 16;
477 v++; 525 v++;
478 return v; 526 return v;
479 } 527 }
480 close() { 528 close() {
481 this._callback(this._buffer.sublist(0, this._bufferIndex)); 529 this._callback(this._buffer.sublist(0, this._bufferIndex));
482 } 530 }
483 } 531 }
484 _ByteCallbackSink._INITIAL_BUFFER_SIZE = 1024; 532 _ByteCallbackSink._INITIAL_BUFFER_SIZE = 1024;
485
486 let ChunkedConversionSink$ = dart.generic(function(T) { 533 let ChunkedConversionSink$ = dart.generic(function(T) {
487 class ChunkedConversionSink extends dart.Object { 534 class ChunkedConversionSink extends dart.Object {
488 ChunkedConversionSink() { 535 ChunkedConversionSink() {
489 } 536 }
490 ChunkedConversionSink$withCallback(callback) { 537 ChunkedConversionSink$withCallback(callback) {
491 return new _SimpleCallbackSink(callback); 538 return new _SimpleCallbackSink(callback);
492 } 539 }
493 } 540 }
494 dart.defineNamedConstructor(ChunkedConversionSink, "withCallback"); 541 dart.defineNamedConstructor(ChunkedConversionSink, 'withCallback');
495 return ChunkedConversionSink; 542 return ChunkedConversionSink;
496 }); 543 });
497 let ChunkedConversionSink = ChunkedConversionSink$(dynamic); 544 let ChunkedConversionSink = ChunkedConversionSink$(dynamic);
498
499 let _SimpleCallbackSink$ = dart.generic(function(T) { 545 let _SimpleCallbackSink$ = dart.generic(function(T) {
500 class _SimpleCallbackSink extends ChunkedConversionSink$(T) { 546 class _SimpleCallbackSink extends ChunkedConversionSink$(T) {
501 _SimpleCallbackSink(_callback) { 547 _SimpleCallbackSink(_callback) {
502 this._accumulated = new List.from([]); 548 this._accumulated = new List.from([]);
503 this._callback = _callback; 549 this._callback = _callback;
504 super.ChunkedConversionSink(); 550 super.ChunkedConversionSink();
505 } 551 }
506 add(chunk) { 552 add(chunk) {
507 this._accumulated.add(chunk); 553 this._accumulated.add(chunk);
508 } 554 }
509 close() { 555 close() {
510 this._callback(this._accumulated); 556 this._callback(this._accumulated);
511 } 557 }
512 } 558 }
513 return _SimpleCallbackSink; 559 return _SimpleCallbackSink;
514 }); 560 });
515 let _SimpleCallbackSink = _SimpleCallbackSink$(dynamic); 561 let _SimpleCallbackSink = _SimpleCallbackSink$(dynamic);
516
517 let _EventSinkAdapter$ = dart.generic(function(T) { 562 let _EventSinkAdapter$ = dart.generic(function(T) {
518 class _EventSinkAdapter extends dart.Object { 563 class _EventSinkAdapter extends dart.Object {
519 _EventSinkAdapter(_sink) { 564 _EventSinkAdapter(_sink) {
520 this._sink = _sink; 565 this._sink = _sink;
521 } 566 }
522 add(data) { return this._sink.add(data); } 567 add(data) {
523 close() { return this._sink.close(); } 568 return this._sink.add(data);
569 }
570 close() {
571 return this._sink.close();
572 }
524 } 573 }
525 return _EventSinkAdapter; 574 return _EventSinkAdapter;
526 }); 575 });
527 let _EventSinkAdapter = _EventSinkAdapter$(dynamic); 576 let _EventSinkAdapter = _EventSinkAdapter$(dynamic);
528
529 let _ConverterStreamEventSink$ = dart.generic(function(S, T) { 577 let _ConverterStreamEventSink$ = dart.generic(function(S, T) {
530 class _ConverterStreamEventSink extends dart.Object { 578 class _ConverterStreamEventSink extends dart.Object {
531 _ConverterStreamEventSink(converter, sink) { 579 _ConverterStreamEventSink(converter, sink) {
532 this._eventSink = sink; 580 this._eventSink = sink;
533 this._chunkedSink = converter.startChunkedConversion(sink); 581 this._chunkedSink = converter.startChunkedConversion(sink);
534 } 582 }
535 add(o) { return this._chunkedSink.add(o); } 583 add(o) {
584 return this._chunkedSink.add(o);
585 }
536 addError(error, stackTrace) { 586 addError(error, stackTrace) {
537 if (stackTrace === undefined) stackTrace = null; 587 if (stackTrace === void 0)
588 stackTrace = null;
538 this._eventSink.addError(error, stackTrace); 589 this._eventSink.addError(error, stackTrace);
539 } 590 }
540 close() { return this._chunkedSink.close(); } 591 close() {
592 return this._chunkedSink.close();
593 }
541 } 594 }
542 return _ConverterStreamEventSink; 595 return _ConverterStreamEventSink;
543 }); 596 });
544 let _ConverterStreamEventSink = _ConverterStreamEventSink$(dynamic, dynamic); 597 let _ConverterStreamEventSink = _ConverterStreamEventSink$(dynamic, dynamic);
545
546 let Codec$ = dart.generic(function(S, T) { 598 let Codec$ = dart.generic(function(S, T) {
547 class Codec extends dart.Object { 599 class Codec extends dart.Object {
548 Codec() { 600 Codec() {
549 } 601 }
550 encode(input) { return this.encoder.convert(input); } 602 encode(input) {
551 decode(encoded) { return this.decoder.convert(encoded); } 603 return this.encoder.convert(input);
604 }
605 decode(encoded) {
606 return this.decoder.convert(encoded);
607 }
552 fuse(other) { 608 fuse(other) {
553 return new _FusedCodec(this, other); 609 return new _FusedCodec(this, other);
554 } 610 }
555 get inverted() { return new _InvertedCodec(this); } 611 get inverted() {
612 return new _InvertedCodec(this);
613 }
556 } 614 }
557 return Codec; 615 return Codec;
558 }); 616 });
559 let Codec = Codec$(dynamic, dynamic); 617 let Codec = Codec$(dynamic, dynamic);
560
561 let _FusedCodec$ = dart.generic(function(S, M, T) { 618 let _FusedCodec$ = dart.generic(function(S, M, T) {
562 class _FusedCodec extends Codec$(S, T) { 619 class _FusedCodec extends Codec$(S, T) {
563 get encoder() { return dart.as(this._first.encoder.fuse(this._second.encod er), Converter$(S, T)); } 620 get encoder() {
564 get decoder() { return dart.as(this._second.decoder.fuse(this._first.decod er), Converter$(T, S)); } 621 return dart.as(this._first.encoder.fuse(this._second.encoder), Converter $(S, T));
622 }
623 get decoder() {
624 return dart.as(this._second.decoder.fuse(this._first.decoder), Converter $(T, S));
625 }
565 _FusedCodec(_first, _second) { 626 _FusedCodec(_first, _second) {
566 this._first = _first; 627 this._first = _first;
567 this._second = _second; 628 this._second = _second;
568 super.Codec(); 629 super.Codec();
569 } 630 }
570 } 631 }
571 return _FusedCodec; 632 return _FusedCodec;
572 }); 633 });
573 let _FusedCodec = _FusedCodec$(dynamic, dynamic, dynamic); 634 let _FusedCodec = _FusedCodec$(dynamic, dynamic, dynamic);
574
575 let _InvertedCodec$ = dart.generic(function(T, S) { 635 let _InvertedCodec$ = dart.generic(function(T, S) {
576 class _InvertedCodec extends Codec$(T, S) { 636 class _InvertedCodec extends Codec$(T, S) {
577 _InvertedCodec(codec) { 637 _InvertedCodec(codec) {
578 this._codec = codec; 638 this._codec = codec;
579 super.Codec(); 639 super.Codec();
580 } 640 }
581 get encoder() { return this._codec.decoder; } 641 get encoder() {
582 get decoder() { return this._codec.encoder; } 642 return this._codec.decoder;
583 get inverted() { return this._codec; } 643 }
644 get decoder() {
645 return this._codec.encoder;
646 }
647 get inverted() {
648 return this._codec;
649 }
584 } 650 }
585 return _InvertedCodec; 651 return _InvertedCodec;
586 }); 652 });
587 let _InvertedCodec = _InvertedCodec$(dynamic, dynamic); 653 let _InvertedCodec = _InvertedCodec$(dynamic, dynamic);
588
589 let Converter$ = dart.generic(function(S, T) { 654 let Converter$ = dart.generic(function(S, T) {
590 class Converter extends dart.Object { 655 class Converter extends dart.Object {
591 Converter() { 656 Converter() {
592 } 657 }
593 fuse(other) { 658 fuse(other) {
594 return new _FusedConverter(this, other); 659 return new _FusedConverter(this, other);
595 } 660 }
596 startChunkedConversion(sink) { 661 startChunkedConversion(sink) {
597 throw new core.UnsupportedError(`This converter does not support chunked conversions: ${this}`); 662 throw new core.UnsupportedError(`This converter does not support chunked conversions: ${this}`);
598 } 663 }
599 bind(source) { 664 bind(source) {
600 return new async.Stream.eventTransformed(source, ((sink) => new _Convert erStreamEventSink(this, sink)).bind(this)); 665 return new async.Stream.eventTransformed(source, ((sink) => new _Convert erStreamEventSink(this, sink)).bind(this));
601 } 666 }
602 } 667 }
603 return Converter; 668 return Converter;
604 }); 669 });
605 let Converter = Converter$(dynamic, dynamic); 670 let Converter = Converter$(dynamic, dynamic);
606
607 let _FusedConverter$ = dart.generic(function(S, M, T) { 671 let _FusedConverter$ = dart.generic(function(S, M, T) {
608 class _FusedConverter extends Converter$(S, T) { 672 class _FusedConverter extends Converter$(S, T) {
609 _FusedConverter(_first, _second) { 673 _FusedConverter(_first, _second) {
610 this._first = _first; 674 this._first = _first;
611 this._second = _second; 675 this._second = _second;
612 super.Converter(); 676 super.Converter();
613 } 677 }
614 convert(input) { return dart.as(this._second.convert(this._first.convert(i nput)), T); } 678 convert(input) {
679 return dart.as(this._second.convert(this._first.convert(input)), T);
680 }
615 startChunkedConversion(sink) { 681 startChunkedConversion(sink) {
616 return this._first.startChunkedConversion(this._second.startChunkedConve rsion(sink)); 682 return this._first.startChunkedConversion(this._second.startChunkedConve rsion(sink));
617 } 683 }
618 } 684 }
619 return _FusedConverter; 685 return _FusedConverter;
620 }); 686 });
621 let _FusedConverter = _FusedConverter$(dynamic, dynamic, dynamic); 687 let _FusedConverter = _FusedConverter$(dynamic, dynamic, dynamic);
622
623 class Encoding extends Codec$(core.String, core.List$(core.int)) { 688 class Encoding extends Codec$(core.String, core.List$(core.int)) {
624 Encoding() { 689 Encoding() {
625 super.Codec(); 690 super.Codec();
626 } 691 }
627 decodeStream(byteStream) { 692 decodeStream(byteStream) {
628 return dart.as(byteStream.transform(dart.as(this.decoder, async.StreamTran sformer$(core.List$(core.int), dynamic))).fold(new core.StringBuffer(), (buffer, string) => (dart.dinvoke(buffer, "write", string), buffer)).then((buffer) => da rt.dinvoke(buffer, "toString")), async.Future$(core.String)); 693 return dart.as(byteStream.transform(dart.as(this.decoder, async.StreamTran sformer$(core.List$(core.int), dynamic))).fold(new core.StringBuffer(), (buffer, string) => dart.dinvoke(buffer, 'write', string), buffer).then((buffer) => dart .dinvoke(buffer, 'toString')), async.Future$(core.String));
629 } 694 }
630 static getByName(name) { 695 static getByName(name) {
631 if (name === null) return null; 696 if (name === null)
697 return null;
632 name = name.toLowerCase(); 698 name = name.toLowerCase();
633 return _nameToEncoding.get(name); 699 return _nameToEncoding.get(name);
634 } 700 }
635 } 701 }
636 dart.defineLazyProperties(Encoding, { 702 dart.defineLazyProperties(Encoding, {
637 get _nameToEncoding() { return dart.map({ 703 get _nameToEncoding() {
638 "iso_8859-1:1987": LATIN1, 704 return dart.map({"iso_8859-1:1987": LATIN1, "iso-ir-100": LATIN1, "iso_885 9-1": LATIN1, "iso-8859-1": LATIN1, latin1: LATIN1, l1: LATIN1, ibm819: LATIN1, cp819: LATIN1, csisolatin1: LATIN1, "iso-ir-6": ASCII, "ansi_x3.4-1968": ASCII, "ansi_x3.4-1986": ASCII, "iso_646.irv:1991": ASCII, "iso646-us": ASCII, "us-asci i": ASCII, us: ASCII, ibm367: ASCII, cp367: ASCII, csascii: ASCII, ascii: ASCII, csutf8: UTF8, "utf-8": UTF8});
639 "iso-ir-100": LATIN1, 705 },
640 "iso_8859-1": LATIN1, 706 set _nameToEncoding() {}
641 "iso-8859-1": LATIN1,
642 "latin1": LATIN1,
643 "l1": LATIN1,
644 "ibm819": LATIN1,
645 "cp819": LATIN1,
646 "csisolatin1": LATIN1,
647 "iso-ir-6": ASCII,
648 "ansi_x3.4-1968": ASCII,
649 "ansi_x3.4-1986": ASCII,
650 "iso_646.irv:1991": ASCII,
651 "iso646-us": ASCII,
652 "us-ascii": ASCII,
653 "us": ASCII,
654 "ibm367": ASCII,
655 "cp367": ASCII,
656 "csascii": ASCII,
657 "ascii": ASCII,
658 "csutf8": UTF8,
659 "utf-8": UTF8
660 }) },
661 set _nameToEncoding(x) {},
662 }); 707 });
663
664 let HTML_ESCAPE = new HtmlEscape(); 708 let HTML_ESCAPE = new HtmlEscape();
665 class HtmlEscapeMode extends dart.Object { 709 class HtmlEscapeMode extends dart.Object {
666 HtmlEscapeMode$_(_name, escapeLtGt, escapeQuot, escapeApos, escapeSlash) { 710 HtmlEscapeMode$_(_name, escapeLtGt, escapeQuot, escapeApos, escapeSlash) {
667 this._name = _name; 711 this._name = _name;
668 this.escapeLtGt = escapeLtGt; 712 this.escapeLtGt = escapeLtGt;
669 this.escapeQuot = escapeQuot; 713 this.escapeQuot = escapeQuot;
670 this.escapeApos = escapeApos; 714 this.escapeApos = escapeApos;
671 this.escapeSlash = escapeSlash; 715 this.escapeSlash = escapeSlash;
672 } 716 }
673 toString() { return this._name; } 717 toString() {
718 return this._name;
719 }
674 } 720 }
675 dart.defineNamedConstructor(HtmlEscapeMode, "_"); 721 dart.defineNamedConstructor(HtmlEscapeMode, '_');
676 HtmlEscapeMode.UNKNOWN = new HtmlEscapeMode._('unknown', true, true, true, tru e); 722 HtmlEscapeMode.UNKNOWN = new HtmlEscapeMode._('unknown', true, true, true, tru e);
677 HtmlEscapeMode.ATTRIBUTE = new HtmlEscapeMode._('attribute', false, true, fals e, false); 723 HtmlEscapeMode.ATTRIBUTE = new HtmlEscapeMode._('attribute', false, true, fals e, false);
678 HtmlEscapeMode.ELEMENT = new HtmlEscapeMode._('element', true, false, false, t rue); 724 HtmlEscapeMode.ELEMENT = new HtmlEscapeMode._('element', true, false, false, t rue);
679
680 class HtmlEscape extends Converter$(core.String, core.String) { 725 class HtmlEscape extends Converter$(core.String, core.String) {
681 HtmlEscape(mode) { 726 HtmlEscape(mode) {
682 if (mode === undefined) mode = HtmlEscapeMode.UNKNOWN; 727 if (mode === void 0)
728 mode = HtmlEscapeMode.UNKNOWN;
683 this.mode = mode; 729 this.mode = mode;
684 super.Converter(); 730 super.Converter();
685 } 731 }
686 convert(text) { 732 convert(text) {
687 let val = this._convert(text, 0, text.length); 733 let val = this._convert(text, 0, text.length);
688 return val === null ? text : val; 734 return val === null ? text : val;
689 } 735 }
690 _convert(text, start, end) { 736 _convert(text, start, end) {
691 let result = null; 737 let result = null;
692 for (let i = start; i < end; i++) { 738 for (let i = start; i < end; i++) {
693 let ch = text.get(i); 739 let ch = text.get(i);
694 let replace = null; 740 let replace = null;
695 switch (ch) { 741 switch (ch) {
696 case '&': 742 case '&':
697 replace = '&amp;'; 743 replace = '&amp;';
698 break; 744 break;
699 case ' ': 745 case ' ':
700 replace = '&nbsp;'; 746 replace = '&nbsp;';
701 break; 747 break;
702 case '"': 748 case '"':
703 if (this.mode.escapeQuot) replace = '&quot;'; 749 if (this.mode.escapeQuot)
750 replace = '&quot;';
704 break; 751 break;
705 case "'": 752 case "'":
706 if (this.mode.escapeApos) replace = '&#x27;'; 753 if (this.mode.escapeApos)
754 replace = '&#x27;';
707 break; 755 break;
708 case '<': 756 case '<':
709 if (this.mode.escapeLtGt) replace = '&lt;'; 757 if (this.mode.escapeLtGt)
758 replace = '&lt;';
710 break; 759 break;
711 case '>': 760 case '>':
712 if (this.mode.escapeLtGt) replace = '&gt;'; 761 if (this.mode.escapeLtGt)
762 replace = '&gt;';
713 break; 763 break;
714 case '/': 764 case '/':
715 if (this.mode.escapeSlash) replace = '&#x2F;'; 765 if (this.mode.escapeSlash)
766 replace = '&#x2F;';
716 break; 767 break;
717 } 768 }
718 if (replace !== null) { 769 if (replace !== null) {
719 if (result === null) result = new core.StringBuffer(text.substring(sta rt, i)); 770 if (result === null)
771 result = new core.StringBuffer(text.substring(start, i));
720 result.write(replace); 772 result.write(replace);
721 } else if (result !== null) { 773 } else if (result !== null) {
722 result.write(ch); 774 result.write(ch);
723 } 775 }
724 } 776 }
725 return dart.as(result !== null ? result.toString() : null, core.String); 777 return dart.as(result !== null ? result.toString() : null, core.String);
726 } 778 }
727 startChunkedConversion(sink) { 779 startChunkedConversion(sink) {
728 if (!dart.is(sink, StringConversionSink)) { 780 if (!dart.is(sink, StringConversionSink)) {
729 sink = new StringConversionSink.from(sink); 781 sink = new StringConversionSink.from(sink);
730 } 782 }
731 return new _HtmlEscapeSink(this, sink); 783 return new _HtmlEscapeSink(this, sink);
732 } 784 }
733 } 785 }
734
735 class _HtmlEscapeSink extends StringConversionSinkBase { 786 class _HtmlEscapeSink extends StringConversionSinkBase {
736 _HtmlEscapeSink(_escape, _sink) { 787 _HtmlEscapeSink(_escape, _sink) {
737 this._escape = _escape; 788 this._escape = _escape;
738 this._sink = _sink; 789 this._sink = _sink;
739 super.StringConversionSinkBase(); 790 super.StringConversionSinkBase();
740 } 791 }
741 addSlice(chunk, start, end, isLast) { 792 addSlice(chunk, start, end, isLast) {
742 let val = this._escape._convert(chunk, start, end); 793 let val = this._escape._convert(chunk, start, end);
743 if (val === null) { 794 if (val === null) {
744 this._sink.addSlice(chunk, start, end, isLast); 795 this._sink.addSlice(chunk, start, end, isLast);
745 } else { 796 } else {
746 this._sink.add(val); 797 this._sink.add(val);
747 if (isLast) this._sink.close(); 798 if (isLast)
799 this._sink.close();
748 } 800 }
749 } 801 }
750 close() { return this._sink.close(); } 802 close() {
803 return this._sink.close();
804 }
751 } 805 }
752
753 class JsonUnsupportedObjectError extends core.Error { 806 class JsonUnsupportedObjectError extends core.Error {
754 JsonUnsupportedObjectError(unsupportedObject, opt$) { 807 JsonUnsupportedObjectError(unsupportedObject, opt$) {
755 let cause = opt$.cause === undefined ? null : opt$.cause; 808 let cause = opt$.cause === void 0 ? null : opt$.cause;
756 this.unsupportedObject = unsupportedObject; 809 this.unsupportedObject = unsupportedObject;
757 this.cause = cause; 810 this.cause = cause;
758 super.Error(); 811 super.Error();
759 } 812 }
760 toString() { 813 toString() {
761 if (this.cause !== null) { 814 if (this.cause !== null) {
762 return "Converting object to an encodable object failed."; 815 return "Converting object to an encodable object failed.";
763 } else { 816 } else {
764 return "Converting object did not return an encodable object."; 817 return "Converting object did not return an encodable object.";
765 } 818 }
766 } 819 }
767 } 820 }
768
769 class JsonCyclicError extends JsonUnsupportedObjectError { 821 class JsonCyclicError extends JsonUnsupportedObjectError {
770 JsonCyclicError(object) { 822 JsonCyclicError(object) {
771 super.JsonUnsupportedObjectError(object); 823 super.JsonUnsupportedObjectError(object);
772 } 824 }
773 toString() { return "Cyclic error in JSON stringify"; } 825 toString() {
826 return "Cyclic error in JSON stringify";
827 }
774 } 828 }
775
776 let JSON = new JsonCodec(); 829 let JSON = new JsonCodec();
777 class JsonCodec extends Codec$(core.Object, core.String) { 830 class JsonCodec extends Codec$(core.Object, core.String) {
778 JsonCodec(opt$) { 831 JsonCodec(opt$) {
779 let reviver = opt$.reviver === undefined ? null : opt$.reviver; 832 let reviver = opt$.reviver === void 0 ? null : opt$.reviver;
780 let toEncodable = opt$.toEncodable === undefined ? null : opt$.toEncodable ; 833 let toEncodable = opt$.toEncodable === void 0 ? null : opt$.toEncodable;
781 this._reviver = reviver; 834 this._reviver = reviver;
782 this._toEncodable = toEncodable; 835 this._toEncodable = toEncodable;
783 super.Codec(); 836 super.Codec();
784 } 837 }
785 JsonCodec$withReviver(reviver) { 838 JsonCodec$withReviver(reviver) {
786 withReviver.call(this, {reviver: reviver}); 839 this.JsonCodec({reviver: reviver});
787 } 840 }
788 decode(source, opt$) { 841 decode(source, opt$) {
789 let reviver = opt$.reviver === undefined ? null : opt$.reviver; 842 let reviver = opt$.reviver === void 0 ? null : opt$.reviver;
790 if (reviver === null) reviver = this._reviver; 843 if (reviver === null)
791 if (reviver === null) return this.decoder.convert(source); 844 reviver = this._reviver;
845 if (reviver === null)
846 return this.decoder.convert(source);
792 return new JsonDecoder(reviver).convert(source); 847 return new JsonDecoder(reviver).convert(source);
793 } 848 }
794 encode(value, opt$) { 849 encode(value, opt$) {
795 let toEncodable = opt$.toEncodable === undefined ? null : opt$.toEncodable ; 850 let toEncodable = opt$.toEncodable === void 0 ? null : opt$.toEncodable;
796 if (toEncodable === null) toEncodable = this._toEncodable; 851 if (toEncodable === null)
797 if (toEncodable === null) return this.encoder.convert(value); 852 toEncodable = this._toEncodable;
853 if (toEncodable === null)
854 return this.encoder.convert(value);
798 return new JsonEncoder(toEncodable).convert(value); 855 return new JsonEncoder(toEncodable).convert(value);
799 } 856 }
800 get encoder() { 857 get encoder() {
801 if (this._toEncodable === null) return new JsonEncoder(); 858 if (this._toEncodable === null)
859 return new JsonEncoder();
802 return new JsonEncoder(this._toEncodable); 860 return new JsonEncoder(this._toEncodable);
803 } 861 }
804 get decoder() { 862 get decoder() {
805 if (this._reviver === null) return new JsonDecoder(); 863 if (this._reviver === null)
864 return new JsonDecoder();
806 return new JsonDecoder(this._reviver); 865 return new JsonDecoder(this._reviver);
807 } 866 }
808 } 867 }
809 dart.defineNamedConstructor(JsonCodec, "withReviver"); 868 dart.defineNamedConstructor(JsonCodec, 'withReviver');
810
811 class JsonEncoder extends Converter$(core.Object, core.String) { 869 class JsonEncoder extends Converter$(core.Object, core.String) {
812 JsonEncoder(toEncodable) { 870 JsonEncoder(toEncodable) {
813 if (toEncodable === undefined) toEncodable = null; 871 if (toEncodable === void 0)
872 toEncodable = null;
814 this.indent = null; 873 this.indent = null;
815 this._toEncodable = toEncodable; 874 this._toEncodable = toEncodable;
816 super.Converter(); 875 super.Converter();
817 } 876 }
818 JsonEncoder$withIndent(indent, toEncodable) { 877 JsonEncoder$withIndent(indent, toEncodable) {
819 if (toEncodable === undefined) toEncodable = null; 878 if (toEncodable === void 0)
879 toEncodable = null;
820 this.indent = indent; 880 this.indent = indent;
821 this._toEncodable = toEncodable; 881 this._toEncodable = toEncodable;
822 super.Converter(); 882 super.Converter();
823 } 883 }
824 convert(object) { return _JsonStringStringifier.stringify(object, dart.as(th is._toEncodable, /* Unimplemented type (dynamic) → dynamic */), this.indent); } 884 convert(object) {
885 return _JsonStringStringifier.stringify(object, dart.as(this._toEncodable, dart.throw_("Unimplemented type (dynamic) → dynamic")), this.indent);
886 }
825 startChunkedConversion(sink) { 887 startChunkedConversion(sink) {
826 if (!dart.is(sink, StringConversionSink)) { 888 if (!dart.is(sink, StringConversionSink)) {
827 sink = new StringConversionSink.from(sink); 889 sink = new StringConversionSink.from(sink);
828 } else if (dart.is(sink, _Utf8EncoderSink)) { 890 } else if (dart.is(sink, _Utf8EncoderSink)) {
829 return new _JsonUtf8EncoderSink(sink._sink, this._toEncodable, JsonUtf8E ncoder._utf8Encode(this.indent), JsonUtf8Encoder.DEFAULT_BUFFER_SIZE); 891 return new _JsonUtf8EncoderSink(sink._sink, this._toEncodable, JsonUtf8E ncoder._utf8Encode(this.indent), JsonUtf8Encoder.DEFAULT_BUFFER_SIZE);
830 } 892 }
831 return new _JsonEncoderSink(sink, this._toEncodable, this.indent); 893 return new _JsonEncoderSink(sink, this._toEncodable, this.indent);
832 } 894 }
833 bind(stream) { return dart.as(super.bind(stream), async.Stream$(core.String) ); } 895 bind(stream) {
896 return dart.as(super.bind(stream), async.Stream$(core.String));
897 }
834 fuse(other) { 898 fuse(other) {
835 if (dart.is(other, Utf8Encoder)) { 899 if (dart.is(other, Utf8Encoder)) {
836 return new JsonUtf8Encoder(this.indent, this._toEncodable); 900 return new JsonUtf8Encoder(this.indent, this._toEncodable);
837 } 901 }
838 return super.fuse(other); 902 return super.fuse(other);
839 } 903 }
840 } 904 }
841 dart.defineNamedConstructor(JsonEncoder, "withIndent"); 905 dart.defineNamedConstructor(JsonEncoder, 'withIndent');
842
843 class JsonUtf8Encoder extends Converter$(core.Object, core.List$(core.int)) { 906 class JsonUtf8Encoder extends Converter$(core.Object, core.List$(core.int)) {
844 JsonUtf8Encoder(indent, toEncodable, bufferSize) { 907 JsonUtf8Encoder(indent, toEncodable, bufferSize) {
845 if (indent === undefined) indent = null; 908 if (indent === void 0)
846 if (toEncodable === undefined) toEncodable = null; 909 indent = null;
847 if (bufferSize === undefined) bufferSize = DEFAULT_BUFFER_SIZE; 910 if (toEncodable === void 0)
911 toEncodable = null;
912 if (bufferSize === void 0)
913 bufferSize = DEFAULT_BUFFER_SIZE;
848 this._indent = _utf8Encode(indent); 914 this._indent = _utf8Encode(indent);
849 this._toEncodable = toEncodable; 915 this._toEncodable = toEncodable;
850 this._bufferSize = bufferSize; 916 this._bufferSize = bufferSize;
851 super.Converter(); 917 super.Converter();
852 } 918 }
853 static _utf8Encode(string) { 919 static _utf8Encode(string) {
854 if (string === null) return null; 920 if (string === null)
855 if (string.isEmpty) return new typed_data.Uint8List(0); 921 return null;
922 if (string.isEmpty)
923 return new typed_data.Uint8List(0);
856 checkAscii: { 924 checkAscii: {
857 for (let i = 0; i < string.length; i++) { 925 for (let i = 0; i < string.length; i++) {
858 if (string.codeUnitAt(i) >= 128) break checkAscii; 926 if (string.codeUnitAt(i) >= 128)
927 break checkAscii;
859 } 928 }
860 return string.codeUnits; 929 return string.codeUnits;
861 } 930 }
862 return UTF8.encode(string); 931 return UTF8.encode(string);
863 } 932 }
864 convert(object) { 933 convert(object) {
865 let bytes = dart.as(new List.from([]), core.List$(core.List$(core.int))); 934 let bytes = dart.as(new List.from([]), core.List$(core.List$(core.int)));
866 // Function addChunk: (Uint8List, int, int) → void 935 // Function addChunk: (Uint8List, int, int) → void
867 function addChunk(chunk, start, end) { 936 function addChunk(chunk, start, end) {
868 if (dart.notNull(start > 0) || dart.notNull(end < chunk.length)) { 937 if (dart.notNull(start > 0) || dart.notNull(end < chunk.length)) {
869 let length = end - start; 938 let length = end - start;
870 chunk = new typed_data.Uint8List.view(chunk.buffer, chunk.offsetInByte s + start, length); 939 chunk = new typed_data.Uint8List.view(chunk.buffer, chunk.offsetInByte s + start, length);
871 } 940 }
872 bytes.add(chunk); 941 bytes.add(chunk);
873 } 942 }
874 _JsonUtf8Stringifier.stringify(object, this._indent, dart.as(this._toEncod able, /* Unimplemented type (Object) → dynamic */), this._bufferSize, addChunk); 943 _JsonUtf8Stringifier.stringify(object, this._indent, dart.as(this._toEncod able, dart.throw_("Unimplemented type (Object) → dynamic")), this._bufferSize, a ddChunk);
875 if (bytes.length === 1) return bytes.get(0); 944 if (bytes.length === 1)
945 return bytes.get(0);
876 let length = 0; 946 let length = 0;
877 for (let i = 0; i < bytes.length; i++) { 947 for (let i = 0; i < bytes.length; i++) {
878 length = bytes.get(i).length; 948 length = bytes.get(i).length;
879 } 949 }
880 let result = new typed_data.Uint8List(length); 950 let result = new typed_data.Uint8List(length);
881 for (let i = 0, offset = 0; i < bytes.length; i++) { 951 for (let i = 0, offset = 0; i < bytes.length; i++) {
882 let byteList = bytes.get(i); 952 let byteList = bytes.get(i);
883 let end = offset + byteList.length; 953 let end = offset + byteList.length;
884 result.setRange(offset, end, byteList); 954 result.setRange(offset, end, byteList);
885 offset = end; 955 offset = end;
(...skipping 10 matching lines...) Expand all
896 return new _JsonUtf8EncoderSink(byteSink, this._toEncodable, this._indent, this._bufferSize); 966 return new _JsonUtf8EncoderSink(byteSink, this._toEncodable, this._indent, this._bufferSize);
897 } 967 }
898 bind(stream) { 968 bind(stream) {
899 return dart.as(super.bind(stream), async.Stream$(core.List$(core.int))); 969 return dart.as(super.bind(stream), async.Stream$(core.List$(core.int)));
900 } 970 }
901 fuse(other) { 971 fuse(other) {
902 return super.fuse(other); 972 return super.fuse(other);
903 } 973 }
904 } 974 }
905 JsonUtf8Encoder.DEFAULT_BUFFER_SIZE = 256; 975 JsonUtf8Encoder.DEFAULT_BUFFER_SIZE = 256;
906
907 class _JsonEncoderSink extends ChunkedConversionSink$(core.Object) { 976 class _JsonEncoderSink extends ChunkedConversionSink$(core.Object) {
908 _JsonEncoderSink(_sink, _toEncodable, _indent) { 977 _JsonEncoderSink(_sink, _toEncodable, _indent) {
909 this._sink = _sink; 978 this._sink = _sink;
910 this._toEncodable = _toEncodable; 979 this._toEncodable = _toEncodable;
911 this._indent = _indent; 980 this._indent = _indent;
912 this._isDone = false; 981 this._isDone = false;
913 super.ChunkedConversionSink(); 982 super.ChunkedConversionSink();
914 } 983 }
915 add(o) { 984 add(o) {
916 if (this._isDone) { 985 if (this._isDone) {
917 throw new core.StateError("Only one call to add allowed"); 986 throw new core.StateError("Only one call to add allowed");
918 } 987 }
919 this._isDone = true; 988 this._isDone = true;
920 let stringSink = this._sink.asStringSink(); 989 let stringSink = this._sink.asStringSink();
921 _JsonStringStringifier.printOn(o, stringSink, dart.as(this._toEncodable, / * Unimplemented type (dynamic) → dynamic */), this._indent); 990 _JsonStringStringifier.printOn(o, stringSink, dart.as(this._toEncodable, d art.throw_("Unimplemented type (dynamic) → dynamic")), this._indent);
922 stringSink.close(); 991 stringSink.close();
923 } 992 }
924 close() { 993 close() {}
925 }
926 } 994 }
927
928 class _JsonUtf8EncoderSink extends ChunkedConversionSink$(core.Object) { 995 class _JsonUtf8EncoderSink extends ChunkedConversionSink$(core.Object) {
929 _JsonUtf8EncoderSink(_sink, _toEncodable, _indent, _bufferSize) { 996 _JsonUtf8EncoderSink(_sink, _toEncodable, _indent, _bufferSize) {
930 this._sink = _sink; 997 this._sink = _sink;
931 this._toEncodable = _toEncodable; 998 this._toEncodable = _toEncodable;
932 this._indent = _indent; 999 this._indent = _indent;
933 this._bufferSize = _bufferSize; 1000 this._bufferSize = _bufferSize;
934 this._isDone = false; 1001 this._isDone = false;
935 super.ChunkedConversionSink(); 1002 super.ChunkedConversionSink();
936 } 1003 }
937 _addChunk(chunk, start, end) { 1004 _addChunk(chunk, start, end) {
938 this._sink.addSlice(chunk, start, end, false); 1005 this._sink.addSlice(chunk, start, end, false);
939 } 1006 }
940 add(object) { 1007 add(object) {
941 if (this._isDone) { 1008 if (this._isDone) {
942 throw new core.StateError("Only one call to add allowed"); 1009 throw new core.StateError("Only one call to add allowed");
943 } 1010 }
944 this._isDone = true; 1011 this._isDone = true;
945 _JsonUtf8Stringifier.stringify(object, this._indent, dart.as(this._toEncod able, /* Unimplemented type (Object) → dynamic */), this._bufferSize, this._addC hunk); 1012 _JsonUtf8Stringifier.stringify(object, this._indent, dart.as(this._toEncod able, dart.throw_("Unimplemented type (Object) → dynamic")), this._bufferSize, t his._addChunk);
946 this._sink.close(); 1013 this._sink.close();
947 } 1014 }
948 close() { 1015 close() {
949 if (!dart.notNull(this._isDone)) { 1016 if (!dart.notNull(this._isDone)) {
950 this._isDone = true; 1017 this._isDone = true;
951 this._sink.close(); 1018 this._sink.close();
952 } 1019 }
953 } 1020 }
954 } 1021 }
955
956 class JsonDecoder extends Converter$(core.String, core.Object) { 1022 class JsonDecoder extends Converter$(core.String, core.Object) {
957 JsonDecoder(reviver) { 1023 JsonDecoder(reviver) {
958 if (reviver === undefined) reviver = null; 1024 if (reviver === void 0)
1025 reviver = null;
959 this._reviver = reviver; 1026 this._reviver = reviver;
960 super.Converter(); 1027 super.Converter();
961 } 1028 }
962 convert(input) { return _parseJson(input, this._reviver); } 1029 convert(input) {
1030 return _parseJson(input, this._reviver);
1031 }
963 startChunkedConversion(sink) { 1032 startChunkedConversion(sink) {
964 return new _JsonDecoderSink(this._reviver, sink); 1033 return new _JsonDecoderSink(this._reviver, sink);
965 } 1034 }
966 bind(stream) { return dart.as(super.bind(stream), async.Stream$(core.Object) ); } 1035 bind(stream) {
1036 return dart.as(super.bind(stream), async.Stream$(core.Object));
1037 }
967 } 1038 }
968
969 // Function _parseJson: (String, (dynamic, dynamic) → dynamic) → dynamic 1039 // Function _parseJson: (String, (dynamic, dynamic) → dynamic) → dynamic
970 function _parseJson(source, reviver) { 1040 function _parseJson(source, reviver) {
971 if (!(typeof source == "string")) throw new core.ArgumentError(source); 1041 if (!(typeof source == string))
1042 throw new core.ArgumentError(source);
972 let parsed = null; 1043 let parsed = null;
973 try { 1044 try {
974 parsed = dart.dinvokef(/* Unimplemented unknown name */JS, '=Object|JSExte ndableArray|Null|bool|num|String', 'JSON.parse(#)', source); 1045 parsed = dart.dinvokef(/* Unimplemented unknown name */JS, '=Object|JSExte ndableArray|Null|bool|num|String', 'JSON.parse(#)', source);
975 } 1046 } catch (e) {
976 catch (e) {
977 throw new core.FormatException(dart.dinvokef(/* Unimplemented unknown name */JS, 'String', 'String(#)', e)); 1047 throw new core.FormatException(dart.dinvokef(/* Unimplemented unknown name */JS, 'String', 'String(#)', e));
978 } 1048 }
1049
979 if (reviver === null) { 1050 if (reviver === null) {
980 return _convertJsonToDartLazy(parsed); 1051 return _convertJsonToDartLazy(parsed);
981 } else { 1052 } else {
982 return _convertJsonToDart(parsed, reviver); 1053 return _convertJsonToDart(parsed, reviver);
983 } 1054 }
984 } 1055 }
985
986 // Function _defaultToEncodable: (dynamic) → Object 1056 // Function _defaultToEncodable: (dynamic) → Object
987 function _defaultToEncodable(object) { return dart.dinvoke(object, "toJson"); } 1057 function _defaultToEncodable(object) {
988 1058 return dart.dinvoke(object, 'toJson');
1059 }
989 class _JsonStringifier extends dart.Object { 1060 class _JsonStringifier extends dart.Object {
990 _JsonStringifier(_toEncodable) { 1061 _JsonStringifier(_toEncodable) {
991 this._seen = new core.List(); 1062 this._seen = new core.List();
992 this._toEncodable = (_toEncodable !== null) ? _toEncodable : _defaultToEnc odable; 1063 this._toEncodable = _toEncodable !== null ? _toEncodable : _defaultToEncod able;
993 } 1064 }
994 static hexDigit(x) { return x < 10 ? 48 + x : 87 + x; } 1065 static hexDigit(x) {
1066 return x < 10 ? 48 + x : 87 + x;
1067 }
995 writeStringContent(s) { 1068 writeStringContent(s) {
996 let offset = 0; 1069 let offset = 0;
997 let length = s.length; 1070 let length = s.length;
998 for (let i = 0; i < length; i++) { 1071 for (let i = 0; i < length; i++) {
999 let charCode = s.codeUnitAt(i); 1072 let charCode = s.codeUnitAt(i);
1000 if (charCode > BACKSLASH) continue; 1073 if (charCode > BACKSLASH)
1074 continue;
1001 if (charCode < 32) { 1075 if (charCode < 32) {
1002 if (i > offset) this.writeStringSlice(s, offset, i); 1076 if (i > offset)
1077 this.writeStringSlice(s, offset, i);
1003 offset = i + 1; 1078 offset = i + 1;
1004 this.writeCharCode(BACKSLASH); 1079 this.writeCharCode(BACKSLASH);
1005 switch (charCode) { 1080 switch (charCode) {
1006 case BACKSPACE: 1081 case BACKSPACE:
1007 this.writeCharCode(CHAR_b); 1082 this.writeCharCode(CHAR_b);
1008 break; 1083 break;
1009 case TAB: 1084 case TAB:
1010 this.writeCharCode(CHAR_t); 1085 this.writeCharCode(CHAR_t);
1011 break; 1086 break;
1012 case NEWLINE: 1087 case NEWLINE:
1013 this.writeCharCode(CHAR_n); 1088 this.writeCharCode(CHAR_n);
1014 break; 1089 break;
1015 case FORM_FEED: 1090 case FORM_FEED:
1016 this.writeCharCode(CHAR_f); 1091 this.writeCharCode(CHAR_f);
1017 break; 1092 break;
1018 case CARRIAGE_RETURN: 1093 case CARRIAGE_RETURN:
1019 this.writeCharCode(CHAR_r); 1094 this.writeCharCode(CHAR_r);
1020 break; 1095 break;
1021 default: 1096 default:
1022 this.writeCharCode(CHAR_u); 1097 this.writeCharCode(CHAR_u);
1023 this.writeCharCode(CHAR_0); 1098 this.writeCharCode(CHAR_0);
1024 this.writeCharCode(CHAR_0); 1099 this.writeCharCode(CHAR_0);
1025 this.writeCharCode(hexDigit((charCode >> 4) & 15)); 1100 this.writeCharCode(hexDigit(charCode >> 4 & 15));
1026 this.writeCharCode(hexDigit(charCode & 15)); 1101 this.writeCharCode(hexDigit(charCode & 15));
1027 break; 1102 break;
1028 } 1103 }
1029 } else if (dart.notNull(charCode === QUOTE) || dart.notNull(charCode === BACKSLASH)) { 1104 } else if (dart.notNull(charCode === QUOTE) || dart.notNull(charCode === BACKSLASH)) {
1030 if (i > offset) this.writeStringSlice(s, offset, i); 1105 if (i > offset)
1106 this.writeStringSlice(s, offset, i);
1031 offset = i + 1; 1107 offset = i + 1;
1032 this.writeCharCode(BACKSLASH); 1108 this.writeCharCode(BACKSLASH);
1033 this.writeCharCode(charCode); 1109 this.writeCharCode(charCode);
1034 } 1110 }
1035 } 1111 }
1036 if (offset === 0) { 1112 if (offset === 0) {
1037 this.writeString(s); 1113 this.writeString(s);
1038 } else if (offset < length) { 1114 } else if (offset < length) {
1039 this.writeStringSlice(s, offset, length); 1115 this.writeStringSlice(s, offset, length);
1040 } 1116 }
1041 } 1117 }
1042 _checkCycle(object) { 1118 _checkCycle(object) {
1043 for (let i = 0; i < this._seen.length; i++) { 1119 for (let i = 0; i < this._seen.length; i++) {
1044 if (core.identical(object, this._seen.get(i))) { 1120 if (core.identical(object, this._seen.get(i))) {
1045 throw new JsonCyclicError(object); 1121 throw new JsonCyclicError(object);
1046 } 1122 }
1047 } 1123 }
1048 this._seen.add(object); 1124 this._seen.add(object);
1049 } 1125 }
1050 _removeSeen(object) { 1126 _removeSeen(object) {
1051 dart.assert(!dart.notNull(this._seen.isEmpty)); 1127 dart.assert(!dart.notNull(this._seen.isEmpty));
1052 dart.assert(core.identical(this._seen.last, object)); 1128 dart.assert(core.identical(this._seen.last, object));
1053 this._seen.removeLast(); 1129 this._seen.removeLast();
1054 } 1130 }
1055 writeObject(object) { 1131 writeObject(object) {
1056 if (this.writeJsonValue(object)) return; 1132 if (this.writeJsonValue(object))
1133 return;
1057 this._checkCycle(object); 1134 this._checkCycle(object);
1058 try { 1135 try {
1059 let customJson = dart.dinvokef(this._toEncodable, object); 1136 let customJson = dart.dinvokef(this._toEncodable, object);
1060 if (!dart.notNull(this.writeJsonValue(customJson))) { 1137 if (!dart.notNull(this.writeJsonValue(customJson))) {
1061 throw new JsonUnsupportedObjectError(object); 1138 throw new JsonUnsupportedObjectError(object);
1062 } 1139 }
1063 this._removeSeen(object); 1140 this._removeSeen(object);
1064 } 1141 } catch (e) {
1065 catch (e) {
1066 throw new JsonUnsupportedObjectError(object, {cause: e}); 1142 throw new JsonUnsupportedObjectError(object, {cause: e});
1067 } 1143 }
1144
1068 } 1145 }
1069 writeJsonValue(object) { 1146 writeJsonValue(object) {
1070 if (dart.is(object, core.num)) { 1147 if (dart.is(object, core.num)) {
1071 if (/* Unimplemented postfix operator: !object.isFinite */) return false ; 1148 if (dart.throw_("Unimplemented PrefixExpression: !object.isFinite"))
1149 return false;
1072 this.writeNumber(dart.as(object, core.num)); 1150 this.writeNumber(dart.as(object, core.num));
1073 return true; 1151 return true;
1074 } else if (core.identical(object, true)) { 1152 } else if (core.identical(object, true)) {
1075 this.writeString('true'); 1153 this.writeString('true');
1076 return true; 1154 return true;
1077 } else if (core.identical(object, false)) { 1155 } else if (core.identical(object, false)) {
1078 this.writeString('false'); 1156 this.writeString('false');
1079 return true; 1157 return true;
1080 } else if (object === null) { 1158 } else if (object === null) {
1081 this.writeString('null'); 1159 this.writeString('null');
1082 return true; 1160 return true;
1083 } else if (typeof object == "string") { 1161 } else if (typeof object == string) {
1084 this.writeString('"'); 1162 this.writeString('"');
1085 this.writeStringContent(dart.as(object, core.String)); 1163 this.writeStringContent(dart.as(object, core.String));
1086 this.writeString('"'); 1164 this.writeString('"');
1087 return true; 1165 return true;
1088 } else if (dart.is(object, core.List)) { 1166 } else if (dart.is(object, core.List)) {
1089 this._checkCycle(object); 1167 this._checkCycle(object);
1090 this.writeList(dart.as(object, core.List)); 1168 this.writeList(dart.as(object, core.List));
1091 this._removeSeen(object); 1169 this._removeSeen(object);
1092 return true; 1170 return true;
1093 } else if (dart.is(object, core.Map)) { 1171 } else if (dart.is(object, core.Map)) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 _JsonStringifier.FORM_FEED = 12; 1208 _JsonStringifier.FORM_FEED = 12;
1131 _JsonStringifier.QUOTE = 34; 1209 _JsonStringifier.QUOTE = 34;
1132 _JsonStringifier.CHAR_0 = 48; 1210 _JsonStringifier.CHAR_0 = 48;
1133 _JsonStringifier.BACKSLASH = 92; 1211 _JsonStringifier.BACKSLASH = 92;
1134 _JsonStringifier.CHAR_b = 98; 1212 _JsonStringifier.CHAR_b = 98;
1135 _JsonStringifier.CHAR_f = 102; 1213 _JsonStringifier.CHAR_f = 102;
1136 _JsonStringifier.CHAR_n = 110; 1214 _JsonStringifier.CHAR_n = 110;
1137 _JsonStringifier.CHAR_r = 114; 1215 _JsonStringifier.CHAR_r = 114;
1138 _JsonStringifier.CHAR_t = 116; 1216 _JsonStringifier.CHAR_t = 116;
1139 _JsonStringifier.CHAR_u = 117; 1217 _JsonStringifier.CHAR_u = 117;
1140
1141 class _JsonPrettyPrintMixin extends dart.Object { 1218 class _JsonPrettyPrintMixin extends dart.Object {
1142 _JsonPrettyPrintMixin() { 1219 _JsonPrettyPrintMixin() {
1143 this._indentLevel = 0; 1220 this._indentLevel = 0;
1144 } 1221 }
1145 writeList(list) { 1222 writeList(list) {
1146 if (list.isEmpty) { 1223 if (list.isEmpty) {
1147 this.writeString('[]'); 1224 this.writeString('[]');
1148 } else { 1225 } else {
1149 this.writeString('[\n'); 1226 this.writeString('[\n');
1150 this._indentLevel++; 1227 this._indentLevel++;
(...skipping 20 matching lines...) Expand all
1171 map.forEach(dart.as(((key, value) => { 1248 map.forEach(dart.as(((key, value) => {
1172 if (!dart.notNull(first)) { 1249 if (!dart.notNull(first)) {
1173 this.writeString(",\n"); 1250 this.writeString(",\n");
1174 } 1251 }
1175 this.writeIndentation(this._indentLevel); 1252 this.writeIndentation(this._indentLevel);
1176 this.writeString('"'); 1253 this.writeString('"');
1177 this.writeStringContent(key); 1254 this.writeStringContent(key);
1178 this.writeString('": '); 1255 this.writeString('": ');
1179 this.writeObject(value); 1256 this.writeObject(value);
1180 first = false; 1257 first = false;
1181 }).bind(this), /* Unimplemented type (dynamic, dynamic) → void */)); 1258 }).bind(this), dart.throw_("Unimplemented type (dynamic, dynamic) → void ")));
1182 this.writeString('\n'); 1259 this.writeString('\n');
1183 this._indentLevel--; 1260 this._indentLevel--;
1184 this.writeIndentation(this._indentLevel); 1261 this.writeIndentation(this._indentLevel);
1185 this.writeString('}'); 1262 this.writeString('}');
1186 } 1263 }
1187 } 1264 }
1188 } 1265 }
1189
1190 class _JsonStringStringifier extends _JsonStringifier { 1266 class _JsonStringStringifier extends _JsonStringifier {
1191 _JsonStringStringifier(_sink, _toEncodable) { 1267 _JsonStringStringifier(_sink, _toEncodable) {
1192 this._sink = _sink; 1268 this._sink = _sink;
1193 super._JsonStringifier(dart.as(_toEncodable, /* Unimplemented type (Object ) → Object */)); 1269 super._JsonStringifier(dart.as(_toEncodable, dart.throw_("Unimplemented ty pe (Object) → Object")));
1194 } 1270 }
1195 static stringify(object, toEncodable, indent) { 1271 static stringify(object, toEncodable, indent) {
1196 let output = new core.StringBuffer(); 1272 let output = new core.StringBuffer();
1197 printOn(object, output, toEncodable, indent); 1273 printOn(object, output, toEncodable, indent);
1198 return output.toString(); 1274 return output.toString();
1199 } 1275 }
1200 static printOn(object, output, toEncodable, indent) { 1276 static printOn(object, output, toEncodable, indent) {
1201 let stringifier = null; 1277 let stringifier = null;
1202 if (indent === null) { 1278 if (indent === null) {
1203 stringifier = new _JsonStringStringifier(output, toEncodable); 1279 stringifier = new _JsonStringStringifier(output, toEncodable);
1204 } else { 1280 } else {
1205 stringifier = new _JsonStringStringifierPretty(output, toEncodable, inde nt); 1281 stringifier = new _JsonStringStringifierPretty(output, toEncodable, inde nt);
1206 } 1282 }
1207 dart.dinvoke(stringifier, "writeObject", object); 1283 dart.dinvoke(stringifier, 'writeObject', object);
1208 } 1284 }
1209 writeNumber(number) { 1285 writeNumber(number) {
1210 this._sink.write(number.toString()); 1286 this._sink.write(number.toString());
1211 } 1287 }
1212 writeString(string) { 1288 writeString(string) {
1213 this._sink.write(string); 1289 this._sink.write(string);
1214 } 1290 }
1215 writeStringSlice(string, start, end) { 1291 writeStringSlice(string, start, end) {
1216 this._sink.write(string.substring(start, end)); 1292 this._sink.write(string.substring(start, end));
1217 } 1293 }
1218 writeCharCode(charCode) { 1294 writeCharCode(charCode) {
1219 this._sink.writeCharCode(charCode); 1295 this._sink.writeCharCode(charCode);
1220 } 1296 }
1221 } 1297 }
1222
1223 class _JsonStringStringifierPretty extends dart.mixin(_JsonStringStringifier, _JsonPrettyPrintMixin) { 1298 class _JsonStringStringifierPretty extends dart.mixin(_JsonStringStringifier, _JsonPrettyPrintMixin) {
1224 _JsonStringStringifierPretty(sink, toEncodable, _indent) { 1299 _JsonStringStringifierPretty(sink, toEncodable, _indent) {
1225 this._indent = _indent; 1300 this._indent = _indent;
1226 super._JsonStringStringifier(sink, toEncodable); 1301 super._JsonStringStringifier(sink, toEncodable);
1227 } 1302 }
1228 writeIndentation(count) { 1303 writeIndentation(count) {
1229 for (let i = 0; i < count; i++) this.writeString(this._indent); 1304 for (let i = 0; i < count; i++)
1305 this.writeString(this._indent);
1230 } 1306 }
1231 } 1307 }
1232
1233 class _JsonUtf8Stringifier extends _JsonStringifier { 1308 class _JsonUtf8Stringifier extends _JsonStringifier {
1234 _JsonUtf8Stringifier(toEncodable, bufferSize, addChunk) { 1309 _JsonUtf8Stringifier(toEncodable, bufferSize, addChunk) {
1235 this.addChunk = addChunk; 1310 this.addChunk = addChunk;
1236 this.bufferSize = bufferSize; 1311 this.bufferSize = bufferSize;
1237 this.buffer = new typed_data.Uint8List(bufferSize); 1312 this.buffer = new typed_data.Uint8List(bufferSize);
1238 this.index = 0; 1313 this.index = 0;
1239 super._JsonStringifier(dart.as(toEncodable, /* Unimplemented type (Object) → Object */)); 1314 super._JsonStringifier(dart.as(toEncodable, dart.throw_("Unimplemented typ e (Object) → Object")));
1240 } 1315 }
1241 static stringify(object, indent, toEncodableFunction, bufferSize, addChunk) { 1316 static stringify(object, indent, toEncodableFunction, bufferSize, addChunk) {
1242 let stringifier = null; 1317 let stringifier = null;
1243 if (indent !== null) { 1318 if (indent !== null) {
1244 stringifier = new _JsonUtf8StringifierPretty(toEncodableFunction, indent , bufferSize, addChunk); 1319 stringifier = new _JsonUtf8StringifierPretty(toEncodableFunction, indent , bufferSize, addChunk);
1245 } else { 1320 } else {
1246 stringifier = new _JsonUtf8Stringifier(toEncodableFunction, bufferSize, addChunk); 1321 stringifier = new _JsonUtf8Stringifier(toEncodableFunction, bufferSize, addChunk);
1247 } 1322 }
1248 stringifier.writeObject(object); 1323 stringifier.writeObject(object);
1249 stringifier.flush(); 1324 stringifier.flush();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 } 1364 }
1290 writeCharCode(charCode) { 1365 writeCharCode(charCode) {
1291 if (charCode <= 127) { 1366 if (charCode <= 127) {
1292 this.writeByte(charCode); 1367 this.writeByte(charCode);
1293 return; 1368 return;
1294 } 1369 }
1295 this.writeMultiByteCharCode(charCode); 1370 this.writeMultiByteCharCode(charCode);
1296 } 1371 }
1297 writeMultiByteCharCode(charCode) { 1372 writeMultiByteCharCode(charCode) {
1298 if (charCode <= 2047) { 1373 if (charCode <= 2047) {
1299 this.writeByte(192 | (charCode >> 6)); 1374 this.writeByte(192 | charCode >> 6);
1300 this.writeByte(128 | (charCode & 63)); 1375 this.writeByte(128 | charCode & 63);
1301 return; 1376 return;
1302 } 1377 }
1303 if (charCode <= 65535) { 1378 if (charCode <= 65535) {
1304 this.writeByte(224 | (charCode >> 12)); 1379 this.writeByte(224 | charCode >> 12);
1305 this.writeByte(128 | ((charCode >> 6) & 63)); 1380 this.writeByte(128 | charCode >> 6 & 63);
1306 this.writeByte(128 | (charCode & 63)); 1381 this.writeByte(128 | charCode & 63);
1307 return; 1382 return;
1308 } 1383 }
1309 this.writeFourByteCharCode(charCode); 1384 this.writeFourByteCharCode(charCode);
1310 } 1385 }
1311 writeFourByteCharCode(charCode) { 1386 writeFourByteCharCode(charCode) {
1312 dart.assert(charCode <= 1114111); 1387 dart.assert(charCode <= 1114111);
1313 this.writeByte(240 | (charCode >> 18)); 1388 this.writeByte(240 | charCode >> 18);
1314 this.writeByte(128 | ((charCode >> 12) & 63)); 1389 this.writeByte(128 | charCode >> 12 & 63);
1315 this.writeByte(128 | ((charCode >> 6) & 63)); 1390 this.writeByte(128 | charCode >> 6 & 63);
1316 this.writeByte(128 | (charCode & 63)); 1391 this.writeByte(128 | charCode & 63);
1317 } 1392 }
1318 writeByte(byte) { 1393 writeByte(byte) {
1319 dart.assert(byte <= 255); 1394 dart.assert(byte <= 255);
1320 if (this.index === this.buffer.length) { 1395 if (this.index === this.buffer.length) {
1321 dart.dinvokef(this.addChunk, this.buffer, 0, this.index); 1396 dart.dinvokef(this.addChunk, this.buffer, 0, this.index);
1322 this.buffer = new typed_data.Uint8List(this.bufferSize); 1397 this.buffer = new typed_data.Uint8List(this.bufferSize);
1323 this.index = 0; 1398 this.index = 0;
1324 } 1399 }
1325 this.buffer.set(this.index++, byte); 1400 this.buffer.set(this.index++, byte);
1326 } 1401 }
1327 } 1402 }
1328
1329 class _JsonUtf8StringifierPretty extends dart.mixin(_JsonUtf8Stringifier, _Jso nPrettyPrintMixin) { 1403 class _JsonUtf8StringifierPretty extends dart.mixin(_JsonUtf8Stringifier, _Jso nPrettyPrintMixin) {
1330 _JsonUtf8StringifierPretty(toEncodableFunction, indent, bufferSize, addChunk ) { 1404 _JsonUtf8StringifierPretty(toEncodableFunction, indent, bufferSize, addChunk ) {
1331 this.indent = indent; 1405 this.indent = indent;
1332 super._JsonUtf8Stringifier(toEncodableFunction, dart.as(bufferSize, core.i nt), dart.as(addChunk, core.Function)); 1406 super._JsonUtf8Stringifier(toEncodableFunction, dart.as(bufferSize, core.i nt), dart.as(addChunk, core.Function));
1333 } 1407 }
1334 writeIndentation(count) { 1408 writeIndentation(count) {
1335 let indent = this.indent; 1409 let indent = this.indent;
1336 let indentLength = indent.length; 1410 let indentLength = indent.length;
1337 if (indentLength === 1) { 1411 if (indentLength === 1) {
1338 let char = indent.get(0); 1412 let char = indent.get(0);
(...skipping 10 matching lines...) Expand all
1349 this.buffer.setRange(this.index, end, indent); 1423 this.buffer.setRange(this.index, end, indent);
1350 this.index = end; 1424 this.index = end;
1351 } else { 1425 } else {
1352 for (let i = 0; i < indentLength; i++) { 1426 for (let i = 0; i < indentLength; i++) {
1353 this.writeByte(indent.get(i)); 1427 this.writeByte(indent.get(i));
1354 } 1428 }
1355 } 1429 }
1356 } 1430 }
1357 } 1431 }
1358 } 1432 }
1359
1360 let LATIN1 = new Latin1Codec(); 1433 let LATIN1 = new Latin1Codec();
1361 let _LATIN1_MASK = 255; 1434 let _LATIN1_MASK = 255;
1362 class Latin1Codec extends Encoding { 1435 class Latin1Codec extends Encoding {
1363 Latin1Codec(opt$) { 1436 Latin1Codec(opt$) {
1364 let allowInvalid = opt$.allowInvalid === undefined ? false : opt$.allowInv alid; 1437 let allowInvalid = opt$.allowInvalid === void 0 ? false : opt$.allowInvali d;
1365 this._allowInvalid = allowInvalid; 1438 this._allowInvalid = allowInvalid;
1366 super.Encoding(); 1439 super.Encoding();
1367 } 1440 }
1368 get name() { return "iso-8859-1"; } 1441 get name() {
1442 return "iso-8859-1";
1443 }
1369 decode(bytes, opt$) { 1444 decode(bytes, opt$) {
1370 let allowInvalid = opt$.allowInvalid === undefined ? null : opt$.allowInva lid; 1445 let allowInvalid = opt$.allowInvalid === void 0 ? null : opt$.allowInvalid ;
1371 if (allowInvalid === null) allowInvalid = this._allowInvalid; 1446 if (allowInvalid === null)
1447 allowInvalid = this._allowInvalid;
1372 if (allowInvalid) { 1448 if (allowInvalid) {
1373 return new Latin1Decoder({allowInvalid: true}).convert(bytes); 1449 return new Latin1Decoder({allowInvalid: true}).convert(bytes);
1374 } else { 1450 } else {
1375 return new Latin1Decoder({allowInvalid: false}).convert(bytes); 1451 return new Latin1Decoder({allowInvalid: false}).convert(bytes);
1376 } 1452 }
1377 } 1453 }
1378 get encoder() { return new Latin1Encoder(); } 1454 get encoder() {
1379 get decoder() { return this._allowInvalid ? new Latin1Decoder({allowInvalid: true}) : new Latin1Decoder({allowInvalid: false}); } 1455 return new Latin1Encoder();
1456 }
1457 get decoder() {
1458 return this._allowInvalid ? new Latin1Decoder({allowInvalid: true}) : new Latin1Decoder({allowInvalid: false});
1459 }
1380 } 1460 }
1381
1382 class Latin1Encoder extends _UnicodeSubsetEncoder { 1461 class Latin1Encoder extends _UnicodeSubsetEncoder {
1383 Latin1Encoder() { 1462 Latin1Encoder() {
1384 super._UnicodeSubsetEncoder(_LATIN1_MASK); 1463 super._UnicodeSubsetEncoder(_LATIN1_MASK);
1385 } 1464 }
1386 } 1465 }
1387
1388 class Latin1Decoder extends _UnicodeSubsetDecoder { 1466 class Latin1Decoder extends _UnicodeSubsetDecoder {
1389 Latin1Decoder(opt$) { 1467 Latin1Decoder(opt$) {
1390 let allowInvalid = opt$.allowInvalid === undefined ? false : opt$.allowInv alid; 1468 let allowInvalid = opt$.allowInvalid === void 0 ? false : opt$.allowInvali d;
1391 super._UnicodeSubsetDecoder(allowInvalid, _LATIN1_MASK); 1469 super._UnicodeSubsetDecoder(allowInvalid, _LATIN1_MASK);
1392 } 1470 }
1393 startChunkedConversion(sink) { 1471 startChunkedConversion(sink) {
1394 let stringSink = null; 1472 let stringSink = null;
1395 if (dart.is(sink, StringConversionSink)) { 1473 if (dart.is(sink, StringConversionSink)) {
1396 stringSink = sink; 1474 stringSink = sink;
1397 } else { 1475 } else {
1398 stringSink = new StringConversionSink.from(sink); 1476 stringSink = new StringConversionSink.from(sink);
1399 } 1477 }
1400 if (!dart.notNull(this._allowInvalid)) return new _Latin1DecoderSink(strin gSink); 1478 if (!dart.notNull(this._allowInvalid))
1479 return new _Latin1DecoderSink(stringSink);
1401 return new _Latin1AllowInvalidDecoderSink(stringSink); 1480 return new _Latin1AllowInvalidDecoderSink(stringSink);
1402 } 1481 }
1403 } 1482 }
1404
1405 class _Latin1DecoderSink extends ByteConversionSinkBase { 1483 class _Latin1DecoderSink extends ByteConversionSinkBase {
1406 _Latin1DecoderSink(_sink) { 1484 _Latin1DecoderSink(_sink) {
1407 this._sink = _sink; 1485 this._sink = _sink;
1408 super.ByteConversionSinkBase(); 1486 super.ByteConversionSinkBase();
1409 } 1487 }
1410 close() { 1488 close() {
1411 this._sink.close(); 1489 this._sink.close();
1412 } 1490 }
1413 add(source) { 1491 add(source) {
1414 this.addSlice(source, 0, source.length, false); 1492 this.addSlice(source, 0, source.length, false);
1415 } 1493 }
1416 _addSliceToSink(source, start, end, isLast) { 1494 _addSliceToSink(source, start, end, isLast) {
1417 this._sink.add(new core.String.fromCharCodes(source, start, end)); 1495 this._sink.add(new core.String.fromCharCodes(source, start, end));
1418 if (isLast) this.close(); 1496 if (isLast)
1497 this.close();
1419 } 1498 }
1420 addSlice(source, start, end, isLast) { 1499 addSlice(source, start, end, isLast) {
1421 core.RangeError.checkValidRange(start, end, source.length); 1500 core.RangeError.checkValidRange(start, end, source.length);
1422 for (let i = start; i < end; i++) { 1501 for (let i = start; i < end; i++) {
1423 let char = source.get(i); 1502 let char = source.get(i);
1424 if (dart.notNull(char > _LATIN1_MASK) || dart.notNull(char < 0)) { 1503 if (dart.notNull(char > _LATIN1_MASK) || dart.notNull(char < 0)) {
1425 throw new core.FormatException("Source contains non-Latin-1 characters ."); 1504 throw new core.FormatException("Source contains non-Latin-1 characters .");
1426 } 1505 }
1427 } 1506 }
1428 if (start < end) { 1507 if (start < end) {
1429 this._addSliceToSink(source, start, end, isLast); 1508 this._addSliceToSink(source, start, end, isLast);
1430 } 1509 }
1431 if (isLast) { 1510 if (isLast) {
1432 this.close(); 1511 this.close();
1433 } 1512 }
1434 } 1513 }
1435 } 1514 }
1436
1437 class _Latin1AllowInvalidDecoderSink extends _Latin1DecoderSink { 1515 class _Latin1AllowInvalidDecoderSink extends _Latin1DecoderSink {
1438 _Latin1AllowInvalidDecoderSink(sink) { 1516 _Latin1AllowInvalidDecoderSink(sink) {
1439 super._Latin1DecoderSink(sink); 1517 super._Latin1DecoderSink(sink);
1440 } 1518 }
1441 addSlice(source, start, end, isLast) { 1519 addSlice(source, start, end, isLast) {
1442 core.RangeError.checkValidRange(start, end, source.length); 1520 core.RangeError.checkValidRange(start, end, source.length);
1443 for (let i = start; i < end; i++) { 1521 for (let i = start; i < end; i++) {
1444 let char = source.get(i); 1522 let char = source.get(i);
1445 if (dart.notNull(char > _LATIN1_MASK) || dart.notNull(char < 0)) { 1523 if (dart.notNull(char > _LATIN1_MASK) || dart.notNull(char < 0)) {
1446 if (i > start) this._addSliceToSink(source, start, i, false); 1524 if (i > start)
1525 this._addSliceToSink(source, start, i, false);
1447 this._addSliceToSink(dart.as(/* Unimplemented const */new List.from([6 5533]), core.List$(core.int)), 0, 1, false); 1526 this._addSliceToSink(dart.as(/* Unimplemented const */new List.from([6 5533]), core.List$(core.int)), 0, 1, false);
1448 start = i + 1; 1527 start = i + 1;
1449 } 1528 }
1450 } 1529 }
1451 if (start < end) { 1530 if (start < end) {
1452 this._addSliceToSink(source, start, end, isLast); 1531 this._addSliceToSink(source, start, end, isLast);
1453 } 1532 }
1454 if (isLast) { 1533 if (isLast) {
1455 this.close(); 1534 this.close();
1456 } 1535 }
1457 } 1536 }
1458 } 1537 }
1459
1460 class LineSplitter extends Converter$(core.String, core.List$(core.String)) { 1538 class LineSplitter extends Converter$(core.String, core.List$(core.String)) {
1461 LineSplitter() { 1539 LineSplitter() {
1462 super.Converter(); 1540 super.Converter();
1463 } 1541 }
1464 convert(data) { 1542 convert(data) {
1465 let lines = new core.List(); 1543 let lines = new core.List();
1466 _LineSplitterSink._addSlice(data, 0, data.length, true, lines.add); 1544 _LineSplitterSink._addSlice(data, 0, data.length, true, lines.add);
1467 return lines; 1545 return lines;
1468 } 1546 }
1469 startChunkedConversion(sink) { 1547 startChunkedConversion(sink) {
1470 if (!dart.is(sink, StringConversionSink)) { 1548 if (!dart.is(sink, StringConversionSink)) {
1471 sink = new StringConversionSink.from(sink); 1549 sink = new StringConversionSink.from(sink);
1472 } 1550 }
1473 return new _LineSplitterSink(sink); 1551 return new _LineSplitterSink(sink);
1474 } 1552 }
1475 } 1553 }
1476
1477 class _LineSplitterSink extends StringConversionSinkBase { 1554 class _LineSplitterSink extends StringConversionSinkBase {
1478 _LineSplitterSink(_sink) { 1555 _LineSplitterSink(_sink) {
1479 this._sink = _sink; 1556 this._sink = _sink;
1480 this._carry = null; 1557 this._carry = null;
1481 super.StringConversionSinkBase(); 1558 super.StringConversionSinkBase();
1482 } 1559 }
1483 addSlice(chunk, start, end, isLast) { 1560 addSlice(chunk, start, end, isLast) {
1484 if (this._carry !== null) { 1561 if (this._carry !== null) {
1485 chunk = core.String['+'](this._carry, chunk.substring(start, end)); 1562 chunk = core.String['+'](this._carry, chunk.substring(start, end));
1486 start = 0; 1563 start = 0;
1487 end = chunk.length; 1564 end = chunk.length;
1488 this._carry = null; 1565 this._carry = null;
1489 } 1566 }
1490 this._carry = _addSlice(chunk, start, end, isLast, this._sink.add); 1567 this._carry = _addSlice(chunk, start, end, isLast, this._sink.add);
1491 if (isLast) this._sink.close(); 1568 if (isLast)
1569 this._sink.close();
1492 } 1570 }
1493 close() { 1571 close() {
1494 this.addSlice('', 0, 0, true); 1572 this.addSlice('', 0, 0, true);
1495 } 1573 }
1496 static _addSlice(chunk, start, end, isLast, adder) { 1574 static _addSlice(chunk, start, end, isLast, adder) {
1497 let pos = start; 1575 let pos = start;
1498 while (pos < end) { 1576 while (pos < end) {
1499 let skip = 0; 1577 let skip = 0;
1500 let char = chunk.codeUnitAt(pos); 1578 let char = chunk.codeUnitAt(pos);
1501 if (char === _LF) { 1579 if (char === _LF) {
(...skipping 21 matching lines...) Expand all
1523 adder(carry); 1601 adder(carry);
1524 } else { 1602 } else {
1525 return carry; 1603 return carry;
1526 } 1604 }
1527 } 1605 }
1528 return null; 1606 return null;
1529 } 1607 }
1530 } 1608 }
1531 _LineSplitterSink._LF = 10; 1609 _LineSplitterSink._LF = 10;
1532 _LineSplitterSink._CR = 13; 1610 _LineSplitterSink._CR = 13;
1533
1534 class StringConversionSink extends ChunkedConversionSink$(core.String) { 1611 class StringConversionSink extends ChunkedConversionSink$(core.String) {
1535 StringConversionSink() { 1612 StringConversionSink() {
1536 super.ChunkedConversionSink(); 1613 super.ChunkedConversionSink();
1537 } 1614 }
1538 StringConversionSink$withCallback(callback) { 1615 StringConversionSink$withCallback(callback) {
1539 return new _StringCallbackSink(callback); 1616 return new _StringCallbackSink(callback);
1540 } 1617 }
1541 StringConversionSink$from(sink) { 1618 StringConversionSink$from(sink) {
1542 return new _StringAdapterSink(sink); 1619 return new _StringAdapterSink(sink);
1543 } 1620 }
1544 StringConversionSink$fromStringSink(sink) { 1621 StringConversionSink$fromStringSink(sink) {
1545 return new _StringSinkConversionSink(sink); 1622 return new _StringSinkConversionSink(sink);
1546 } 1623 }
1547 } 1624 }
1548 dart.defineNamedConstructor(StringConversionSink, "withCallback"); 1625 dart.defineNamedConstructor(StringConversionSink, 'withCallback');
1549 dart.defineNamedConstructor(StringConversionSink, "from"); 1626 dart.defineNamedConstructor(StringConversionSink, 'from');
1550 dart.defineNamedConstructor(StringConversionSink, "fromStringSink"); 1627 dart.defineNamedConstructor(StringConversionSink, 'fromStringSink');
1551
1552 class ClosableStringSink extends core.StringSink { 1628 class ClosableStringSink extends core.StringSink {
1553 ClosableStringSink$fromStringSink(sink, onClose) { 1629 ClosableStringSink$fromStringSink(sink, onClose) {
1554 return new _ClosableStringSink(sink, onClose); 1630 return new _ClosableStringSink(sink, onClose);
1555 } 1631 }
1556 } 1632 }
1557 dart.defineNamedConstructor(ClosableStringSink, "fromStringSink"); 1633 dart.defineNamedConstructor(ClosableStringSink, 'fromStringSink');
1558
1559 class _ClosableStringSink extends dart.Object { 1634 class _ClosableStringSink extends dart.Object {
1560 _ClosableStringSink(_sink, _callback) { 1635 _ClosableStringSink(_sink, _callback) {
1561 this._sink = _sink; 1636 this._sink = _sink;
1562 this._callback = _callback; 1637 this._callback = _callback;
1563 } 1638 }
1564 close() { return this._callback(); } 1639 close() {
1565 writeCharCode(charCode) { return this._sink.writeCharCode(charCode); } 1640 return this._callback();
1566 write(o) { return this._sink.write(o); } 1641 }
1642 writeCharCode(charCode) {
1643 return this._sink.writeCharCode(charCode);
1644 }
1645 write(o) {
1646 return this._sink.write(o);
1647 }
1567 writeln(o) { 1648 writeln(o) {
1568 if (o === undefined) o = ""; 1649 if (o === void 0)
1569 return this._sink.writeln(o) 1650 o = "";
1651 return this._sink.writeln(o);
1570 } 1652 }
1571 writeAll(objects, separator) { 1653 writeAll(objects, separator) {
1572 if (separator === undefined) separator = ""; 1654 if (separator === void 0)
1573 return this._sink.writeAll(objects, separator) 1655 separator = "";
1656 return this._sink.writeAll(objects, separator);
1574 } 1657 }
1575 } 1658 }
1576
1577 class _StringConversionSinkAsStringSinkAdapter extends dart.Object { 1659 class _StringConversionSinkAsStringSinkAdapter extends dart.Object {
1578 _StringConversionSinkAsStringSinkAdapter(_chunkedSink) { 1660 _StringConversionSinkAsStringSinkAdapter(_chunkedSink) {
1579 this._chunkedSink = _chunkedSink; 1661 this._chunkedSink = _chunkedSink;
1580 this._buffer = new core.StringBuffer(); 1662 this._buffer = new core.StringBuffer();
1581 } 1663 }
1582 close() { 1664 close() {
1583 if (this._buffer.isNotEmpty) this._flush(); 1665 if (this._buffer.isNotEmpty)
1666 this._flush();
1584 this._chunkedSink.close(); 1667 this._chunkedSink.close();
1585 } 1668 }
1586 writeCharCode(charCode) { 1669 writeCharCode(charCode) {
1587 this._buffer.writeCharCode(charCode); 1670 this._buffer.writeCharCode(charCode);
1588 if (this._buffer.length['>'](_MIN_STRING_SIZE)) this._flush(); 1671 if (this._buffer.length['>'](_MIN_STRING_SIZE))
1672 this._flush();
1589 } 1673 }
1590 write(o) { 1674 write(o) {
1591 if (this._buffer.isNotEmpty) this._flush(); 1675 if (this._buffer.isNotEmpty)
1676 this._flush();
1592 let str = o.toString(); 1677 let str = o.toString();
1593 this._chunkedSink.add(o.toString()); 1678 this._chunkedSink.add(o.toString());
1594 } 1679 }
1595 writeln(o) { 1680 writeln(o) {
1596 if (o === undefined) o = ""; 1681 if (o === void 0)
1682 o = "";
1597 this._buffer.writeln(o); 1683 this._buffer.writeln(o);
1598 if (this._buffer.length['>'](_MIN_STRING_SIZE)) this._flush(); 1684 if (this._buffer.length['>'](_MIN_STRING_SIZE))
1685 this._flush();
1599 } 1686 }
1600 writeAll(objects, separator) { 1687 writeAll(objects, separator) {
1601 if (separator === undefined) separator = ""; 1688 if (separator === void 0)
1602 if (this._buffer.isNotEmpty) this._flush(); 1689 separator = "";
1690 if (this._buffer.isNotEmpty)
1691 this._flush();
1603 let iterator = objects.iterator; 1692 let iterator = objects.iterator;
1604 if (!dart.notNull(iterator.moveNext())) return; 1693 if (!dart.notNull(iterator.moveNext()))
1694 return;
1605 if (separator.isEmpty) { 1695 if (separator.isEmpty) {
1606 do { 1696 do {
1607 this._chunkedSink.add(dart.as(dart.dinvoke(iterator.current, "toString "), core.String)); 1697 this._chunkedSink.add(dart.as(dart.dinvoke(iterator.current, 'toString '), core.String));
1608 } 1698 } while (iterator.moveNext());
1609 while (iterator.moveNext());
1610 } else { 1699 } else {
1611 this._chunkedSink.add(dart.as(dart.dinvoke(iterator.current, "toString") , core.String)); 1700 this._chunkedSink.add(dart.as(dart.dinvoke(iterator.current, 'toString') , core.String));
1612 while (iterator.moveNext()) { 1701 while (iterator.moveNext()) {
1613 this.write(separator); 1702 this.write(separator);
1614 this._chunkedSink.add(dart.as(dart.dinvoke(iterator.current, "toString "), core.String)); 1703 this._chunkedSink.add(dart.as(dart.dinvoke(iterator.current, 'toString '), core.String));
1615 } 1704 }
1616 } 1705 }
1617 } 1706 }
1618 _flush() { 1707 _flush() {
1619 let accumulated = this._buffer.toString(); 1708 let accumulated = this._buffer.toString();
1620 this._buffer.clear(); 1709 this._buffer.clear();
1621 this._chunkedSink.add(accumulated); 1710 this._chunkedSink.add(accumulated);
1622 } 1711 }
1623 } 1712 }
1624 _StringConversionSinkAsStringSinkAdapter._MIN_STRING_SIZE = 16; 1713 _StringConversionSinkAsStringSinkAdapter._MIN_STRING_SIZE = 16;
1625
1626 class StringConversionSinkBase extends StringConversionSinkMixin { 1714 class StringConversionSinkBase extends StringConversionSinkMixin {
1627 } 1715 }
1628
1629 class StringConversionSinkMixin extends dart.Object { 1716 class StringConversionSinkMixin extends dart.Object {
1630 add(str) { return this.addSlice(str, 0, str.length, false); } 1717 add(str) {
1718 return this.addSlice(str, 0, str.length, false);
1719 }
1631 asUtf8Sink(allowMalformed) { 1720 asUtf8Sink(allowMalformed) {
1632 return new _Utf8ConversionSink(this, allowMalformed); 1721 return new _Utf8ConversionSink(this, allowMalformed);
1633 } 1722 }
1634 asStringSink() { 1723 asStringSink() {
1635 return new _StringConversionSinkAsStringSinkAdapter(this); 1724 return new _StringConversionSinkAsStringSinkAdapter(this);
1636 } 1725 }
1637 } 1726 }
1638
1639 class _StringSinkConversionSink extends StringConversionSinkBase { 1727 class _StringSinkConversionSink extends StringConversionSinkBase {
1640 _StringSinkConversionSink(_stringSink) { 1728 _StringSinkConversionSink(_stringSink) {
1641 this._stringSink = _stringSink; 1729 this._stringSink = _stringSink;
1642 super.StringConversionSinkBase(); 1730 super.StringConversionSinkBase();
1643 } 1731 }
1644 close() { 1732 close() {}
1645 }
1646 addSlice(str, start, end, isLast) { 1733 addSlice(str, start, end, isLast) {
1647 if (dart.notNull(start !== 0) || dart.notNull(end !== str.length)) { 1734 if (dart.notNull(start !== 0) || dart.notNull(end !== str.length)) {
1648 for (let i = start; i < end; i++) { 1735 for (let i = start; i < end; i++) {
1649 this._stringSink.writeCharCode(str.codeUnitAt(i)); 1736 this._stringSink.writeCharCode(str.codeUnitAt(i));
1650 } 1737 }
1651 } else { 1738 } else {
1652 this._stringSink.write(str); 1739 this._stringSink.write(str);
1653 } 1740 }
1654 if (isLast) this.close(); 1741 if (isLast)
1742 this.close();
1655 } 1743 }
1656 add(str) { return this._stringSink.write(str); } 1744 add(str) {
1745 return this._stringSink.write(str);
1746 }
1657 asUtf8Sink(allowMalformed) { 1747 asUtf8Sink(allowMalformed) {
1658 return new _Utf8StringSinkAdapter(this, this._stringSink, allowMalformed); 1748 return new _Utf8StringSinkAdapter(this, this._stringSink, allowMalformed);
1659 } 1749 }
1660 asStringSink() { 1750 asStringSink() {
1661 return new ClosableStringSink.fromStringSink(this._stringSink, this.close) ; 1751 return new ClosableStringSink.fromStringSink(this._stringSink, this.close) ;
1662 } 1752 }
1663 } 1753 }
1664
1665 class _StringCallbackSink extends _StringSinkConversionSink { 1754 class _StringCallbackSink extends _StringSinkConversionSink {
1666 _StringCallbackSink(_callback) { 1755 _StringCallbackSink(_callback) {
1667 this._callback = _callback; 1756 this._callback = _callback;
1668 super._StringSinkConversionSink(new core.StringBuffer()); 1757 super._StringSinkConversionSink(new core.StringBuffer());
1669 } 1758 }
1670 close() { 1759 close() {
1671 let buffer = dart.as(this._stringSink, core.StringBuffer); 1760 let buffer = dart.as(this._stringSink, core.StringBuffer);
1672 let accumulated = buffer.toString(); 1761 let accumulated = buffer.toString();
1673 buffer.clear(); 1762 buffer.clear();
1674 this._callback(accumulated); 1763 this._callback(accumulated);
1675 } 1764 }
1676 asUtf8Sink(allowMalformed) { 1765 asUtf8Sink(allowMalformed) {
1677 return new _Utf8StringSinkAdapter(this, this._stringSink, allowMalformed); 1766 return new _Utf8StringSinkAdapter(this, this._stringSink, allowMalformed);
1678 } 1767 }
1679 } 1768 }
1680
1681 class _StringAdapterSink extends StringConversionSinkBase { 1769 class _StringAdapterSink extends StringConversionSinkBase {
1682 _StringAdapterSink(_sink) { 1770 _StringAdapterSink(_sink) {
1683 this._sink = _sink; 1771 this._sink = _sink;
1684 super.StringConversionSinkBase(); 1772 super.StringConversionSinkBase();
1685 } 1773 }
1686 add(str) { return this._sink.add(str); } 1774 add(str) {
1775 return this._sink.add(str);
1776 }
1687 addSlice(str, start, end, isLast) { 1777 addSlice(str, start, end, isLast) {
1688 if (dart.notNull(start === 0) && dart.notNull(end === str.length)) { 1778 if (dart.notNull(start === 0) && dart.notNull(end === str.length)) {
1689 this.add(str); 1779 this.add(str);
1690 } else { 1780 } else {
1691 this.add(str.substring(start, end)); 1781 this.add(str.substring(start, end));
1692 } 1782 }
1693 if (isLast) this.close(); 1783 if (isLast)
1784 this.close();
1694 } 1785 }
1695 close() { return this._sink.close(); } 1786 close() {
1787 return this._sink.close();
1788 }
1696 } 1789 }
1697
1698 class _Utf8StringSinkAdapter extends ByteConversionSink { 1790 class _Utf8StringSinkAdapter extends ByteConversionSink {
1699 _Utf8StringSinkAdapter(_sink, stringSink, allowMalformed) { 1791 _Utf8StringSinkAdapter(_sink, stringSink, allowMalformed) {
1700 this._sink = _sink; 1792 this._sink = _sink;
1701 this._decoder = new _Utf8Decoder(stringSink, allowMalformed); 1793 this._decoder = new _Utf8Decoder(stringSink, allowMalformed);
1702 super.ByteConversionSink(); 1794 super.ByteConversionSink();
1703 } 1795 }
1704 close() { 1796 close() {
1705 this._decoder.close(); 1797 this._decoder.close();
1706 if (this._sink !== null) this._sink.close(); 1798 if (this._sink !== null)
1799 this._sink.close();
1707 } 1800 }
1708 add(chunk) { 1801 add(chunk) {
1709 this.addSlice(chunk, 0, chunk.length, false); 1802 this.addSlice(chunk, 0, chunk.length, false);
1710 } 1803 }
1711 addSlice(codeUnits, startIndex, endIndex, isLast) { 1804 addSlice(codeUnits, startIndex, endIndex, isLast) {
1712 this._decoder.convert(codeUnits, startIndex, endIndex); 1805 this._decoder.convert(codeUnits, startIndex, endIndex);
1713 if (isLast) this.close(); 1806 if (isLast)
1807 this.close();
1714 } 1808 }
1715 } 1809 }
1716
1717 class _Utf8ConversionSink extends ByteConversionSink { 1810 class _Utf8ConversionSink extends ByteConversionSink {
1718 _Utf8ConversionSink(sink, allowMalformed) { 1811 _Utf8ConversionSink(sink, allowMalformed) {
1719 _Utf8ConversionSink.call(this, sink, new core.StringBuffer(), allowMalform ed); 1812 this._Utf8ConversionSink$_(sink, new core.StringBuffer(), allowMalformed);
1720 } 1813 }
1721 _Utf8ConversionSink$_(_chunkedSink, stringBuffer, allowMalformed) { 1814 _Utf8ConversionSink$_(_chunkedSink, stringBuffer, allowMalformed) {
1722 this._chunkedSink = _chunkedSink; 1815 this._chunkedSink = _chunkedSink;
1723 this._decoder = new _Utf8Decoder(stringBuffer, allowMalformed); 1816 this._decoder = new _Utf8Decoder(stringBuffer, allowMalformed);
1724 this._buffer = stringBuffer; 1817 this._buffer = stringBuffer;
1725 super.ByteConversionSink(); 1818 super.ByteConversionSink();
1726 } 1819 }
1727 close() { 1820 close() {
1728 this._decoder.close(); 1821 this._decoder.close();
1729 if (this._buffer.isNotEmpty) { 1822 if (this._buffer.isNotEmpty) {
1730 let accumulated = this._buffer.toString(); 1823 let accumulated = this._buffer.toString();
1731 this._buffer.clear(); 1824 this._buffer.clear();
1732 this._chunkedSink.addSlice(accumulated, 0, accumulated.length, true); 1825 this._chunkedSink.addSlice(accumulated, 0, accumulated.length, true);
1733 } else { 1826 } else {
1734 this._chunkedSink.close(); 1827 this._chunkedSink.close();
1735 } 1828 }
1736 } 1829 }
1737 add(chunk) { 1830 add(chunk) {
1738 this.addSlice(chunk, 0, chunk.length, false); 1831 this.addSlice(chunk, 0, chunk.length, false);
1739 } 1832 }
1740 addSlice(chunk, startIndex, endIndex, isLast) { 1833 addSlice(chunk, startIndex, endIndex, isLast) {
1741 this._decoder.convert(chunk, startIndex, endIndex); 1834 this._decoder.convert(chunk, startIndex, endIndex);
1742 if (this._buffer.isNotEmpty) { 1835 if (this._buffer.isNotEmpty) {
1743 let accumulated = this._buffer.toString(); 1836 let accumulated = this._buffer.toString();
1744 this._chunkedSink.addSlice(accumulated, 0, accumulated.length, isLast); 1837 this._chunkedSink.addSlice(accumulated, 0, accumulated.length, isLast);
1745 this._buffer.clear(); 1838 this._buffer.clear();
1746 return; 1839 return;
1747 } 1840 }
1748 if (isLast) this.close(); 1841 if (isLast)
1842 this.close();
1749 } 1843 }
1750 } 1844 }
1751 dart.defineNamedConstructor(_Utf8ConversionSink, "_"); 1845 dart.defineNamedConstructor(_Utf8ConversionSink, '_');
1752
1753 let UNICODE_REPLACEMENT_CHARACTER_RUNE = 65533; 1846 let UNICODE_REPLACEMENT_CHARACTER_RUNE = 65533;
1754 let UNICODE_BOM_CHARACTER_RUNE = 65279; 1847 let UNICODE_BOM_CHARACTER_RUNE = 65279;
1755 let UTF8 = new Utf8Codec(); 1848 let UTF8 = new Utf8Codec();
1756 class Utf8Codec extends Encoding { 1849 class Utf8Codec extends Encoding {
1757 Utf8Codec(opt$) { 1850 Utf8Codec(opt$) {
1758 let allowMalformed = opt$.allowMalformed === undefined ? false : opt$.allo wMalformed; 1851 let allowMalformed = opt$.allowMalformed === void 0 ? false : opt$.allowMa lformed;
1759 this._allowMalformed = allowMalformed; 1852 this._allowMalformed = allowMalformed;
1760 super.Encoding(); 1853 super.Encoding();
1761 } 1854 }
1762 get name() { return "utf-8"; } 1855 get name() {
1856 return "utf-8";
1857 }
1763 decode(codeUnits, opt$) { 1858 decode(codeUnits, opt$) {
1764 let allowMalformed = opt$.allowMalformed === undefined ? null : opt$.allow Malformed; 1859 let allowMalformed = opt$.allowMalformed === void 0 ? null : opt$.allowMal formed;
1765 if (allowMalformed === null) allowMalformed = this._allowMalformed; 1860 if (allowMalformed === null)
1861 allowMalformed = this._allowMalformed;
1766 return new Utf8Decoder({allowMalformed: allowMalformed}).convert(codeUnits ); 1862 return new Utf8Decoder({allowMalformed: allowMalformed}).convert(codeUnits );
1767 } 1863 }
1768 get encoder() { return new Utf8Encoder(); } 1864 get encoder() {
1865 return new Utf8Encoder();
1866 }
1769 get decoder() { 1867 get decoder() {
1770 return new Utf8Decoder({allowMalformed: this._allowMalformed}); 1868 return new Utf8Decoder({allowMalformed: this._allowMalformed});
1771 } 1869 }
1772 } 1870 }
1773
1774 class Utf8Encoder extends Converter$(core.String, core.List$(core.int)) { 1871 class Utf8Encoder extends Converter$(core.String, core.List$(core.int)) {
1775 Utf8Encoder() { 1872 Utf8Encoder() {
1776 super.Converter(); 1873 super.Converter();
1777 } 1874 }
1778 convert(string, start, end) { 1875 convert(string, start, end) {
1779 if (start === undefined) start = 0; 1876 if (start === void 0)
1780 if (end === undefined) end = null; 1877 start = 0;
1878 if (end === void 0)
1879 end = null;
1781 let stringLength = string.length; 1880 let stringLength = string.length;
1782 core.RangeError.checkValidRange(start, end, stringLength); 1881 core.RangeError.checkValidRange(start, end, stringLength);
1783 if (end === null) end = stringLength; 1882 if (end === null)
1883 end = stringLength;
1784 let length = end - start; 1884 let length = end - start;
1785 if (length === 0) return new typed_data.Uint8List(0); 1885 if (length === 0)
1886 return new typed_data.Uint8List(0);
1786 let encoder = new _Utf8Encoder.withBufferSize(length * 3); 1887 let encoder = new _Utf8Encoder.withBufferSize(length * 3);
1787 let endPosition = encoder._fillBuffer(string, start, end); 1888 let endPosition = encoder._fillBuffer(string, start, end);
1788 dart.assert(endPosition >= end - 1); 1889 dart.assert(endPosition >= end - 1);
1789 if (endPosition !== end) { 1890 if (endPosition !== end) {
1790 let lastCodeUnit = string.codeUnitAt(end - 1); 1891 let lastCodeUnit = string.codeUnitAt(end - 1);
1791 dart.assert(_isLeadSurrogate(lastCodeUnit)); 1892 dart.assert(_isLeadSurrogate(lastCodeUnit));
1792 let wasCombined = encoder._writeSurrogate(lastCodeUnit, 0); 1893 let wasCombined = encoder._writeSurrogate(lastCodeUnit, 0);
1793 dart.assert(!dart.notNull(wasCombined)); 1894 dart.assert(!dart.notNull(wasCombined));
1794 } 1895 }
1795 return encoder._buffer.sublist(0, encoder._bufferIndex); 1896 return encoder._buffer.sublist(0, encoder._bufferIndex);
1796 } 1897 }
1797 startChunkedConversion(sink) { 1898 startChunkedConversion(sink) {
1798 if (!dart.is(sink, ByteConversionSink)) { 1899 if (!dart.is(sink, ByteConversionSink)) {
1799 sink = new ByteConversionSink.from(sink); 1900 sink = new ByteConversionSink.from(sink);
1800 } 1901 }
1801 return new _Utf8EncoderSink(sink); 1902 return new _Utf8EncoderSink(sink);
1802 } 1903 }
1803 bind(stream) { return dart.as(super.bind(stream), async.Stream$(core.List$(c ore.int))); } 1904 bind(stream) {
1905 return dart.as(super.bind(stream), async.Stream$(core.List$(core.int)));
1906 }
1804 } 1907 }
1805
1806 class _Utf8Encoder extends dart.Object { 1908 class _Utf8Encoder extends dart.Object {
1807 _Utf8Encoder() { 1909 _Utf8Encoder() {
1808 _Utf8Encoder.call(this, dart.as(_DEFAULT_BYTE_BUFFER_SIZE, core.int)); 1910 this._Utf8Encoder$withBufferSize(dart.as(_DEFAULT_BYTE_BUFFER_SIZE, core.i nt));
1809 } 1911 }
1810 _Utf8Encoder$withBufferSize(bufferSize) { 1912 _Utf8Encoder$withBufferSize(bufferSize) {
1811 this._buffer = _createBuffer(bufferSize); 1913 this._buffer = _createBuffer(bufferSize);
1812 this._carry = 0; 1914 this._carry = 0;
1813 this._bufferIndex = 0; 1915 this._bufferIndex = 0;
1814 } 1916 }
1815 static _createBuffer(size) { return new typed_data.Uint8List(size); } 1917 static _createBuffer(size) {
1918 return new typed_data.Uint8List(size);
1919 }
1816 _writeSurrogate(leadingSurrogate, nextCodeUnit) { 1920 _writeSurrogate(leadingSurrogate, nextCodeUnit) {
1817 if (_isTailSurrogate(nextCodeUnit)) { 1921 if (_isTailSurrogate(nextCodeUnit)) {
1818 let rune = _combineSurrogatePair(leadingSurrogate, nextCodeUnit); 1922 let rune = _combineSurrogatePair(leadingSurrogate, nextCodeUnit);
1819 dart.assert(rune > _THREE_BYTE_LIMIT); 1923 dart.assert(rune > _THREE_BYTE_LIMIT);
1820 dart.assert(rune <= _FOUR_BYTE_LIMIT); 1924 dart.assert(rune <= _FOUR_BYTE_LIMIT);
1821 this._buffer.set(this._bufferIndex++, 240 | (rune >> 18)); 1925 this._buffer.set(this._bufferIndex++, 240 | rune >> 18);
1822 this._buffer.set(this._bufferIndex++, 128 | ((rune >> 12) & 63)); 1926 this._buffer.set(this._bufferIndex++, 128 | rune >> 12 & 63);
1823 this._buffer.set(this._bufferIndex++, 128 | ((rune >> 6) & 63)); 1927 this._buffer.set(this._bufferIndex++, 128 | rune >> 6 & 63);
1824 this._buffer.set(this._bufferIndex++, 128 | (rune & 63)); 1928 this._buffer.set(this._bufferIndex++, 128 | rune & 63);
1825 return true; 1929 return true;
1826 } else { 1930 } else {
1827 this._buffer.set(this._bufferIndex++, 224 | (leadingSurrogate >> 12)); 1931 this._buffer.set(this._bufferIndex++, 224 | leadingSurrogate >> 12);
1828 this._buffer.set(this._bufferIndex++, 128 | ((leadingSurrogate >> 6) & 6 3)); 1932 this._buffer.set(this._bufferIndex++, 128 | leadingSurrogate >> 6 & 63);
1829 this._buffer.set(this._bufferIndex++, 128 | (leadingSurrogate & 63)); 1933 this._buffer.set(this._bufferIndex++, 128 | leadingSurrogate & 63);
1830 return false; 1934 return false;
1831 } 1935 }
1832 } 1936 }
1833 _fillBuffer(str, start, end) { 1937 _fillBuffer(str, start, end) {
1834 if (dart.notNull(start !== end) && dart.notNull(_isLeadSurrogate(str.codeU nitAt(end - 1)))) { 1938 if (dart.notNull(start !== end) && dart.notNull(_isLeadSurrogate(str.codeU nitAt(end - 1)))) {
1835 end--; 1939 end--;
1836 } 1940 }
1837 let stringIndex = null; 1941 let stringIndex = null;
1838 for (stringIndex = start; stringIndex < end; stringIndex++) { 1942 for (stringIndex = start; stringIndex < end; stringIndex++) {
1839 let codeUnit = str.codeUnitAt(stringIndex); 1943 let codeUnit = str.codeUnitAt(stringIndex);
1840 if (codeUnit <= _ONE_BYTE_LIMIT) { 1944 if (codeUnit <= _ONE_BYTE_LIMIT) {
1841 if (this._bufferIndex >= this._buffer.length) break; 1945 if (this._bufferIndex >= this._buffer.length)
1946 break;
1842 this._buffer.set(this._bufferIndex++, codeUnit); 1947 this._buffer.set(this._bufferIndex++, codeUnit);
1843 } else if (_isLeadSurrogate(codeUnit)) { 1948 } else if (_isLeadSurrogate(codeUnit)) {
1844 if (this._bufferIndex + 3 >= this._buffer.length) break; 1949 if (this._bufferIndex + 3 >= this._buffer.length)
1950 break;
1845 let nextCodeUnit = str.codeUnitAt(stringIndex + 1); 1951 let nextCodeUnit = str.codeUnitAt(stringIndex + 1);
1846 let wasCombined = this._writeSurrogate(codeUnit, nextCodeUnit); 1952 let wasCombined = this._writeSurrogate(codeUnit, nextCodeUnit);
1847 if (wasCombined) stringIndex++; 1953 if (wasCombined)
1954 stringIndex++;
1848 } else { 1955 } else {
1849 let rune = codeUnit; 1956 let rune = codeUnit;
1850 if (rune <= _TWO_BYTE_LIMIT) { 1957 if (rune <= _TWO_BYTE_LIMIT) {
1851 if (this._bufferIndex + 1 >= this._buffer.length) break; 1958 if (this._bufferIndex + 1 >= this._buffer.length)
1852 this._buffer.set(this._bufferIndex++, 192 | (rune >> 6)); 1959 break;
1853 this._buffer.set(this._bufferIndex++, 128 | (rune & 63)); 1960 this._buffer.set(this._bufferIndex++, 192 | rune >> 6);
1961 this._buffer.set(this._bufferIndex++, 128 | rune & 63);
1854 } else { 1962 } else {
1855 dart.assert(rune <= _THREE_BYTE_LIMIT); 1963 dart.assert(rune <= _THREE_BYTE_LIMIT);
1856 if (this._bufferIndex + 2 >= this._buffer.length) break; 1964 if (this._bufferIndex + 2 >= this._buffer.length)
1857 this._buffer.set(this._bufferIndex++, 224 | (rune >> 12)); 1965 break;
1858 this._buffer.set(this._bufferIndex++, 128 | ((rune >> 6) & 63)); 1966 this._buffer.set(this._bufferIndex++, 224 | rune >> 12);
1859 this._buffer.set(this._bufferIndex++, 128 | (rune & 63)); 1967 this._buffer.set(this._bufferIndex++, 128 | rune >> 6 & 63);
1968 this._buffer.set(this._bufferIndex++, 128 | rune & 63);
1860 } 1969 }
1861 } 1970 }
1862 } 1971 }
1863 return stringIndex; 1972 return stringIndex;
1864 } 1973 }
1865 } 1974 }
1866 dart.defineNamedConstructor(_Utf8Encoder, "withBufferSize"); 1975 dart.defineNamedConstructor(_Utf8Encoder, 'withBufferSize');
1867 _Utf8Encoder._DEFAULT_BYTE_BUFFER_SIZE = 1024; 1976 _Utf8Encoder._DEFAULT_BYTE_BUFFER_SIZE = 1024;
1868
1869 class _Utf8EncoderSink extends dart.mixin(_Utf8Encoder, StringConversionSinkMi xin) { 1977 class _Utf8EncoderSink extends dart.mixin(_Utf8Encoder, StringConversionSinkMi xin) {
1870 _Utf8EncoderSink(_sink) { 1978 _Utf8EncoderSink(_sink) {
1871 this._sink = _sink; 1979 this._sink = _sink;
1872 super._Utf8Encoder(); 1980 super._Utf8Encoder();
1873 } 1981 }
1874 close() { 1982 close() {
1875 if (this._carry !== 0) { 1983 if (this._carry !== 0) {
1876 this.addSlice("", 0, 0, true); 1984 this.addSlice("", 0, 0, true);
1877 return; 1985 return;
1878 } 1986 }
1879 this._sink.close(); 1987 this._sink.close();
1880 } 1988 }
1881 addSlice(str, start, end, isLast) { 1989 addSlice(str, start, end, isLast) {
1882 this._bufferIndex = 0; 1990 this._bufferIndex = 0;
1883 if (dart.notNull(start === end) && dart.notNull(!dart.notNull(isLast))) { 1991 if (dart.notNull(start === end) && dart.notNull(!dart.notNull(isLast))) {
1884 return; 1992 return;
1885 } 1993 }
1886 if (this._carry !== 0) { 1994 if (this._carry !== 0) {
1887 let nextCodeUnit = 0; 1995 let nextCodeUnit = 0;
1888 if (start !== end) { 1996 if (start !== end) {
1889 nextCodeUnit = str.codeUnitAt(start); 1997 nextCodeUnit = str.codeUnitAt(start);
1890 } else { 1998 } else {
1891 dart.assert(isLast); 1999 dart.assert(isLast);
1892 } 2000 }
1893 let wasCombined = this._writeSurrogate(this._carry, nextCodeUnit); 2001 let wasCombined = this._writeSurrogate(this._carry, nextCodeUnit);
1894 dart.assert(dart.notNull(!dart.notNull(wasCombined)) || dart.notNull(sta rt !== end)); 2002 dart.assert(dart.notNull(!dart.notNull(wasCombined)) || dart.notNull(sta rt !== end));
1895 if (wasCombined) start++; 2003 if (wasCombined)
2004 start++;
1896 this._carry = 0; 2005 this._carry = 0;
1897 } 2006 }
1898 do { 2007 do {
1899 start = this._fillBuffer(str, start, end); 2008 start = this._fillBuffer(str, start, end);
1900 let isLastSlice = dart.notNull(isLast) && dart.notNull((start === end)); 2009 let isLastSlice = dart.notNull(isLast) && dart.notNull(start === end);
1901 if (dart.notNull(start === end - 1) && dart.notNull(_isLeadSurrogate(str .codeUnitAt(start)))) { 2010 if (dart.notNull(start === end - 1) && dart.notNull(_isLeadSurrogate(str .codeUnitAt(start)))) {
1902 if (dart.notNull(isLast) && dart.notNull(this._bufferIndex < this._buf fer.length - 3)) { 2011 if (dart.notNull(isLast) && dart.notNull(this._bufferIndex < this._buf fer.length - 3)) {
1903 let hasBeenCombined = this._writeSurrogate(str.codeUnitAt(start), 0) ; 2012 let hasBeenCombined = this._writeSurrogate(str.codeUnitAt(start), 0) ;
1904 dart.assert(!dart.notNull(hasBeenCombined)); 2013 dart.assert(!dart.notNull(hasBeenCombined));
1905 } else { 2014 } else {
1906 this._carry = str.codeUnitAt(start); 2015 this._carry = str.codeUnitAt(start);
1907 } 2016 }
1908 start++; 2017 start++;
1909 } 2018 }
1910 this._sink.addSlice(this._buffer, 0, this._bufferIndex, isLastSlice); 2019 this._sink.addSlice(this._buffer, 0, this._bufferIndex, isLastSlice);
1911 this._bufferIndex = 0; 2020 this._bufferIndex = 0;
1912 } 2021 } while (start < end);
1913 while (start < end); 2022 if (isLast)
1914 if (isLast) this.close(); 2023 this.close();
1915 } 2024 }
1916 } 2025 }
1917
1918 class Utf8Decoder extends Converter$(core.List$(core.int), core.String) { 2026 class Utf8Decoder extends Converter$(core.List$(core.int), core.String) {
1919 Utf8Decoder(opt$) { 2027 Utf8Decoder(opt$) {
1920 let allowMalformed = opt$.allowMalformed === undefined ? false : opt$.allo wMalformed; 2028 let allowMalformed = opt$.allowMalformed === void 0 ? false : opt$.allowMa lformed;
1921 this._allowMalformed = allowMalformed; 2029 this._allowMalformed = allowMalformed;
1922 super.Converter(); 2030 super.Converter();
1923 } 2031 }
1924 convert(codeUnits, start, end) { 2032 convert(codeUnits, start, end) {
1925 if (start === undefined) start = 0; 2033 if (start === void 0)
1926 if (end === undefined) end = null; 2034 start = 0;
2035 if (end === void 0)
2036 end = null;
1927 let length = codeUnits.length; 2037 let length = codeUnits.length;
1928 core.RangeError.checkValidRange(start, end, length); 2038 core.RangeError.checkValidRange(start, end, length);
1929 if (end === null) end = length; 2039 if (end === null)
2040 end = length;
1930 let buffer = new core.StringBuffer(); 2041 let buffer = new core.StringBuffer();
1931 let decoder = new _Utf8Decoder(buffer, this._allowMalformed); 2042 let decoder = new _Utf8Decoder(buffer, this._allowMalformed);
1932 decoder.convert(codeUnits, start, end); 2043 decoder.convert(codeUnits, start, end);
1933 decoder.close(); 2044 decoder.close();
1934 return buffer.toString(); 2045 return buffer.toString();
1935 } 2046 }
1936 startChunkedConversion(sink) { 2047 startChunkedConversion(sink) {
1937 let stringSink = null; 2048 let stringSink = null;
1938 if (dart.is(sink, StringConversionSink)) { 2049 if (dart.is(sink, StringConversionSink)) {
1939 stringSink = sink; 2050 stringSink = sink;
1940 } else { 2051 } else {
1941 stringSink = new StringConversionSink.from(sink); 2052 stringSink = new StringConversionSink.from(sink);
1942 } 2053 }
1943 return stringSink.asUtf8Sink(this._allowMalformed); 2054 return stringSink.asUtf8Sink(this._allowMalformed);
1944 } 2055 }
1945 bind(stream) { return dart.as(super.bind(stream), async.Stream$(core.String) ); } 2056 bind(stream) {
2057 return dart.as(super.bind(stream), async.Stream$(core.String));
2058 }
1946 fuse(next) { 2059 fuse(next) {
1947 return super.fuse(next); 2060 return super.fuse(next);
1948 } 2061 }
1949 } 2062 }
1950
1951 let _ONE_BYTE_LIMIT = 127; 2063 let _ONE_BYTE_LIMIT = 127;
1952 let _TWO_BYTE_LIMIT = 2047; 2064 let _TWO_BYTE_LIMIT = 2047;
1953 let _THREE_BYTE_LIMIT = 65535; 2065 let _THREE_BYTE_LIMIT = 65535;
1954 let _FOUR_BYTE_LIMIT = 1114111; 2066 let _FOUR_BYTE_LIMIT = 1114111;
1955 let _SURROGATE_MASK = 63488; 2067 let _SURROGATE_MASK = 63488;
1956 let _SURROGATE_TAG_MASK = 64512; 2068 let _SURROGATE_TAG_MASK = 64512;
1957 let _SURROGATE_VALUE_MASK = 1023; 2069 let _SURROGATE_VALUE_MASK = 1023;
1958 let _LEAD_SURROGATE_MIN = 55296; 2070 let _LEAD_SURROGATE_MIN = 55296;
1959 let _TAIL_SURROGATE_MIN = 56320; 2071 let _TAIL_SURROGATE_MIN = 56320;
1960 // Function _isSurrogate: (int) → bool 2072 // Function _isSurrogate: (int) → bool
1961 function _isSurrogate(codeUnit) { return (codeUnit & _SURROGATE_MASK) === _LEA D_SURROGATE_MIN; } 2073 function _isSurrogate(codeUnit) {
1962 2074 return (codeUnit & _SURROGATE_MASK) === _LEAD_SURROGATE_MIN;
2075 }
1963 // Function _isLeadSurrogate: (int) → bool 2076 // Function _isLeadSurrogate: (int) → bool
1964 function _isLeadSurrogate(codeUnit) { return (codeUnit & _SURROGATE_TAG_MASK) === _LEAD_SURROGATE_MIN; } 2077 function _isLeadSurrogate(codeUnit) {
1965 2078 return (codeUnit & _SURROGATE_TAG_MASK) === _LEAD_SURROGATE_MIN;
2079 }
1966 // Function _isTailSurrogate: (int) → bool 2080 // Function _isTailSurrogate: (int) → bool
1967 function _isTailSurrogate(codeUnit) { return (codeUnit & _SURROGATE_TAG_MASK) === _TAIL_SURROGATE_MIN; } 2081 function _isTailSurrogate(codeUnit) {
1968 2082 return (codeUnit & _SURROGATE_TAG_MASK) === _TAIL_SURROGATE_MIN;
2083 }
1969 // Function _combineSurrogatePair: (int, int) → int 2084 // Function _combineSurrogatePair: (int, int) → int
1970 function _combineSurrogatePair(lead, tail) { return 65536 + ((lead & _SURROGAT E_VALUE_MASK) << 10) | (tail & _SURROGATE_VALUE_MASK); } 2085 function _combineSurrogatePair(lead, tail) {
1971 2086 return 65536 + ((lead & _SURROGATE_VALUE_MASK) << 10) | tail & _SURROGATE_VA LUE_MASK;
2087 }
1972 class _Utf8Decoder extends dart.Object { 2088 class _Utf8Decoder extends dart.Object {
1973 _Utf8Decoder(_stringSink, _allowMalformed) { 2089 _Utf8Decoder(_stringSink, _allowMalformed) {
1974 this._stringSink = _stringSink; 2090 this._stringSink = _stringSink;
1975 this._allowMalformed = _allowMalformed; 2091 this._allowMalformed = _allowMalformed;
1976 this._isFirstCharacter = true; 2092 this._isFirstCharacter = true;
1977 this._value = 0; 2093 this._value = 0;
1978 this._expectedUnits = 0; 2094 this._expectedUnits = 0;
1979 this._extraUnits = 0; 2095 this._extraUnits = 0;
1980 } 2096 }
1981 get hasPartialInput() { return this._expectedUnits > 0; } 2097 get hasPartialInput() {
2098 return this._expectedUnits > 0;
2099 }
1982 close() { 2100 close() {
1983 this.flush(); 2101 this.flush();
1984 } 2102 }
1985 flush() { 2103 flush() {
1986 if (this.hasPartialInput) { 2104 if (this.hasPartialInput) {
1987 if (!dart.notNull(this._allowMalformed)) { 2105 if (!dart.notNull(this._allowMalformed)) {
1988 throw new core.FormatException("Unfinished UTF-8 octet sequence"); 2106 throw new core.FormatException("Unfinished UTF-8 octet sequence");
1989 } 2107 }
1990 this._stringSink.writeCharCode(UNICODE_REPLACEMENT_CHARACTER_RUNE); 2108 this._stringSink.writeCharCode(UNICODE_REPLACEMENT_CHARACTER_RUNE);
1991 this._value = 0; 2109 this._value = 0;
1992 this._expectedUnits = 0; 2110 this._expectedUnits = 0;
1993 this._extraUnits = 0; 2111 this._extraUnits = 0;
1994 } 2112 }
1995 } 2113 }
1996 convert(codeUnits, startIndex, endIndex) { 2114 convert(codeUnits, startIndex, endIndex) {
1997 let value = this._value; 2115 let value = this._value;
1998 let expectedUnits = this._expectedUnits; 2116 let expectedUnits = this._expectedUnits;
1999 let extraUnits = this._extraUnits; 2117 let extraUnits = this._extraUnits;
2000 this._value = 0; 2118 this._value = 0;
2001 this._expectedUnits = 0; 2119 this._expectedUnits = 0;
2002 this._extraUnits = 0; 2120 this._extraUnits = 0;
2003 // Function scanOneByteCharacters: (dynamic, int) → int 2121 // Function scanOneByteCharacters: (dynamic, int) → int
2004 function scanOneByteCharacters(units, from) { 2122 function scanOneByteCharacters(units, from) {
2005 let to = endIndex; 2123 let to = endIndex;
2006 let mask = _ONE_BYTE_LIMIT; 2124 let mask = _ONE_BYTE_LIMIT;
2007 for (let i = from; i < to; i++) { 2125 for (let i = from; i < to; i++) {
2008 let unit = dart.dindex(units, i); 2126 let unit = dart.dindex(units, i);
2009 if (!dart.equals((dart.dbinary(unit, "&", mask)), unit)) return i - fr om; 2127 if (!dart.equals(dart.dbinary(unit, '&', mask), unit))
2128 return i - from;
2010 } 2129 }
2011 return to - from; 2130 return to - from;
2012 } 2131 }
2013 // Function addSingleBytes: (int, int) → void 2132 // Function addSingleBytes: (int, int) → void
2014 function addSingleBytes(from, to) { 2133 function addSingleBytes(from, to) {
2015 dart.assert(dart.notNull(from >= startIndex) && dart.notNull(from <= end Index)); 2134 dart.assert(dart.notNull(from >= startIndex) && dart.notNull(from <= end Index));
2016 dart.assert(dart.notNull(to >= startIndex) && dart.notNull(to <= endInde x)); 2135 dart.assert(dart.notNull(to >= startIndex) && dart.notNull(to <= endInde x));
2017 this._stringSink.write(new core.String.fromCharCodes(codeUnits, from, to )); 2136 this._stringSink.write(new core.String.fromCharCodes(codeUnits, from, to ));
2018 } 2137 }
2019 let i = startIndex; 2138 let i = startIndex;
2020 loop: while (true) { 2139 loop:
2021 multibyte: if (expectedUnits > 0) { 2140 while (true) {
2022 do { 2141 multibyte:
2023 if (i === endIndex) { 2142 if (expectedUnits > 0) {
2024 break loop; 2143 do {
2144 if (i === endIndex) {
2145 break loop;
2146 }
2147 let unit = codeUnits.get(i);
2148 if ((unit & 192) !== 128) {
2149 expectedUnits = 0;
2150 if (!dart.notNull(this._allowMalformed)) {
2151 throw new core.FormatException(`Bad UTF-8 encoding 0x${unit. toRadixString(16)}`);
2152 }
2153 this._isFirstCharacter = false;
2154 this._stringSink.writeCharCode(UNICODE_REPLACEMENT_CHARACTER_R UNE);
2155 break multibyte;
2156 } else {
2157 value = value << 6 | unit & 63;
2158 expectedUnits--;
2159 i++;
2160 }
2161 } while (expectedUnits > 0);
2162 if (value <= _LIMITS.get(extraUnits - 1)) {
2163 if (!dart.notNull(this._allowMalformed)) {
2164 throw new core.FormatException(`Overlong encoding of 0x${value .toRadixString(16)}`);
2165 }
2166 expectedUnits = extraUnits = 0;
2167 value = UNICODE_REPLACEMENT_CHARACTER_RUNE;
2168 }
2169 if (value > _FOUR_BYTE_LIMIT) {
2170 if (!dart.notNull(this._allowMalformed)) {
2171 throw new core.FormatException("Character outside valid Unicod e range: " + `0x${value.toRadixString(16)}`);
2172 }
2173 value = UNICODE_REPLACEMENT_CHARACTER_RUNE;
2174 }
2175 if (dart.notNull(!dart.notNull(this._isFirstCharacter)) || dart.no tNull(value !== UNICODE_BOM_CHARACTER_RUNE)) {
2176 this._stringSink.writeCharCode(value);
2177 }
2178 this._isFirstCharacter = false;
2025 } 2179 }
2026 let unit = codeUnits.get(i); 2180 while (i < endIndex) {
2027 if ((unit & 192) !== 128) { 2181 let oneBytes = scanOneByteCharacters(codeUnits, i);
2028 expectedUnits = 0; 2182 if (oneBytes > 0) {
2183 this._isFirstCharacter = false;
2184 addSingleBytes(i, i + oneBytes);
2185 i = oneBytes;
2186 if (i === endIndex)
2187 break;
2188 }
2189 let unit = codeUnits.get(i++);
2190 if (unit < 0) {
2191 if (!dart.notNull(this._allowMalformed)) {
2192 throw new core.FormatException(`Negative UTF-8 code unit: -0x${( -unit).toRadixString(16)}`);
2193 }
2194 this._stringSink.writeCharCode(UNICODE_REPLACEMENT_CHARACTER_RUNE) ;
2195 } else {
2196 dart.assert(unit > _ONE_BYTE_LIMIT);
2197 if ((unit & 224) === 192) {
2198 value = unit & 31;
2199 expectedUnits = extraUnits = 1;
2200 continue loop;
2201 }
2202 if ((unit & 240) === 224) {
2203 value = unit & 15;
2204 expectedUnits = extraUnits = 2;
2205 continue loop;
2206 }
2207 if (dart.notNull((unit & 248) === 240) && dart.notNull(unit < 245) ) {
2208 value = unit & 7;
2209 expectedUnits = extraUnits = 3;
2210 continue loop;
2211 }
2029 if (!dart.notNull(this._allowMalformed)) { 2212 if (!dart.notNull(this._allowMalformed)) {
2030 throw new core.FormatException(`Bad UTF-8 encoding 0x${unit.toRa dixString(16)}`); 2213 throw new core.FormatException(`Bad UTF-8 encoding 0x${unit.toRa dixString(16)}`);
2031 } 2214 }
2215 value = UNICODE_REPLACEMENT_CHARACTER_RUNE;
2216 expectedUnits = extraUnits = 0;
2032 this._isFirstCharacter = false; 2217 this._isFirstCharacter = false;
2033 this._stringSink.writeCharCode(UNICODE_REPLACEMENT_CHARACTER_RUNE) ; 2218 this._stringSink.writeCharCode(value);
2034 break multibyte;
2035 } else {
2036 value = (value << 6) | (unit & 63);
2037 expectedUnits--;
2038 i++;
2039 } 2219 }
2040 } 2220 }
2041 while (expectedUnits > 0); 2221 break loop;
2042 if (value <= _LIMITS.get(extraUnits - 1)) {
2043 if (!dart.notNull(this._allowMalformed)) {
2044 throw new core.FormatException(`Overlong encoding of 0x${value.toR adixString(16)}`);
2045 }
2046 expectedUnits = extraUnits = 0;
2047 value = UNICODE_REPLACEMENT_CHARACTER_RUNE;
2048 }
2049 if (value > _FOUR_BYTE_LIMIT) {
2050 if (!dart.notNull(this._allowMalformed)) {
2051 throw new core.FormatException("Character outside valid Unicode ra nge: " +
2052 `0x${value.toRadixString(16)}`);
2053 }
2054 value = UNICODE_REPLACEMENT_CHARACTER_RUNE;
2055 }
2056 if (dart.notNull(!dart.notNull(this._isFirstCharacter)) || dart.notNul l(value !== UNICODE_BOM_CHARACTER_RUNE)) {
2057 this._stringSink.writeCharCode(value);
2058 }
2059 this._isFirstCharacter = false;
2060 } 2222 }
2061 while (i < endIndex) {
2062 let oneBytes = scanOneByteCharacters(codeUnits, i);
2063 if (oneBytes > 0) {
2064 this._isFirstCharacter = false;
2065 addSingleBytes(i, i + oneBytes);
2066 i = oneBytes;
2067 if (i === endIndex) break;
2068 }
2069 let unit = codeUnits.get(i++);
2070 if (unit < 0) {
2071 if (!dart.notNull(this._allowMalformed)) {
2072 throw new core.FormatException(`Negative UTF-8 code unit: -0x${(-u nit).toRadixString(16)}`);
2073 }
2074 this._stringSink.writeCharCode(UNICODE_REPLACEMENT_CHARACTER_RUNE);
2075 } else {
2076 dart.assert(unit > _ONE_BYTE_LIMIT);
2077 if ((unit & 224) === 192) {
2078 value = unit & 31;
2079 expectedUnits = extraUnits = 1;
2080 continue loop;
2081 }
2082 if ((unit & 240) === 224) {
2083 value = unit & 15;
2084 expectedUnits = extraUnits = 2;
2085 continue loop;
2086 }
2087 if (dart.notNull((unit & 248) === 240) && dart.notNull(unit < 245)) {
2088 value = unit & 7;
2089 expectedUnits = extraUnits = 3;
2090 continue loop;
2091 }
2092 if (!dart.notNull(this._allowMalformed)) {
2093 throw new core.FormatException(`Bad UTF-8 encoding 0x${unit.toRadi xString(16)}`);
2094 }
2095 value = UNICODE_REPLACEMENT_CHARACTER_RUNE;
2096 expectedUnits = extraUnits = 0;
2097 this._isFirstCharacter = false;
2098 this._stringSink.writeCharCode(value);
2099 }
2100 }
2101 break loop;
2102 }
2103 if (expectedUnits > 0) { 2223 if (expectedUnits > 0) {
2104 this._value = value; 2224 this._value = value;
2105 this._expectedUnits = expectedUnits; 2225 this._expectedUnits = expectedUnits;
2106 this._extraUnits = extraUnits; 2226 this._extraUnits = extraUnits;
2107 } 2227 }
2108 } 2228 }
2109 } 2229 }
2110 _Utf8Decoder._LIMITS = /* Unimplemented const */new List.from([_ONE_BYTE_LIMIT , _TWO_BYTE_LIMIT, _THREE_BYTE_LIMIT, _FOUR_BYTE_LIMIT]); 2230 _Utf8Decoder._LIMITS = /* Unimplemented const */new List.from([_ONE_BYTE_LIMIT , _TWO_BYTE_LIMIT, _THREE_BYTE_LIMIT, _FOUR_BYTE_LIMIT]);
2111
2112 // Exports: 2231 // Exports:
2113 convert.ASCII = ASCII; 2232 convert.ASCII = ASCII;
2114 convert.AsciiCodec = AsciiCodec; 2233 convert.AsciiCodec = AsciiCodec;
2115 convert.AsciiEncoder = AsciiEncoder; 2234 convert.AsciiEncoder = AsciiEncoder;
2116 convert.AsciiDecoder = AsciiDecoder; 2235 convert.AsciiDecoder = AsciiDecoder;
2117 convert.ByteConversionSink = ByteConversionSink; 2236 convert.ByteConversionSink = ByteConversionSink;
2118 convert.ByteConversionSinkBase = ByteConversionSinkBase; 2237 convert.ByteConversionSinkBase = ByteConversionSinkBase;
2119 convert.ChunkedConversionSink = ChunkedConversionSink; 2238 convert.ChunkedConversionSink = ChunkedConversionSink;
2120 convert.ChunkedConversionSink$ = ChunkedConversionSink$; 2239 convert.ChunkedConversionSink$ = ChunkedConversionSink$;
2121 convert.Codec = Codec; 2240 convert.Codec = Codec;
(...skipping 20 matching lines...) Expand all
2142 convert.ClosableStringSink = ClosableStringSink; 2261 convert.ClosableStringSink = ClosableStringSink;
2143 convert.StringConversionSinkBase = StringConversionSinkBase; 2262 convert.StringConversionSinkBase = StringConversionSinkBase;
2144 convert.StringConversionSinkMixin = StringConversionSinkMixin; 2263 convert.StringConversionSinkMixin = StringConversionSinkMixin;
2145 convert.UNICODE_REPLACEMENT_CHARACTER_RUNE = UNICODE_REPLACEMENT_CHARACTER_RUN E; 2264 convert.UNICODE_REPLACEMENT_CHARACTER_RUNE = UNICODE_REPLACEMENT_CHARACTER_RUN E;
2146 convert.UNICODE_BOM_CHARACTER_RUNE = UNICODE_BOM_CHARACTER_RUNE; 2265 convert.UNICODE_BOM_CHARACTER_RUNE = UNICODE_BOM_CHARACTER_RUNE;
2147 convert.UTF8 = UTF8; 2266 convert.UTF8 = UTF8;
2148 convert.Utf8Codec = Utf8Codec; 2267 convert.Utf8Codec = Utf8Codec;
2149 convert.Utf8Encoder = Utf8Encoder; 2268 convert.Utf8Encoder = Utf8Encoder;
2150 convert.Utf8Decoder = Utf8Decoder; 2269 convert.Utf8Decoder = Utf8Decoder;
2151 })(convert || (convert = {})); 2270 })(convert || (convert = {}));
OLDNEW
« no previous file with comments | « test/codegen/expect/constructors/constructors.js ('k') | test/codegen/expect/core/core.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698