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

Side by Side Diff: runtime/lib/errors_patch.dart

Issue 1307363005: Add optional message argument to assert statements in the VM. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 import 'dart:_internal' as internal; 5 import 'dart:_internal' as internal;
6 import 'dart:convert' show JSON; 6 import 'dart:convert' show JSON;
7 7
8 patch class Error { 8 patch class Error {
9 /* patch */ static String _objectToString(Object object) { 9 /* patch */ static String _objectToString(Object object) {
10 return Object._toString(object); 10 return Object._toString(object);
11 } 11 }
12 12
13 /* patch */ static String _stringToSafeString(String string) { 13 /* patch */ static String _stringToSafeString(String string) {
14 return JSON.encode(string); 14 return JSON.encode(string);
15 } 15 }
16 16
17 /* patch */ StackTrace get stackTrace => _stackTrace; 17 /* patch */ StackTrace get stackTrace => _stackTrace;
18 18
19 StackTrace _stackTrace; 19 StackTrace _stackTrace;
20 } 20 }
21 21
22 class _AssertionError extends Error implements AssertionError { 22 class _AssertionError extends Error implements AssertionError {
23 _AssertionError._create( 23 _AssertionError._create(
24 this._failedAssertion, this._url, this._line, this._column); 24 this._failedAssertion, this._url, this._line, this._column,
25 this.message);
25 26
26 static _throwNew(int assertionStart, int assertionEnd) 27 static _throwNew(int assertionStart, int assertionEnd, Object message)
27 native "AssertionError_throwNew"; 28 native "AssertionError_throwNew";
28 29
30 String get _messageString {
31 if (message == null) return "is not true.";
32 if (message is String) return message;
33 return Error.safeToString(message);
34 }
35
29 String toString() { 36 String toString() {
30 if (_url == null) { 37 if (_url == null) {
31 return _failedAssertion; 38 if (message == null) return _failedAssertion;
39 return "'$_failedAssertion' $_messageString";
32 } 40 }
33 var columnInfo = ""; 41 var columnInfo = "";
34 if (_column > 0) { 42 if (_column > 0) {
35 // Only add column information if it is valid. 43 // Only add column information if it is valid.
36 columnInfo = " pos $_column"; 44 columnInfo = " pos $_column";
37 } 45 }
38 return "'$_url': Failed assertion: line $_line$columnInfo: " 46 return "'$_url': Failed assertion: line $_line$columnInfo: "
39 "'$_failedAssertion' is not true."; 47 "'$_failedAssertion' $_messageString";
Lasse Reichstein Nielsen 2015/08/28 18:51:59 The format is negotiable.
40 } 48 }
41 final String _failedAssertion; 49 final String _failedAssertion;
42 final String _url; 50 final String _url;
43 final int _line; 51 final int _line;
44 final int _column; 52 final int _column;
53 final Object message;
45 } 54 }
46 55
47 class _TypeError extends _AssertionError implements TypeError { 56 class _TypeError extends _AssertionError implements TypeError {
48 _TypeError._create(String url, int line, int column, 57 _TypeError._create(String url, int line, int column,
49 this._srcType, this._dstType, this._dstName, 58 this._srcType, this._dstType, this._dstName,
50 this._errorMsg) 59 String error_msg)
51 : super._create("is assignable", url, line, column); 60 : super._create("is assignable", url, line, column, error_msg);
52 61
53 static _throwNew(int location, 62 static _throwNew(int location,
54 Object src_value, 63 Object src_value,
55 String dst_type_name, 64 String dst_type_name,
56 String dst_name, 65 String dst_name,
57 String error_msg) 66 String error_msg)
58 native "TypeError_throwNew"; 67 native "TypeError_throwNew";
59 68
60 static _throwNewIfNotLoaded(_LibraryPrefix prefix, 69 static _throwNewIfNotLoaded(_LibraryPrefix prefix,
61 int location, 70 int location,
62 Object src_value, 71 Object src_value,
63 String dst_type_name, 72 String dst_type_name,
64 String dst_name, 73 String dst_name,
65 String error_msg) { 74 String error_msg) {
66 if (!prefix.isLoaded()) { 75 if (!prefix.isLoaded()) {
67 _throwNew(location, src_value, dst_type_name, dst_name, error_msg); 76 _throwNew(location, src_value, dst_type_name, dst_name, error_msg);
68 } 77 }
69 } 78 }
70 79
71 80
72 String toString() { 81 String toString() {
73 String str = (_errorMsg != null) ? _errorMsg : ""; 82 String str = (message != null) ? message : "";
74 if ((_dstName != null) && (_dstName.length > 0)) { 83 if ((_dstName != null) && (_dstName.length > 0)) {
75 str = "${str}type '$_srcType' is not a subtype of " 84 str = "${str}type '$_srcType' is not a subtype of "
76 "type '$_dstType' of '$_dstName'."; 85 "type '$_dstType' of '$_dstName'.";
77 } else { 86 } else {
78 str = "${str}type error."; 87 str = "${str}type error.";
79 } 88 }
80 return str; 89 return str;
81 } 90 }
82 91
83 final String _srcType; 92 final String _srcType;
84 final String _dstType; 93 final String _dstType;
85 final String _dstName; 94 final String _dstName;
86 final String _errorMsg;
87 } 95 }
88 96
89 class _CastError extends Error implements CastError { 97 class _CastError extends Error implements CastError {
90 _CastError._create(this._url, this._line, this._column, 98 _CastError._create(this._url, this._line, this._column,
91 this._srcType, this._dstType, this._dstName, 99 this._srcType, this._dstType, this._dstName,
92 this._errorMsg); 100 this._errorMsg);
93 101
94 // A CastError is allocated by TypeError._throwNew() when dst_name equals 102 // A CastError is allocated by TypeError._throwNew() when dst_name equals
95 // Exceptions::kCastErrorDstName. 103 // Exceptions::kCastErrorDstName.
96 104
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 String toString() => "Javascript Integer Overflow: $_value"; 378 String toString() => "Javascript Integer Overflow: $_value";
371 } 379 }
372 380
373 class _JavascriptCompatibilityError extends Error { 381 class _JavascriptCompatibilityError extends Error {
374 final String _msg; 382 final String _msg;
375 383
376 _JavascriptCompatibilityError(this._msg); 384 _JavascriptCompatibilityError(this._msg);
377 String toString() => "Javascript Compatibility Error: $_msg"; 385 String toString() => "Javascript Compatibility Error: $_msg";
378 } 386 }
379 387
OLDNEW
« no previous file with comments | « runtime/lib/errors.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | runtime/vm/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698