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

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

Issue 1245023004: fixes dart.throw to work for non-objects (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 5 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 | test/browser/runtime_tests.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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 } 262 }
263 return map; 263 return map;
264 } 264 }
265 exports.map = map; 265 exports.map = map;
266 266
267 function assert(condition) { 267 function assert(condition) {
268 if (!condition) errors.throwAssertionError(); 268 if (!condition) errors.throwAssertionError();
269 } 269 }
270 exports.assert = assert; 270 exports.assert = assert;
271 271
272 let _stack = Symbol('_stack'); 272 let _stack = new WeakMap();
273
274 function throw_(obj) { 273 function throw_(obj) {
275 obj[_stack] = new Error(); 274 if (obj != null && (typeof obj == 'object' || typeof obj == 'function')) {
275 // TODO(jmesserly): couldn't we store the most recent stack in a single
276 // variable? There should only be one active stack trace. That would
277 // allow it to work for things like strings and numbers.
vsm 2015/07/23 14:00:04 I don't think we want this in the general case. I
Jennifer Messerly 2015/07/23 15:51:30 Sure, but they should be wrapping the stack trace
278 _stack.set(obj, new Error());
279 }
276 throw obj; 280 throw obj;
277 } 281 }
278 exports.throw = throw_; 282 exports.throw = throw_;
279 283
280 function getError(exception) { 284 function getError(exception) {
281 return exception[_stack] ? exception[_stack] : exception; 285 var stack = _stack.get(exception);
286 return stack !== void 0 ? stack : exception;
282 } 287 }
283 288
284 // This is a utility function: it is only intended to be called from dev 289 // This is a utility function: it is only intended to be called from dev
285 // tools. 290 // tools.
286 function stackPrint(exception) { 291 function stackPrint(exception) {
287 var error = getError(exception); 292 var error = getError(exception);
288 console.log(error.stack ? error.stack : 'No stack trace for: ' + error); 293 console.log(error.stack ? error.stack : 'No stack trace for: ' + error);
289 } 294 }
290 exports.stackPrint = stackPrint; 295 exports.stackPrint = stackPrint;
291 296
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 next() { 411 next() {
407 let i = this.dartIterator; 412 let i = this.dartIterator;
408 let done = !i.moveNext(); 413 let done = !i.moveNext();
409 return { done: done, value: done ? void 0 : i.current }; 414 return { done: done, value: done ? void 0 : i.current };
410 } 415 }
411 } 416 }
412 exports.JsIterator = JsIterator; 417 exports.JsIterator = JsIterator;
413 418
414 419
415 }); 420 });
OLDNEW
« no previous file with comments | « no previous file | test/browser/runtime_tests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698