Bug 1874684 - Part 21: Rename SecondsAndNanoseconds::toTotalNanoseconds. r=dminor
[gecko.git] / js / src / builtin / Error.js
bloba8633a0a53b0ccb4c70a3757c9de7e6032cb523f
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 /* ES6 20140718 draft 19.5.3.4. */
6 function ErrorToString() {
7   /* Steps 1-2. */
8   var obj = this;
9   if (!IsObject(obj)) {
10     ThrowTypeError(JSMSG_INCOMPATIBLE_PROTO, "Error", "toString", "value");
11   }
13   /* Steps 3-5. */
14   var name = obj.name;
15   name = name === undefined ? "Error" : ToString(name);
17   /* Steps 6-8. */
18   var msg = obj.message;
19   msg = msg === undefined ? "" : ToString(msg);
21   /* Step 9. */
22   if (name === "") {
23     return msg;
24   }
26   /* Step 10. */
27   if (msg === "") {
28     return name;
29   }
31   /* Step 11. */
32   return name + ": " + msg;
35 function ErrorToStringWithTrailingNewline() {
36   return FUN_APPLY(ErrorToString, this, []) + "\n";