diff --git a/js/ctypes/tests/Makefile.in b/js/ctypes/tests/Makefile.in
--- a/js/ctypes/tests/Makefile.in
+++ b/js/ctypes/tests/Makefile.in
@@ -61,16 +61,16 @@ include $(topsrcdir)/config/rules.mk
 
 xpctestdir = $(testxpcobjdir)/$(MODULE)/unit
 
 # preprocess and install our unit test into the appropriate directory,
 # and install the test library as well. the xpcshell test rules will
 # install the .js.in from the tests srcdir, so remove it when we're done.
 libs:: unit/test_jsctypes.js.in
 	$(PYTHON) $(MOZILLA_DIR)/config/Preprocessor.py $(DEFINES) $(ACDEFINES) \
-	  $^ > $(xpctestdir)/test_jsctypes.js
+          -DCTYPES_TEST_LIB=\"$(SHARED_LIBRARY)\" $^ > $(xpctestdir)/test_jsctypes.js
 	$(TEST_INSTALLER) $(SHARED_LIBRARY) $(xpctestdir)
 	$(RM) $(xpctestdir)/test_jsctypes.js.in
 
 GARBAGE += \
     $(xpctestdir)/test_jsctypes.js \
     $(xpctestdir)/$(SHARED_LIBRARY) \
     $(NULL)
diff --git a/js/ctypes/tests/unit/test_jsctypes.js.in b/js/ctypes/tests/unit/test_jsctypes.js.in
--- a/js/ctypes/tests/unit/test_jsctypes.js.in
+++ b/js/ctypes/tests/unit/test_jsctypes.js.in
@@ -38,16 +38,18 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 Components.utils.import("resource://gre/modules/ctypes.jsm");
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
+#expand const CTYPES_TEST_LIB = __CTYPES_TEST_LIB__;
+
 function do_check_throws(f, type, stack)
 {
   if (!stack)
     stack = Components.stack.caller;
 
   try {
     f();
   } catch (exc) {
@@ -55,26 +57,17 @@ function do_check_throws(f, type, stack)
       return;
     do_throw("expected " + type.name + " exception, caught " + exc, stack);
   }
   do_throw("expected " + type.name + " exception, none thrown", stack);
 }
 
 function run_test()
 {
-#ifdef XP_WIN
-  var libfile = do_get_file("jsctypes-test.dll");
-#elifdef XP_MACOSX
-  var libfile = do_get_file("libjsctypes-test.dylib");
-#elifdef XP_UNIX
-  var libfile = do_get_file("libjsctypes-test.so");
-#else
-  // unsupported OS - don't run the test
-  return;
-#endif
+  var libfile = do_get_file(CTYPES_TEST_LIB);
 
   // open the library with an nsILocalFile
   var library = ctypes.open(libfile);
 
   run_void_tests(library);
   run_int8_tests(library);
   run_int16_tests(library);
   run_int32_tests(library);
