| 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 var dart, _js_helper, _js_primitives; | 5 var dart, _js_helper, _js_primitives; |
| 6 (function (dart) { | 6 (function (dart) { |
| 7 'use strict'; | 7 'use strict'; |
| 8 | 8 |
| 9 let defineProperty = Object.defineProperty; | 9 let defineProperty = Object.defineProperty; |
| 10 let getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; | 10 let getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 let result; | 203 let result; |
| 204 if (map) { | 204 if (map) { |
| 205 result = map.get(t2); | 205 result = map.get(t2); |
| 206 if (result !== void 0) return result; | 206 if (result !== void 0) return result; |
| 207 } else { | 207 } else { |
| 208 subtypeMap.set(t1, map = new Map()); | 208 subtypeMap.set(t1, map = new Map()); |
| 209 } | 209 } |
| 210 if (t2 == core.Type) { | 210 if (t2 == core.Type) { |
| 211 // Special case Types. | 211 // Special case Types. |
| 212 result = t1.prototype instanceof core.Type || | 212 result = t1.prototype instanceof core.Type || |
| 213 t1 instanceof FunctionType || | 213 t1 instanceof AbstractFunctionType || |
| 214 isSubtype_(t1, t2); | 214 isSubtype_(t1, t2); |
| 215 } else { | 215 } else { |
| 216 result = isSubtype_(t1, t2) | 216 result = isSubtype_(t1, t2) |
| 217 } | 217 } |
| 218 map.set(t2, result); | 218 map.set(t2, result); |
| 219 return result; | 219 return result; |
| 220 } | 220 } |
| 221 dart.isSubtype = isSubtype; | 221 dart.isSubtype = isSubtype; |
| 222 | 222 |
| 223 function _isBottom(type, dynamicIsBottom) { | 223 function _isBottom(type, dynamicIsBottom) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 | 332 |
| 333 return false; | 333 return false; |
| 334 } | 334 } |
| 335 | 335 |
| 336 // TODO(jmesserly): this isn't currently used, but it could be if we want | 336 // TODO(jmesserly): this isn't currently used, but it could be if we want |
| 337 // `obj is NonGroundType<T,S>` to be rejected at runtime instead of compile | 337 // `obj is NonGroundType<T,S>` to be rejected at runtime instead of compile |
| 338 // time. | 338 // time. |
| 339 function isGroundType(type) { | 339 function isGroundType(type) { |
| 340 // TODO(vsm): Cache this if we start using it at runtime. | 340 // TODO(vsm): Cache this if we start using it at runtime. |
| 341 | 341 |
| 342 if (type instanceof FunctionType) { | 342 if (type instanceof AbstractFunctionType) { |
| 343 if (!_isTop(type.returnType, false)) return false; | 343 if (!_isTop(type.returnType, false)) return false; |
| 344 for (let i = 0; i < type.args.length; ++i) { | 344 for (let i = 0; i < type.args.length; ++i) { |
| 345 if (!_isBottom(type.args[i], true)) return false; | 345 if (!_isBottom(type.args[i], true)) return false; |
| 346 } | 346 } |
| 347 for (let i = 0; i < type.optionals.length; ++i) { | 347 for (let i = 0; i < type.optionals.length; ++i) { |
| 348 if (!_isBottom(type.optionals[i], true)) return false; | 348 if (!_isBottom(type.optionals[i], true)) return false; |
| 349 } | 349 } |
| 350 var names = getOwnPropertyNames(type.named); | 350 var names = getOwnPropertyNames(type.named); |
| 351 for (let i = 0; i < names.length; ++i) { | 351 for (let i = 0; i < names.length; ++i) { |
| 352 if (!_isBottom(type.named[names[i]], true)) return false; | 352 if (!_isBottom(type.named[names[i]], true)) return false; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 383 return x; | 383 return x; |
| 384 } | 384 } |
| 385 dart.notNull = notNull; | 385 dart.notNull = notNull; |
| 386 | 386 |
| 387 function _typeName(type) { | 387 function _typeName(type) { |
| 388 var name = type.name; | 388 var name = type.name; |
| 389 if (!name) throw 'Unexpected type: ' + type; | 389 if (!name) throw 'Unexpected type: ' + type; |
| 390 return name; | 390 return name; |
| 391 } | 391 } |
| 392 | 392 |
| 393 // TODO(jmesserly): extends Type? | 393 class AbstractFunctionType { |
| 394 class FunctionType { | 394 constructor() { |
| 395 constructor(returnType, args, optionals, named, opt_typedefName) { | 395 this._stringValue = null; |
| 396 this.returnType = returnType; | |
| 397 this.args = args; | |
| 398 this.optionals = optionals; | |
| 399 this.named = named; | |
| 400 this._stringValue = opt_typedefName; | |
| 401 } | 396 } |
| 402 | 397 |
| 403 get name() { | 398 get name() { |
| 404 if (this._stringValue) return this._stringValue; | 399 if (this._stringValue) return this._stringValue; |
| 405 | 400 |
| 406 var buffer = '('; | 401 var buffer = '('; |
| 407 for (let i = 0; i < this.args.length; ++i) { | 402 for (let i = 0; i < this.args.length; ++i) { |
| 408 if (i > 0) { | 403 if (i > 0) { |
| 409 buffer += ', '; | 404 buffer += ', '; |
| 410 } | 405 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 432 } | 427 } |
| 433 buffer += '}'; | 428 buffer += '}'; |
| 434 } | 429 } |
| 435 | 430 |
| 436 buffer += ') -> ' + _typeName(this.returnType); | 431 buffer += ') -> ' + _typeName(this.returnType); |
| 437 this._stringValue = buffer; | 432 this._stringValue = buffer; |
| 438 return buffer; | 433 return buffer; |
| 439 } | 434 } |
| 440 } | 435 } |
| 441 | 436 |
| 437 class FunctionType extends AbstractFunctionType { |
| 438 constructor(returnType, args, optionals, named) { |
| 439 super(); |
| 440 this.returnType = returnType; |
| 441 this.args = args; |
| 442 this.optionals = optionals; |
| 443 this.named = named; |
| 444 } |
| 445 } |
| 446 |
| 442 function functionType(returnType, args, extra) { | 447 function functionType(returnType, args, extra) { |
| 443 // TODO(vsm): Cache / memomize? | 448 // TODO(vsm): Cache / memomize? |
| 444 var optionals; | 449 var optionals; |
| 445 var named; | 450 var named; |
| 446 if (extra === void 0) { | 451 if (extra === void 0) { |
| 447 optionals = []; | 452 optionals = []; |
| 448 named = {}; | 453 named = {}; |
| 449 } else if (extra instanceof Array) { | 454 } else if (extra instanceof Array) { |
| 450 optionals = extra; | 455 optionals = extra; |
| 451 named = {}; | 456 named = {}; |
| 452 } else { | 457 } else { |
| 453 optionals = []; | 458 optionals = []; |
| 454 named = extra; | 459 named = extra; |
| 455 } | 460 } |
| 456 return new FunctionType(returnType, args, optionals, named); | 461 return new FunctionType(returnType, args, optionals, named); |
| 457 } | 462 } |
| 458 dart.functionType = functionType; | 463 dart.functionType = functionType; |
| 459 | 464 |
| 460 function typedef(name, functionType) { | 465 class Typedef extends AbstractFunctionType { |
| 461 let f = functionType; | 466 constructor(name, closure) { |
| 462 return new FunctionType(f.returnType, f.args, f.optionals, f.named, name); | 467 super(); |
| 468 this._name = name; |
| 469 this._closure = closure; |
| 470 this._functionType = null; |
| 471 } |
| 472 |
| 473 get name() { |
| 474 return this._name; |
| 475 } |
| 476 |
| 477 get functionType() { |
| 478 if (!this._functionType) { |
| 479 this._functionType = this._closure(); |
| 480 } |
| 481 return this._functionType; |
| 482 } |
| 483 |
| 484 get returnType() { |
| 485 return this.functionType.returnType; |
| 486 } |
| 487 |
| 488 get args() { |
| 489 return this.functionType.args; |
| 490 } |
| 491 |
| 492 get optionals() { |
| 493 return this.functionType.optionals; |
| 494 } |
| 495 |
| 496 get named() { |
| 497 return this.functionType.named; |
| 498 } |
| 499 } |
| 500 |
| 501 function typedef(name, closure) { |
| 502 return new Typedef(name, closure); |
| 463 } | 503 } |
| 464 dart.typedef = typedef; | 504 dart.typedef = typedef; |
| 465 | 505 |
| 466 function isFunctionType(type) { | 506 function isFunctionType(type) { |
| 467 return isClassSubType(type, core.Function) || type instanceof FunctionType; | 507 return isClassSubType(type, core.Function) || |
| 508 type instanceof AbstractFunctionType; |
| 468 } | 509 } |
| 469 | 510 |
| 470 function getFunctionType(obj) { | 511 function getFunctionType(obj) { |
| 471 // TODO(vsm): Encode this properly on the function for Dart-generated code. | 512 // TODO(vsm): Encode this properly on the function for Dart-generated code. |
| 472 var args = Array.apply(null, new Array(obj.length)).map(function(){return co
re.Object}); | 513 var args = Array.apply(null, new Array(obj.length)).map(() => core.Object); |
| 473 return functionType(dart.bottom, args); | 514 return functionType(dart.bottom, args); |
| 474 } | 515 } |
| 475 | 516 |
| 476 function isFunctionSubType(ft1, ft2) { | 517 function isFunctionSubType(ft1, ft2) { |
| 477 if (ft2 == core.Function) { | 518 if (ft2 == core.Function) { |
| 478 return true; | 519 return true; |
| 479 } | 520 } |
| 480 | 521 |
| 481 let ret1 = ft1.returnType; | 522 let ret1 = ft1.returnType; |
| 482 let ret2 = ft2.returnType; | 523 let ret2 = ft2.returnType; |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 dart.defineLibrary = defineLibrary; | 986 dart.defineLibrary = defineLibrary; |
| 946 | 987 |
| 947 // TODO(jmesserly): hack to bootstrap the SDK | 988 // TODO(jmesserly): hack to bootstrap the SDK |
| 948 _js_helper = _js_helper || {}; | 989 _js_helper = _js_helper || {}; |
| 949 _js_helper.checkNum = notNull; | 990 _js_helper.checkNum = notNull; |
| 950 | 991 |
| 951 _js_primitives = _js_primitives || {}; | 992 _js_primitives = _js_primitives || {}; |
| 952 _js_primitives.printString = (s) => console.log(s); | 993 _js_primitives.printString = (s) => console.log(s); |
| 953 | 994 |
| 954 })(dart || (dart = {})); | 995 })(dart || (dart = {})); |
| OLD | NEW |