Bug 501536 - Make jsd compile as C++; r=luke
authorTerrence Cole <terrence@mozilla.com>
Tue, 04 Sep 2012 09:02:03 -0700
changeset 107800 24298fb507104eb602f9d7fe32d8d4b6fc3c9f25
parent 107799 da6a55f4fdaef05a441c129e6a69ef885d16180f
child 107801 0a1df1ce441fb77b9e4ccc40c4641099960483e0
push idunknown
push userunknown
push dateunknown
reviewersluke
bugs501536
milestone18.0a1
Bug 501536 - Make jsd compile as C++; r=luke This should be the last real C consumer of JS-API in mozilla-central.
js/jsd/Makefile.in
js/jsd/jsd.h
js/jsd/jsd_atom.c
js/jsd/jsd_atom.cpp
js/jsd/jsd_high.c
js/jsd/jsd_high.cpp
js/jsd/jsd_hook.c
js/jsd/jsd_hook.cpp
js/jsd/jsd_java.c
js/jsd/jsd_java.cpp
js/jsd/jsd_lock.c
js/jsd/jsd_lock.cpp
js/jsd/jsd_lock.h
js/jsd/jsd_obj.c
js/jsd/jsd_obj.cpp
js/jsd/jsd_scpt.c
js/jsd/jsd_scpt.cpp
js/jsd/jsd_stak.c
js/jsd/jsd_stak.cpp
js/jsd/jsd_step.c
js/jsd/jsd_step.cpp
js/jsd/jsd_text.c
js/jsd/jsd_text.cpp
js/jsd/jsd_val.c
js/jsd/jsd_val.cpp
js/jsd/jsdebug.c
js/jsd/jsdebug.cpp
js/jsd/jsdebug.h
js/jsd/jsdstubs.c
js/jsd/jsdstubs.cpp
--- a/js/jsd/Makefile.in
+++ b/js/jsd/Makefile.in
@@ -31,28 +31,28 @@ XPCSHELL_TESTS  = test
 # REQUIRES	= java js
 
 EXPORTS		= jsdebug.h
 
 ifdef JS_THREADSAFE
 DEFINES         += -DJS_THREADSAFE
 endif
 
-CSRCS		= \
-		  jsdebug.c \
-		  jsd_atom.c \
-		  jsd_high.c \
-		  jsd_hook.c \
-		  jsd_lock.c \
-		  jsd_obj.c \
-		  jsd_scpt.c \
-		  jsd_stak.c \
-		  jsd_step.c \
-		  jsd_text.c \
-		  jsd_val.c \
+CPPSRCS		+= \
+		  jsdebug.cpp \
+		  jsd_atom.cpp \
+		  jsd_high.cpp \
+		  jsd_hook.cpp \
+		  jsd_lock.cpp \
+		  jsd_obj.cpp \
+		  jsd_scpt.cpp \
+		  jsd_stak.cpp \
+		  jsd_step.cpp \
+		  jsd_text.cpp \
+		  jsd_val.cpp \
 		  $(NULL)
 
 ifdef ENABLE_TESTS
 TOOL_DIRS		+= test
 endif
 
 include $(topsrcdir)/config/rules.mk
 
--- a/js/jsd/jsd.h
+++ b/js/jsd/jsd.h
@@ -23,30 +23,17 @@
 * in other embeddings.
 */
 #ifdef MOZILLA_CLIENT
 #define JSD_THREADSAFE 1
 /* define JSD_HAS_DANGEROUS_THREAD 1 */
 #define JSD_USE_NSPR_LOCKS 1
 #endif /* MOZILLA_CLIENT */
 
-
-/* Get jstypes.h included first. After that we can use PR macros for doing
-*  this extern "C" stuff!
-*/
-#ifdef __cplusplus
-extern "C"
-{
-#endif
 #include "jstypes.h"
-#ifdef __cplusplus
-}
-#endif
-
-JS_BEGIN_EXTERN_C
 #include "jsprf.h"
 #include "jsutil.h" /* Added by JSIFY */
 #include "jshash.h" /* Added by JSIFY */
 #include "jsclist.h"
 #include "jsdebug.h"
 #include "jsapi.h"
 #include "jsdbgapi.h"
 #include "jsd_lock.h"
@@ -56,19 +43,16 @@ JS_BEGIN_EXTERN_C
 #include <string.h>
 
 #ifdef LIVEWIRE
 #include <base/pblock.h>
 #include <base/session.h>
 #include <frame/log.h>
 #include <frame/req.h>
 #endif /* LIVEWIRE */
