Bug 538324 - Move ctypes into js/src. Part 8: Add ctypes JS module bits to toolkit. r=bsmedberg
authorDan Witte <dwitte@mozilla.com>
Fri, 02 Apr 2010 13:16:51 -0700
changeset 40449 2ffce4096c56868ae20d4c13ec328f353957cb94
parent 40448 e93ce383b699d0f9795342d1fcb8f12055fe17b0
child 40450 49e1438ca5c1f48153291fe47adea033251f532e
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg
bugs538324
milestone1.9.3a4pre
Bug 538324 - Move ctypes into js/src. Part 8: Add ctypes JS module bits to toolkit. r=bsmedberg
js/ctypes/Makefile.in
js/ctypes/Module.cpp
js/ctypes/Module.h
js/ctypes/ctypes.jsm
js/ctypes/tests/Makefile.in
js/ctypes/tests/jsctypes-test.cpp
js/ctypes/tests/jsctypes-test.h
js/ctypes/tests/unit/test_jsctypes.js.in
toolkit/components/Makefile.in
toolkit/components/ctypes/Makefile.in
toolkit/components/ctypes/Module.cpp
toolkit/components/ctypes/Module.h
toolkit/components/ctypes/ctypes.jsm
toolkit/components/ctypes/tests/Makefile.in
toolkit/components/ctypes/tests/jsctypes-test.cpp
toolkit/components/ctypes/tests/jsctypes-test.h
toolkit/components/ctypes/tests/unit/test_jsctypes.js.in
toolkit/toolkit-makefiles.sh
--- a/toolkit/components/Makefile.in
+++ b/toolkit/components/Makefile.in
@@ -64,16 +64,22 @@ PARALLEL_DIRS += \
   places \
   startup \
   statusfilter \
   typeaheadfind \
   urlformatter \
   viewconfig \
   $(NULL)
 
+ifdef BUILD_CTYPES
+PARALLEL_DIRS += \
+  ctypes \
+  $(NULL)
+endif
+
 ifneq (,$(filter cocoa, $(MOZ_WIDGET_TOOLKIT)))
 TOOL_DIRS += alerts
 else
 PARALLEL_DIRS += alerts
 endif
 
 ifdef MOZ_FEEDS
 PARALLEL_DIRS += feeds
rename from js/ctypes/Makefile.in
rename to toolkit/components/ctypes/Makefile.in
--- a/js/ctypes/Makefile.in
+++ b/toolkit/components/ctypes/Makefile.in
@@ -31,63 +31,42 @@
 # use your version of this file under the terms of the MPL, indicate your
 # decision by deleting the provisions above and replace them with the notice
 # and other provisions required by the GPL or the LGPL. If you do not delete
 # the provisions above, a recipient may use your version of this file under
 # the terms of any one of the MPL, the GPL or the LGPL.
 #
 # ***** END LICENSE BLOCK *****
 
-DEPTH = ../..
+DEPTH = ../../..
 topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 MODULE = jsctypes
 MODULE_NAME = jsctypes
 GRE_MODULE = 1
 
-# package the js module whether ctypes is enabled or not.
 EXTRA_JS_MODULES = \
     ctypes.jsm \
     $(NULL)
 
-ifdef BUILD_CTYPES
-
 LIBRARY_NAME = jsctypes
 LIBXUL_LIBRARY = 1
 EXPORT_LIBRARY = 1
 IS_COMPONENT = 1
 
 CPPSRCS = \
-    Library.cpp \
-    CTypes.cpp \
     Module.cpp \
     $(NULL)
 
-LOCAL_INCLUDES = \
-    -Ilibffi/include \
-    $(NULL)
-
-ifeq ($(OS_ARCH),OS2)
-# libffi builds an aout lib on OS/2; convert it to an OMF lib.
-libffi/.libs/libffi.$(LIB_SUFFIX): libffi/.libs/libffi.a
-	emxomf $<
-endif
-
-SHARED_LIBRARY_LIBS = \
-    libffi/.libs/libffi.$(LIB_SUFFIX) \
-    $(NULL)
-
 EXTRA_DSO_LDOPTS += \
     $(MOZ_COMPONENT_LIBS) \
     $(MOZ_JS_LIBS) \
     $(NULL)
 
 ifdef ENABLE_TESTS
 DIRS += tests
 endif
 
