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

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

Issue 1291623005: Skip type checks on native JavaScriptObjects (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Skip type checks on JSOs Created 5 years, 4 months 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 | lib/runtime/_rtti.js » ('j') | 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_runtime/_operations', null, /* Imports */[ 8 dart_library.library('dart_runtime/_operations', null, /* Imports */[
9 ], /* Lazy Imports */[ 9 ], /* Lazy Imports */[
10 'dart/async', 10 'dart/async',
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 isSubtype(type, async.StreamSubscription) && 185 isSubtype(type, async.StreamSubscription) &&
186 isSubtype(actual, async.StreamSubscription)) { 186 isSubtype(actual, async.StreamSubscription)) {
187 console.warn('Ignoring cast fail from ' + types.typeName(actual) + 187 console.warn('Ignoring cast fail from ' + types.typeName(actual) +
188 ' to ' + types.typeName(type)); 188 ' to ' + types.typeName(type));
189 return true; 189 return true;
190 } 190 }
191 return false; 191 return false;
192 } 192 }
193 193
194 function strongInstanceOf(obj, type) { 194 function strongInstanceOf(obj, type) {
195 return types.isSubtype(rtti.realRuntimeType(obj), type); 195 let actual = rtti.realRuntimeType(obj);
196 return types.isSubtype(actual, type) || actual == types.jsobject;
196 } 197 }
197 exports.strongInstanceOf = strongInstanceOf; 198 exports.strongInstanceOf = strongInstanceOf;
198 199
199 function instanceOfOrNull(obj, type) { 200 function instanceOfOrNull(obj, type) {
200 if ((obj == null) || strongInstanceOf(obj, type)) return true; 201 if ((obj == null) || strongInstanceOf(obj, type)) return true;
201 return false; 202 return false;
202 } 203 }
203 204
204 function instanceOf(obj, type) { 205 function instanceOf(obj, type) {
205 if (strongInstanceOf(obj, type)) return true; 206 if (strongInstanceOf(obj, type)) return true;
206 // TODO(vsm): This is perhaps too eager to throw a StrongModeError? 207 // TODO(#296): This is perhaps too eager to throw a StrongModeError?
207 // It will throw on <int>[] is List<String>. 208 // It will throw on <int>[] is List<String>.
208 // TODO(vsm): We can statically detect many cases where this 209 // TODO(vsm): We can statically detect many cases where this
209 // check is unnecessary. 210 // check is unnecessary.
210 if (types.isGroundType(type)) return false; 211 if (types.isGroundType(type)) return false;
211 let actual = rtti.realRuntimeType(obj); 212 let actual = rtti.realRuntimeType(obj);
212 dart_utils.throwStrongModeError('Strong mode is check failure: ' + 213 dart_utils.throwStrongModeError('Strong mode is check failure: ' +
213 types.typeName(actual) + ' does not soundly subtype ' + 214 types.typeName(actual) + ' does not soundly subtype ' +
214 types.typeName(type)); 215 types.typeName(type));
215 } 216 }
216 exports.instanceOf = instanceOf; 217 exports.instanceOf = instanceOf;
217 218
218 function cast(obj, type) { 219 function cast(obj, type) {
220 // TODO(#296): This is perhaps too eager to throw a StrongModeError?
219 // TODO(vsm): handle non-nullable types 221 // TODO(vsm): handle non-nullable types
220 if (instanceOfOrNull(obj, type)) return obj; 222 if (instanceOfOrNull(obj, type)) return obj;
221 let actual = rtti.realRuntimeType(obj); 223 let actual = rtti.realRuntimeType(obj);
222 if (_ignoreTypeFailure(actual, type)) { 224 if (types.isGroundType(type)) errors.throwCastError(actual, type);
223 // TODO(vsm): track why this is happening in our async / await tests. 225
224 if (types.isGroundType(type)) { 226 if (_ignoreTypeFailure(actual, type)) return obj;
225 console.error('Should not ignore cast failure from ' + 227
226 types.typeName(actual) + ' to ' + types.typeName(type));
227 }
228 return obj;
229 }
230 if (types.isGroundType(type)) {
231 errors.throwCastError(actual, type);
232 }
233 dart_utils.throwStrongModeError('Strong mode cast failure from ' + 228 dart_utils.throwStrongModeError('Strong mode cast failure from ' +
234 types.typeName(actual) + ' to ' + types.typeName(type)); 229 types.typeName(actual) + ' to ' + types.typeName(type));
235 } 230 }
236 exports.cast = cast; 231 exports.cast = cast;
237 232
238 function arity(f) { 233 function arity(f) {
239 // TODO(jmesserly): need to parse optional params. 234 // TODO(jmesserly): need to parse optional params.
240 // In ES6, length is the number of required arguments. 235 // In ES6, length is the number of required arguments.
241 return { min: f.length, max: f.length }; 236 return { min: f.length, max: f.length };
242 } 237 }
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 next() { 429 next() {
435 let i = this.dartIterator; 430 let i = this.dartIterator;
436 let done = !i.moveNext(); 431 let done = !i.moveNext();
437 return { done: done, value: done ? void 0 : i.current }; 432 return { done: done, value: done ? void 0 : i.current };
438 } 433 }
439 } 434 }
440 exports.JsIterator = JsIterator; 435 exports.JsIterator = JsIterator;
441 436
442 437
443 }); 438 });
OLDNEW
« no previous file with comments | « no previous file | lib/runtime/_rtti.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698