| 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 // TODO(vsm): This is referenced (as init.globalState) from | 9 // TODO(vsm): This is referenced (as init.globalState) from |
| 10 // isolate_helper.dart. Where should it go? | 10 // isolate_helper.dart. Where should it go? |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 } | 233 } |
| 234 return result; | 234 return result; |
| 235 } | 235 } |
| 236 dart.realRuntimeType = realRuntimeType; | 236 dart.realRuntimeType = realRuntimeType; |
| 237 | 237 |
| 238 function instanceOf(obj, type) { | 238 function instanceOf(obj, type) { |
| 239 return isSubtype(realRuntimeType(obj), type); | 239 return isSubtype(realRuntimeType(obj), type); |
| 240 } | 240 } |
| 241 dart.is = instanceOf; | 241 dart.is = instanceOf; |
| 242 | 242 |
| 243 function instanceOfOrNull(obj, type) { |
| 244 return (obj == null) || instanceOf(obj, type); |
| 245 } |
| 246 |
| 243 /** | 247 /** |
| 244 * Computes the canonical type. | 248 * Computes the canonical type. |
| 245 * This maps JS types onto their corresponding Dart Type. | 249 * This maps JS types onto their corresponding Dart Type. |
| 246 */ | 250 */ |
| 247 // TODO(jmesserly): lots more needs to be done here. | 251 // TODO(jmesserly): lots more needs to be done here. |
| 248 function canonicalType(t) { | 252 function canonicalType(t) { |
| 249 if (t === Object) return core.Object; | 253 if (t === Object) return core.Object; |
| 250 if (t === Function) return core.Function; | 254 if (t === Function) return core.Function; |
| 251 if (t === Array) return core.List; | 255 if (t === Array) return core.List; |
| 252 | 256 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 constructor() { | 462 constructor() { |
| 459 this._stringValue = null; | 463 this._stringValue = null; |
| 460 } | 464 } |
| 461 | 465 |
| 462 /// Check that a function of this type can be applied to | 466 /// Check that a function of this type can be applied to |
| 463 /// actuals. | 467 /// actuals. |
| 464 checkApply(actuals) { | 468 checkApply(actuals) { |
| 465 if (actuals.length < this.args.length) return false; | 469 if (actuals.length < this.args.length) return false; |
| 466 var index = 0; | 470 var index = 0; |
| 467 for(let i = 0; i < this.args.length; ++i) { | 471 for(let i = 0; i < this.args.length; ++i) { |
| 468 let t = realRuntimeType(actuals[i]); | 472 if (!instanceOfOrNull(actuals[i], this.args[i])) return false; |
| 469 if (!isSubtype(t, this.args[i])) return false; | |
| 470 ++index; | 473 ++index; |
| 471 } | 474 } |
| 472 if (actuals.length == this.args.length) return true; | 475 if (actuals.length == this.args.length) return true; |
| 473 let extras = actuals.length - this.args.length; | 476 let extras = actuals.length - this.args.length; |
| 474 if (this.optionals.length > 0) { | 477 if (this.optionals.length > 0) { |
| 475 if (extras > this.optionals.length) return false; | 478 if (extras > this.optionals.length) return false; |
| 476 for(let i = 0; i < extras; ++i) { | 479 for(let i = 0, j=index; i < extras; ++i, ++j) { |
| 477 let t = realRuntimeType(actuals[index + i]); | 480 if (!instanceOfOrNull(actuals[j], this.optionals[i])) return false; |
| 478 if (!isSubtype(t, this.optionals[i])) return false; | |
| 479 } | 481 } |
| 480 return true; | 482 return true; |
| 481 } | 483 } |
| 482 // TODO(leafp): We can't tell when someone might be calling | 484 // TODO(leafp): We can't tell when someone might be calling |
| 483 // something expecting an optional argument with named arguments | 485 // something expecting an optional argument with named arguments |
| 484 | 486 |
| 485 if (extras != 1) return false; | 487 if (extras != 1) return false; |
| 486 // An empty named list means no named arguments | 488 // An empty named list means no named arguments |
| 487 if (getOwnPropertyNames(this.named).length == 0) return false; | 489 if (getOwnPropertyNames(this.named).length == 0) return false; |
| 488 let opts = actuals[index]; | 490 let opts = actuals[index]; |
| 489 let names = getOwnPropertyNames(opts); | 491 let names = getOwnPropertyNames(opts); |
| 490 // This is something other than a map | 492 // This is something other than a map |
| 491 if (names.length == 0) return false; | 493 if (names.length == 0) return false; |
| 492 for (name of names) { | 494 for (name of names) { |
| 493 if (!(Object.prototype.hasOwnProperty.call(this.named, name))) { | 495 if (!(Object.prototype.hasOwnProperty.call(this.named, name))) { |
| 494 return false; | 496 return false; |
| 495 } | 497 } |
| 496 let t = realRuntimeType(opts[name]); | 498 if (!instanceOfOrNull(opts[name], this.named[name])) return false; |
| 497 if (!isSubtype(t, this.named[name])) return false; | |
| 498 } | 499 } |
| 499 return true; | 500 return true; |
| 500 } | 501 } |
| 501 | 502 |
| 502 get name() { | 503 get name() { |
| 503 if (this._stringValue) return this._stringValue; | 504 if (this._stringValue) return this._stringValue; |
| 504 | 505 |
| 505 var buffer = '('; | 506 var buffer = '('; |
| 506 for (let i = 0; i < this.args.length; ++i) { | 507 for (let i = 0; i < this.args.length; ++i) { |
| 507 if (i > 0) { | 508 if (i > 0) { |
| (...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 Number.prototype['>'] = function(arg) { return this.valueOf() > arg; }; | 1285 Number.prototype['>'] = function(arg) { return this.valueOf() > arg; }; |
| 1285 Number.prototype['+'] = function(arg) { return this.valueOf() + arg; }; | 1286 Number.prototype['+'] = function(arg) { return this.valueOf() + arg; }; |
| 1286 | 1287 |
| 1287 // TODO(vsm): DOM facades? | 1288 // TODO(vsm): DOM facades? |
| 1288 // See: https://github.com/dart-lang/dev_compiler/issues/173 | 1289 // See: https://github.com/dart-lang/dev_compiler/issues/173 |
| 1289 NodeList.prototype.get = function(i) { return this[i]; }; | 1290 NodeList.prototype.get = function(i) { return this[i]; }; |
| 1290 NamedNodeMap.prototype.get = function(i) { return this[i]; }; | 1291 NamedNodeMap.prototype.get = function(i) { return this[i]; }; |
| 1291 DOMTokenList.prototype.get = function(i) { return this[i]; }; | 1292 DOMTokenList.prototype.get = function(i) { return this[i]; }; |
| 1292 | 1293 |
| 1293 })(dart || (dart = {})); | 1294 })(dart || (dart = {})); |
| OLD | NEW |