| 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; | 5 var dart, _js_helper; |
| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 return checkAndCall(obj.set, obj, [index, value], '[]='); | 89 return checkAndCall(obj.set, obj, [index, value], '[]='); |
| 90 } | 90 } |
| 91 dart.dsetindex = dindex; | 91 dart.dsetindex = dindex; |
| 92 | 92 |
| 93 function dbinary(left, op, right) { | 93 function dbinary(left, op, right) { |
| 94 return checkAndCall(left[op], left, [right], op); | 94 return checkAndCall(left[op], left, [right], op); |
| 95 } | 95 } |
| 96 dart.dbinary = dbinary; | 96 dart.dbinary = dbinary; |
| 97 | 97 |
| 98 function cast(obj, type) { | 98 function cast(obj, type) { |
| 99 //TODO(vsm): handle non-nullable types | 99 // TODO(vsm): handle non-nullable types |
| 100 if (obj == null) return obj; | 100 if (obj == null) return obj; |
| 101 let actual = getRuntimeType(obj); | 101 let actual = getRuntimeType(obj); |
| 102 if (isSubtype(actual, type)) return obj; | 102 if (isSubtype(actual, type)) return obj; |
| 103 throw new _js_helper.CastErrorImplementation(actual, type); | 103 throw new _js_helper.CastErrorImplementation(actual, type); |
| 104 } | 104 } |
| 105 dart.as = cast; | 105 dart.as = cast; |
| 106 | 106 |
| 107 /** | 107 /** |
| 108 * Returns the runtime type of obj. This is the same as `obj.runtimeType` | 108 * Returns the runtime type of obj. This is the same as `obj.runtimeType` |
| 109 * but will not call an overridden getter. | 109 * but will not call an overridden getter. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 182 |
| 183 if (t2 == core.Object) return true; | 183 if (t2 == core.Object) return true; |
| 184 if (t1 == core.Object) return false; | 184 if (t1 == core.Object) return false; |
| 185 | 185 |
| 186 // "Traditional" name-based subtype check. | 186 // "Traditional" name-based subtype check. |
| 187 if (isClassSubType(t1, t2)) { | 187 if (isClassSubType(t1, t2)) { |
| 188 return true; | 188 return true; |
| 189 } | 189 } |
| 190 | 190 |
| 191 // Function subtyping. | 191 // Function subtyping. |
| 192 // TODO(jmesserly): implement. | 192 // TODO(jmesserly): implement this properly. |
| 193 if (isClassSubType(t1, core.Function) && |
| 194 isClassSubType(t2, core.Function)) { |
| 195 return true; |
| 196 } |
| 193 return false; | 197 return false; |
| 194 } | 198 } |
| 195 | 199 |
| 196 function safeGetOwnProperty(obj, name) { | 200 function safeGetOwnProperty(obj, name) { |
| 197 var desc = getOwnPropertyDescriptor(obj, name); | 201 var desc = getOwnPropertyDescriptor(obj, name); |
| 198 if (desc) return desc.value; | 202 if (desc) return desc.value; |
| 199 } | 203 } |
| 200 | 204 |
| 201 function isClassSubType(t1, t2) { | 205 function isClassSubType(t1, t2) { |
| 202 // We support Dart's covariant generics with the caveat that we do not | 206 // We support Dart's covariant generics with the caveat that we do not |
| (...skipping 25 matching lines...) Expand all Loading... |
| 228 if (!isSubtype(typeArguments1[i], typeArguments2[i])) { | 232 if (!isSubtype(typeArguments1[i], typeArguments2[i])) { |
| 229 return false; | 233 return false; |
| 230 } | 234 } |
| 231 } | 235 } |
| 232 return true; | 236 return true; |
| 233 } | 237 } |
| 234 | 238 |
| 235 // Check superclass. | 239 // Check superclass. |
| 236 if (isClassSubType(t1.__proto__, t2)) return true; | 240 if (isClassSubType(t1.__proto__, t2)) return true; |
| 237 | 241 |
| 242 // Check mixins. |
| 243 let mixins = safeGetOwnProperty(t1, dart.mixins); |
| 244 if (mixins) { |
| 245 for (let m1 of mixins) { |
| 246 // TODO(jmesserly): remove the != null check once we can load core libs. |
| 247 if (m1 != null && isClassSubType(m1, t2)) return true; |
| 248 } |
| 249 } |
| 250 |
| 238 // Check interfaces. | 251 // Check interfaces. |
| 239 let getInterfaces = safeGetOwnProperty(t1, dart.implements); | 252 let getInterfaces = safeGetOwnProperty(t1, dart.implements); |
| 240 if (getInterfaces) { | 253 if (getInterfaces) { |
| 241 for (let i1 of getInterfaces()) { | 254 for (let i1 of getInterfaces()) { |
| 242 // TODO(jmesserly): remove the != null check once we can load core libs. | 255 // TODO(jmesserly): remove the != null check once we can load core libs. |
| 243 if (i1 != null && isClassSubType(i1, t2)) return true; | 256 if (i1 != null && isClassSubType(i1, t2)) return true; |
| 244 } | 257 } |
| 245 } | 258 } |
| 246 | 259 |
| 247 return false; | 260 return false; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 let mixins = Array.prototype.slice.call(arguments, 1); | 377 let mixins = Array.prototype.slice.call(arguments, 1); |
| 365 | 378 |
| 366 // Create a class that will hold all of the mixin methods. | 379 // Create a class that will hold all of the mixin methods. |
| 367 class Mixin extends base { | 380 class Mixin extends base { |
| 368 // Initializer method: run mixin initializers, then the base. | 381 // Initializer method: run mixin initializers, then the base. |
| 369 [base.name](/*...args*/) { | 382 [base.name](/*...args*/) { |
| 370 // Run mixin initializers. They cannot have arguments. | 383 // Run mixin initializers. They cannot have arguments. |
| 371 // Run them backwards so most-derived mixin is initialized first. | 384 // Run them backwards so most-derived mixin is initialized first. |
| 372 for (let i = mixins.length - 1; i >= 0; i--) { | 385 for (let i = mixins.length - 1; i >= 0; i--) { |
| 373 let mixin = mixins[i]; | 386 let mixin = mixins[i]; |
| 374 mixin.prototype[mixin.name].call(this); | 387 let init = mixin.prototype[mixin.name]; |
| 388 if (init) init.call(this); |
| 375 } | 389 } |
| 376 // Run base initializer. | 390 // Run base initializer. |
| 377 base.prototype[base.name].apply(this, arguments); | 391 let init = base.prototype[base.name]; |
| 392 if (init) init.apply(this, arguments); |
| 378 } | 393 } |
| 379 } | 394 } |
| 380 // Copy each mixin's methods, with later ones overwriting earlier entries. | 395 // Copy each mixin's methods, with later ones overwriting earlier entries. |
| 381 for (let m of mixins) { | 396 for (let m of mixins) { |
| 382 copyProperties(Mixin.prototype, m.prototype); | 397 copyProperties(Mixin.prototype, m.prototype); |
| 383 } | 398 } |
| 384 // Save mixins for reflection | 399 // Save mixins for reflection |
| 385 Mixin[dart.mixins] = mixins; | 400 Mixin[dart.mixins] = mixins; |
| 386 return Mixin; | 401 return Mixin; |
| 387 } | 402 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 // of some sort, assuming we keep around `dynamic` at runtime. | 509 // of some sort, assuming we keep around `dynamic` at runtime. |
| 495 dart.dynamic = { toString() { return 'dynamic'; } }; | 510 dart.dynamic = { toString() { return 'dynamic'; } }; |
| 496 | 511 |
| 497 dart.JsSymbol = Symbol; | 512 dart.JsSymbol = Symbol; |
| 498 | 513 |
| 499 // TODO(jmesserly): hack to bootstrap the SDK | 514 // TODO(jmesserly): hack to bootstrap the SDK |
| 500 _js_helper = _js_helper || {}; | 515 _js_helper = _js_helper || {}; |
| 501 _js_helper.checkNum = notNull; | 516 _js_helper.checkNum = notNull; |
| 502 | 517 |
| 503 })(dart || (dart = {})); | 518 })(dart || (dart = {})); |
| OLD | NEW |