OLD | NEW |
1 dart_library.library('dart/js', null, /* Imports */[ | 1 dart_library.library('dart/js', null, /* Imports */[ |
2 "dart_runtime/dart", | 2 "dart_runtime/dart", |
3 'dart/_foreign_helper', | |
4 'dart/core', | 3 'dart/core', |
5 'dart/collection', | 4 'dart/collection', |
6 'dart/typed_data', | |
7 'dart/_js_helper' | 5 'dart/_js_helper' |
8 ], /* Lazy imports */[ | 6 ], /* Lazy imports */[ |
9 ], function(exports, dart, _foreign_helper, core, collection, typed_data, _js_he
lper) { | 7 ], function(exports, dart, core, collection, _js_helper) { |
10 'use strict'; | 8 'use strict'; |
11 let dartx = dart.dartx; | 9 let dartx = dart.dartx; |
12 dart.defineLazyProperties(exports, { | 10 dart.defineLazyProperties(exports, { |
13 get context() { | 11 get context() { |
14 return _wrapToDart(self); | 12 return dart.as(_wrapToDart(dart.global), JsObject); |
15 } | 13 } |
16 }); | 14 }); |
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, dart.dynamic, [core.Function], {captureThis: cor
e.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, dart.dynamic, [dart.dynamic, core.bool, dart.dynami
c, core.List]); | |
36 let _jsObject = Symbol('_jsObject'); | 15 let _jsObject = Symbol('_jsObject'); |
37 class JsObject extends core.Object { | 16 class JsObject extends core.Object { |
38 _fromJs(jsObject) { | 17 _fromJs(jsObject) { |
39 this[_jsObject] = jsObject; | 18 this[_jsObject] = jsObject; |
40 dart.assert(this[_jsObject] != null); | 19 dart.assert(this[_jsObject] != null); |
41 } | 20 } |
42 static new(constructor, arguments$) { | 21 static new(constructor, arguments$) { |
43 if (arguments$ === void 0) | 22 if (arguments$ === void 0) |
44 arguments$ = null; | 23 arguments$ = null; |
45 let constr = _convertToJS(constructor); | 24 let ctor = constructor[_jsObject]; |
46 if (arguments$ == null) { | 25 if (arguments$ == null) { |
47 return _wrapToDart(new constr()); | 26 return dart.as(_wrapToDart(new ctor()), JsObject); |
48 } | 27 } |
49 let args = [null]; | 28 return dart.as(_wrapToDart(new ctor(...arguments$)), JsObject); |
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 } | 29 } |
56 static fromBrowserObject(object) { | 30 static fromBrowserObject(object) { |
57 if (dart.is(object, core.num) || typeof object == 'string' || typeof objec
t == 'boolean' || object == null) { | 31 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"); | 32 throw new core.ArgumentError("object cannot be a num, string, bool, or n
ull"); |
59 } | 33 } |
60 return _wrapToDart(_convertToJS(object)); | 34 return dart.as(_wrapToDart(_convertToJS(object)), JsObject); |
61 } | 35 } |
62 static jsify(object) { | 36 static jsify(object) { |
63 if (!dart.is(object, core.Map) && !dart.is(object, core.Iterable)) { | 37 if (!dart.is(object, core.Map) && !dart.is(object, core.Iterable)) { |
64 throw new core.ArgumentError("object must be a Map or Iterable"); | 38 throw new core.ArgumentError("object must be a Map or Iterable"); |
65 } | 39 } |
66 return _wrapToDart(JsObject._convertDataTree(object)); | 40 return dart.as(_wrapToDart(JsObject._convertDataTree(object)), JsObject); |
67 } | 41 } |
68 static _convertDataTree(data) { | 42 static _convertDataTree(data) { |
69 let _convertedObjects = collection.HashMap.identity(); | 43 let _convertedObjects = collection.HashMap.identity(); |
70 let _convert = o => { | 44 let _convert = o => { |
71 if (dart.notNull(_convertedObjects.containsKey(o))) { | 45 if (dart.notNull(_convertedObjects.containsKey(o))) { |
72 return _convertedObjects.get(o); | 46 return _convertedObjects.get(o); |
73 } | 47 } |
74 if (dart.is(o, core.Map)) { | 48 if (dart.is(o, core.Map)) { |
75 let convertedMap = {}; | 49 let convertedMap = {}; |
76 _convertedObjects.set(o, convertedMap); | 50 _convertedObjects.set(o, convertedMap); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 return super.toString(); | 104 return super.toString(); |
131 } | 105 } |
132 | 106 |
133 } | 107 } |
134 callMethod(method, args) { | 108 callMethod(method, args) { |
135 if (args === void 0) | 109 if (args === void 0) |
136 args = null; | 110 args = null; |
137 if (!(typeof method == 'string') && !dart.is(method, core.num)) { | 111 if (!(typeof method == 'string') && !dart.is(method, core.num)) { |
138 throw new core.ArgumentError("method is not a String or num"); | 112 throw new core.ArgumentError("method is not a String or num"); |
139 } | 113 } |
140 return _convertToDart(this[_jsObject][method].apply(this[_jsObject], args
== null ? null : core.List.from(args[dartx.map](_convertToJS)))); | 114 if (args != null) |
| 115 args = core.List.from(args[dartx.map](_convertToJS)); |
| 116 let fn = this[_jsObject][method]; |
| 117 if (!(fn instanceof Function)) { |
| 118 throw new core.NoSuchMethodError(this[_jsObject], core.Symbol.new(dart.a
s(method, core.String)), args, dart.map()); |
| 119 } |
| 120 return _convertToDart(fn.apply(this[_jsObject], args)); |
141 } | 121 } |
142 } | 122 } |
143 dart.defineNamedConstructor(JsObject, '_fromJs'); | 123 dart.defineNamedConstructor(JsObject, '_fromJs'); |
144 dart.setSignature(JsObject, { | 124 dart.setSignature(JsObject, { |
145 constructors: () => ({ | 125 constructors: () => ({ |
146 _fromJs: [JsObject, [dart.dynamic]], | 126 _fromJs: [JsObject, [dart.dynamic]], |
147 new: [JsObject, [JsFunction], [core.List]], | 127 new: [JsObject, [JsFunction], [core.List]], |
148 fromBrowserObject: [JsObject, [dart.dynamic]], | 128 fromBrowserObject: [JsObject, [dart.dynamic]], |
149 jsify: [JsObject, [dart.dynamic]] | 129 jsify: [JsObject, [dart.dynamic]] |
150 }), | 130 }), |
151 methods: () => ({ | 131 methods: () => ({ |
152 get: [dart.dynamic, [dart.dynamic]], | 132 get: [dart.dynamic, [dart.dynamic]], |
153 set: [dart.dynamic, [dart.dynamic, dart.dynamic]], | 133 set: [dart.dynamic, [dart.dynamic, dart.dynamic]], |
154 hasProperty: [core.bool, [dart.dynamic]], | 134 hasProperty: [core.bool, [dart.dynamic]], |
155 deleteProperty: [dart.void, [dart.dynamic]], | 135 deleteProperty: [dart.void, [dart.dynamic]], |
156 instanceof: [core.bool, [JsFunction]], | 136 instanceof: [core.bool, [JsFunction]], |
157 callMethod: [dart.dynamic, [dart.dynamic], [core.List]] | 137 callMethod: [dart.dynamic, [dart.dynamic], [core.List]] |
158 }), | 138 }), |
159 statics: () => ({_convertDataTree: [dart.dynamic, [dart.dynamic]]}), | 139 statics: () => ({_convertDataTree: [dart.dynamic, [dart.dynamic]]}), |
160 names: ['_convertDataTree'] | 140 names: ['_convertDataTree'] |
161 }); | 141 }); |
162 class JsFunction extends JsObject { | 142 class JsFunction extends JsObject { |
163 static withThis(f) { | 143 static withThis(f) { |
164 let jsFunc = _convertDartFunction(f, {captureThis: true}); | 144 return new JsFunction._fromJs(function() { |
165 return new JsFunction._fromJs(jsFunc); | 145 let args = [_convertToDart(this)]; |
| 146 for (let arg of arguments) { |
| 147 args.push(_convertToDart(arg)); |
| 148 } |
| 149 return _convertToJS(f(...args)); |
| 150 }); |
166 } | 151 } |
167 _fromJs(jsObject) { | 152 _fromJs(jsObject) { |
168 super._fromJs(jsObject); | 153 super._fromJs(jsObject); |
169 } | 154 } |
170 apply(args, opts) { | 155 apply(args, opts) { |
171 let thisArg = opts && 'thisArg' in opts ? opts.thisArg : null; | 156 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)))); | 157 return _convertToDart(this[_jsObject].apply(_convertToJS(thisArg), args ==
null ? null : core.List.from(args[dartx.map](_convertToJS)))); |
173 } | 158 } |
174 } | 159 } |
175 dart.defineNamedConstructor(JsFunction, '_fromJs'); | 160 dart.defineNamedConstructor(JsFunction, '_fromJs'); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 return dart.as(this.callMethod('pop'), E); | 247 return dart.as(this.callMethod('pop'), E); |
263 } | 248 } |
264 removeRange(start, end) { | 249 removeRange(start, end) { |
265 JsArray$()._checkRange(start, end, this.length); | 250 JsArray$()._checkRange(start, end, this.length); |
266 this.callMethod('splice', [start, dart.notNull(end) - dart.notNull(start
)]); | 251 this.callMethod('splice', [start, dart.notNull(end) - dart.notNull(start
)]); |
267 } | 252 } |
268 setRange(start, end, iterable, skipCount) { | 253 setRange(start, end, iterable, skipCount) { |
269 dart.as(iterable, core.Iterable$(E)); | 254 dart.as(iterable, core.Iterable$(E)); |
270 if (skipCount === void 0) | 255 if (skipCount === void 0) |
271 skipCount = 0; | 256 skipCount = 0; |
272 JsArray$()._checkRange(start, end, length); | 257 JsArray$()._checkRange(start, end, this.length); |
273 let length = dart.notNull(end) - dart.notNull(start); | 258 let length = dart.notNull(end) - dart.notNull(start); |
274 if (length == 0) | 259 if (length == 0) |
275 return; | 260 return; |
276 if (dart.notNull(skipCount) < 0) | 261 if (dart.notNull(skipCount) < 0) |
277 throw new core.ArgumentError(skipCount); | 262 throw new core.ArgumentError(skipCount); |
278 let args = [start, length]; | 263 let args = [start, length]; |
279 args[dartx.addAll](iterable[dartx.skip](skipCount)[dartx.take](length)); | 264 args[dartx.addAll](iterable[dartx.skip](skipCount)[dartx.take](length)); |
280 this.callMethod('splice', args); | 265 this.callMethod('splice', args); |
281 } | 266 } |
282 sort(compare) { | 267 sort(compare) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 'removeLast', | 305 'removeLast', |
321 'removeRange', | 306 'removeRange', |
322 'setRange', | 307 'setRange', |
323 'sort', | 308 'sort', |
324 'length', | 309 'length', |
325 'length' | 310 'length' |
326 ]); | 311 ]); |
327 return JsArray; | 312 return JsArray; |
328 }); | 313 }); |
329 let JsArray = JsArray$(); | 314 let JsArray = JsArray$(); |
330 let _JS_OBJECT_PROPERTY_NAME = '_$dart_jsObject'; | 315 function _isBrowserType(o) { |
331 let _JS_FUNCTION_PROPERTY_NAME = '$dart_jsFunction'; | 316 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; |
332 dart.defineLazyProperties(exports, { | 317 } |
333 get _DART_OBJECT_PROPERTY_NAME() { | 318 dart.fn(_isBrowserType, core.bool, [dart.dynamic]); |
334 return dart.as(dart.dcall(/* Unimplemented unknown name */getIsolateAffini
tyTag, '_$dart_dartObject'), core.String); | 319 let _dartObj = Symbol('_dartObj'); |
335 }, | 320 class _DartObject extends core.Object { |
336 get _DART_CLOSURE_PROPERTY_NAME() { | 321 _DartObject(dartObj) { |
337 return dart.as(dart.dcall(/* Unimplemented unknown name */getIsolateAffini
tyTag, '_$dart_dartClosure'), core.String); | 322 this[_dartObj] = dartObj; |
338 } | 323 } |
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 } | 324 } |
351 dart.fn(_defineProperty, core.bool, [dart.dynamic, core.String, dart.dynamic])
; | 325 dart.setSignature(_DartObject, { |
352 function _hasOwnProperty(o, name) { | 326 constructors: () => ({_DartObject: [_DartObject, [dart.dynamic]]}) |
353 return Object.prototype.hasOwnProperty.call(o, name); | |
354 } | |
355 dart.fn(_hasOwnProperty, core.bool, [dart.dynamic, core.String]); | |
356 function _isExtensible(o) { | |
357 return Object.isExtensible(o); | |
358 } | |
359 dart.fn(_isExtensible, core.bool, [dart.dynamic]); | |
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, [dart.dynamic, core.String]); | |
367 function _isLocalObject(o) { | |
368 return o instanceof Object; | |
369 } | |
370 dart.fn(_isLocalObject, core.bool, [dart.dynamic]); | |
371 dart.defineLazyProperties(exports, { | |
372 get _dartProxyCtor() { | |
373 return function DartObject(o) { | |
374 this.o = o; | |
375 }; | |
376 } | |
377 }); | 327 }); |
378 function _convertToJS(o) { | 328 function _convertToJS(o) { |
379 if (o == null || typeof o == 'string' || dart.is(o, core.num) || typeof o ==
'boolean') { | 329 if (o == null || typeof o == 'string' || dart.is(o, core.num) || typeof o ==
'boolean' || dart.notNull(_isBrowserType(o))) { |
380 return o; | |
381 } else if (dart.is(o, dart.dynamic) || dart.is(o, dart.dynamic) || dart.is(o
, dart.dynamic) || dart.is(o, dart.dynamic) || dart.is(o, dart.dynamic) || dart.
is(o, typed_data.TypedData) || dart.is(o, dart.dynamic)) { | |
382 return o; | 330 return o; |
383 } else if (dart.is(o, core.DateTime)) { | 331 } else if (dart.is(o, core.DateTime)) { |
384 return _js_helper.Primitives.lazyAsJsDate(o); | 332 return _js_helper.Primitives.lazyAsJsDate(o); |
385 } else if (dart.is(o, JsObject)) { | 333 } else if (dart.is(o, JsObject)) { |
386 return dart.dload(o, _jsObject); | 334 return dart.dload(o, _jsObject); |
387 } else if (dart.is(o, core.Function)) { | 335 } else if (dart.is(o, core.Function)) { |
388 return _getJsProxy(o, _JS_FUNCTION_PROPERTY_NAME, dart.fn(o => { | 336 return _putIfAbsent(exports._jsProxies, o, _wrapDartFunction); |
389 let jsFunction = _convertDartFunction(dart.as(o, core.Function)); | |
390 _defineProperty(jsFunction, exports._DART_CLOSURE_PROPERTY_NAME, o); | |
391 return jsFunction; | |
392 })); | |
393 } else { | 337 } else { |
394 let ctor = exports._dartProxyCtor; | 338 return _putIfAbsent(exports._jsProxies, o, dart.fn(o => new _DartObject(o)
, _DartObject, [dart.dynamic])); |
395 return _getJsProxy(o, _JS_OBJECT_PROPERTY_NAME, dart.fn(o => new ctor(o)))
; | |
396 } | 339 } |
397 } | 340 } |
398 dart.fn(_convertToJS); | 341 dart.fn(_convertToJS); |
399 function _getJsProxy(o, propertyName, createProxy) { | 342 function _wrapDartFunction(f) { |
400 let jsProxy = _getOwnProperty(o, propertyName); | 343 let wrapper = function() { |
401 if (jsProxy == null) { | 344 let args = Array.prototype.map.call(arguments, _convertToDart); |
402 jsProxy = dart.dcall(createProxy, o); | 345 return _convertToJS(f(...args)); |
403 _defineProperty(o, propertyName, jsProxy); | 346 }; |
404 } | 347 dart.dsetindex(exports._dartProxies, wrapper, f); |
405 return jsProxy; | 348 return wrapper; |
406 } | 349 } |
407 dart.fn(_getJsProxy, core.Object, [dart.dynamic, core.String, dart.functionTyp
e(dart.dynamic, [dart.dynamic])]); | 350 dart.fn(_wrapDartFunction); |
408 function _convertToDart(o) { | 351 function _convertToDart(o) { |
409 if (o == null || typeof o == "string" || typeof o == "number" || typeof o ==
"boolean") { | 352 if (o == null || typeof o == "string" || typeof o == "number" || typeof o ==
"boolean" || dart.notNull(_isBrowserType(o))) { |
410 return o; | |
411 } else if (dart.notNull(_isLocalObject(o)) && (dart.is(o, dart.dynamic) || d
art.is(o, dart.dynamic) || dart.is(o, dart.dynamic) || dart.is(o, dart.dynamic)
|| dart.is(o, dart.dynamic) || dart.is(o, typed_data.TypedData) || dart.is(o, da
rt.dynamic))) { | |
412 return o; | 353 return o; |
413 } else if (o instanceof Date) { | 354 } else if (o instanceof Date) { |
414 let ms = o.getTime(); | 355 let ms = o.getTime(); |
415 return new core.DateTime.fromMillisecondsSinceEpoch(ms); | 356 return new core.DateTime.fromMillisecondsSinceEpoch(ms); |
416 } else if (o.constructor === exports._dartProxyCtor) { | 357 } else if (dart.is(o, _DartObject)) { |
417 return o.o; | 358 return dart.dload(o, _dartObj); |
418 } else { | 359 } else { |
419 return _wrapToDart(o); | 360 return _putIfAbsent(exports._dartProxies, o, _wrapToDart); |
420 } | 361 } |
421 } | 362 } |
422 dart.fn(_convertToDart, core.Object, [dart.dynamic]); | 363 dart.fn(_convertToDart, core.Object, [dart.dynamic]); |
423 function _wrapToDart(o) { | 364 function _wrapToDart(o) { |
424 if (typeof o == "function") { | 365 if (typeof o == "function") { |
425 return dart.as(_getDartProxy(o, exports._DART_CLOSURE_PROPERTY_NAME, dart.
fn(o => new JsFunction._fromJs(o), JsFunction, [dart.dynamic])), JsObject); | 366 return new JsFunction._fromJs(o); |
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, [dart.dynamic])), JsObject); | |
428 } else { | |
429 return dart.as(_getDartProxy(o, exports._DART_OBJECT_PROPERTY_NAME, dart.f
n(o => new JsObject._fromJs(o), JsObject, [dart.dynamic])), JsObject); | |
430 } | 367 } |
| 368 if (o instanceof Array) { |
| 369 return new JsArray._fromJs(o); |
| 370 } |
| 371 return new JsObject._fromJs(o); |
431 } | 372 } |
432 dart.fn(_wrapToDart, JsObject, [dart.dynamic]); | 373 dart.fn(_wrapToDart); |
433 function _getDartProxy(o, propertyName, createProxy) { | 374 dart.defineLazyProperties(exports, { |
434 let dartProxy = _getOwnProperty(o, propertyName); | 375 get _dartProxies() { |
435 if (dartProxy == null || !dart.notNull(_isLocalObject(o))) { | 376 return new WeakMap(); |
436 dartProxy = dart.dcall(createProxy, o); | 377 }, |
437 _defineProperty(o, propertyName, dartProxy); | 378 get _jsProxies() { |
| 379 return new WeakMap(); |
438 } | 380 } |
439 return dartProxy; | 381 }); |
| 382 function _putIfAbsent(weakMap, o, getValue) { |
| 383 let value = weakMap.get(o); |
| 384 if (value == null) { |
| 385 value = dart.dcall(getValue, o); |
| 386 weakMap.set(o, value); |
| 387 } |
| 388 return value; |
440 } | 389 } |
441 dart.fn(_getDartProxy, core.Object, [dart.dynamic, core.String, dart.functionT
ype(dart.dynamic, [dart.dynamic])]); | 390 dart.fn(_putIfAbsent, core.Object, [dart.dynamic, dart.dynamic, dart.functionT
ype(dart.dynamic, [dart.dynamic])]); |
442 let __CastType0$ = dart.generic(function(E) { | 391 let __CastType0$ = dart.generic(function(E) { |
443 let __CastType0 = dart.typedef('__CastType0', () => dart.functionType(dart.d
ynamic, [E])); | 392 let __CastType0 = dart.typedef('__CastType0', () => dart.functionType(dart.d
ynamic, [E])); |
444 return __CastType0; | 393 return __CastType0; |
445 }); | 394 }); |
446 let __CastType0 = __CastType0$(); | 395 let __CastType0 = __CastType0$(); |
447 // Exports: | 396 // Exports: |
448 exports.JsObject = JsObject; | 397 exports.JsObject = JsObject; |
449 exports.JsFunction = JsFunction; | 398 exports.JsFunction = JsFunction; |
450 exports.JsArray$ = JsArray$; | 399 exports.JsArray$ = JsArray$; |
451 exports.JsArray = JsArray; | 400 exports.JsArray = JsArray; |
452 }); | 401 }); |
OLD | NEW |