From f4b8189f4a3b2b4505e9b638122b24667d45de39 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 24 Sep 2013 08:21:22 -0700 Subject: [PATCH] Bug 918023 - SpiderMonkey: Const-qualify various static variables. r=njn --- dom/bindings/DOMJSProxyHandler.cpp | 4 +-- dom/bindings/DOMJSProxyHandler.h | 7 +++-- js/jsd/jsd_scpt.cpp | 2 +- js/jsd/jsd_xpc.cpp | 8 ++++-- js/jsd/jshash.cpp | 6 ++-- js/jsd/jshash.h | 4 +-- js/src/builtin/ParallelArray.cpp | 10 ++++--- js/src/ctypes/CTypes.cpp | 2 +- js/src/jit/IonMacroAssembler.h | 2 +- js/src/jsapi.cpp | 14 +++++----- js/src/jsapi.h | 12 ++++---- js/src/jsarray.cpp | 2 +- js/src/jscntxt.cpp | 4 +-- js/src/jsfriendapi.cpp | 8 +++--- js/src/jsfriendapi.h | 4 +-- js/src/jsgc.cpp | 2 +- js/src/jskwgen.cpp | 2 +- js/src/jsproxy.cpp | 10 ++++--- js/src/jsproxy.h | 8 +++--- js/src/jsstr.cpp | 4 +-- js/src/jswrapper.cpp | 4 +-- js/src/jswrapper.h | 6 ++-- js/src/shell/js.cpp | 44 ++++++++++++++---------------- js/src/vm/Runtime.h | 6 ++-- js/src/vm/WrapperObject.h | 3 +- js/xpconnect/shell/xpcshell.cpp | 2 +- js/xpconnect/src/Sandbox.cpp | 2 +- js/xpconnect/src/XPCJSID.cpp | 4 +-- js/xpconnect/src/XPCJSRuntime.cpp | 2 +- js/xpconnect/src/XPCMaps.cpp | 10 +++---- js/xpconnect/src/XPCMaps.h | 10 +++---- js/xpconnect/src/xpcprivate.h | 2 +- 32 files changed, 109 insertions(+), 101 deletions(-) diff --git a/dom/bindings/DOMJSProxyHandler.cpp b/dom/bindings/DOMJSProxyHandler.cpp index 44c24590b0b..b1fdb8a5f6d 100644 --- a/dom/bindings/DOMJSProxyHandler.cpp +++ b/dom/bindings/DOMJSProxyHandler.cpp @@ -33,7 +33,7 @@ DefineStaticJSVals(JSContext* cx) } -int HandlerFamily; +const char HandlerFamily = 0; js::DOMProxyShadowsResult DOMProxyShadows(JSContext* cx, JS::Handle proxy, JS::Handle id) @@ -62,7 +62,7 @@ DOMProxyShadows(JSContext* cx, JS::Handle proxy, JS::Handle id) struct SetDOMProxyInformation { SetDOMProxyInformation() { - js::SetDOMProxyInformation((void*) &HandlerFamily, + js::SetDOMProxyInformation((const void*) &HandlerFamily, js::PROXY_EXTRA_SLOT + JSPROXYSLOT_EXPANDO, DOMProxyShadows); } }; diff --git a/dom/bindings/DOMJSProxyHandler.h b/dom/bindings/DOMJSProxyHandler.h index 7cb2cc69f26..02cd8c39f24 100644 --- a/dom/bindings/DOMJSProxyHandler.h +++ b/dom/bindings/DOMJSProxyHandler.h @@ -27,8 +27,9 @@ enum { template struct Prefable; -extern int HandlerFamily; -inline void* ProxyFamily() { return &HandlerFamily; } +// This variable exists solely to provide a unique address for use as an identifier. +extern const char HandlerFamily; +inline const void* ProxyFamily() { return &HandlerFamily; } inline bool IsDOMProxy(JSObject *obj, const js::Class* clasp) { @@ -45,7 +46,7 @@ inline bool IsDOMProxy(JSObject *obj) class BaseDOMProxyHandler : public js::BaseProxyHandler { public: - BaseDOMProxyHandler(void* aProxyFamily) + BaseDOMProxyHandler(const void* aProxyFamily) : js::BaseProxyHandler(aProxyFamily) {} diff --git a/js/jsd/jsd_scpt.cpp b/js/jsd/jsd_scpt.cpp index 03b0731a2fe..5589b195c6a 100644 --- a/js/jsd/jsd_scpt.cpp +++ b/js/jsd/jsd_scpt.cpp @@ -186,7 +186,7 @@ jsd_free_script_entry(void *priv, JSHashEntry *he, unsigned flag) } } -static JSHashAllocOps script_alloc_ops = { +static const JSHashAllocOps script_alloc_ops = { jsd_alloc_script_table, jsd_free_script_table, jsd_alloc_script_entry, jsd_free_script_entry }; diff --git a/js/jsd/jsd_xpc.cpp b/js/jsd/jsd_xpc.cpp index 4f0669508ab..d4ce5ddc919 100644 --- a/js/jsd/jsd_xpc.cpp +++ b/js/jsd/jsd_xpc.cpp @@ -1002,9 +1002,11 @@ jsdScript::CreatePPLineMap() } JS::Anchor kungFuDeathGrip(jsstr); - const char *argnames[] = {"arg1", "arg2", "arg3", "arg4", - "arg5", "arg6", "arg7", "arg8", - "arg9", "arg10", "arg11", "arg12" }; + static const char *const argnames[] = { + "arg1", "arg2", "arg3", "arg4", + "arg5", "arg6", "arg7", "arg8", + "arg9", "arg10", "arg11", "arg12" + }; fun = JS_CompileUCFunction (cx, obj, "ppfun", nargs, argnames, chars, length, "x-jsd:ppbuffer?type=function", 3); if (!fun || !(script = JS_GetFunctionScript(cx, fun))) diff --git a/js/jsd/jshash.cpp b/js/jsd/jshash.cpp index 32eade3e294..6949dbf72d8 100644 --- a/js/jsd/jshash.cpp +++ b/js/jsd/jshash.cpp @@ -64,7 +64,7 @@ DefaultFreeEntry(void *pool, JSHashEntry *he, unsigned flag) js_free(he); } -static JSHashAllocOps defaultHashAllocOps = { +static const JSHashAllocOps defaultHashAllocOps = { DefaultAllocTable, DefaultFreeTable, DefaultAllocEntry, DefaultFreeEntry }; @@ -72,7 +72,7 @@ static JSHashAllocOps defaultHashAllocOps = { JSHashTable * JS_NewHashTable(uint32_t n, JSHashFunction keyHash, JSHashComparator keyCompare, JSHashComparator valueCompare, - JSHashAllocOps *allocOps, void *allocPriv) + const JSHashAllocOps *allocOps, void *allocPriv) { JSHashTable *ht; size_t nb; @@ -114,7 +114,7 @@ JS_HashTableDestroy(JSHashTable *ht) { uint32_t i, n; JSHashEntry *he, **hep; - JSHashAllocOps *allocOps = ht->allocOps; + const JSHashAllocOps *allocOps = ht->allocOps; void *allocPriv = ht->allocPriv; n = NBUCKETS(ht); diff --git a/js/jsd/jshash.h b/js/jsd/jshash.h index a0baa17683c..76077977eec 100644 --- a/js/jsd/jshash.h +++ b/js/jsd/jshash.h @@ -56,7 +56,7 @@ struct JSHashTable { JSHashFunction keyHash; /* key hash function */ JSHashComparator keyCompare; /* key comparison function */ JSHashComparator valueCompare; /* value comparison function */ - JSHashAllocOps *allocOps; /* allocation operations */ + const JSHashAllocOps *allocOps; /* allocation operations */ void *allocPriv; /* allocation private data */ #ifdef JS_HASHMETER uint32_t nlookups; /* total number of lookups */ @@ -73,7 +73,7 @@ struct JSHashTable { extern JSHashTable * JS_NewHashTable(uint32_t n, JSHashFunction keyHash, JSHashComparator keyCompare, JSHashComparator valueCompare, - JSHashAllocOps *allocOps, void *allocPriv); + const JSHashAllocOps *allocOps, void *allocPriv); extern void JS_HashTableDestroy(JSHashTable *ht); diff --git a/js/src/builtin/ParallelArray.cpp b/js/src/builtin/ParallelArray.cpp index c8e7f288560..020691b7efe 100644 --- a/js/src/builtin/ParallelArray.cpp +++ b/js/src/builtin/ParallelArray.cpp @@ -186,10 +186,12 @@ ParallelArrayObject::initClass(JSContext *cx, HandleObject obj) // Cache constructor names. { - const char *ctorStrs[NumCtors] = { "ParallelArrayConstructEmpty", - "ParallelArrayConstructFromArray", - "ParallelArrayConstructFromFunction", - "ParallelArrayConstructFromFunctionMode" }; + static const char *const ctorStrs[NumCtors] = { + "ParallelArrayConstructEmpty", + "ParallelArrayConstructFromArray", + "ParallelArrayConstructFromFunction", + "ParallelArrayConstructFromFunctionMode" + }; for (uint32_t i = 0; i < NumCtors; i++) { JSAtom *atom = Atomize(cx, ctorStrs[i], strlen(ctorStrs[i]), InternAtom); if (!atom) diff --git a/js/src/ctypes/CTypes.cpp b/js/src/ctypes/CTypes.cpp index 32478f4b326..5b3af4190f7 100644 --- a/js/src/ctypes/CTypes.cpp +++ b/js/src/ctypes/CTypes.cpp @@ -787,7 +787,7 @@ GetABICode(JSObject* obj) return ABICode(JSVAL_TO_INT(result)); } -static JSErrorFormatString ErrorFormatString[CTYPESERR_LIMIT] = { +static const JSErrorFormatString ErrorFormatString[CTYPESERR_LIMIT] = { #define MSG_DEF(name, number, count, exception, format) \ { format, count, exception } , #include "ctypes/ctypes.msg" diff --git a/js/src/jit/IonMacroAssembler.h b/js/src/jit/IonMacroAssembler.h index dfa172553f3..d81d07db4d3 100644 --- a/js/src/jit/IonMacroAssembler.h +++ b/js/src/jit/IonMacroAssembler.h @@ -304,7 +304,7 @@ class MacroAssembler : public MacroAssemblerSpecific branchPtr(cond, Address(obj, JSObject::offsetOfShape()), shape, label); } void branchTestProxyHandlerFamily(Condition cond, Register proxy, Register scratch, - void *handlerp, Label *label) { + const void *handlerp, Label *label) { Address handlerAddr(proxy, ProxyObject::offsetOfHandler()); loadPrivate(handlerAddr, scratch); Address familyAddr(scratch, BaseProxyHandler::offsetOfFamily()); diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index a6c4e8cac29..c57d0c198d5 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -884,7 +884,7 @@ JS_SetVersionForCompartment(JSCompartment *compartment, JSVersion version) compartment->options().setVersion(version); } -static struct v2smap { +static const struct v2smap { JSVersion version; const char *string; } v2smap[] = { @@ -3992,7 +3992,7 @@ JS_GetSecurityCallbacks(JSRuntime *rt) } JS_PUBLIC_API(void) -JS_SetTrustedPrincipals(JSRuntime *rt, JSPrincipals *prin) +JS_SetTrustedPrincipals(JSRuntime *rt, const JSPrincipals *prin) { rt->setTrustedPrincipals(prin); } @@ -4661,7 +4661,7 @@ JS_GetGlobalFromScript(JSScript *script) JS_PUBLIC_API(JSFunction *) JS::CompileFunction(JSContext *cx, HandleObject obj, CompileOptions options, - const char *name, unsigned nargs, const char **argnames, + const char *name, unsigned nargs, const char *const *argnames, const jschar *chars, size_t length) { JS_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment())); @@ -4705,7 +4705,7 @@ JS::CompileFunction(JSContext *cx, HandleObject obj, CompileOptions options, JS_PUBLIC_API(JSFunction *) JS::CompileFunction(JSContext *cx, HandleObject obj, CompileOptions options, - const char *name, unsigned nargs, const char **argnames, + const char *name, unsigned nargs, const char *const *argnames, const char *bytes, size_t length) { jschar *chars; @@ -4723,7 +4723,7 @@ JS::CompileFunction(JSContext *cx, HandleObject obj, CompileOptions options, JS_PUBLIC_API(JSFunction *) JS_CompileUCFunction(JSContext *cx, JSObject *objArg, const char *name, - unsigned nargs, const char **argnames, + unsigned nargs, const char *const *argnames, const jschar *chars, size_t length, const char *filename, unsigned lineno) { @@ -4737,7 +4737,7 @@ JS_CompileUCFunction(JSContext *cx, JSObject *objArg, const char *name, JS_PUBLIC_API(JSFunction *) JS_CompileFunctionForPrincipals(JSContext *cx, JSObject *objArg, JSPrincipals *principals, const char *name, - unsigned nargs, const char **argnames, + unsigned nargs, const char *const *argnames, const char *ascii, size_t length, const char *filename, unsigned lineno) { @@ -4751,7 +4751,7 @@ JS_CompileFunctionForPrincipals(JSContext *cx, JSObject *objArg, JS_PUBLIC_API(JSFunction *) JS_CompileFunction(JSContext *cx, JSObject *objArg, const char *name, - unsigned nargs, const char **argnames, + unsigned nargs, const char *const *argnames, const char *ascii, size_t length, const char *filename, unsigned lineno) { diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 88915e8d478..36032d4b87b 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -3074,7 +3074,7 @@ JS_GetSecurityCallbacks(JSRuntime *rt); * called again, passing NULL for 'prin'. */ extern JS_PUBLIC_API(void) -JS_SetTrustedPrincipals(JSRuntime *rt, JSPrincipals *prin); +JS_SetTrustedPrincipals(JSRuntime *rt, const JSPrincipals *prin); /* * Initialize the callback that is called to destroy JSPrincipals instance @@ -3216,20 +3216,20 @@ JS_GetGlobalFromScript(JSScript *script); extern JS_PUBLIC_API(JSFunction *) JS_CompileFunction(JSContext *cx, JSObject *obj, const char *name, - unsigned nargs, const char **argnames, + unsigned nargs, const char *const *argnames, const char *bytes, size_t length, const char *filename, unsigned lineno); extern JS_PUBLIC_API(JSFunction *) JS_CompileFunctionForPrincipals(JSContext *cx, JSObject *obj, JSPrincipals *principals, const char *name, - unsigned nargs, const char **argnames, + unsigned nargs, const char *const *argnames, const char *bytes, size_t length, const char *filename, unsigned lineno); extern JS_PUBLIC_API(JSFunction *) JS_CompileUCFunction(JSContext *cx, JSObject *obj, const char *name, - unsigned nargs, const char **argnames, + unsigned nargs, const char *const *argnames, const jschar *chars, size_t length, const char *filename, unsigned lineno); @@ -3330,12 +3330,12 @@ FinishOffThreadScript(JSContext *maybecx, JSRuntime *rt, void *token); extern JS_PUBLIC_API(JSFunction *) CompileFunction(JSContext *cx, JS::Handle obj, CompileOptions options, - const char *name, unsigned nargs, const char **argnames, + const char *name, unsigned nargs, const char *const *argnames, const char *bytes, size_t length); extern JS_PUBLIC_API(JSFunction *) CompileFunction(JSContext *cx, JS::Handle obj, CompileOptions options, - const char *name, unsigned nargs, const char **argnames, + const char *name, unsigned nargs, const char *const *argnames, const jschar *chars, size_t length); } /* namespace JS */ diff --git a/js/src/jsarray.cpp b/js/src/jsarray.cpp index 497c59072ff..06b99cca479 100644 --- a/js/src/jsarray.cpp +++ b/js/src/jsarray.cpp @@ -1358,7 +1358,7 @@ CompareStringValues(JSContext *cx, const Value &a, const Value &b, bool *lessOrE return true; } -static uint64_t const powersOf10[] = { +static const uint64_t powersOf10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 1000000000000ULL }; diff --git a/js/src/jscntxt.cpp b/js/src/jscntxt.cpp index 620e1269268..7be1fbd7eae 100644 --- a/js/src/jscntxt.cpp +++ b/js/src/jscntxt.cpp @@ -1190,7 +1190,7 @@ ComputeIsJITBroken() std::ifstream cpuinfo("/proc/cpuinfo"); do { if (0 == line.find("Hardware")) { - const char* blacklist[] = { + static const char* const blacklist[] = { "SCH-I400", // Samsung Continuum "SGH-T959", // Samsung i9000, Vibrant device "SGH-I897", // Samsung i9000, Captivate device @@ -1199,7 +1199,7 @@ ComputeIsJITBroken() "GT-I9000", // Samsung i9000, UK/Europe device NULL }; - for (const char** hw = &blacklist[0]; *hw; ++hw) { + for (const char* const* hw = &blacklist[0]; *hw; ++hw) { if (line.npos != line.find(*hw)) { __android_log_print(ANDROID_LOG_INFO, "Gecko", "Blacklisted device `%s'", *hw); diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp index 45f95a70dc1..a986da04abf 100644 --- a/js/src/jsfriendapi.cpp +++ b/js/src/jsfriendapi.cpp @@ -218,7 +218,7 @@ JS_SetCompartmentPrincipals(JSCompartment *compartment, JSPrincipals *principals // Any compartment with the trusted principals -- and there can be // multiple -- is a system compartment. - JSPrincipals *trusted = compartment->runtimeFromMainThread()->trustedPrincipals(); + const JSPrincipals *trusted = compartment->runtimeFromMainThread()->trustedPrincipals(); bool isSystem = principals && principals == trusted; // Clear out the old principals, if any. @@ -1031,12 +1031,12 @@ js::GetDOMCallbacks(JSRuntime *rt) return rt->DOMcallbacks; } -static void *gDOMProxyHandlerFamily = NULL; +static const void *gDOMProxyHandlerFamily = NULL; static uint32_t gDOMProxyExpandoSlot = 0; static DOMProxyShadowsCheck gDOMProxyShadowsCheck; JS_FRIEND_API(void) -js::SetDOMProxyInformation(void *domProxyHandlerFamily, uint32_t domProxyExpandoSlot, +js::SetDOMProxyInformation(const void *domProxyHandlerFamily, uint32_t domProxyExpandoSlot, DOMProxyShadowsCheck domProxyShadowsCheck) { gDOMProxyHandlerFamily = domProxyHandlerFamily; @@ -1044,7 +1044,7 @@ js::SetDOMProxyInformation(void *domProxyHandlerFamily, uint32_t domProxyExpando gDOMProxyShadowsCheck = domProxyShadowsCheck; } -void * +const void * js::GetDOMProxyHandlerFamily() { return gDOMProxyHandlerFamily; diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h index 9e648ae847e..9565a752e83 100644 --- a/js/src/jsfriendapi.h +++ b/js/src/jsfriendapi.h @@ -854,10 +854,10 @@ typedef enum DOMProxyShadowsResult { typedef DOMProxyShadowsResult (* DOMProxyShadowsCheck)(JSContext* cx, JS::HandleObject object, JS::HandleId id); JS_FRIEND_API(void) -SetDOMProxyInformation(void *domProxyHandlerFamily, uint32_t domProxyExpandoSlot, +SetDOMProxyInformation(const void *domProxyHandlerFamily, uint32_t domProxyExpandoSlot, DOMProxyShadowsCheck domProxyShadowsCheck); -void *GetDOMProxyHandlerFamily(); +const void *GetDOMProxyHandlerFamily(); uint32_t GetDOMProxyExpandoSlot(); DOMProxyShadowsCheck GetDOMProxyShadowsCheck(); diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index 6b9622a4fdd..94683ed64c7 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -4790,7 +4790,7 @@ js::NewCompartment(JSContext *cx, Zone *zone, JSPrincipals *principals, zone->setGCLastBytes(8192, GC_NORMAL); - JSPrincipals *trusted = rt->trustedPrincipals(); + const JSPrincipals *trusted = rt->trustedPrincipals(); zone->isSystem = principals && principals == trusted; } diff --git a/js/src/jskwgen.cpp b/js/src/jskwgen.cpp index 0714744a31c..87a153922ed 100644 --- a/js/src/jskwgen.cpp +++ b/js/src/jskwgen.cpp @@ -13,7 +13,7 @@ #include "vm/Keywords.h" -const char * const keyword_list[] = { +static const char * const keyword_list[] = { #define KEYWORD_STRING(keyword, name, type, version) #keyword, FOR_EACH_JAVASCRIPT_KEYWORD(KEYWORD_STRING) #undef KEYWORD_STRING diff --git a/js/src/jsproxy.cpp b/js/src/jsproxy.cpp index e672ea2259a..863c5f1dc17 100644 --- a/js/src/jsproxy.cpp +++ b/js/src/jsproxy.cpp @@ -76,7 +76,7 @@ js::assertEnteredPolicy(JSContext *cx, JSObject *proxy, jsid id) } #endif -BaseProxyHandler::BaseProxyHandler(void *family) +BaseProxyHandler::BaseProxyHandler(const void *family) : mFamily(family), mHasPrototype(false), mHasPolicy(false) @@ -524,7 +524,7 @@ DirectProxyHandler::weakmapKeyDelegate(JSObject *proxy) return UncheckedUnwrap(proxy); } -DirectProxyHandler::DirectProxyHandler(void *family) +DirectProxyHandler::DirectProxyHandler(const void *family) : BaseProxyHandler(family) { } @@ -785,7 +785,8 @@ class ScriptedIndirectProxyHandler : public BaseProxyHandler } /* anonymous namespace */ -static int sScriptedIndirectProxyHandlerFamily = 0; +// This variable exists solely to provide a unique address for use as an identifier. +static const char sScriptedIndirectProxyHandlerFamily = 0; ScriptedIndirectProxyHandler::ScriptedIndirectProxyHandler() : BaseProxyHandler(&sScriptedIndirectProxyHandlerFamily) @@ -1083,7 +1084,8 @@ class ScriptedDirectProxyHandler : public DirectProxyHandler { static ScriptedDirectProxyHandler singleton; }; -static int sScriptedDirectProxyHandlerFamily = 0; +// This variable exists solely to provide a unique address for use as an identifier. +static const char sScriptedDirectProxyHandlerFamily = 0; // Aux.2 FromGenericPropertyDescriptor(Desc) static bool diff --git a/js/src/jsproxy.h b/js/src/jsproxy.h index 9cce4eddf8e..464a746deeb 100644 --- a/js/src/jsproxy.h +++ b/js/src/jsproxy.h @@ -67,7 +67,7 @@ class JS_FRIEND_API(Wrapper); */ class JS_FRIEND_API(BaseProxyHandler) { - void *mFamily; + const void *mFamily; bool mHasPrototype; bool mHasPolicy; protected: @@ -76,7 +76,7 @@ class JS_FRIEND_API(BaseProxyHandler) void setHasPolicy(bool aHasPolicy) { mHasPolicy = aHasPolicy; } public: - explicit BaseProxyHandler(void *family); + explicit BaseProxyHandler(const void *family); virtual ~BaseProxyHandler(); bool hasPrototype() { @@ -87,7 +87,7 @@ class JS_FRIEND_API(BaseProxyHandler) return mHasPolicy; } - inline void *family() { + inline const void *family() { return mFamily; } static size_t offsetOfFamily() { @@ -179,7 +179,7 @@ class JS_FRIEND_API(BaseProxyHandler) class JS_PUBLIC_API(DirectProxyHandler) : public BaseProxyHandler { public: - explicit DirectProxyHandler(void *family); + explicit DirectProxyHandler(const void *family); /* ES5 Harmony fundamental proxy traps. */ virtual bool preventExtensions(JSContext *cx, HandleObject proxy) MOZ_OVERRIDE; diff --git a/js/src/jsstr.cpp b/js/src/jsstr.cpp index 8f53a93e31e..879bf065cae 100644 --- a/js/src/jsstr.cpp +++ b/js/src/jsstr.cpp @@ -106,8 +106,8 @@ str_escape(JSContext *cx, unsigned argc, Value *vp) { CallArgs args = CallArgsFromVp(argc, vp); - const char digits[] = {'0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; + static const char digits[] = {'0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; JSLinearString *str = ArgToRootedString(cx, args, 0); if (!str) diff --git a/js/src/jswrapper.cpp b/js/src/jswrapper.cpp index 17fee7573ae..73d8c1b782b 100644 --- a/js/src/jswrapper.cpp +++ b/js/src/jswrapper.cpp @@ -21,7 +21,7 @@ using namespace js; using namespace js::gc; -int js::sWrapperFamily; +const char js::sWrapperFamily = 0; /* * Wrapper forwards this call directly to the wrapped object for efficiency @@ -833,7 +833,7 @@ DeadObjectProxy::getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandle } DeadObjectProxy DeadObjectProxy::singleton; -int DeadObjectProxy::sDeadObjectFamily; +const char DeadObjectProxy::sDeadObjectFamily = 0; JSObject * js::NewDeadProxyObject(JSContext *cx, JSObject *parent) diff --git a/js/src/jswrapper.h b/js/src/jswrapper.h index 84df39582ec..de4994d8e01 100644 --- a/js/src/jswrapper.h +++ b/js/src/jswrapper.h @@ -169,7 +169,8 @@ typedef SecurityWrapper CrossCompartmentSecurityWrapper class JS_FRIEND_API(DeadObjectProxy) : public BaseProxyHandler { public: - static int sDeadObjectFamily; + // This variable exists solely to provide a unique address for use as an identifier. + static const char sDeadObjectFamily; explicit DeadObjectProxy(); @@ -219,7 +220,8 @@ TransparentObjectWrapper(JSContext *cx, HandleObject existing, HandleObject obj, // Proxy family for wrappers. Public so that IsWrapper() can be fully inlined by // jsfriendapi users. -extern JS_FRIEND_DATA(int) sWrapperFamily; +// This variable exists solely to provide a unique address for use as an identifier. +extern JS_FRIEND_DATA(const char) sWrapperFamily; inline bool IsWrapper(JSObject *obj) diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index b9a9c3bce2a..d2530c6e63d 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -80,23 +80,23 @@ using namespace js::cli; using mozilla::ArrayLength; using mozilla::Maybe; -typedef enum JSShellExitCode { +enum JSShellExitCode { EXITCODE_RUNTIME_ERROR = 3, EXITCODE_FILE_NOT_FOUND = 4, EXITCODE_OUT_OF_MEMORY = 5, EXITCODE_TIMEOUT = 6 -} JSShellExitCode; +}; -size_t gStackChunkSize = 8192; +static size_t gStackChunkSize = 8192; /* * Note: This limit should match the stack limit set by the browser in * js/xpconnect/src/XPCJSRuntime.cpp */ #if defined(MOZ_ASAN) || (defined(DEBUG) && !defined(XP_WIN)) -size_t gMaxStackSize = 2 * 128 * sizeof(size_t) * 1024; +static size_t gMaxStackSize = 2 * 128 * sizeof(size_t) * 1024; #else -size_t gMaxStackSize = 128 * sizeof(size_t) * 1024; +static size_t gMaxStackSize = 128 * sizeof(size_t) * 1024; #endif #ifdef JS_THREADSAFE @@ -156,11 +156,11 @@ static JSRuntime *gRuntime = NULL; #endif -int gExitCode = 0; -bool gQuitting = false; -bool gGotError = false; -FILE *gErrFile = NULL; -FILE *gOutFile = NULL; +static int gExitCode = 0; +static bool gQuitting = false; +static bool gGotError = false; +static FILE *gErrFile = NULL; +static FILE *gOutFile = NULL; static bool reportWarnings = true; static bool compileOnly = false; @@ -171,13 +171,13 @@ static bool dumpEntrainedVariables = false; static bool OOM_printAllocationCount = false; #endif -typedef enum JSShellErrNum { +enum JSShellErrNum { #define MSG_DEF(name, number, count, exception, format) \ name = number, #include "jsshell.msg" #undef MSG_DEF JSShellErr_Limit -} JSShellErrNum; +}; static JSContext * NewContext(JSRuntime *rt); @@ -612,8 +612,6 @@ MapContextOptionNameToFlag(JSContext* cx, const char* name) return 0; } -extern const JSClass global_class; - static bool Version(JSContext *cx, unsigned argc, jsval *vp) { @@ -4254,7 +4252,7 @@ Help(JSContext *cx, unsigned argc, jsval *vp) return true; } -JSErrorFormatString jsShell_ErrorFormatString[JSShellErr_Limit] = { +static const JSErrorFormatString jsShell_ErrorFormatString[JSShellErr_Limit] = { #define MSG_DEF(name, number, count, exception, format) \ { format, count, JSEXN_ERR } , #include "jsshell.msg" @@ -4426,7 +4424,7 @@ global_resolve(JSContext *cx, HandleObject obj, HandleId id, unsigned flags, #endif } -const JSClass global_class = { +static const JSClass global_class = { "global", JSCLASS_NEW_RESOLVE | JSCLASS_GLOBAL_FLAGS, JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, @@ -4588,7 +4586,7 @@ dom_doFoo(JSContext* cx, HandleObject obj, void *self, const JSJitMethodCallArgs return true; } -const JSJitInfo dom_x_getterinfo = { +static const JSJitInfo dom_x_getterinfo = { { (JSJitGetterOp)dom_get_x }, 0, /* protoID */ 0, /* depth */ @@ -4597,7 +4595,7 @@ const JSJitInfo dom_x_getterinfo = { true /* isConstant. Only relevant for getters. */ }; -const JSJitInfo dom_x_setterinfo = { +static const JSJitInfo dom_x_setterinfo = { { (JSJitGetterOp)dom_set_x }, 0, /* protoID */ 0, /* depth */ @@ -4606,7 +4604,7 @@ const JSJitInfo dom_x_setterinfo = { false /* isConstant. Only relevant for getters. */ }; -const JSJitInfo doFoo_methodinfo = { +static const JSJitInfo doFoo_methodinfo = { { (JSJitGetterOp)dom_doFoo }, 0, /* protoID */ 0, /* depth */ @@ -5128,7 +5126,7 @@ ProcessArgs(JSContext *cx, JSObject *obj_, OptionParser *op) return gExitCode ? gExitCode : EXIT_SUCCESS; } -int +static int Shell(JSContext *cx, OptionParser *op, char **envp) { JSAutoRequest ar(cx); @@ -5180,16 +5178,16 @@ MaybeOverrideOutFileFromEnv(const char* const envVar, } /* Set the initial counter to 1 so the principal will never be destroyed. */ -JSPrincipals shellTrustedPrincipals = { 1 }; +static const JSPrincipals shellTrustedPrincipals = { 1 }; -bool +static bool CheckObjectAccess(JSContext *cx, HandleObject obj, HandleId id, JSAccessMode mode, MutableHandleValue vp) { return true; } -const JSSecurityCallbacks securityCallbacks = { +static const JSSecurityCallbacks securityCallbacks = { CheckObjectAccess, NULL }; diff --git a/js/src/vm/Runtime.h b/js/src/vm/Runtime.h index db6ff9ca578..0b3f6629396 100644 --- a/js/src/vm/Runtime.h +++ b/js/src/vm/Runtime.h @@ -1393,10 +1393,10 @@ struct JSRuntime : public JS::shadow::Runtime, } private: - JSPrincipals *trustedPrincipals_; + const JSPrincipals *trustedPrincipals_; public: - void setTrustedPrincipals(JSPrincipals *p) { trustedPrincipals_ = p; } - JSPrincipals *trustedPrincipals() const { return trustedPrincipals_; } + void setTrustedPrincipals(const JSPrincipals *p) { trustedPrincipals_ = p; } + const JSPrincipals *trustedPrincipals() const { return trustedPrincipals_; } // Set of all currently-living atoms, and the compartment in which they // reside. The atoms compartment is additionally used to hold runtime diff --git a/js/src/vm/WrapperObject.h b/js/src/vm/WrapperObject.h index 85e921318f2..dfb77a45616 100644 --- a/js/src/vm/WrapperObject.h +++ b/js/src/vm/WrapperObject.h @@ -15,7 +15,8 @@ namespace js { // Proxy family for wrappers. -extern int sWrapperFamily; +// This variable exists solely to provide a unique address for use as an identifier. +extern const char sWrapperFamily; class WrapperObject : public ProxyObject { diff --git a/js/xpconnect/shell/xpcshell.cpp b/js/xpconnect/shell/xpcshell.cpp index 0acd2e7b5d8..5fd150b286e 100644 --- a/js/xpconnect/shell/xpcshell.cpp +++ b/js/xpconnect/shell/xpcshell.cpp @@ -1026,7 +1026,7 @@ typedef enum JSShellErrNum { JSShellErr_Limit } JSShellErrNum; -JSErrorFormatString jsShell_ErrorFormatString[JSShellErr_Limit] = { +const JSErrorFormatString jsShell_ErrorFormatString[JSShellErr_Limit] = { #define MSG_DEF(name, number, count, exception, format) \ { format, count } , #include "jsshell.msg" diff --git a/js/xpconnect/src/Sandbox.cpp b/js/xpconnect/src/Sandbox.cpp index c434a18b0f0..718ae51d20a 100644 --- a/js/xpconnect/src/Sandbox.cpp +++ b/js/xpconnect/src/Sandbox.cpp @@ -381,7 +381,7 @@ CloneNonReflectorsWrite(JSContext *cx, JSStructuredCloneWriter *writer, return false; } -JSStructuredCloneCallbacks gForwarderStructuredCloneCallbacks = { +const JSStructuredCloneCallbacks gForwarderStructuredCloneCallbacks = { CloneNonReflectorsRead, CloneNonReflectorsWrite, nullptr diff --git a/js/xpconnect/src/XPCJSID.cpp b/js/xpconnect/src/XPCJSID.cpp index 2a66d8b79be..d0a5cb03b51 100644 --- a/js/xpconnect/src/XPCJSID.cpp +++ b/js/xpconnect/src/XPCJSID.cpp @@ -158,8 +158,8 @@ const nsID& nsJSID::GetInvalidIID() const { // {BB1F47B0-D137-11d2-9841-006008962422} - static nsID invalid = {0xbb1f47b0, 0xd137, 0x11d2, - {0x98, 0x41, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22}}; + static const nsID invalid = {0xbb1f47b0, 0xd137, 0x11d2, + {0x98, 0x41, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22}}; return invalid; } diff --git a/js/xpconnect/src/XPCJSRuntime.cpp b/js/xpconnect/src/XPCJSRuntime.cpp index 6ffc83a145b..0e1d466bec2 100644 --- a/js/xpconnect/src/XPCJSRuntime.cpp +++ b/js/xpconnect/src/XPCJSRuntime.cpp @@ -54,7 +54,7 @@ using mozilla::dom::PerThreadAtomCache; /***************************************************************************/ -const char* XPCJSRuntime::mStrings[] = { +const char* const XPCJSRuntime::mStrings[] = { "constructor", // IDX_CONSTRUCTOR "toString", // IDX_TO_STRING "toSource", // IDX_TO_SOURCE diff --git a/js/xpconnect/src/XPCMaps.cpp b/js/xpconnect/src/XPCMaps.cpp index 74d2fe46e64..2d55a7308e7 100644 --- a/js/xpconnect/src/XPCMaps.cpp +++ b/js/xpconnect/src/XPCMaps.cpp @@ -157,7 +157,7 @@ Native2WrappedNativeMap::SizeOfEntryExcludingThis(PLDHashEntryHdr *hdr, /***************************************************************************/ // implement IID2WrappedJSClassMap... -struct PLDHashTableOps IID2WrappedJSClassMap::Entry::sOps = +const struct PLDHashTableOps IID2WrappedJSClassMap::Entry::sOps = { PL_DHashAllocTable, PL_DHashFreeTable, @@ -194,7 +194,7 @@ IID2WrappedJSClassMap::~IID2WrappedJSClassMap() /***************************************************************************/ // implement IID2NativeInterfaceMap... -struct PLDHashTableOps IID2NativeInterfaceMap::Entry::sOps = +const struct PLDHashTableOps IID2NativeInterfaceMap::Entry::sOps = { PL_DHashAllocTable, PL_DHashFreeTable, @@ -401,7 +401,7 @@ NativeSetMap::Entry::Match(PLDHashTable *table, return true; } -struct PLDHashTableOps NativeSetMap::Entry::sOps = +const struct PLDHashTableOps NativeSetMap::Entry::sOps = { PL_DHashAllocTable, PL_DHashFreeTable, @@ -468,7 +468,7 @@ IID2ThisTranslatorMap::Entry::Clear(PLDHashTable *table, PLDHashEntryHdr *entry) memset(entry, 0, table->entrySize); } -struct PLDHashTableOps IID2ThisTranslatorMap::Entry::sOps = +const struct PLDHashTableOps IID2ThisTranslatorMap::Entry::sOps = { PL_DHashAllocTable, PL_DHashFreeTable, @@ -548,7 +548,7 @@ XPCNativeScriptableSharedMap::Entry::Match(PLDHashTable *table, return 0 == strcmp(name1, name2); } -struct PLDHashTableOps XPCNativeScriptableSharedMap::Entry::sOps = +const struct PLDHashTableOps XPCNativeScriptableSharedMap::Entry::sOps = { PL_DHashAllocTable, PL_DHashFreeTable, diff --git a/js/xpconnect/src/XPCMaps.h b/js/xpconnect/src/XPCMaps.h index 244dce7fb66..77bb18f3f94 100644 --- a/js/xpconnect/src/XPCMaps.h +++ b/js/xpconnect/src/XPCMaps.h @@ -175,7 +175,7 @@ public: const nsIID* key; nsXPCWrappedJSClass* value; - static struct PLDHashTableOps sOps; + static const struct PLDHashTableOps sOps; }; static IID2WrappedJSClassMap* newMap(int size); @@ -232,7 +232,7 @@ public: const nsIID* key; XPCNativeInterface* value; - static struct PLDHashTableOps sOps; + static const struct PLDHashTableOps sOps; }; static IID2NativeInterfaceMap* newMap(int size); @@ -417,7 +417,7 @@ public: const PLDHashEntryHdr *entry, const void *key); - static struct PLDHashTableOps sOps; + static const struct PLDHashTableOps sOps; }; static NativeSetMap* newMap(int size); @@ -494,7 +494,7 @@ public: static void Clear(PLDHashTable *table, PLDHashEntryHdr *entry); - static struct PLDHashTableOps sOps; + static const struct PLDHashTableOps sOps; }; static IID2ThisTranslatorMap* newMap(int size); @@ -557,7 +557,7 @@ public: const PLDHashEntryHdr *entry, const void *key); - static struct PLDHashTableOps sOps; + static const struct PLDHashTableOps sOps; }; static XPCNativeScriptableSharedMap* newMap(int size); diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index 7523b931ffb..dd165be1901 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -786,7 +786,7 @@ private: void ReleaseIncrementally(nsTArray &array); - static const char* mStrings[IDX_TOTAL_COUNT]; + static const char* const mStrings[IDX_TOTAL_COUNT]; jsid mStrIDs[IDX_TOTAL_COUNT]; jsval mStrJSVals[IDX_TOTAL_COUNT];