Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include <Foundation/Foundation.h>
8 #include "mac_utils.h"
9 #include "nsXPCOM.h"
11 void GetObjCExceptionInfo(void* inException, nsACString& outString)
12 {
13 NSException* e = (NSException*)inException;
15 NSString* name = [e name];
16 NSString* reason = [e reason];
17 unsigned int nameLength = [name length];
18 unsigned int reasonLength = [reason length];
20 unichar* nameBuffer = (unichar*)NS_Alloc(sizeof(unichar) * (nameLength + 1));
21 if (!nameBuffer)
22 return;
23 unichar* reasonBuffer = (unichar*)NS_Alloc(sizeof(unichar) * (reasonLength + 1));
24 if (!reasonBuffer) {
25 NS_Free(nameBuffer);
26 return;
27 }
29 [name getCharacters:nameBuffer];
30 [reason getCharacters:reasonBuffer];
31 nameBuffer[nameLength] = '\0';
32 reasonBuffer[reasonLength] = '\0';
34 outString.AssignLiteral("\nObj-C Exception data:\n");
35 AppendUTF16toUTF8(reinterpret_cast<const char16_t*>(nameBuffer), outString);
36 outString.AppendLiteral(": ");
37 AppendUTF16toUTF8(reinterpret_cast<const char16_t*>(reasonBuffer), outString);
39 NS_Free(nameBuffer);
40 NS_Free(reasonBuffer);
41 }