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