OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // ------------------------------------------------------------------- | 5 // ------------------------------------------------------------------- |
6 | 6 |
7 (function(global, utils) { | 7 (function(global, utils) { |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 "column_offset" | 108 "column_offset" |
109 ], [ | 109 ], [ |
110 "locationFromPosition", ScriptLocationFromPosition, | 110 "locationFromPosition", ScriptLocationFromPosition, |
111 "nameOrSourceURL", ScriptNameOrSourceURL, | 111 "nameOrSourceURL", ScriptNameOrSourceURL, |
112 ] | 112 ] |
113 ); | 113 ); |
114 | 114 |
115 // ---------------------------------------------------------------------------- | 115 // ---------------------------------------------------------------------------- |
116 // Error implementation | 116 // Error implementation |
117 | 117 |
118 function ErrorToString() { | |
119 if (!IS_RECEIVER(this)) { | |
120 throw MakeTypeError(kCalledOnNonObject, "Error.prototype.toString"); | |
121 } | |
122 | |
123 var name = this.name; | |
124 name = IS_UNDEFINED(name) ? "Error" : TO_STRING(name); | |
125 | |
126 var message = this.message; | |
127 message = IS_UNDEFINED(message) ? "" : TO_STRING(message); | |
128 | |
129 if (name == "") return message; | |
130 if (message == "") return name; | |
131 return `${name}: ${message}` | |
132 } | |
133 | |
134 function MakeError(type, arg0, arg1, arg2) { | 118 function MakeError(type, arg0, arg1, arg2) { |
135 return MakeGenericError(GlobalError, type, arg0, arg1, arg2); | 119 return MakeGenericError(GlobalError, type, arg0, arg1, arg2); |
136 } | 120 } |
137 | 121 |
138 function MakeRangeError(type, arg0, arg1, arg2) { | 122 function MakeRangeError(type, arg0, arg1, arg2) { |
139 return MakeGenericError(GlobalRangeError, type, arg0, arg1, arg2); | 123 return MakeGenericError(GlobalRangeError, type, arg0, arg1, arg2); |
140 } | 124 } |
141 | 125 |
142 function MakeSyntaxError(type, arg0, arg1, arg2) { | 126 function MakeSyntaxError(type, arg0, arg1, arg2) { |
143 return MakeGenericError(GlobalSyntaxError, type, arg0, arg1, arg2); | 127 return MakeGenericError(GlobalSyntaxError, type, arg0, arg1, arg2); |
144 } | 128 } |
145 | 129 |
146 function MakeTypeError(type, arg0, arg1, arg2) { | 130 function MakeTypeError(type, arg0, arg1, arg2) { |
147 return MakeGenericError(GlobalTypeError, type, arg0, arg1, arg2); | 131 return MakeGenericError(GlobalTypeError, type, arg0, arg1, arg2); |
148 } | 132 } |
149 | 133 |
150 function MakeURIError() { | 134 function MakeURIError() { |
151 return MakeGenericError(GlobalURIError, kURIMalformed); | 135 return MakeGenericError(GlobalURIError, kURIMalformed); |
152 } | 136 } |
153 | 137 |
154 %InstallToContext([ | 138 %InstallToContext([ |
155 "make_range_error", MakeRangeError, | 139 "make_range_error", MakeRangeError, |
156 "make_type_error", MakeTypeError, | 140 "make_type_error", MakeTypeError, |
157 "message_get_column_number", GetColumnNumber, | 141 "message_get_column_number", GetColumnNumber, |
158 "message_get_line_number", GetLineNumber, | 142 "message_get_line_number", GetLineNumber, |
159 "message_get_source_line", GetSourceLine, | 143 "message_get_source_line", GetSourceLine, |
160 ]); | 144 ]); |
161 | 145 |
162 utils.Export(function(to) { | 146 utils.Export(function(to) { |
163 to.ErrorToString = ErrorToString; | |
164 to.MakeError = MakeError; | 147 to.MakeError = MakeError; |
165 to.MakeRangeError = MakeRangeError; | 148 to.MakeRangeError = MakeRangeError; |
166 to.MakeSyntaxError = MakeSyntaxError; | 149 to.MakeSyntaxError = MakeSyntaxError; |
167 to.MakeTypeError = MakeTypeError; | 150 to.MakeTypeError = MakeTypeError; |
168 to.MakeURIError = MakeURIError; | 151 to.MakeURIError = MakeURIError; |
169 }); | 152 }); |
170 | 153 |
171 }); | 154 }); |
OLD | NEW |