-endif
-
 include $(topsrcdir)/config/rules.mk
rename from js/ctypes/Module.cpp
rename to toolkit/components/ctypes/Module.cpp
--- a/js/ctypes/Module.cpp
+++ b/toolkit/components/ctypes/Module.cpp
@@ -33,18 +33,17 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "Module.h"
-#include "Library.h"
-#include "CTypes.h"
+#include "jsapi.h"
 #include "nsIGenericFactory.h"
 #include "nsMemory.h"
 
 #define JSCTYPES_CONTRACTID \
   "@mozilla.org/jsctypes;1"
 
 #define JSCTYPES_CID \
 { 0xc797702, 0x1c60, 0x4051, { 0x9d, 0xd7, 0x4d, 0x74, 0x5, 0x60, 0x56, 0x42 } }
@@ -65,88 +64,63 @@ Module::~Module()
 }
 
 #define XPC_MAP_CLASSNAME Module
 #define XPC_MAP_QUOTED_CLASSNAME "Module"
 #define XPC_MAP_WANT_CALL
 #define XPC_MAP_FLAGS nsIXPCScriptable::WANT_CALL
 #include "xpc_map_end.h"
 
-NS_IMETHODIMP
-Module::Call(nsIXPConnectWrappedNative* wrapper,
-             JSContext* cx,
-             JSObject* obj,
-             PRUint32 argc,
-             jsval* argv,
-             jsval* vp,
-             PRBool* _retval)
-{
-  JSObject* global = JS_GetGlobalObject(cx);
-  *_retval = Init(cx, global);
-  return NS_OK;
-}
-
-#define CTYPESFN_FLAGS \
-  (JSFUN_FAST_NATIVE | JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)
-
-static JSFunctionSpec sModuleFunctions[] = {
-  JS_FN("open", Library::Open, 1, CTYPESFN_FLAGS),
-  JS_FN("cast", CData::Cast, 2, CTYPESFN_FLAGS),
-  JS_FS_END
-};
-
 static JSBool
 SealObjectAndPrototype(JSContext* cx, JSObject* parent, const char* name)
 {
   jsval prop;
   if (!JS_GetProperty(cx, parent, name, &prop))
     return false;
 
   JSObject* obj = JSVAL_TO_OBJECT(prop);
   if (!JS_GetProperty(cx, obj, "prototype", &prop))
     return false;
 
   JSObject* prototype = JSVAL_TO_OBJECT(prop);
   return JS_SealObject(cx, obj, JS_FALSE) &&
          JS_SealObject(cx, prototype, JS_FALSE);
 }
 
