| 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; | 5 var dart; |
| 6 (function (dart) { | 6 (function (dart) { |
| 7 var defineProperty = Object.defineProperty; | 7 var defineProperty = Object.defineProperty; |
| 8 var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; | 8 var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; |
| 9 var getOwnPropertyNames = Object.getOwnPropertyNames; | 9 var getOwnPropertyNames = Object.getOwnPropertyNames; |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 } | 31 } |
| 32 | 32 |
| 33 function dload(obj, field) { | 33 function dload(obj, field) { |
| 34 if (!(field in obj)) { | 34 if (!(field in obj)) { |
| 35 throw new core.NoSuchMethodError(obj, field); | 35 throw new core.NoSuchMethodError(obj, field); |
| 36 } | 36 } |
| 37 return obj[field]; | 37 return obj[field]; |
| 38 } | 38 } |
| 39 dart.dload = dload; | 39 dart.dload = dload; |
| 40 | 40 |
| 41 // TODO(jmesserly): this should call noSuchMethod, not throw. |
| 41 function throwNoSuchMethod(obj, name, args, opt_func) { | 42 function throwNoSuchMethod(obj, name, args, opt_func) { |
| 42 if (obj === void 0) obj = opt_func; | 43 if (obj === void 0) obj = opt_func; |
| 43 throw new core.NoSuchMethodError(obj, name, args); | 44 throw new core.NoSuchMethodError(obj, name, args); |
| 44 } | 45 } |
| 45 | 46 |
| 46 function checkAndCall(f, obj, args, name) { | 47 function checkAndCall(f, obj, args, name) { |
| 47 if (!(f instanceof Function)) { | 48 if (!(f instanceof Function)) { |
| 48 // Grab the `call` method if it's not a function. | 49 // Grab the `call` method if it's not a function. |
| 49 if (f !== null) f = f.call; | 50 if (f !== null) f = f.call; |
| 50 if (!(f instanceof Function)) { | 51 if (!(f instanceof Function)) { |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 } | 260 } |
| 260 return map; | 261 return map; |
| 261 } | 262 } |
| 262 | 263 |
| 263 function assert(condition) { | 264 function assert(condition) { |
| 264 // TODO(jmesserly): throw assertion error. | 265 // TODO(jmesserly): throw assertion error. |
| 265 if (!condition) throw 'assertion failed'; | 266 if (!condition) throw 'assertion failed'; |
| 266 } | 267 } |
| 267 dart.assert = assert; | 268 dart.assert = assert; |
| 268 | 269 |
| 270 function throw_(obj) { throw obj; } |
| 271 dart.throw_ = throw_; |
| 272 |
| 269 /** | 273 /** |
| 270 * Given a class and an initializer method name, creates a constructor | 274 * Given a class and an initializer method name, creates a constructor |
| 271 * function with the same name. For example `new SomeClass.name(args)`. | 275 * function with the same name. For example `new SomeClass.name(args)`. |
| 272 */ | 276 */ |
| 273 function defineNamedConstructor(clazz, name) { | 277 function defineNamedConstructor(clazz, name) { |
| 274 var proto = clazz.prototype; | 278 var proto = clazz.prototype; |
| 275 var initMethod = proto[clazz.name + '$' + name]; | 279 var initMethod = proto[clazz.name + '$' + name]; |
| 276 var ctor = function() { return initMethod.apply(this, arguments); } | 280 var ctor = function() { return initMethod.apply(this, arguments); } |
| 277 ctor.prototype = proto; | 281 ctor.prototype = proto; |
| 278 clazz[name] = ctor; | 282 clazz[name] = ctor; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 * we use the same trick as named constructors, and do them as instance | 338 * we use the same trick as named constructors, and do them as instance |
| 335 * methods that perform initialization. | 339 * methods that perform initialization. |
| 336 */ | 340 */ |
| 337 // TODO(jmesserly): we'll need to rethink this once the ES6 spec and V8 | 341 // TODO(jmesserly): we'll need to rethink this once the ES6 spec and V8 |
| 338 // settles. See <https://github.com/dart-lang/dart-dev-compiler/issues/51>. | 342 // settles. See <https://github.com/dart-lang/dart-dev-compiler/issues/51>. |
| 339 // Performance of this pattern is likely to be bad. | 343 // Performance of this pattern is likely to be bad. |
| 340 dart.Object = function Object() { | 344 dart.Object = function Object() { |
| 341 // Get the class name for this instance. | 345 // Get the class name for this instance. |
| 342 var name = this.constructor.name; | 346 var name = this.constructor.name; |
| 343 // Call the default constructor. | 347 // Call the default constructor. |
| 344 var result = this[name].apply(this, arguments); | 348 var init = this[name]; |
| 349 var result = void 0; |
| 350 if (init) result = init.apply(this, arguments); |
| 345 return result === void 0 ? this : result; | 351 return result === void 0 ? this : result; |
| 346 }; | 352 }; |
| 347 // The initializer for dart.Object | 353 // The initializer for dart.Object |
| 348 dart.Object.prototype.Object = function() {}; | 354 dart.Object.prototype.Object = function() {}; |
| 349 dart.Object.prototype.constructor = dart.Object; | 355 dart.Object.prototype.constructor = dart.Object; |
| 350 | 356 |
| 351 })(dart || (dart = {})); | 357 })(dart || (dart = {})); |
| OLD | NEW |