-JS_END_EXTERN_C
-
-JS_BEGIN_EXTERN_C
 
 #define JSD_MAJOR_VERSION 1
 #define JSD_MINOR_VERSION 1
 
 /***************************************************************************/
 /* handy macros */
 #undef  CHECK_BIT_FLAG
 #define CHECK_BIT_FLAG(f,b) ((f)&(b))
@@ -133,21 +117,21 @@ struct JSDContext
     JSCList                 removedSources;
     unsigned                   sourceAlterCount;
     JSHashTable*            atoms;
     JSCList                 objectsList;
     JSHashTable*            objectsTable;
     JSDProfileData*         callingFunctionPData;
     int64_t                 lastReturnTime;
 #ifdef JSD_THREADSAFE
-    void*                   scriptsLock;
-    void*                   sourceTextLock;
-    void*                   objectsLock;
-    void*                   atomsLock;
-    void*                   threadStatesLock;
+    JSDStaticLock*          scriptsLock;
+    JSDStaticLock*          sourceTextLock;
+    JSDStaticLock*          objectsLock;
+    JSDStaticLock*          atomsLock;
+    JSDStaticLock*          threadStatesLock;
 #endif /* JSD_THREADSAFE */
 #ifdef JSD_HAS_DANGEROUS_THREAD
     void*                   dangerousThread;
 #endif /* JSD_HAS_DANGEROUS_THREAD */
 
 };
 
 struct JSDScript
