| 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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 dart.equals = equals; | 295 dart.equals = equals; |
| 296 | 296 |
| 297 /** Checks that `x` is not null or undefined. */ | 297 /** Checks that `x` is not null or undefined. */ |
| 298 function notNull(x) { | 298 function notNull(x) { |
| 299 if (x == null) throw 'expected not-null value'; | 299 if (x == null) throw 'expected not-null value'; |
| 300 return x; | 300 return x; |
| 301 } | 301 } |
| 302 dart.notNull = notNull; | 302 dart.notNull = notNull; |
| 303 | 303 |
| 304 /** | 304 /** |
| 305 * A null-checking property wrapper. |
| 306 * |
| 307 * Used when we need an assignable expression: |
| 308 * |
| 309 * obj.foo++; // normal variant |
| 310 * prop(obj, 'foo').notNull++; // checking variant |
| 311 * |
| 312 * This checks on read, not on write. |
| 313 */ |
| 314 function prop(obj, prop) { |
| 315 return { |
| 316 get notNull() { return notNull(obj[prop]); }, |
| 317 set notNull(x) { obj[prop] = x; } |
| 318 }; |
| 319 } |
| 320 dart.prop = prop; |
| 321 |
| 322 /** A null checking get/set index wrapper. */ |
| 323 function index(obj, index) { |
| 324 return { |
| 325 get notNull() { return notNull(obj[core.$get](index)); }, |
| 326 set notNull(x) { obj[core.$set](index, x); } |
| 327 }; |
| 328 } |
| 329 dart.index = index; |
| 330 |
| 331 /** |
| 305 * Defines a lazy property. | 332 * Defines a lazy property. |
| 306 * After initial get or set, it will replace itself with a value property. | 333 * After initial get or set, it will replace itself with a value property. |
| 307 */ | 334 */ |
| 308 // TODO(jmesserly): is this the best implementation for JS engines? | 335 // TODO(jmesserly): is this the best implementation for JS engines? |
| 309 // TODO(jmesserly): reusing descriptor objects has been shown to improve | 336 // TODO(jmesserly): reusing descriptor objects has been shown to improve |
| 310 // performance in other projects (e.g. webcomponents.js ShadowDOM polyfill). | 337 // performance in other projects (e.g. webcomponents.js ShadowDOM polyfill). |
| 311 function defineLazyProperty(to, name, desc) { | 338 function defineLazyProperty(to, name, desc) { |
| 312 let init = desc.get; | 339 let init = desc.get; |
| 313 let writable = !!desc.set; | 340 let writable = !!desc.set; |
| 314 function lazySetter(value) { | 341 function lazySetter(value) { |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 // of some sort, assuming we keep around `dynamic` at runtime. | 536 // of some sort, assuming we keep around `dynamic` at runtime. |
| 510 dart.dynamic = { toString() { return 'dynamic'; } }; | 537 dart.dynamic = { toString() { return 'dynamic'; } }; |
| 511 | 538 |
| 512 dart.JsSymbol = Symbol; | 539 dart.JsSymbol = Symbol; |
| 513 | 540 |
| 514 // TODO(jmesserly): hack to bootstrap the SDK | 541 // TODO(jmesserly): hack to bootstrap the SDK |
| 515 _js_helper = _js_helper || {}; | 542 _js_helper = _js_helper || {}; |
| 516 _js_helper.checkNum = notNull; | 543 _js_helper.checkNum = notNull; |
| 517 | 544 |
| 518 })(dart || (dart = {})); | 545 })(dart || (dart = {})); |
| OLD | NEW |