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

Side by Side Diff: lib/runtime/dart/_operations.js

Issue 1485353002: Expand generic type whitelist for function application checks (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Cleanup Created 5 years 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
« no previous file with comments | « no previous file | no next file » | 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) 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 /* This library defines runtime operations on objects used by the code 5 /* This library defines runtime operations on objects used by the code
6 * generator. 6 * generator.
7 */ 7 */
8 dart_library.library('dart/_operations', null, /* Imports */[ 8 dart_library.library('dart/_operations', null, /* Imports */[
9 ], /* Lazy Imports */[ 9 ], /* Lazy Imports */[
10 'dart/_utils', 10 'dart/_utils',
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 isSubtype(type, async.Stream) && isSubtype(actual, async.Stream) || 178 isSubtype(type, async.Stream) && isSubtype(actual, async.Stream) ||
179 isSubtype(type, async.StreamSubscription) && 179 isSubtype(type, async.StreamSubscription) &&
180 isSubtype(actual, async.StreamSubscription)) { 180 isSubtype(actual, async.StreamSubscription)) {
181 console.warn('Ignoring cast fail from ' + types.typeName(actual) + 181 console.warn('Ignoring cast fail from ' + types.typeName(actual) +
182 ' to ' + types.typeName(type)); 182 ' to ' + types.typeName(type));
183 return true; 183 return true;
184 } 184 }
185 return false; 185 return false;
186 } 186 }
187 187
188 function strongInstanceOf(obj, type) { 188 function strongInstanceOf(obj, type, ignoreFromWhiteList) {
189 let actual = rtti.realRuntimeType(obj); 189 let actual = rtti.realRuntimeType(obj);
190 return types.isSubtype(actual, type) || actual == types.jsobject; 190 if (types.isSubtype(actual, type) || actual == types.jsobject) return true;
191 if (ignoreFromWhiteList == void 0) return false;
192 if (types.isGroundType(type)) return false;
193 if (_ignoreTypeFailure(actual, type)) return true;
194 return false;
191 } 195 }
192 exports.strongInstanceOf = strongInstanceOf; 196 exports.strongInstanceOf = strongInstanceOf;
193 197
194 function instanceOfOrNull(obj, type) { 198 function instanceOfOrNull(obj, type) {
195 if ((obj == null) || strongInstanceOf(obj, type)) return true; 199 if ((obj == null) || strongInstanceOf(obj, type, true)) return true;
196 return false; 200 return false;
197 } 201 }
198 202
199 function instanceOf(obj, type) { 203 function instanceOf(obj, type) {
200 if (strongInstanceOf(obj, type)) return true; 204 if (strongInstanceOf(obj, type)) return true;
201 // TODO(#296): This is perhaps too eager to throw a StrongModeError? 205 // TODO(#296): This is perhaps too eager to throw a StrongModeError?
202 // It will throw on <int>[] is List<String>. 206 // It will throw on <int>[] is List<String>.
203 // TODO(vsm): We can statically detect many cases where this 207 // TODO(vsm): We can statically detect many cases where this
204 // check is unnecessary. 208 // check is unnecessary.
205 if (types.isGroundType(type)) return false; 209 if (types.isGroundType(type)) return false;
(...skipping 12 matching lines...) Expand all
218 if (types.isGroundType(type)) errors.throwCastError(actual, type); 222 if (types.isGroundType(type)) errors.throwCastError(actual, type);
219 223
220 if (_ignoreTypeFailure(actual, type)) return obj; 224 if (_ignoreTypeFailure(actual, type)) return obj;
221 225
222 dart_utils.throwStrongModeError('Strong mode cast failure from ' + 226 dart_utils.throwStrongModeError('Strong mode cast failure from ' +
223 types.typeName(actual) + ' to ' + types.typeName(type)); 227 types.typeName(actual) + ' to ' + types.typeName(type));
224 } 228 }
225 exports.cast = cast; 229 exports.cast = cast;
226 230
227 function asInt(obj) { 231 function asInt(obj) {
232 if (obj == null) {
vsm 2015/12/01 23:52:14 This is an unrelated fix.
233 return null;
234 }
228 if (Math.floor(obj) != obj) { 235 if (Math.floor(obj) != obj) {
229 // Note: null will also be caught by this check 236 // Note: null will also be caught by this check
230 errors.throwCastError(rtti.realRuntimeType(obj), core.int); 237 errors.throwCastError(rtti.realRuntimeType(obj), core.int);
231 } 238 }
232 return obj; 239 return obj;
233 } 240 }
234 exports.asInt = asInt; 241 exports.asInt = asInt;
235 242
236 function arity(f) { 243 function arity(f) {
237 // TODO(jmesserly): need to parse optional params. 244 // TODO(jmesserly): need to parse optional params.
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 next() { 455 next() {
449 let i = this.dartIterator; 456 let i = this.dartIterator;
450 let done = !i.moveNext(); 457 let done = !i.moveNext();
451 return { done: done, value: done ? void 0 : i.current }; 458 return { done: done, value: done ? void 0 : i.current };
452 } 459 }
453 } 460 }
454 exports.JsIterator = JsIterator; 461 exports.JsIterator = JsIterator;
455 462
456 463
457 }); 464 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698