OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 import 'package:expect/expect.dart'; |
| 6 import 'package:compiler/src/native/native.dart'; |
| 7 import 'package:compiler/src/js/js.dart' as js; |
| 8 |
| 9 void test(String source, NativeThrowBehavior expectedThrowBehavior) { |
| 10 js.Template template = js.js.parseForeignJS(source); |
| 11 NativeThrowBehavior throwBehavior = |
| 12 new ThrowBehaviorVisitor().analyze(template.ast); |
| 13 Expect.equals(expectedThrowBehavior, throwBehavior, 'source "$source"'); |
| 14 } |
| 15 |
| 16 void main() { |
| 17 final MAY = NativeThrowBehavior.MAY; |
| 18 final MUST = NativeThrowBehavior.MUST; |
| 19 final NEVER = NativeThrowBehavior.NEVER; |
| 20 final NULL_NSM = NativeThrowBehavior.MAY_THROW_ONLY_ON_FIRST_ARGUMENT_ACCESS; |
| 21 |
| 22 test('0', NEVER); |
| 23 test('void 0', NEVER); |
| 24 test('#', NEVER); |
| 25 test('void #', NEVER); |
| 26 test('# + 1', NEVER); |
| 27 test('!#', NEVER); |
| 28 test('!!#', NEVER); |
| 29 test('~#', NEVER); |
| 30 test('~~#', NEVER); |
| 31 |
| 32 test('# * #', NEVER); |
| 33 test('# / #', NEVER); |
| 34 test('# % #', NEVER); |
| 35 test('# + #', NEVER); |
| 36 test('# - #', NEVER); |
| 37 |
| 38 test('# << #', NEVER); |
| 39 test('# >> #', NEVER); |
| 40 test('# >>> #', NEVER); |
| 41 |
| 42 test('# < #', NEVER); |
| 43 test('# > #', NEVER); |
| 44 test('# <= #', NEVER); |
| 45 test('# >= #', NEVER); |
| 46 |
| 47 test('# == #', NEVER); |
| 48 test('# != #', NEVER); |
| 49 test('# === #', NEVER); |
| 50 test('# !== #', NEVER); |
| 51 |
| 52 test('# & #', NEVER); |
| 53 test('# ^ #', NEVER); |
| 54 test('# | #', NEVER); |
| 55 |
| 56 test('# , #', NEVER); |
| 57 |
| 58 test('typeof(#) == "string"', NEVER); |
| 59 test('"object" === typeof #', NEVER); |
| 60 |
| 61 test('# == 1 || # == 2 || # == 3', NEVER); |
| 62 test('# != 1 && # != 2 && # != 3', NEVER); |
| 63 |
| 64 test('#.x', NULL_NSM); |
| 65 test('!!#.x', NULL_NSM); |
| 66 test('#.x + 1', NULL_NSM); |
| 67 test('1 + #.x', NULL_NSM); |
| 68 test('#[#] + 2', NULL_NSM); |
| 69 test('2 + #[#]', NULL_NSM); |
| 70 |
| 71 test('#.x == 1 || # == 1', NULL_NSM); |
| 72 test('# == 1 || #.x == 1', MAY); |
| 73 |
| 74 test('#[#][#]', MAY); |
| 75 test('# + #[#]', MAY); |
| 76 test('#()', MAY); |
| 77 test('(function(){})()', MAY); |
| 78 |
| 79 test('new Date(#)', MAY); |
| 80 test('# in #', MAY); |
| 81 |
| 82 test('console', MAY); |
| 83 test('Array', NEVER); |
| 84 test('Object', NEVER); |
| 85 |
| 86 test('typeof #', NEVER); |
| 87 test('typeof console', NEVER); |
| 88 test('typeof foo.#', MAY); |
| 89 test('typeof #.foo', NULL_NSM); |
| 90 |
| 91 test('throw 123', MUST); |
| 92 test('throw #', MUST); |
| 93 test('throw #.x', MUST); // Could be better: is also an NSM guard. |
| 94 test('throw #.x = 123', MUST); |
| 95 } |
OLD | NEW |