@@ -754,17 +738,17 @@ jsd_SetException(JSDContext* jsdc, JSDTh
  *      jsd_Unlock
  *      jsd_IsLocked
  *      jsd_CurrentThread
  */
 
 #ifdef JSD_THREADSAFE
 
 /* the system-wide lock */
-extern void* _jsd_global_lock;
+extern JSDStaticLock* _jsd_global_lock;
 #define JSD_LOCK()                               \
     JS_BEGIN_MACRO                               \
         if(!_jsd_global_lock)                    \
             _jsd_global_lock = jsd_CreateLock(); \
         JS_ASSERT(_jsd_global_lock);             \
         jsd_Lock(_jsd_global_lock);              \
     JS_END_MACRO
 
@@ -1106,11 +1090,9 @@ jsdlw_AppHookProc(LWDBGApp* app,
                   JSBool created,
                   void *callerdata);
 #endif
 
 
 #endif
 /***************************************************************************/
 
-JS_END_EXTERN_C
-
 #endif /* jsd_h___ */
rename from js/jsd/jsd_atom.c
rename to js/jsd/jsd_atom.cpp
rename from js/jsd/jsd_high.c
rename to js/jsd/jsd_high.cpp
--- a/js/jsd/jsd_high.c
+++ b/js/jsd/jsd_high.cpp
@@ -19,17 +19,17 @@ static JSD_UserCallbacks _callbacks;
 static void*             _user = NULL; 
 static JSRuntime*        _jsrt = NULL;
 
 #ifdef JSD_HAS_DANGEROUS_THREAD
 static void* _dangerousThread = NULL;
 #endif
 
 #ifdef JSD_THREADSAFE
-void* _jsd_global_lock = NULL;
+JSDStaticLock* _jsd_global_lock = NULL;
 #endif
 
 #ifdef DEBUG
 void JSD_ASSERT_VALID_CONTEXT(JSDContext* jsdc)
 {
     JS_ASSERT(jsdc->inited);
     JS_ASSERT(jsdc->jsrt);
     JS_ASSERT(jsdc->dumbContext);
@@ -179,17 +179,16 @@ static void
 
 JSDContext*
 jsd_DebuggerOnForUser(JSRuntime*         jsrt, 
                       JSD_UserCallbacks* callbacks, 
                       void*              user,
                       JSObject*          scopeobj)
 {
     JSDContext* jsdc;
-    JSContext* iter = NULL;
 
     jsdc = _newJSDContext(jsrt, callbacks, user, scopeobj);
     if( ! jsdc )
         return NULL;
 
     /*
      * Set hooks here.  The new/destroy script hooks are on even when
      * the debugger is paused.  The destroy hook so we'll clean up
@@ -279,17 +278,16 @@ jsd_SetUserCallbacks(JSRuntime* jsrt, JS
         memcpy(&_callbacks, callbacks, sizeof(JSD_UserCallbacks));
     else
         memset(&_callbacks, 0 , sizeof(JSD_UserCallbacks));
 }
 
 void*
 jsd_SetContextPrivate(JSDContext* jsdc, void *data)
 {
-    void *rval = jsdc->data;
     jsdc->data = data;
     return data;
 }
 
 void*
 jsd_GetContextPrivate(JSDContext* jsdc)
 {
     return jsdc->data;
rename from js/jsd/jsd_hook.c
rename to js/jsd/jsd_hook.cpp
rename from js/jsd/jsd_java.c
rename to js/jsd/jsd_java.cpp
rename from js/jsd/jsd_lock.c
rename to js/jsd/jsd_lock.cpp
--- a/js/jsd/jsd_lock.c
+++ b/js/jsd/jsd_lock.cpp
@@ -12,16 +12,18 @@
 * Otherwise, there are stubs that can be filled in with your own locking     
 * code. Also, note that these stubs include a jsd_CurrentThread()            
 * implementation that only works on Win32 - this is needed for the inprocess 
 * Java-based debugger.                                                       
 */                                                                           
 
 #include "jsd.h"
 
+#include "js/Utility.h"
+
 #ifdef JSD_THREADSAFE
 
 #ifdef JSD_USE_NSPR_LOCKS
 
 #include "prlock.h"
 #include "prthread.h"
 
 #ifdef JSD_ATTACH_THREAD_HACK
@@ -72,22 +74,22 @@ void ASSERT_VALID_LOCK(JSDStaticLock* lo
     JS_ASSERT(lock->lock);
     JS_ASSERT(lock->count >= 0);
     JS_ASSERT(lock->sig == (uint16_t) JSD_LOCK_SIG);
 }    
 #else
 #define ASSERT_VALID_LOCK(x) ((void)0)
 #endif
 
-void*
+JSDStaticLock*
 jsd_CreateLock()
 {
     JSDStaticLock* lock;
 
-    if( ! (lock = calloc(1, sizeof(JSDStaticLock))) || 
+    if( ! (lock = js_pod_calloc<JSDStaticLock>(1)) ||
         ! (lock->lock = PR_NewLock()) )
     {
         if(lock)
         {
             free(lock);
             lock = NULL;
         }
     }
--- a/js/jsd/jsd_lock.h
+++ b/js/jsd/jsd_lock.h
@@ -17,17 +17,17 @@
 
 /*
  * NOTE: These locks must be reentrant in the sense that they support
  * nested calls to lock and unlock.
  */
 
 typedef struct JSDStaticLock JSDStaticLock;
 
-extern void*
+extern JSDStaticLock*
 jsd_CreateLock();
 
 extern void
 jsd_Lock(JSDStaticLock* lock);
 
 extern void
 jsd_Unlock(JSDStaticLock* lock);
 
rename from js/jsd/jsd_obj.c
rename to js/jsd/jsd_obj.cpp
--- a/js/jsd/jsd_obj.c
+++ b/js/jsd/jsd_obj.cpp
@@ -73,38 +73,16 @@ static void
         jsd_DropAtom(jsdc, jsdobj->newURL);
     if(jsdobj->ctorURL)
         jsd_DropAtom(jsdc, jsdobj->ctorURL);
     if(jsdobj->ctorName)
         jsd_DropAtom(jsdc, jsdobj->ctorName);
     free(jsdobj);
 }
 
-static JSDObject*
-_createJSDObject(JSDContext* jsdc, JSContext *cx, JSObject *obj)
-{
-    JSDObject* jsdobj;
-    JSStackFrame* fp;
-    JSStackFrame* iter = NULL;
-    const char* newURL;
-    jsbytecode* pc;
-
-    JS_ASSERT(JSD_OBJECTS_LOCKED(jsdc));
-
-    jsdobj = (JSDObject*) calloc(1, sizeof(JSDObject));
-    if (jsdobj)
-    {
-        JS_INIT_CLIST(&jsdobj->links);
-        JS_APPEND_LINK(&jsdobj->links, &jsdc->objectsList);
-        jsdobj->obj = obj;
-        JS_HashTableAdd(jsdc->objectsTable, obj, jsdobj);
-    }
-    return jsdobj;
-}
-
 void
 jsd_Constructing(JSDContext* jsdc, JSContext *cx, JSObject *obj,
                  JSStackFrame *fp)
 {
     JSDObject* jsdobj;
     JSScript* script;
     JSDScript* jsdscript;
     const char* ctorURL;
rename from js/jsd/jsd_scpt.c
rename to js/jsd/jsd_scpt.cpp
--- a/js/jsd/jsd_scpt.c
+++ b/js/jsd/jsd_scpt.cpp
@@ -549,17 +549,16 @@ JSBool
 jsd_GetLinePCs(JSDContext* jsdc, JSDScript* jsdscript,
                unsigned startLine, unsigned maxLines,
                unsigned* count, unsigned** retLines, uintptr_t** retPCs)
 {
     JSCompartment* oldCompartment;
     unsigned first = jsdscript->lineBase;
     unsigned last = first + jsd_GetScriptLineExtent(jsdc, jsdscript) - 1;
     JSBool ok;
-    unsigned *lines;
     jsbytecode **pcs;
     unsigned i;
 
     if (last < startLine)
         return JS_TRUE;
 
     oldCompartment = JS_EnterCompartmentOfScript(jsdc->dumbContext, jsdscript->script);
 
rename from js/jsd/jsd_stak.c
rename to js/jsd/jsd_stak.cpp
--- a/js/jsd/jsd_stak.c
+++ b/js/jsd/jsd_stak.cpp
@@ -296,17 +296,16 @@ jsd_GetScopeChainForStackFrame(JSDContex
     return jsdval;
 }
 
 JSDValue*
 jsd_GetThisForStackFrame(JSDContext* jsdc, 
                          JSDThreadState* jsdthreadstate,
                          JSDStackFrameInfo* jsdframe)
 {
-    JSObject* obj;
     JSDValue* jsdval = NULL;
     JSD_LOCK_THREADSTATES(jsdc);
 
     if( jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe) )
     {
         JSBool ok;
         jsval thisval;
         JS_BeginRequest(jsdthreadstate->context);
rename from js/jsd/jsd_step.c
rename to js/jsd/jsd_step.cpp
rename from js/jsd/jsd_text.c
rename to js/jsd/jsd_text.cpp
--- a/js/jsd/jsd_text.c
+++ b/js/jsd/jsd_text.cpp
@@ -115,23 +115,16 @@ static JSDSourceText*
     JSDSourceText* jsdsrc = _newSource(jsdc, url);
     if( ! jsdsrc )
         return NULL;
     JS_INSERT_LINK(&jsdsrc->links, &jsdc->sources);
     return jsdsrc;
 }
 
 static void
-_moveSourceToFront(JSDContext* jsdc, JSDSourceText* jsdsrc)
-{
-    JS_REMOVE_LINK(&jsdsrc->links);
-    JS_INSERT_LINK(&jsdsrc->links, &jsdc->sources);
-}
-
-static void
 _moveSourceToRemovedList(JSDContext* jsdc, JSDSourceText* jsdsrc)
 {
     _clearText(jsdc, jsdsrc);
     JS_REMOVE_LINK(&jsdsrc->links);
     JS_INSERT_LINK(&jsdsrc->links, &jsdc->removedSources);
 }
 
 static void
@@ -431,17 +424,17 @@ jsd_AppendUCSourceText(JSDContext* jsdc,
     int remaining = length;
 
     if(!text || !length)
         return jsd_AppendSourceText(jsdc, jsdsrc, NULL, 0, status);
 
     JSD_LOCK_SOURCE_TEXT(jsdc);
     if(!buf)
     {
-        buf = malloc(UNICODE_TRUNCATE_BUF_SIZE);
+        buf = js_pod_malloc<char>(UNICODE_TRUNCATE_BUF_SIZE);
         if(!buf)
         {
             JSD_UNLOCK_SOURCE_TEXT(jsdc);
             return NULL;
         }
     }
     while(remaining && jsdsrc) {
         int bytes = (remaining < UNICODE_TRUNCATE_BUF_SIZE) ? remaining : UNICODE_TRUNCATE_BUF_SIZE;
rename from js/jsd/jsd_val.c
rename to js/jsd/jsd_val.cpp
--- a/js/jsd/jsd_val.c
+++ b/js/jsd/jsd_val.cpp
@@ -170,17 +170,16 @@ jsd_GetValueDouble(JSDContext* jsdc, JSD
 JSString*
 jsd_GetValueString(JSDContext* jsdc, JSDValue* jsdval)
 {
     JSContext* cx = jsdc->dumbContext;
     JSExceptionState* exceptionState;
     JSCompartment* oldCompartment = NULL;
     jsval stringval;
     JSString *string;
-    JSBool needWrap;
     JSObject *scopeObj;
 
     if(jsdval->string)
         return jsdval->string;
 
     /* Reuse the string without copying or re-rooting it */
     if(JSVAL_IS_STRING(jsdval->val)) {
         jsdval->string = JSVAL_TO_STRING(jsdval->val);
rename from js/jsd/jsdebug.c
rename to js/jsd/jsdebug.cpp
--- a/js/jsd/jsdebug.c
+++ b/js/jsd/jsdebug.cpp
@@ -105,17 +105,16 @@ JSD_ClearAllProfileData(JSDContext *jsdc
 {
     JSD_ASSERT_VALID_CONTEXT(jsdc);
     jsd_ClearAllProfileData(jsdc);    
 }
 
 JSD_PUBLIC_API(void)
 JSD_SetContextFlags(JSDContext *jsdc, uint32_t flags)
 {
-    uint32_t oldFlags = jsdc->flags;
     JSD_ASSERT_VALID_CONTEXT(jsdc);
     jsdc->flags = flags;
     if (flags & JSD_COLLECT_PROFILE_DATA) {
         /* Need to reenable our call hooks now */
         JS_SetExecuteHook(jsdc->jsrt, jsd_TopLevelCallHook, jsdc);
         JS_SetCallHook(jsdc->jsrt, jsd_FunctionCallHook, jsdc);
     }
 }
@@ -886,54 +885,54 @@ JSD_IsLockingAndThreadIdSupported()
 {
 #ifdef JSD_THREADSAFE
     return JS_TRUE;
 #else
     return JS_FALSE;
 #endif
 }
 
-JSD_PUBLIC_API(void*)
+JSD_PUBLIC_API(JSDStaticLock*)
 JSD_CreateLock()
 {
 #ifdef JSD_THREADSAFE
     return jsd_CreateLock();
 #else
     return (void*)1;
 #endif
 }
 
 JSD_PUBLIC_API(void)
-JSD_Lock(void* lock)
+JSD_Lock(JSDStaticLock* lock)
 {
 #ifdef JSD_THREADSAFE
     jsd_Lock(lock);
 #endif
 }
 
 JSD_PUBLIC_API(void)
-JSD_Unlock(void* lock)
+JSD_Unlock(JSDStaticLock* lock)
 {
 #ifdef JSD_THREADSAFE
     jsd_Unlock(lock);
 #endif
 }
 
 JSD_PUBLIC_API(JSBool)
-JSD_IsLocked(void* lock)
+JSD_IsLocked(JSDStaticLock* lock)
 {
 #if defined(JSD_THREADSAFE) && defined(DEBUG)
     return jsd_IsLocked(lock);
 #else
     return JS_TRUE;
 #endif
 }
 
 JSD_PUBLIC_API(JSBool)
-JSD_IsUnlocked(void* lock)
+JSD_IsUnlocked(JSDStaticLock* lock)
 {
 #if defined(JSD_THREADSAFE) && defined(DEBUG)
     return ! jsd_IsLocked(lock);
 #else
     return JS_TRUE;
 #endif
 }
 
--- a/js/jsd/jsdebug.h
+++ b/js/jsd/jsdebug.h
@@ -1081,54 +1081,56 @@ JSD_SetErrorReporter(JSDContext*       j
 extern JSD_PUBLIC_API(JSBool)
 JSD_GetErrorReporter(JSDContext*        jsdc,
                      JSD_ErrorReporter* reporter,
                      void**             callerdata);
 
 /***************************************************************************/
 /* Generic locks that callers can use for their own purposes */
 
+struct JSDStaticLock;
+
 /*
 * Is Locking and GetThread supported in this build?
 */
 extern JSD_PUBLIC_API(JSBool)
 JSD_IsLockingAndThreadIdSupported();
 
 /*
 * Create a reentrant/nestable lock
 */
-extern JSD_PUBLIC_API(void*)
+extern JSD_PUBLIC_API(JSDStaticLock*)
 JSD_CreateLock();
 
 /*
 * Aquire lock for this thread (or block until available). Increments a
 * counter if this thread already owns the lock.
 */
 extern JSD_PUBLIC_API(void)
-JSD_Lock(void* lock);
+JSD_Lock(JSDStaticLock* lock);
 
 /*
 * Release lock for this thread (or decrement the counter if JSD_Lock
 * was previous called more than once).
 */
 extern JSD_PUBLIC_API(void)
-JSD_Unlock(void* lock);
+JSD_Unlock(JSDStaticLock* lock);
 
 /*
 * For debugging only if not (JS_THREADSAFE AND DEBUG) then returns JS_TRUE
 *    So JSD_IsLocked(lock) may not equal !JSD_IsUnlocked(lock)
 */
 extern JSD_PUBLIC_API(JSBool)
-JSD_IsLocked(void* lock);
+JSD_IsLocked(JSDStaticLock* lock);
 
 /*
 * See above...
 */
 extern JSD_PUBLIC_API(JSBool)
-JSD_IsUnlocked(void* lock);
+JSD_IsUnlocked(JSDStaticLock* lock);
 
 /*
 * return an ID uniquely identifying this thread.
 */
 extern JSD_PUBLIC_API(void*)
 JSD_CurrentThread();
 
 /***************************************************************************/
rename from js/jsd/jsdstubs.c
rename to js/jsd/jsdstubs.cpp