-JSBool
-Module::Init(JSContext* cx, JSObject* aGlobal)
+static JSBool
+InitAndSealCTypesClass(JSContext* cx, JSObject* global)
 {
-  // attach ctypes property to global object
-  JSObject* ctypes = JS_NewObject(cx, NULL, NULL, NULL);
-  if (!ctypes)
-    return false;
-
-  if (!JS_DefineProperty(cx, aGlobal, "ctypes", OBJECT_TO_JSVAL(ctypes),
-         NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT))
+  // Init the ctypes object.
+  if (!JS_InitCTypesClass(cx, global))
     return false;
 
-  if (!InitTypeClasses(cx, ctypes))
-    return false;
-
-  // attach API functions
-  if (!JS_DefineFunctions(cx, ctypes, sModuleFunctions))
-    return false;
-
-  // Seal the ctypes object, to prevent modification. (This single object
-  // instance is shared amongst everyone who imports the ctypes module.)
-  if (!JS_SealObject(cx, ctypes, JS_FALSE))
-    return false;
-
-  // Seal up Object, Function, and Array and their prototypes.
-  if (!SealObjectAndPrototype(cx, aGlobal, "Object") ||
-      !SealObjectAndPrototype(cx, aGlobal, "Function") ||
-      !SealObjectAndPrototype(cx, aGlobal, "Array"))
+  // Seal up Object, Function, and Array and their prototypes.  (This single
+  // object instance is shared amongst everyone who imports the ctypes module.)
+  if (!SealObjectAndPrototype(cx, global, "Object") ||
+      !SealObjectAndPrototype(cx, global, "Function") ||
+      !SealObjectAndPrototype(cx, global, "Array"))
     return false;
 
   // Finally, seal the global object, for good measure. (But not recursively;
   // this breaks things.)
-  return JS_SealObject(cx, aGlobal, JS_FALSE);
+  return JS_SealObject(cx, global, JS_FALSE);
+}
+
+NS_IMETHODIMP
+Module::Call(nsIXPConnectWrappedNative* wrapper,
+             JSContext* cx,
+             JSObject* obj,
+             PRUint32 argc,
+             jsval* argv,
+             jsval* vp,
+             PRBool* _retval)
+{
+  JSObject* global = JS_GetGlobalObject(cx);
+  *_retval = InitAndSealCTypesClass(cx, global);
+  return NS_OK;
 }
 
 }
 }
 
 static nsModuleComponentInfo components[] =
 {
   {
rename from js/ctypes/Module.h
rename to toolkit/components/ctypes/Module.h
--- a/js/ctypes/Module.h
+++ b/toolkit/components/ctypes/Module.h
@@ -47,19 +47,16 @@ namespace ctypes {
 class Module : public nsIXPCScriptable
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIXPCSCRIPTABLE
 
   Module();
 
-  // Creates the ctypes object and attaches it to the global object.
-  JSBool Init(JSContext* aContext, JSObject* aGlobal);
-
 private:
   ~Module();
 };
 
 }
 }
 
 #endif
rename from js/ctypes/ctypes.jsm
rename to toolkit/components/ctypes/ctypes.jsm
rename from js/ctypes/tests/Makefile.in
rename to toolkit/components/ctypes/tests/Makefile.in
--- a/js/ctypes/tests/Makefile.in
+++ b/toolkit/components/ctypes/tests/Makefile.in
@@ -31,31 +31,35 @@
 # use your version of this file under the terms of the MPL, indicate your
 # decision by deleting the provisions above and replace them with the notice
 # and other provisions required by the GPL or the LGPL. If you do not delete
 # the provisions above, a recipient may use your version of this file under
 # the terms of any one of the MPL, the GPL or the LGPL.
 #
 # ***** END LICENSE BLOCK *****
 
-DEPTH = ../../..
+DEPTH = ../../../..
 topsrcdir = @top_srcdir@
 srcdir = @srcdir@
 VPATH = @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 MODULE = jsctypes-test
 LIBRARY_NAME = jsctypes-test
 SHORT_LIBNAME = jscttest
 FORCE_SHARED_LIB = 1
 NO_DIST_INSTALL = 1
 
 CPPSRCS = jsctypes-test.cpp
 
+LOCAL_INCLUDES = \
+    -I$(topsrcdir)/js/src/ctypes \
+    $(NULL)
+
 EXTRA_DSO_LDOPTS += \
     $(XPCOM_STANDALONE_GLUE_LDOPTS) \
     $(MOZALLOC_LIB) \
     $(NSPR_LIBS) \
     $(NULL)
 
 XPCSHELL_TESTS = unit
 
