OLD | NEW |
1 dart_library.library('notnull', null, /* Imports */[ | 1 dart_library.library('notnull', null, /* Imports */[ |
2 'dart/_runtime', | 2 'dart_sdk' |
3 'dart/core' | 3 ], function(exports, dart_sdk) { |
4 ], /* Lazy imports */[ | |
5 ], function(exports, dart, core) { | |
6 'use strict'; | 4 'use strict'; |
7 let dartx = dart.dartx; | 5 const core = dart_sdk.core; |
8 function intAssignments() { | 6 const dart = dart_sdk.dart; |
| 7 const dartx = dart_sdk.dartx; |
| 8 const notnull = Object.create(null); |
| 9 notnull.intAssignments = function() { |
9 let i = 0; | 10 let i = 0; |
10 i = i & 1; | 11 i = i & 1; |
11 i = i | 1; | 12 i = i | 1; |
12 i = i ^ 1; | 13 i = i ^ 1; |
13 i = i >> 1; | 14 i = i >> 1; |
14 i = i << 1; | 15 i = i << 1; |
15 i = i - 1; | 16 i = i - 1; |
16 i = i % 1; | 17 i = i % 1; |
17 i = i + 1; | 18 i = i + 1; |
18 let t = i; | 19 let t = i; |
19 t == null ? i = 1 : t; | 20 t == null ? i = 1 : t; |
20 i = i * 1; | 21 i = i * 1; |
21 i = (i / 1)[dartx.truncate](); | 22 i = (i / 1)[dartx.truncate](); |
22 i++; | 23 i++; |
23 --i; | 24 --i; |
24 core.print(i + 1); | 25 core.print(i + 1); |
25 let j = 1; | 26 let j = 1; |
26 j = i < 10 ? 1 : 2; | 27 j = i < 10 ? 1 : 2; |
27 core.print(j + 1); | 28 core.print(j + 1); |
28 } | 29 }; |
29 dart.fn(intAssignments, dart.void, []); | 30 dart.fn(notnull.intAssignments, dart.void, []); |
30 function doubleAssignments() { | 31 notnull.doubleAssignments = function() { |
31 let d = 0.0; | 32 let d = 0.0; |
32 d = d / 1; | 33 d = d / 1; |
33 core.print(d + 1); | 34 core.print(d + 1); |
34 } | 35 }; |
35 dart.fn(doubleAssignments, dart.void, []); | 36 dart.fn(notnull.doubleAssignments, dart.void, []); |
36 function boolAssignments() { | 37 notnull.boolAssignments = function() { |
37 let b = true; | 38 let b = true; |
38 b != b; | 39 b != b; |
39 core.print(b); | 40 core.print(b); |
40 } | 41 }; |
41 dart.fn(boolAssignments, dart.void, []); | 42 dart.fn(notnull.boolAssignments, dart.void, []); |
42 function increments() { | 43 notnull.increments = function() { |
43 let i = 1; | 44 let i = 1; |
44 core.print(++i); | 45 core.print(++i); |
45 core.print(i++); | 46 core.print(i++); |
46 core.print(--i); | 47 core.print(--i); |
47 core.print(i--); | 48 core.print(i--); |
48 let j = null; | 49 let j = null; |
49 j = 1; | 50 j = 1; |
50 core.print((j = dart.notNull(j) + 1)); | 51 core.print((j = dart.notNull(j) + 1)); |
51 core.print((() => { | 52 core.print((() => { |
52 let x = j; | 53 let x = j; |
53 j = dart.notNull(x) + 1; | 54 j = dart.notNull(x) + 1; |
54 return x; | 55 return x; |
55 })()); | 56 })()); |
56 core.print((j = dart.notNull(j) - 1)); | 57 core.print((j = dart.notNull(j) - 1)); |
57 core.print((() => { | 58 core.print((() => { |
58 let x = j; | 59 let x = j; |
59 j = dart.notNull(x) - 1; | 60 j = dart.notNull(x) - 1; |
60 return x; | 61 return x; |
61 })()); | 62 })()); |
62 } | 63 }; |
63 dart.fn(increments, dart.void, []); | 64 dart.fn(notnull.increments, dart.void, []); |
64 function conditionals(cond) { | 65 notnull.conditionals = function(cond) { |
65 if (cond === void 0) cond = null; | 66 if (cond === void 0) cond = null; |
66 let nullable = null; | 67 let nullable = null; |
67 nullable = 1; | 68 nullable = 1; |
68 let nonNullable = 1; | 69 let nonNullable = 1; |
69 let a = dart.notNull(cond) ? nullable : nullable; | 70 let a = dart.notNull(cond) ? nullable : nullable; |
70 let b = dart.notNull(cond) ? nullable : nonNullable; | 71 let b = dart.notNull(cond) ? nullable : nonNullable; |
71 let c = dart.notNull(cond) ? nonNullable : nonNullable; | 72 let c = dart.notNull(cond) ? nonNullable : nonNullable; |
72 let d = dart.notNull(cond) ? nonNullable : nullable; | 73 let d = dart.notNull(cond) ? nonNullable : nullable; |
73 core.print(dart.notNull(a) + dart.notNull(b) + c + dart.notNull(d)); | 74 core.print(dart.notNull(a) + dart.notNull(b) + c + dart.notNull(d)); |
74 } | 75 }; |
75 dart.fn(conditionals, dart.void, [], [core.bool]); | 76 dart.fn(notnull.conditionals, dart.void, [], [core.bool]); |
76 function nullAwareOps() { | 77 notnull.nullAwareOps = function() { |
77 let nullable = null; | 78 let nullable = null; |
78 let nonNullable = 1; | 79 let nonNullable = 1; |
79 let a = (nullable != null ? nullable : nullable); | 80 let a = (nullable != null ? nullable : nullable); |
80 let b = (nullable != null ? nullable : nonNullable); | 81 let b = (nullable != null ? nullable : nonNullable); |
81 let c = nonNullable; | 82 let c = nonNullable; |
82 let d = nonNullable; | 83 let d = nonNullable; |
83 core.print(dart.notNull(a) + dart.notNull(b) + c + d); | 84 core.print(dart.notNull(a) + dart.notNull(b) + c + d); |
84 let s = ""; | 85 let s = ""; |
85 core.print(dart.notNull(s[dartx.length]) + 1); | 86 core.print(dart.notNull(s[dartx.length]) + 1); |
86 } | 87 }; |
87 dart.fn(nullAwareOps, dart.void, []); | 88 dart.fn(notnull.nullAwareOps, dart.void, []); |
88 function nullableLocals(param) { | 89 notnull.nullableLocals = function(param) { |
89 core.print(dart.notNull(param) + 1); | 90 core.print(dart.notNull(param) + 1); |
90 let i = null; | 91 let i = null; |
91 i = 1; | 92 i = 1; |
92 core.print(dart.notNull(i) + 1); | 93 core.print(dart.notNull(i) + 1); |
93 let j = 1; | 94 let j = 1; |
94 j = i == 1 ? 1 : null; | 95 j = i == 1 ? 1 : null; |
95 core.print(dart.notNull(j) + 1); | 96 core.print(dart.notNull(j) + 1); |
96 } | 97 }; |
97 dart.fn(nullableLocals, dart.void, [core.int]); | 98 dart.fn(notnull.nullableLocals, dart.void, [core.int]); |
98 function optParams(x, y) { | 99 notnull.optParams = function(x, y) { |
99 if (x === void 0) x = null; | 100 if (x === void 0) x = null; |
100 if (y === void 0) y = 1; | 101 if (y === void 0) y = 1; |
101 core.print(dart.notNull(x) + dart.notNull(y)); | 102 core.print(dart.notNull(x) + dart.notNull(y)); |
102 } | 103 }; |
103 dart.fn(optParams, dart.void, [], [core.int, core.int]); | 104 dart.fn(notnull.optParams, dart.void, [], [core.int, core.int]); |
104 function namedParams(opts) { | 105 notnull.namedParams = function(opts) { |
105 let x = opts && 'x' in opts ? opts.x : null; | 106 let x = opts && 'x' in opts ? opts.x : null; |
106 let y = opts && 'y' in opts ? opts.y : 1; | 107 let y = opts && 'y' in opts ? opts.y : 1; |
107 core.print(dart.notNull(x) + dart.notNull(y)); | 108 core.print(dart.notNull(x) + dart.notNull(y)); |
108 } | 109 }; |
109 dart.fn(namedParams, dart.void, [], {x: core.int, y: core.int}); | 110 dart.fn(notnull.namedParams, dart.void, [], {x: core.int, y: core.int}); |
110 function forLoops(length) { | 111 notnull.forLoops = function(length) { |
111 for (let i = 0; i < 10; i++) { | 112 for (let i = 0; i < 10; i++) { |
112 core.print(i + 1); | 113 core.print(i + 1); |
113 } | 114 } |
114 for (let i = 0; i < dart.notNull(length()); i++) { | 115 for (let i = 0; i < dart.notNull(length()); i++) { |
115 core.print(i + 1); | 116 core.print(i + 1); |
116 } | 117 } |
117 for (let i = 0, n = length(); i < dart.notNull(n); i++) { | 118 for (let i = 0, n = length(); i < dart.notNull(n); i++) { |
118 core.print(i + 1); | 119 core.print(i + 1); |
119 } | 120 } |
120 for (let i = 0, n = dart.notNull(length()) + 0; i < n; i++) { | 121 for (let i = 0, n = dart.notNull(length()) + 0; i < n; i++) { |
121 core.print(i + 1); | 122 core.print(i + 1); |
122 } | 123 } |
123 } | 124 }; |
124 dart.fn(forLoops, dart.void, [dart.functionType(core.int, [])]); | 125 dart.fn(notnull.forLoops, dart.void, [dart.functionType(core.int, [])]); |
125 function nullableCycle() { | 126 notnull.nullableCycle = function() { |
126 let x = 1; | 127 let x = 1; |
127 let y = 2; | 128 let y = 2; |
128 let z = null; | 129 let z = null; |
129 x = y; | 130 x = y; |
130 y = z; | 131 y = z; |
131 z = x; | 132 z = x; |
132 core.print(dart.notNull(x) + dart.notNull(y) + dart.notNull(z)); | 133 core.print(dart.notNull(x) + dart.notNull(y) + dart.notNull(z)); |
133 let s = null; | 134 let s = null; |
134 s = s; | 135 s = s; |
135 core.print(dart.notNull(s) + 1); | 136 core.print(dart.notNull(s) + 1); |
136 } | 137 }; |
137 dart.fn(nullableCycle, dart.void, []); | 138 dart.fn(notnull.nullableCycle, dart.void, []); |
138 function nonNullableCycle() { | 139 notnull.nonNullableCycle = function() { |
139 let x = 1; | 140 let x = 1; |
140 let y = 2; | 141 let y = 2; |
141 let z = 3; | 142 let z = 3; |
142 x = y; | 143 x = y; |
143 y = z; | 144 y = z; |
144 z = x; | 145 z = x; |
145 core.print(x + y + z); | 146 core.print(x + y + z); |
146 let s = 1; | 147 let s = 1; |
147 s = s; | 148 s = s; |
148 core.print(s + 1); | 149 core.print(s + 1); |
149 } | 150 }; |
150 dart.fn(nonNullableCycle, dart.void, []); | 151 dart.fn(notnull.nonNullableCycle, dart.void, []); |
151 class Foo extends core.Object { | 152 notnull.Foo = class Foo extends core.Object { |
152 Foo() { | 153 Foo() { |
153 this.intField = null; | 154 this.intField = null; |
154 this.varField = null; | 155 this.varField = null; |
155 } | 156 } |
156 f(o) { | 157 f(o) { |
157 core.print(1 + dart.notNull(dart.as(this.varField, core.num)) + 2); | 158 core.print(1 + dart.notNull(dart.as(this.varField, core.num)) + 2); |
158 while (dart.notNull(dart.as(dart.dsend(this.varField, '<', 10), core.bool)
)) { | 159 while (dart.notNull(dart.as(dart.dsend(this.varField, '<', 10), core.bool)
)) { |
159 this.varField = dart.dsend(this.varField, '+', 1); | 160 this.varField = dart.dsend(this.varField, '+', 1); |
160 } | 161 } |
161 while (dart.notNull(dart.as(dart.dsend(this.varField, '<', 10), core.bool)
)) | 162 while (dart.notNull(dart.as(dart.dsend(this.varField, '<', 10), core.bool)
)) |
162 this.varField = dart.dsend(this.varField, '+', 1); | 163 this.varField = dart.dsend(this.varField, '+', 1); |
163 core.print(1 + dart.notNull(this.intField) + 2); | 164 core.print(1 + dart.notNull(this.intField) + 2); |
164 while (dart.notNull(this.intField) < 10) { | 165 while (dart.notNull(this.intField) < 10) { |
165 this.intField = dart.notNull(this.intField) + 1; | 166 this.intField = dart.notNull(this.intField) + 1; |
166 } | 167 } |
167 while (dart.notNull(this.intField) < 10) | 168 while (dart.notNull(this.intField) < 10) |
168 this.intField = dart.notNull(this.intField) + 1; | 169 this.intField = dart.notNull(this.intField) + 1; |
169 core.print(1 + dart.notNull(o.intField) + 2); | 170 core.print(1 + dart.notNull(o.intField) + 2); |
170 while (dart.notNull(o.intField) < 10) { | 171 while (dart.notNull(o.intField) < 10) { |
171 o.intField = dart.notNull(o.intField) + 1; | 172 o.intField = dart.notNull(o.intField) + 1; |
172 } | 173 } |
173 while (dart.notNull(o.intField) < 10) | 174 while (dart.notNull(o.intField) < 10) |
174 o.intField = dart.notNull(o.intField) + 1; | 175 o.intField = dart.notNull(o.intField) + 1; |
175 } | 176 } |
176 } | 177 }; |
177 dart.setSignature(Foo, { | 178 dart.setSignature(notnull.Foo, { |
178 methods: () => ({f: [dart.dynamic, [Foo]]}) | 179 methods: () => ({f: [dart.dynamic, [notnull.Foo]]}) |
179 }); | 180 }); |
180 function _foo() { | 181 notnull._foo = function() { |
181 return 1; | 182 return 1; |
182 } | 183 }; |
183 dart.fn(_foo, core.int, []); | 184 dart.fn(notnull._foo, core.int, []); |
184 function calls() { | 185 notnull.calls = function() { |
185 let a = 1; | 186 let a = 1; |
186 let b = 1; | 187 let b = 1; |
187 b = dart.as(dart.dcall(dart.fn(x => x), a), core.int); | 188 b = dart.as(dart.dcall(dart.fn(x => x), a), core.int); |
188 core.print(dart.notNull(b) + 1); | 189 core.print(dart.notNull(b) + 1); |
189 let c = _foo(); | 190 let c = notnull._foo(); |
190 core.print(dart.notNull(c) + 1); | 191 core.print(dart.notNull(c) + 1); |
191 } | 192 }; |
192 dart.fn(calls); | 193 dart.fn(notnull.calls); |
193 function localEscapes() { | 194 notnull.localEscapes = function() { |
194 let a = 1; | 195 let a = 1; |
195 let f = dart.fn(x => a = dart.as(x, core.int)); | 196 let f = dart.fn(x => a = dart.as(x, core.int)); |
196 let b = 1; | 197 let b = 1; |
197 function g(x) { | 198 function g(x) { |
198 return b = dart.as(x, core.int); | 199 return b = dart.as(x, core.int); |
199 } | 200 } |
200 dart.fn(g); | 201 dart.fn(g); |
201 dart.dcall(f, 1); | 202 dart.dcall(f, 1); |
202 g(1); | 203 g(1); |
203 core.print(dart.notNull(a) + dart.notNull(b)); | 204 core.print(dart.notNull(a) + dart.notNull(b)); |
204 } | 205 }; |
205 dart.fn(localEscapes); | 206 dart.fn(notnull.localEscapes); |
206 function controlFlow() { | 207 notnull.controlFlow = function() { |
207 for (let i = null, j = null;;) { | 208 for (let i = null, j = null;;) { |
208 i = j = 1; | 209 i = j = 1; |
209 core.print(dart.notNull(i) + dart.notNull(j) + 1); | 210 core.print(dart.notNull(i) + dart.notNull(j) + 1); |
210 break; | 211 break; |
211 } | 212 } |
212 try { | 213 try { |
213 dart.throw(1); | 214 dart.throw(1); |
214 } catch (e) { | 215 } catch (e) { |
215 core.print(dart.dsend(e, '+', 1)); | 216 core.print(dart.dsend(e, '+', 1)); |
216 } | 217 } |
217 | 218 |
218 try { | 219 try { |
219 dart.dsend(null, 'foo'); | 220 dart.dsend(null, 'foo'); |
220 } catch (e) { | 221 } catch (e) { |
221 let trace = dart.stackTrace(e); | 222 let trace = dart.stackTrace(e); |
222 core.print(`${typeof e == 'string' ? e : dart.toString(e)} at ${trace}`); | 223 core.print(`${typeof e == 'string' ? e : dart.toString(e)} at ${trace}`); |
223 } | 224 } |
224 | 225 |
225 } | 226 }; |
226 dart.fn(controlFlow); | 227 dart.fn(notnull.controlFlow); |
227 function cascadesOnNull() { | 228 notnull.cascadesOnNull = function() { |
228 let x = null; | 229 let x = null; |
229 core.print(dart.hashCode(((() => { | 230 core.print(dart.hashCode(((() => { |
230 dart.toString(x); | 231 dart.toString(x); |
231 dart.runtimeType(x); | 232 dart.runtimeType(x); |
232 return x; | 233 return x; |
233 })()))); | 234 })()))); |
234 let y = null; | 235 let y = null; |
235 core.print(dart.hashCode(((() => { | 236 core.print(dart.hashCode(((() => { |
236 dart.toString(y); | 237 dart.toString(y); |
237 dart.runtimeType(y); | 238 dart.runtimeType(y); |
238 return y; | 239 return y; |
239 })()))); | 240 })()))); |
240 } | 241 }; |
241 dart.fn(cascadesOnNull); | 242 dart.fn(notnull.cascadesOnNull); |
242 function main() { | 243 notnull.main = function() { |
243 intAssignments(); | 244 notnull.intAssignments(); |
244 doubleAssignments(); | 245 notnull.doubleAssignments(); |
245 boolAssignments(); | 246 notnull.boolAssignments(); |
246 nullableLocals(1); | 247 notnull.nullableLocals(1); |
247 optParams(1, 2); | 248 notnull.optParams(1, 2); |
248 namedParams({x: 1, y: 2}); | 249 notnull.namedParams({x: 1, y: 2}); |
249 forLoops(dart.fn(() => 10, core.int, [])); | 250 notnull.forLoops(dart.fn(() => 10, core.int, [])); |
250 increments(); | 251 notnull.increments(); |
251 conditionals(true); | 252 notnull.conditionals(true); |
252 calls(); | 253 notnull.calls(); |
253 localEscapes(); | 254 notnull.localEscapes(); |
254 controlFlow(); | 255 notnull.controlFlow(); |
255 cascadesOnNull(); | 256 notnull.cascadesOnNull(); |
256 nullableCycle(); | 257 notnull.nullableCycle(); |
257 nonNullableCycle(); | 258 notnull.nonNullableCycle(); |
258 } | 259 }; |
259 dart.fn(main); | 260 dart.fn(notnull.main); |
260 // Exports: | 261 // Exports: |
261 exports.intAssignments = intAssignments; | 262 exports.notnull = notnull; |
262 exports.doubleAssignments = doubleAssignments; | |
263 exports.boolAssignments = boolAssignments; | |
264 exports.increments = increments; | |
265 exports.conditionals = conditionals; | |
266 exports.nullAwareOps = nullAwareOps; | |
267 exports.nullableLocals = nullableLocals; | |
268 exports.optParams = optParams; | |
269 exports.namedParams = namedParams; | |
270 exports.forLoops = forLoops; | |
271 exports.nullableCycle = nullableCycle; | |
272 exports.nonNullableCycle = nonNullableCycle; | |
273 exports.Foo = Foo; | |
274 exports.calls = calls; | |
275 exports.localEscapes = localEscapes; | |
276 exports.controlFlow = controlFlow; | |
277 exports.cascadesOnNull = cascadesOnNull; | |
278 exports.main = main; | |
279 }); | 263 }); |
OLD | NEW |