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

Side by Side Diff: pkg/polymer_expressions/lib/eval.dart

Issue 314583004: Silently fail when assigning to properties on null (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/polymer_expressions/test/eval_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library polymer_expressions.eval; 5 library polymer_expressions.eval;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:observe/observe.dart'; 10 import 'package:observe/observe.dart';
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 // transform the values backwards through the filters 127 // transform the values backwards through the filters
128 for (var filterExpr in filters) { 128 for (var filterExpr in filters) {
129 var filter = eval(filterExpr, scope); 129 var filter = eval(filterExpr, scope);
130 if (filter is! Transformer) { 130 if (filter is! Transformer) {
131 throw new EvalException("filter must implement Transformer: $filterExpr"); 131 throw new EvalException("filter must implement Transformer: $filterExpr");
132 } 132 }
133 value = filter.reverse(value); 133 value = filter.reverse(value);
134 } 134 }
135 // make the assignment 135 // make the assignment
136 var o = eval(expression, scope); 136 var o = eval(expression, scope);
137 if (o == null) throw new EvalException("Can't assign to null: $expression"); 137
138 // can't assign to a property on a null LHS object. Silently fail.
139 if (o == null) return null;
140
138 if (isIndex) { 141 if (isIndex) {
139 o[property] = value; 142 o[property] = value;
140 } else { 143 } else {
141 smoke.write(o, smoke.nameToSymbol(property), value); 144 smoke.write(o, smoke.nameToSymbol(property), value);
142 } 145 }
143 return value; 146 return value;
144 } 147 }
145 148
146 149
147 /** 150 /**
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 accept(Visitor v) => v.visitInvoke(this); 717 accept(Visitor v) => v.visitInvoke(this);
715 } 718 }
716 719
717 _toBool(v) => (v == null) ? false : v; 720 _toBool(v) => (v == null) ? false : v;
718 721
719 class EvalException implements Exception { 722 class EvalException implements Exception {
720 final String message; 723 final String message;
721 EvalException(this.message); 724 EvalException(this.message);
722 String toString() => "EvalException: $message"; 725 String toString() => "EvalException: $message";
723 } 726 }
OLDNEW
« no previous file with comments | « no previous file | pkg/polymer_expressions/test/eval_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698