| 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 | 5 |
| 6 library js.safety; | 6 library js.safety; |
| 7 | 7 |
| 8 import "js.dart" as js; | 8 import "js.dart" as js; |
| 9 | 9 |
| 10 typedef bool PositionPredicate(int position); | 10 typedef bool PositionPredicate(int position); |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 296 |
| 297 int visitVariableUse(js.VariableUse node) { | 297 int visitVariableUse(js.VariableUse node) { |
| 298 // We could get a ReferenceError unless the variable is in scope. For JS | 298 // We could get a ReferenceError unless the variable is in scope. For JS |
| 299 // fragments, the only use of VariableUse outside a `function(){...}` should | 299 // fragments, the only use of VariableUse outside a `function(){...}` should |
| 300 // be for global references. Certain global names are almost certainly not | 300 // be for global references. Certain global names are almost certainly not |
| 301 // reference errors, e.g 'Array'. | 301 // reference errors, e.g 'Array'. |
| 302 switch (node.name) { | 302 switch (node.name) { |
| 303 case 'Array': | 303 case 'Array': |
| 304 case 'Date': | 304 case 'Date': |
| 305 case 'Function': | 305 case 'Function': |
| 306 case 'Math': |
| 306 case 'Number': | 307 case 'Number': |
| 307 case 'Object': | 308 case 'Object': |
| 308 case 'RegExp': | 309 case 'RegExp': |
| 309 case 'String': | 310 case 'String': |
| 310 case 'self': | 311 case 'self': |
| 311 case 'window': | 312 case 'window': |
| 312 return NONNULL_VALUE; | 313 return NONNULL_VALUE; |
| 313 default: | 314 default: |
| 314 return unsafe(UNKNOWN_VALUE); | 315 return unsafe(UNKNOWN_VALUE); |
| 315 } | 316 } |
| 316 } | 317 } |
| 317 | 318 |
| 318 int visitFun(js.Fun node) { | 319 int visitFun(js.Fun node) { |
| 319 bool oldSafe = safe; | 320 bool oldSafe = safe; |
| 320 int oldNextPosition = nextPosition; | 321 int oldNextPosition = nextPosition; |
| 321 visit(node.body); | 322 visit(node.body); |
| 322 // Creating a function has no effect on order unless there are embedded | 323 // Creating a function has no effect on order unless there are embedded |
| 323 // placeholders. | 324 // placeholders. |
| 324 safe = (nextPosition == oldNextPosition) && oldSafe; | 325 safe = (nextPosition == oldNextPosition) && oldSafe; |
| 325 return NONNULL_VALUE; | 326 return NONNULL_VALUE; |
| 326 } | 327 } |
| 327 } | 328 } |
| OLD | NEW |