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