Bug 1131424 - Report error message when failing to open ctypes library, r=jorendorff
authorSteve Fink <sfink@mozilla.com>
Tue, 17 Feb 2015 15:44:58 -0800
changeset 245499 0320992e5b3745b4d5f310c2ecca50bbbe19cf6e
parent 245498 a55ca32e464f073d13f57c67a428bbc30f95c878
child 245500 495753e0d44fc74e30c66b55686c1fd60a9ac72e
push id775
push usergszorc@mozilla.com
push dateTue, 24 Feb 2015 02:39:42 +0000
reviewersjorendorff
bugs1131424
milestone39.0a1
Bug 1131424 - Report error message when failing to open ctypes library, r=jorendorff Includes updates to spidermonkey check_style.py to allow new nspr header.
config/check_spidermonkey_style.py
js/src/ctypes/Library.cpp
--- a/config/check_spidermonkey_style.py
+++ b/config/check_spidermonkey_style.py
@@ -62,16 +62,17 @@ included_inclnames_to_ignore = set([
     'devtools/Instruments.h',   # we ignore devtools/ in general
     'double-conversion.h',      # strange MFBT case
     'javascript-trace.h',       # generated in $OBJDIR if HAVE_DTRACE is defined
     'jsautokw.h',               # generated in $OBJDIR
     'jscustomallocator.h',      # provided by embedders;  allowed to be missing
     'js-config.h',              # generated in $OBJDIR
     'pratom.h',                 # NSPR
     'prcvar.h',                 # NSPR
+    'prerror.h',                # NSPR
     'prinit.h',                 # NSPR
     'prlink.h',                 # NSPR
     'prlock.h',                 # NSPR
     'prprf.h',                  # NSPR
     'prthread.h',               # NSPR
     'prtypes.h',                # NSPR
     'selfhosted.out.h',         # generated in $OBJDIR
     'unicode/locid.h',          # ICU
--- a/js/src/ctypes/Library.cpp
+++ b/js/src/ctypes/Library.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * vim: set ts=2 sw=2 et tw=99:
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "ctypes/Library.h"
 
+#include "prerror.h"
 #include "prlink.h"
 
 #include "ctypes/CTypes.h"
 
 namespace js {
 namespace ctypes {
 
 /*******************************************************************************
@@ -141,22 +142,27 @@ Library::Create(JSContext* cx, jsval pat
 
   libSpec.value.pathname = pathBytes;
   libSpec.type = PR_LibSpec_Pathname;
 #endif
 
   PRLibrary* library = PR_LoadLibraryWithFlags(libSpec, 0);
 
   if (!library) {
+    char *error = (char*) JS_malloc(cx, PR_GetErrorTextLength() + 1);
+    if (error)
+      PR_GetErrorText(error);
+
 #ifdef XP_WIN
-    JS_ReportError(cx, "couldn't open library %hs", pathChars);
+    JS_ReportError(cx, "couldn't open library %hs: %s", pathChars, error);
 #else
-    JS_ReportError(cx, "couldn't open library %s", pathBytes);
+    JS_ReportError(cx, "couldn't open library %s: %s", pathBytes, error);
     JS_free(cx, pathBytes);
 #endif
+    JS_free(cx, error);
     return nullptr;
   }
 
 #ifndef XP_WIN
   JS_free(cx, pathBytes);
 #endif
 
   // stash the library