rename from js/ctypes/tests/jsctypes-test.cpp
rename to toolkit/components/ctypes/tests/jsctypes-test.cpp
--- a/js/ctypes/tests/jsctypes-test.cpp
+++ b/toolkit/components/ctypes/tests/jsctypes-test.cpp
@@ -108,17 +108,17 @@ get_##name##_stats(size_t* align, size_t
   *size = sizeof(align_##name);                                                \
   *nalign = offsetof(nested_##name, b);                                        \
   *nsize = sizeof(nested_##name);                                              \
   offsets[0] = offsetof(align_##name, y);                                      \
   offsets[1] = offsetof(nested_##name, b);                                     \
   offsets[2] = offsetof(nested_##name, c);                                     \
 }
 
-#include "../typedefs.h"
+#include "typedefs.h"
 
 #if defined(_WIN32) && !defined(__WIN64)
 
 #define DEFINE_TYPE(name, type, ffiType)                                       \
 type NS_STDCALL                                                                \
 get_##name##_stdcall()                                                         \
 {                                                                              \
   return 109.25;                                                               \
@@ -151,17 +151,17 @@ sum_alignf_##name##_stdcall(float a, typ
 type NS_STDCALL                                                                \
 sum_many_##name##_stdcall(                                                     \
   type a, type b, type c, type d, type e, type f, type g, type h, type i,      \
   type j, type k, type l, type m, type n, type o, type p, type q, type r)      \
 {                                                                              \
   return a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r;\
 }
 
-#include "../typedefs.h"
+#include "typedefs.h"
 
 void NS_STDCALL
 test_void_t_stdcall()
 {
   // do nothing
   return;
 }
 
rename from js/ctypes/tests/jsctypes-test.h
rename to toolkit/components/ctypes/tests/jsctypes-test.h
--- a/js/ctypes/tests/jsctypes-test.h
+++ b/toolkit/components/ctypes/tests/jsctypes-test.h
@@ -62,17 +62,17 @@ NS_EXTERN_C
   EXPORT_CDECL(type) sum_many_##name##_cdecl(                                  \
     type, type, type, type, type, type, type, type, type,                      \
     type, type, type, type, type, type, type, type, type);                     \
                                                                                \
   EXPORT_CDECL(void) get_##name##_stats(size_t* align, size_t* size,           \
                                         size_t* nalign, size_t* nsize,         \
                                         size_t offsets[]);
 
-#include "../typedefs.h"
+#include "typedefs.h"
 
 #if defined(_WIN32) && !defined(__WIN64)
   EXPORT_STDCALL(void) test_void_t_stdcall();
 
   EXPORT_STDCALL(void*) get_voidptr_t_stdcall();
   EXPORT_STDCALL(void*) set_voidptr_t_stdcall(void*);
 
 #define DEFINE_TYPE(name, type, ffiType)                                       \
@@ -82,17 +82,17 @@ NS_EXTERN_C
   EXPORT_STDCALL(type) sum_alignb_##name##_stdcall(                            \
     char, type, char, type, char);                                             \
   EXPORT_STDCALL(type) sum_alignf_##name##_stdcall(                            \
     float, type, float, type, float);                                          \
   EXPORT_STDCALL(type) sum_many_##name##_stdcall(                              \
     type, type, type, type, type, type, type, type, type,                      \
     type, type, type, type, type, type, type, type, type);
 
-#include "../typedefs.h"
+#include "typedefs.h"
 
 #endif /* defined(_WIN32) && !defined(__WIN64) */
 
   NS_EXPORT PRInt32 test_ansi_len(const char*);
   NS_EXPORT PRInt32 test_wide_len(const PRUnichar*);
   NS_EXPORT const char* test_ansi_ret();
   NS_EXPORT const PRUnichar* test_wide_ret();
   NS_EXPORT char* test_ansi_echo(const char*);
rename from js/ctypes/tests/unit/test_jsctypes.js.in
rename to toolkit/components/ctypes/tests/unit/test_jsctypes.js.in
--- a/toolkit/toolkit-makefiles.sh
+++ b/toolkit/toolkit-makefiles.sh
@@ -764,16 +764,21 @@ MAKEFILES_xulapp="
   toolkit/themes/pinstripe/mozapps/Makefile
   toolkit/themes/winstripe/Makefile
   toolkit/themes/winstripe/global/Makefile
   toolkit/themes/winstripe/help/Makefile
   toolkit/themes/winstripe/mozapps/Makefile
   toolkit/xre/Makefile
 "
 
+MAKEFILES_ctypes="
+  toolkit/components/ctypes/Makefile
+  toolkit/components/ctypes/tests/Makefile
+"
+
 MAKEFILES_libpr0n="
   modules/libpr0n/Makefile
   modules/libpr0n/build/Makefile
   modules/libpr0n/public/Makefile
   modules/libpr0n/src/Makefile
   modules/libpr0n/decoders/Makefile
   modules/libpr0n/decoders/gif/Makefile
   modules/libpr0n/decoders/png/Makefile