Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(459)

Side by Side Diff: sky/framework/fn.dart

Issue 1052793002: [Effen] Remove '_isInCheckedMode' flag and use an assert() instead, since presumably that will more… (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 library fn; 5 library fn;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 import 'dart:sky' as sky; 9 import 'dart:sky' as sky;
10 import 'reflect.dart' as reflect; 10 import 'reflect.dart' as reflect;
11 11
12 final sky.Tracing _tracing = sky.window.tracing; 12 final sky.Tracing _tracing = sky.window.tracing;
13 13
14 bool _initIsInCheckedMode() {
15 String testFn(i) { double d = i; return d.toString(); }
16 try {
17 testFn('not a double');
18 } catch (ex) {
19 return true;
20 }
21 return false;
22 }
23
24 final bool _isInCheckedMode = _initIsInCheckedMode();
25 final bool _shouldLogRenderDuration = false; 14 final bool _shouldLogRenderDuration = false;
26 final bool _shouldTrace = false; 15 final bool _shouldTrace = false;
27 16
28 class Style { 17 class Style {
29 final String _className; 18 final String _className;
30 static final Map<String, Style> _cache = new HashMap<String, Style>(); 19 static final Map<String, Style> _cache = new HashMap<String, Style>();
31 20
32 static int _nextStyleId = 1; 21 static int _nextStyleId = 1;
33 22
34 static String _getNextClassName() { return "style${_nextStyleId++}"; } 23 static String _getNextClassName() { return "style${_nextStyleId++}"; }
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 String _class; 378 String _class;
390 379
391 WrapperNode({ 380 WrapperNode({
392 Object key, 381 Object key,
393 List<UINode> children, 382 List<UINode> children,
394 this.style, 383 this.style,
395 this.inlineStyle 384 this.inlineStyle
396 }) : this.children = children == null ? _emptyList : children, 385 }) : this.children = children == null ? _emptyList : children,
397 super(key:key) { 386 super(key:key) {
398 387
399 if (_isInCheckedMode) { 388 assert(!_debugHasDuplicateIds());
400 _debugReportDuplicateIds();
401 }
402 } 389 }
403 390
404 void _remove() { 391 void _remove() {
405 super._remove(); 392 super._remove();
406 if (children != null) { 393 if (children != null) {
407 for (var child in children) { 394 for (var child in children) {
408 _removeChild(child); 395 _removeChild(child);
409 } 396 }
410 } 397 }
411 } 398 }
412 399
413 void _debugReportDuplicateIds() { 400 bool _debugHasDuplicateIds() {
414 var idSet = new HashSet<String>(); 401 var idSet = new HashSet<String>();
415 for (var child in children) { 402 for (var child in children) {
416 if (child is Text) { 403 if (child is Text) {
417 continue; // Text nodes all have the same key and are never reordered. 404 continue; // Text nodes all have the same key and are never reordered.
418 } 405 }
419 406
420 if (!idSet.add(child._key)) { 407 if (!idSet.add(child._key)) {
421 throw '''If multiple (non-Text) nodes of the same type exist as children 408 throw '''If multiple (non-Text) nodes of the same type exist as children
422 of another node, they must have unique keys.'''; 409 of another node, they must have unique keys.''';
423 } 410 }
424 } 411 }
412 return false;
425 } 413 }
426 414
427 void _ensureClass() { 415 void _ensureClass() {
428 if (_class == null) { 416 if (_class == null) {
429 List<Style> styles = new List<Style>(); 417 List<Style> styles = new List<Style>();
430 if (style != null) { 418 if (style != null) {
431 styles.add(style); 419 styles.add(style);
432 } 420 }
433 421
434 UINode parent = _parent; 422 UINode parent = _parent;
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 881
894 abstract class App extends Component { 882 abstract class App extends Component {
895 sky.Node _host; 883 sky.Node _host;
896 884
897 App() : super(stateful: true) { 885 App() : super(stateful: true) {
898 _host = sky.document.createElement('div'); 886 _host = sky.document.createElement('div');
899 sky.document.appendChild(_host); 887 sky.document.appendChild(_host);
900 _scheduleComponentForRender(this); 888 _scheduleComponentForRender(this);
901 } 889 }
902 } 890 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698