| OLD | NEW |
| (Empty) |
| 1 dart_library.library('dart/js', null, /* Imports */[ | |
| 2 "dart_runtime/dart", | |
| 3 'dart/core', | |
| 4 'dart/collection', | |
| 5 'dart/_js_helper' | |
| 6 ], /* Lazy imports */[ | |
| 7 ], function(exports, dart, core, collection, _js_helper) { | |
| 8 'use strict'; | |
| 9 let dartx = dart.dartx; | |
| 10 dart.defineLazyProperties(exports, { | |
| 11 get context() { | |
| 12 return dart.as(_wrapToDart(dart.global), JsObject); | |
| 13 } | |
| 14 }); | |
| 15 let _jsObject = Symbol('_jsObject'); | |
| 16 class JsObject extends core.Object { | |
| 17 _fromJs(jsObject) { | |
| 18 this[_jsObject] = jsObject; | |
| 19 dart.assert(this[_jsObject] != null); | |
| 20 } | |
| 21 static new(constructor, arguments$) { | |
| 22 if (arguments$ === void 0) | |
| 23 arguments$ = null; | |
| 24 let ctor = constructor[_jsObject]; | |
| 25 if (arguments$ == null) { | |
| 26 return dart.as(_wrapToDart(new ctor()), JsObject); | |
| 27 } | |
| 28 return dart.as(_wrapToDart(new ctor(...arguments$)), JsObject); | |
| 29 } | |
| 30 static fromBrowserObject(object) { | |
| 31 if (dart.is(object, core.num) || typeof object == 'string' || typeof objec
t == 'boolean' || object == null) { | |
| 32 dart.throw(new core.ArgumentError("object cannot be a num, string, bool,
or null")); | |
| 33 } | |
| 34 return dart.as(_wrapToDart(_convertToJS(object)), JsObject); | |
| 35 } | |
| 36 static jsify(object) { | |
| 37 if (!dart.is(object, core.Map) && !dart.is(object, core.Iterable)) { | |
| 38 dart.throw(new core.ArgumentError("object must be a Map or Iterable")); | |
| 39 } | |
| 40 return dart.as(_wrapToDart(JsObject._convertDataTree(object)), JsObject); | |
| 41 } | |
| 42 static _convertDataTree(data) { | |
| 43 let _convertedObjects = collection.HashMap.identity(); | |
| 44 function _convert(o) { | |
| 45 if (dart.notNull(_convertedObjects.containsKey(o))) { | |
| 46 return _convertedObjects.get(o); | |
| 47 } | |
| 48 if (dart.is(o, core.Map)) { | |
| 49 let convertedMap = {}; | |
| 50 _convertedObjects.set(o, convertedMap); | |
| 51 for (let key of dart.as(dart.dload(o, 'keys'), core.Iterable)) { | |
| 52 convertedMap[key] = _convert(dart.dindex(o, key)); | |
| 53 } | |
| 54 return convertedMap; | |
| 55 } else if (dart.is(o, core.Iterable)) { | |
| 56 let convertedList = []; | |
| 57 _convertedObjects.set(o, convertedList); | |
| 58 convertedList[dartx.addAll](dart.as(dart.dsend(o, 'map', _convert), co
re.Iterable)); | |
| 59 return convertedList; | |
| 60 } else { | |
| 61 return _convertToJS(o); | |
| 62 } | |
| 63 } | |
| 64 dart.fn(_convert); | |
| 65 return _convert(data); | |
| 66 } | |
| 67 get(property) { | |
| 68 if (!(typeof property == 'string') && !dart.is(property, core.num)) { | |
| 69 dart.throw(new core.ArgumentError("property is not a String or num")); | |
| 70 } | |
| 71 return _convertToDart(this[_jsObject][property]); | |
| 72 } | |
| 73 set(property, value) { | |
| 74 if (!(typeof property == 'string') && !dart.is(property, core.num)) { | |
| 75 dart.throw(new core.ArgumentError("property is not a String or num")); | |
| 76 } | |
| 77 this[_jsObject][property] = _convertToJS(value); | |
| 78 return value; | |
| 79 } | |
| 80 get hashCode() { | |
| 81 return 0; | |
| 82 } | |
| 83 ['=='](other) { | |
| 84 return dart.is(other, JsObject) && this[_jsObject] === dart.dload(other, _
jsObject); | |
| 85 } | |
| 86 hasProperty(property) { | |
| 87 if (!(typeof property == 'string') && !dart.is(property, core.num)) { | |
| 88 dart.throw(new core.ArgumentError("property is not a String or num")); | |
| 89 } | |
| 90 return property in this[_jsObject]; | |
| 91 } | |
| 92 deleteProperty(property) { | |
| 93 if (!(typeof property == 'string') && !dart.is(property, core.num)) { | |
| 94 dart.throw(new core.ArgumentError("property is not a String or num")); | |
| 95 } | |
| 96 delete this[_jsObject][property]; | |
| 97 } | |
| 98 instanceof(type) { | |
| 99 return this[_jsObject] instanceof _convertToJS(type); | |
| 100 } | |
| 101 toString() { | |
| 102 try { | |
| 103 return String(this[_jsObject]); | |
| 104 } catch (e) { | |
| 105 return super.toString(); | |
| 106 } | |
| 107 | |
| 108 } | |
| 109 callMethod(method, args) { | |
| 110 if (args === void 0) | |
| 111 args = null; | |
| 112 if (!(typeof method == 'string') && !dart.is(method, core.num)) { | |
| 113 dart.throw(new core.ArgumentError("method is not a String or num")); | |
| 114 } | |
| 115 if (args != null) | |
| 116 args = core.List.from(args[dartx.map](_convertToJS)); | |
| 117 let fn = this[_jsObject][method]; | |
| 118 if (!(fn instanceof Function)) { | |
| 119 dart.throw(new core.NoSuchMethodError(this[_jsObject], core.Symbol.new(d
art.as(method, core.String)), args, dart.map())); | |
| 120 } | |
| 121 return _convertToDart(fn.apply(this[_jsObject], args)); | |
| 122 } | |
| 123 } | |
| 124 dart.defineNamedConstructor(JsObject, '_fromJs'); | |
| 125 dart.setSignature(JsObject, { | |
| 126 constructors: () => ({ | |
| 127 _fromJs: [JsObject, [dart.dynamic]], | |
| 128 new: [JsObject, [JsFunction], [core.List]], | |
| 129 fromBrowserObject: [JsObject, [dart.dynamic]], | |
| 130 jsify: [JsObject, [dart.dynamic]] | |
| 131 }), | |
| 132 methods: () => ({ | |
| 133 get: [dart.dynamic, [dart.dynamic]], | |
| 134 set: [dart.dynamic, [dart.dynamic, dart.dynamic]], | |
| 135 hasProperty: [core.bool, [dart.dynamic]], | |
| 136 deleteProperty: [dart.void, [dart.dynamic]], | |
| 137 instanceof: [core.bool, [JsFunction]], | |
| 138 callMethod: [dart.dynamic, [dart.dynamic], [core.List]] | |
| 139 }), | |
| 140 statics: () => ({_convertDataTree: [dart.dynamic, [dart.dynamic]]}), | |
| 141 names: ['_convertDataTree'] | |
| 142 }); | |
| 143 class JsFunction extends JsObject { | |
| 144 static withThis(f) { | |
| 145 return new JsFunction._fromJs(function() { | |
| 146 let args = [_convertToDart(this)]; | |
| 147 for (let arg of arguments) { | |
| 148 args.push(_convertToDart(arg)); | |
| 149 } | |
| 150 return _convertToJS(f(...args)); | |
| 151 }); | |
| 152 } | |
| 153 _fromJs(jsObject) { | |
| 154 super._fromJs(jsObject); | |
| 155 } | |
| 156 apply(args, opts) { | |
| 157 let thisArg = opts && 'thisArg' in opts ? opts.thisArg : null; | |
| 158 return _convertToDart(this[_jsObject].apply(_convertToJS(thisArg), args ==
null ? null : core.List.from(args[dartx.map](_convertToJS)))); | |
| 159 } | |
| 160 } | |
| 161 dart.defineNamedConstructor(JsFunction, '_fromJs'); | |
| 162 dart.setSignature(JsFunction, { | |
| 163 constructors: () => ({ | |
| 164 withThis: [JsFunction, [core.Function]], | |
| 165 _fromJs: [JsFunction, [dart.dynamic]] | |
| 166 }), | |
| 167 methods: () => ({apply: [dart.dynamic, [core.List], {thisArg: dart.dynamic}]
}) | |
| 168 }); | |
| 169 let _checkIndex = Symbol('_checkIndex'); | |
| 170 let _checkInsertIndex = Symbol('_checkInsertIndex'); | |
| 171 let JsArray$ = dart.generic(function(E) { | |
| 172 class JsArray extends dart.mixin(JsObject, collection.ListMixin$(E)) { | |
| 173 JsArray() { | |
| 174 super._fromJs([]); | |
| 175 } | |
| 176 from(other) { | |
| 177 super._fromJs((() => { | |
| 178 let _ = []; | |
| 179 _[dartx.addAll](other[dartx.map](dart.as(_convertToJS, __CastType0))); | |
| 180 return _; | |
| 181 })()); | |
| 182 } | |
| 183 _fromJs(jsObject) { | |
| 184 super._fromJs(jsObject); | |
| 185 } | |
| 186 [_checkIndex](index) { | |
| 187 if (typeof index == 'number' && (dart.notNull(index) < 0 || dart.notNull
(index) >= dart.notNull(this.length))) { | |
| 188 dart.throw(new core.RangeError.range(index, 0, this.length)); | |
| 189 } | |
| 190 } | |
| 191 [_checkInsertIndex](index) { | |
| 192 if (typeof index == 'number' && (dart.notNull(index) < 0 || dart.notNull
(index) >= dart.notNull(this.length) + 1)) { | |
| 193 dart.throw(new core.RangeError.range(index, 0, this.length)); | |
| 194 } | |
| 195 } | |
| 196 static _checkRange(start, end, length) { | |
| 197 if (dart.notNull(start) < 0 || dart.notNull(start) > dart.notNull(length
)) { | |
| 198 dart.throw(new core.RangeError.range(start, 0, length)); | |
| 199 } | |
| 200 if (dart.notNull(end) < dart.notNull(start) || dart.notNull(end) > dart.
notNull(length)) { | |
| 201 dart.throw(new core.RangeError.range(end, start, length)); | |
| 202 } | |
| 203 } | |
| 204 get(index) { | |
| 205 if (dart.is(index, core.num) && index == index[dartx.toInt]()) { | |
| 206 this[_checkIndex](index); | |
| 207 } | |
| 208 return dart.as(super.get(index), E); | |
| 209 } | |
| 210 set(index, value) { | |
| 211 dart.as(value, E); | |
| 212 if (dart.is(index, core.num) && index == index[dartx.toInt]()) { | |
| 213 this[_checkIndex](index); | |
| 214 } | |
| 215 super.set(index, value); | |
| 216 return value; | |
| 217 } | |
| 218 get length() { | |
| 219 let len = this[_jsObject].length; | |
| 220 if (typeof len === "number" && len >>> 0 === len) { | |
| 221 return len; | |
| 222 } | |
| 223 dart.throw(new core.StateError('Bad JsArray length')); | |
| 224 } | |
| 225 set length(length) { | |
| 226 super.set('length', length); | |
| 227 } | |
| 228 add(value) { | |
| 229 dart.as(value, E); | |
| 230 this.callMethod('push', [value]); | |
| 231 } | |
| 232 addAll(iterable) { | |
| 233 dart.as(iterable, core.Iterable$(E)); | |
| 234 let list = iterable instanceof Array ? iterable : core.List.from(iterabl
e); | |
| 235 this.callMethod('push', dart.as(list, core.List)); | |
| 236 } | |
| 237 insert(index, element) { | |
| 238 dart.as(element, E); | |
| 239 this[_checkInsertIndex](index); | |
| 240 this.callMethod('splice', [index, 0, element]); | |
| 241 } | |
| 242 removeAt(index) { | |
| 243 this[_checkIndex](index); | |
| 244 return dart.as(dart.dindex(this.callMethod('splice', [index, 1]), 0), E)
; | |
| 245 } | |
| 246 removeLast() { | |
| 247 if (this.length == 0) | |
| 248 dart.throw(new core.RangeError(-1)); | |
| 249 return dart.as(this.callMethod('pop'), E); | |
| 250 } | |
| 251 removeRange(start, end) { | |
| 252 JsArray$()._checkRange(start, end, this.length); | |
| 253 this.callMethod('splice', [start, dart.notNull(end) - dart.notNull(start
)]); | |
| 254 } | |
| 255 setRange(start, end, iterable, skipCount) { | |
| 256 dart.as(iterable, core.Iterable$(E)); | |
| 257 if (skipCount === void 0) | |
| 258 skipCount = 0; | |
| 259 JsArray$()._checkRange(start, end, this.length); | |
| 260 let length = dart.notNull(end) - dart.notNull(start); | |
| 261 if (length == 0) | |
| 262 return; | |
| 263 if (dart.notNull(skipCount) < 0) | |
| 264 dart.throw(new core.ArgumentError(skipCount)); | |
| 265 let args = [start, length]; | |
| 266 args[dartx.addAll](iterable[dartx.skip](skipCount)[dartx.take](length)); | |
| 267 this.callMethod('splice', args); | |
| 268 } | |
| 269 sort(compare) { | |
| 270 if (compare === void 0) | |
| 271 compare = null; | |
| 272 dart.as(compare, dart.functionType(core.int, [E, E])); | |
| 273 this.callMethod('sort', compare == null ? [] : [compare]); | |
| 274 } | |
| 275 } | |
| 276 dart.defineNamedConstructor(JsArray, 'from'); | |
| 277 dart.defineNamedConstructor(JsArray, '_fromJs'); | |
| 278 dart.setSignature(JsArray, { | |
| 279 constructors: () => ({ | |
| 280 JsArray: [JsArray$(E), []], | |
| 281 from: [JsArray$(E), [core.Iterable$(E)]], | |
| 282 _fromJs: [JsArray$(E), [dart.dynamic]] | |
| 283 }), | |
| 284 methods: () => ({ | |
| 285 [_checkIndex]: [dart.dynamic, [core.int]], | |
| 286 [_checkInsertIndex]: [dart.dynamic, [core.int]], | |
| 287 get: [E, [core.int]], | |
| 288 set: [dart.void, [core.int, E]], | |
| 289 add: [dart.void, [E]], | |
| 290 addAll: [dart.void, [core.Iterable$(E)]], | |
| 291 insert: [dart.void, [core.int, E]], | |
| 292 removeAt: [E, [core.int]], | |
| 293 removeLast: [E, []], | |
| 294 setRange: [dart.void, [core.int, core.int, core.Iterable$(E)], [core.int
]], | |
| 295 sort: [dart.void, [], [dart.functionType(core.int, [E, E])]] | |
| 296 }), | |
| 297 statics: () => ({_checkRange: [dart.dynamic, [core.int, core.int, core.int
]]}), | |
| 298 names: ['_checkRange'] | |
| 299 }); | |
| 300 dart.defineExtensionMembers(JsArray, [ | |
| 301 'get', | |
| 302 'set', | |
| 303 'add', | |
| 304 'addAll', | |
| 305 'insert', | |
| 306 'removeAt', | |
| 307 'removeLast', | |
| 308 'removeRange', | |
| 309 'setRange', | |
| 310 'sort', | |
| 311 'length', | |
| 312 'length' | |
| 313 ]); | |
| 314 return JsArray; | |
| 315 }); | |
| 316 let JsArray = JsArray$(); | |
| 317 function _isBrowserType(o) { | |
| 318 return o instanceof Blob || o instanceof Event || window.KeyRange && o insta
nceof KeyRange || o instanceof ImageData || o instanceof Node || window.TypedDat
a && o instanceof TypedData || o instanceof Window; | |
| 319 } | |
| 320 dart.fn(_isBrowserType, core.bool, [dart.dynamic]); | |
| 321 let _dartObj = Symbol('_dartObj'); | |
| 322 class _DartObject extends core.Object { | |
| 323 _DartObject(dartObj) { | |
| 324 this[_dartObj] = dartObj; | |
| 325 } | |
| 326 } | |
| 327 dart.setSignature(_DartObject, { | |
| 328 constructors: () => ({_DartObject: [_DartObject, [dart.dynamic]]}) | |
| 329 }); | |
| 330 function _convertToJS(o) { | |
| 331 if (o == null || typeof o == 'string' || dart.is(o, core.num) || typeof o ==
'boolean' || dart.notNull(_isBrowserType(o))) { | |
| 332 return o; | |
| 333 } else if (dart.is(o, core.DateTime)) { | |
| 334 return _js_helper.Primitives.lazyAsJsDate(o); | |
| 335 } else if (dart.is(o, JsObject)) { | |
| 336 return dart.dload(o, _jsObject); | |
| 337 } else if (dart.is(o, core.Function)) { | |
| 338 return _putIfAbsent(exports._jsProxies, o, _wrapDartFunction); | |
| 339 } else { | |
| 340 return _putIfAbsent(exports._jsProxies, o, dart.fn(o => new _DartObject(o)
, _DartObject, [dart.dynamic])); | |
| 341 } | |
| 342 } | |
| 343 dart.fn(_convertToJS); | |
| 344 function _wrapDartFunction(f) { | |
| 345 let wrapper = function() { | |
| 346 let args = Array.prototype.map.call(arguments, _convertToDart); | |
| 347 return _convertToJS(f(...args)); | |
| 348 }; | |
| 349 dart.dsetindex(exports._dartProxies, wrapper, f); | |
| 350 return wrapper; | |
| 351 } | |
| 352 dart.fn(_wrapDartFunction); | |
| 353 function _convertToDart(o) { | |
| 354 if (o == null || typeof o == "string" || typeof o == "number" || typeof o ==
"boolean" || dart.notNull(_isBrowserType(o))) { | |
| 355 return o; | |
| 356 } else if (o instanceof Date) { | |
| 357 let ms = o.getTime(); | |
| 358 return new core.DateTime.fromMillisecondsSinceEpoch(ms); | |
| 359 } else if (dart.is(o, _DartObject)) { | |
| 360 return dart.dload(o, _dartObj); | |
| 361 } else { | |
| 362 return _putIfAbsent(exports._dartProxies, o, _wrapToDart); | |
| 363 } | |
| 364 } | |
| 365 dart.fn(_convertToDart, core.Object, [dart.dynamic]); | |
| 366 function _wrapToDart(o) { | |
| 367 if (typeof o == "function") { | |
| 368 return new JsFunction._fromJs(o); | |
| 369 } | |
| 370 if (o instanceof Array) { | |
| 371 return new JsArray._fromJs(o); | |
| 372 } | |
| 373 return new JsObject._fromJs(o); | |
| 374 } | |
| 375 dart.fn(_wrapToDart); | |
| 376 dart.defineLazyProperties(exports, { | |
| 377 get _dartProxies() { | |
| 378 return new WeakMap(); | |
| 379 }, | |
| 380 get _jsProxies() { | |
| 381 return new WeakMap(); | |
| 382 } | |
| 383 }); | |
| 384 function _putIfAbsent(weakMap, o, getValue) { | |
| 385 let value = weakMap.get(o); | |
| 386 if (value == null) { | |
| 387 value = dart.dcall(getValue, o); | |
| 388 weakMap.set(o, value); | |
| 389 } | |
| 390 return value; | |
| 391 } | |
| 392 dart.fn(_putIfAbsent, core.Object, [dart.dynamic, dart.dynamic, dart.functionT
ype(dart.dynamic, [dart.dynamic])]); | |
| 393 let __CastType0$ = dart.generic(function(E) { | |
| 394 let __CastType0 = dart.typedef('__CastType0', () => dart.functionType(dart.d
ynamic, [E])); | |
| 395 return __CastType0; | |
| 396 }); | |
| 397 let __CastType0 = __CastType0$(); | |
| 398 // Exports: | |
| 399 exports.JsObject = JsObject; | |
| 400 exports.JsFunction = JsFunction; | |
| 401 exports.JsArray$ = JsArray$; | |
| 402 exports.JsArray = JsArray; | |
| 403 }); | |
| OLD | NEW |