OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // TODO(jmesserly, sigmund): remove these two lines: | 5 var dart, _js_helper; |
6 var math = Math; | |
7 var core = core || {int: { parse: Number }, print: e => console.log(e) }; | |
8 | |
9 var dart; | |
10 (function (dart) { | 6 (function (dart) { |
11 'use strict'; | 7 'use strict'; |
12 | 8 |
13 var defineProperty = Object.defineProperty; | 9 var defineProperty = Object.defineProperty; |
14 var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; | 10 var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; |
15 var getOwnPropertyNames = Object.getOwnPropertyNames; | 11 var getOwnPropertyNames = Object.getOwnPropertyNames; |
16 | 12 |
17 // Adapted from Angular.js | 13 // Adapted from Angular.js |
18 var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m; | 14 var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m; |
19 var FN_ARG_SPLIT = /,/; | 15 var FN_ARG_SPLIT = /,/; |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 /** The Symbol for storing type arguments on a specialized generic type. */ | 296 /** The Symbol for storing type arguments on a specialized generic type. */ |
301 dart.typeSignature = Symbol('typeSignature'); | 297 dart.typeSignature = Symbol('typeSignature'); |
302 | 298 |
303 /** Memoize a generic type constructor function. */ | 299 /** Memoize a generic type constructor function. */ |
304 function generic(typeConstructor) { | 300 function generic(typeConstructor) { |
305 var length = typeConstructor.length; | 301 var length = typeConstructor.length; |
306 if (length < 1) throw 'must have at least one generic type argument'; | 302 if (length < 1) throw 'must have at least one generic type argument'; |
307 | 303 |
308 var resultMap = new Map(); | 304 var resultMap = new Map(); |
309 function makeGenericType(/*...arguments*/) { | 305 function makeGenericType(/*...arguments*/) { |
310 if (arguments.length != length) { | 306 if (arguments.length != length && arguments.length != 0) { |
Jennifer Messerly
2015/03/19 22:57:34
a previous change allows this to be called with 0
| |
311 throw 'requires ' + length + ' type arguments'; | 307 throw 'requires ' + length + ' or 0 type arguments'; |
312 } | 308 } |
313 | 309 |
314 var value = resultMap; | 310 var value = resultMap; |
315 for (var i = 0; i < length; i++) { | 311 for (var i = 0; i < length; i++) { |
316 var arg = arguments[i]; | 312 var arg = arguments[i]; |
317 if (arg === void 0) arg = dart.dynamic; | 313 if (arg === void 0) arg = dart.dynamic; |
318 | 314 |
319 var map = value; | 315 var map = value; |
320 value = map.get(arg); | 316 value = map.get(arg); |
321 if (value === void 0) { | 317 if (value === void 0) { |
322 if (i + 1 == length) { | 318 if (i + 1 == length) { |
323 value = typeConstructor.apply(null, arguments); | 319 value = typeConstructor.apply(null, arguments); |
324 // Save the type constructor and arguments for reflection. | 320 // Save the type constructor and arguments for reflection. |
325 if (value) { | 321 if (value) { |
326 var args = Array.prototype.slice.call(arguments); | 322 var args = Array.prototype.slice.call(arguments); |
327 value[dart.typeSignature] = [makeGenericType].concat(args); | 323 value[dart.typeSignature] = [makeGenericType].concat(args); |
328 } | 324 } |
329 } else { | 325 } else { |
330 value = new Map(); | 326 value = new Map(); |
331 } | 327 } |
332 map.set(arg, value); | 328 map.set(arg, value); |
333 } | 329 } |
334 } | 330 } |
335 return value; | 331 return value; |
336 } | 332 } |
337 return makeGenericType; | 333 return makeGenericType; |
338 } | 334 } |
339 dart.generic = generic; | 335 dart.generic = generic; |
340 | 336 |
341 // TODO(jmesserly): this is just a placeholder. | 337 // TODO(jmesserly): right now this is a sentinel. It should be a type object |
338 // of some sort, assuming we keep around `dynamic` at runtime. | |
342 dart.dynamic = Object.create(null); | 339 dart.dynamic = Object.create(null); |
343 | 340 |
341 dart.JsSymbol = Symbol; | |
342 | |
343 // TODO(jmesserly): hack to bootstrap the SDK | |
344 _js_helper = _js_helper || {}; | |
345 _js_helper.checkNum = notNull; | |
346 | |
344 })(dart || (dart = {})); | 347 })(dart || (dart = {})); |
OLD | NEW |