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 library js.safety; | 5 library js.safety; |
6 | 6 |
7 import "js.dart" as js; | 7 import "js.dart" as js; |
8 | 8 |
9 typedef bool PositionPredicate(int position); | 9 typedef bool PositionPredicate(int position); |
10 | 10 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 160 } |
161 if (left is js.PropertyAccess) { | 161 if (left is js.PropertyAccess) { |
162 // "a.b.x = c.y" gives a TypeError for null values in this order: `a`, | 162 // "a.b.x = c.y" gives a TypeError for null values in this order: `a`, |
163 // `c`, `a.b`. | 163 // `c`, `a.b`. |
164 int receiver = visit(left.receiver); | 164 int receiver = visit(left.receiver); |
165 visit(left.selector); | 165 visit(left.selector); |
166 int value = visit(right); | 166 int value = visit(right); |
167 if (canBeNull(receiver)) safe = false; | 167 if (canBeNull(receiver)) safe = false; |
168 return value; | 168 return value; |
169 } | 169 } |
170 // Be conserative with unrecognized LHS expressions. | 170 // Be conservative with unrecognized LHS expressions. |
171 safe = false; | 171 safe = false; |
172 return leftToRight(); | 172 return leftToRight(); |
173 } | 173 } |
174 | 174 |
175 int visitCall(js.Call node) { | 175 int visitCall(js.Call node) { |
176 // TODO(sra): Recognize JavaScript built-ins like | 176 // TODO(sra): Recognize JavaScript built-ins like |
177 // 'Object.prototype.hasOwnProperty.call'. | 177 // 'Object.prototype.hasOwnProperty.call'. |
178 visit(node.target); | 178 visit(node.target); |
179 node.arguments.forEach(visit); | 179 node.arguments.forEach(visit); |
180 return unsafe(UNKNOWN_VALUE); | 180 return unsafe(UNKNOWN_VALUE); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 int visitFun(js.Fun node) { | 318 int visitFun(js.Fun node) { |
319 bool oldSafe = safe; | 319 bool oldSafe = safe; |
320 int oldNextPosition = nextPosition; | 320 int oldNextPosition = nextPosition; |
321 visit(node.body); | 321 visit(node.body); |
322 // Creating a function has no effect on order unless there are embedded | 322 // Creating a function has no effect on order unless there are embedded |
323 // placeholders. | 323 // placeholders. |
324 safe = (nextPosition == oldNextPosition) && oldSafe; | 324 safe = (nextPosition == oldNextPosition) && oldSafe; |
325 return NONNULL_VALUE; | 325 return NONNULL_VALUE; |
326 } | 326 } |
327 } | 327 } |
OLD | NEW |