Bug 910829 - SpiderMonkey: Put cpp-private classes in anonymous namespaces. r=waldo

This commit is contained in:
Dan Gohman 2013-08-31 06:19:15 -07:00
parent 4621665b7f
commit f5f6317d04
19 changed files with 159 additions and 5 deletions

View File

@ -3621,6 +3621,8 @@ EmitSingletonInitialiser(ExclusiveContext *cx, BytecodeEmitter *bce, ParseNode *
JS_STATIC_ASSERT(JSOP_NOP_LENGTH == 1);
JS_STATIC_ASSERT(JSOP_POP_LENGTH == 1);
namespace {
class EmitLevelManager
{
BytecodeEmitter *bce;
@ -3629,6 +3631,8 @@ class EmitLevelManager
~EmitLevelManager() { bce->emitLevel--; }
};
} /* anonymous namespace */
static bool
EmitCatch(ExclusiveContext *cx, BytecodeEmitter *bce, ParseNode *pn)
{

View File

@ -20,6 +20,8 @@
using namespace js;
using namespace js::frontend;
namespace {
class NameResolver
{
static const size_t MaxParents = 100;
@ -325,6 +327,8 @@ class NameResolver
}
};
} /* anonymous namespace */
bool
frontend::NameFunctions(JSContext *cx, ParseNode *pn)
{

View File

@ -70,6 +70,8 @@ ParseNodeAllocator::freeNode(ParseNode *pn)
freelist = pn;
}
namespace {
/*
* A work pool of ParseNodes. The work pool is a stack, chained together
* by nodes' pn_next fields. We use this to avoid creating deep C++ stacks
@ -104,6 +106,8 @@ class NodeStack {
ParseNode *top;
};
} /* anonymous namespace */
/*
* Push the children of |pn| on |stack|. Return true if |pn| itself could be
* safely recycled, or false if it must be cleaned later (pn_used and pn_defn

View File

@ -623,6 +623,8 @@ operator<=(Type lhs, VarType rhs)
static inline MIRType ToMIRType(MIRType t) { return t; }
static inline MIRType ToMIRType(VarType t) { return t.toMIRType(); }
namespace {
template <class VecT>
class ABIArgIter
{
@ -683,6 +685,8 @@ class Signature
RetType retType() const { return retType_; }
};
} /* namespace anonymous */
static
bool operator==(const Signature &lhs, const Signature &rhs)
{
@ -907,11 +911,11 @@ TypedArrayStoreType(ArrayBufferView::ViewType viewType)
/*****************************************************************************/
namespace {
typedef Vector<PropertyName*,1> LabelVector;
typedef Vector<MBasicBlock*,8> BlockVector;
namespace {
// ModuleCompiler encapsulates the compilation of an entire asm.js module. Over
// the course of an ModuleCompiler object's lifetime, many FunctionCompiler
// objects will be created and destroyed in sequence, one for each function in

View File

@ -2875,6 +2875,8 @@ JS_GetObjectId(JSContext *cx, JSObject *obj, jsid *idp)
return true;
}
namespace {
class AutoHoldZone
{
public:
@ -2895,6 +2897,8 @@ class AutoHoldZone
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
};
} /* anonymous namespace */
JS_PUBLIC_API(JSObject *)
JS_NewGlobalObject(JSContext *cx, JSClass *clasp, JSPrincipals *principals,
JS::OnNewGlobalHookOption hookOption,
@ -4713,6 +4717,8 @@ ReadCompleteFile(JSContext *cx, FILE *fp, FileContents &buffer)
return true;
}
namespace {
class AutoFile
{
FILE *fp_;
@ -4734,6 +4740,8 @@ class AutoFile
}
};
} /* anonymous namespace */
/*
* Open a source file for reading. Supports "-" and NULL to mean stdin. The
* return value must be fclosed unless it is stdin.

View File

@ -4023,6 +4023,8 @@ EndSweepPhase(JSRuntime *rt, JSGCInvocationKind gckind, bool lastGC)
rt->gcLastGCTime = PRMJ_Now();
}
namespace {
/* ...while this class is to be used only for garbage collection. */
class AutoGCSession : AutoTraceSession {
public:
@ -4030,6 +4032,8 @@ class AutoGCSession : AutoTraceSession {
~AutoGCSession();
};
} /* anonymous namespace */
/* Start a new heap session. */
AutoTraceSession::AutoTraceSession(JSRuntime *rt, js::HeapState heapState)
: runtime(rt),
@ -4173,6 +4177,8 @@ ResetIncrementalGC(JSRuntime *rt, const char *reason)
#endif
}
namespace {
class AutoGCSlice {
public:
AutoGCSlice(JSRuntime *rt);
@ -4182,6 +4188,8 @@ class AutoGCSlice {
JSRuntime *runtime;
};
} /* anonymous namespace */
AutoGCSlice::AutoGCSlice(JSRuntime *rt)
: runtime(rt)
{
@ -4505,6 +4513,8 @@ ShouldCleanUpEverything(JSRuntime *rt, JS::gcreason::Reason reason, JSGCInvocati
gckind == GC_SHRINK;
}
namespace {
#ifdef JSGC_GENERATIONAL
class AutoDisableStoreBuffer
{
@ -4528,6 +4538,8 @@ struct AutoDisableStoreBuffer
};
#endif
} /* anonymous namespace */
static void
Collect(JSRuntime *rt, bool incremental, int64_t budget,
JSGCInvocationKind gckind, JS::gcreason::Reason reason)

View File

@ -568,6 +568,8 @@ TypeSet::unionSets(TypeSet *a, TypeSet *b, LifoAlloc *alloc)
// TypeSet constraints
/////////////////////////////////////////////////////////////////////
namespace {
/* Standard subset constraint, propagate all types from one set to another. */
class TypeConstraintSubset : public TypeConstraint
{
@ -589,6 +591,8 @@ class TypeConstraintSubset : public TypeConstraint
}
};
} /* anonymous namespace */
void
StackTypeSet::addSubset(JSContext *cx, TypeSet *target)
{
@ -602,6 +606,8 @@ HeapTypeSet::addSubset(JSContext *cx, TypeSet *target)
add(cx, cx->typeLifoAlloc().new_<TypeConstraintSubset>(target));
}
namespace {
enum PropertyAccessKind {
PROPERTY_WRITE,
PROPERTY_READ,
@ -641,6 +647,8 @@ typedef TypeConstraintProp<PROPERTY_WRITE> TypeConstraintSetProperty;
typedef TypeConstraintProp<PROPERTY_READ> TypeConstraintGetProperty;
typedef TypeConstraintProp<PROPERTY_READ_EXISTING> TypeConstraintGetPropertyExisting;
} /* anonymous namespace */
void
StackTypeSet::addGetProperty(JSContext *cx, JSScript *script, jsbytecode *pc,
StackTypeSet *target, jsid id)
@ -669,6 +677,8 @@ HeapTypeSet::addGetProperty(JSContext *cx, JSScript *script, jsbytecode *pc,
add(cx, cx->typeLifoAlloc().new_<TypeConstraintGetProperty>(script, pc, target, id));
}
namespace {
/*
* Constraints for updating the 'this' types of callees on CALLPROP/CALLELEM.
* These are derived from the types on the properties themselves, rather than
@ -701,6 +711,8 @@ class TypeConstraintCallProp : public TypeConstraint
typedef TypeConstraintCallProp<PROPERTY_READ> TypeConstraintCallProperty;
typedef TypeConstraintCallProp<PROPERTY_READ_EXISTING> TypeConstraintCallPropertyExisting;
} /* anonymous namespace */
void
HeapTypeSet::addCallProperty(JSContext *cx, JSScript *script, jsbytecode *pc, jsid id)
{
@ -716,6 +728,8 @@ HeapTypeSet::addCallProperty(JSContext *cx, JSScript *script, jsbytecode *pc, js
add(cx, cx->typeLifoAlloc().new_<TypeConstraintCallProperty>(script, callpc, id));
}
namespace {
/*
* Constraints for generating 'set' property constraints on a SETELEM only if
* the element type may be a number. For SETELEM we only account for integer
@ -745,6 +759,8 @@ class TypeConstraintSetElement : public TypeConstraint
void newType(JSContext *cx, TypeSet *source, Type type);
};
} /* anonymous namespace */
void
StackTypeSet::addSetElement(JSContext *cx, JSScript *script, jsbytecode *pc,
StackTypeSet *objectTypes, StackTypeSet *valueTypes)
@ -753,6 +769,8 @@ StackTypeSet::addSetElement(JSContext *cx, JSScript *script, jsbytecode *pc,
valueTypes));
}
namespace {
/*
* Constraints for watching call edges as they are discovered and invoking native
* function handlers, adding constraints for arguments, receiver objects and the
@ -773,12 +791,16 @@ class TypeConstraintCall : public TypeConstraint
void newType(JSContext *cx, TypeSet *source, Type type);
};
} /* anonymous namespace */
void
StackTypeSet::addCall(JSContext *cx, TypeCallsite *site)
{
add(cx, cx->analysisLifoAlloc().new_<TypeConstraintCall>(site));
}
namespace {
/* Constraints for arithmetic operations. */
class TypeConstraintArith : public TypeConstraint
{
@ -804,6 +826,8 @@ class TypeConstraintArith : public TypeConstraint
void newType(JSContext *cx, TypeSet *source, Type type);
};
} /* anonymous namespace */
void
StackTypeSet::addArith(JSContext *cx, JSScript *script, jsbytecode *pc, TypeSet *target,
TypeSet *other)
@ -811,6 +835,8 @@ StackTypeSet::addArith(JSContext *cx, JSScript *script, jsbytecode *pc, TypeSet
add(cx, cx->analysisLifoAlloc().new_<TypeConstraintArith>(script, pc, target, other));
}
namespace {
/* Subset constraint which transforms primitive values into appropriate objects. */
class TypeConstraintTransformThis : public TypeConstraint
{
@ -828,12 +854,16 @@ class TypeConstraintTransformThis : public TypeConstraint
void newType(JSContext *cx, TypeSet *source, Type type);
};
} /* anonymous namespace */
void
StackTypeSet::addTransformThis(JSContext *cx, JSScript *script, TypeSet *target)
{
add(cx, cx->analysisLifoAlloc().new_<TypeConstraintTransformThis>(script, target));
}
namespace {
/*
* Constraint which adds a particular type to the 'this' types of all
* discovered scripted functions.
@ -856,6 +886,8 @@ class TypeConstraintPropagateThis : public TypeConstraint
void newType(JSContext *cx, TypeSet *source, Type type);
};
} /* anonymous namespace */
void
StackTypeSet::addPropagateThis(JSContext *cx, JSScript *script, jsbytecode *pc,
Type type, StackTypeSet *types)
@ -863,6 +895,8 @@ StackTypeSet::addPropagateThis(JSContext *cx, JSScript *script, jsbytecode *pc,
add(cx, cx->analysisLifoAlloc().new_<TypeConstraintPropagateThis>(script, pc, type, types));
}
namespace {
/* Subset constraint which filters out primitive types. */
class TypeConstraintFilterPrimitive : public TypeConstraint
{
@ -884,6 +918,8 @@ class TypeConstraintFilterPrimitive : public TypeConstraint
}
};
} /* anonymous namespace */
void
HeapTypeSet::addFilterPrimitives(JSContext *cx, TypeSet *target)
{
@ -994,6 +1030,8 @@ void ScriptAnalysis::breakTypeBarriersSSA(JSContext *cx, const SSAValue &v)
breakTypeBarriers(cx, offset, true);
}
namespace {
/*
* Subset constraint for property reads and argument passing which can add type
* barriers on the read instead of passing types along.
@ -1021,6 +1059,8 @@ class TypeConstraintSubsetBarrier : public TypeConstraint
}
};
} /* anonymous namespace */
void
StackTypeSet::addSubsetBarrier(JSContext *cx, JSScript *script, jsbytecode *pc, TypeSet *target)
{
@ -1634,6 +1674,8 @@ TypeConstraintTransformThis::newType(JSContext *cx, TypeSet *source, Type type)
// Freeze constraints
/////////////////////////////////////////////////////////////////////
namespace {
/* Constraint which triggers recompilation of a script if any type is added to a type set. */
class TypeConstraintFreeze : public TypeConstraint
{
@ -1659,6 +1701,8 @@ class TypeConstraintFreeze : public TypeConstraint
}
};
} /* anonymous namespace */
void
HeapTypeSet::addFreeze(JSContext *cx)
{
@ -1754,6 +1798,8 @@ StackTypeSet::mightBeType(JSValueType type)
return baseFlags() & PrimitiveTypeFlag(type);
}
namespace {
/* Constraint which triggers recompilation if an object acquires particular flags. */
class TypeConstraintFreezeObjectFlags : public TypeConstraint
{
@ -1784,6 +1830,8 @@ class TypeConstraintFreezeObjectFlags : public TypeConstraint
}
};
} /* anonymous namespace */
bool
StackTypeSet::hasObjectFlags(JSContext *cx, TypeObjectFlags flags)
{
@ -1881,6 +1929,8 @@ HeapTypeSet::WatchObjectStateChange(JSContext *cx, TypeObject *obj)
0));
}
namespace {
class TypeConstraintFreezeOwnProperty : public TypeConstraint
{
public:
@ -1908,6 +1958,8 @@ class TypeConstraintFreezeOwnProperty : public TypeConstraint
}
};
} /* anonymous namespace */
static void
CheckNewScriptProperties(JSContext *cx, HandleTypeObject type, HandleFunction fun);
@ -2217,6 +2269,8 @@ AddPendingRecompile(JSContext *cx, JSScript *script)
cx->compartment()->types.addPendingRecompile(cx, script);
}
namespace {
/*
* As for TypeConstraintFreeze, but describes an implicit freeze constraint
* added for stack types within a script. Applies to all compilations of the
@ -2243,6 +2297,8 @@ class TypeConstraintFreezeStack : public TypeConstraint
}
};
} /* anonymous namespace */
/////////////////////////////////////////////////////////////////////
// TypeCompartment
/////////////////////////////////////////////////////////////////////
@ -4745,6 +4801,8 @@ ScriptAnalysis::analyzeTypes(JSContext *cx)
TypeScript::AddFreezeConstraints(cx, script_);
}
namespace {
/*
* Persistent constraint clearing out newScript and definite properties from
* an object should a property on another object get a getter or setter.
@ -4777,6 +4835,8 @@ class TypeConstraintClearDefiniteGetterSetter : public TypeConstraint
void newType(JSContext *cx, TypeSet *source, Type type) {}
};
} /* anonymous namespace */
static bool
AddClearDefiniteGetterSetterForPrototypeChain(JSContext *cx, TypeObject *type, jsid id)
{
@ -4799,6 +4859,8 @@ AddClearDefiniteGetterSetterForPrototypeChain(JSContext *cx, TypeObject *type, j
return true;
}
namespace {
/*
* Constraint which clears definite properties on an object should a type set
* contain any types other than a single object.
@ -4835,6 +4897,8 @@ struct NewScriptPropertiesState
{}
};
} /* anonymous namespace */
static bool
AnalyzePoppedThis(JSContext *cx, SSAUseChain *use,
TypeObject *type, JSFunction *fun, NewScriptPropertiesState &state);

View File

@ -1166,6 +1166,8 @@ SuppressDeletedPropertyHelper(JSContext *cx, HandleObject obj, StringPredicate p
return true;
}
namespace {
class SingleStringPredicate {
Handle<JSFlatString*> str;
public:
@ -1175,6 +1177,8 @@ public:
bool matchesAtMostOne() { return true; }
};
} /* anonymous namespace */
bool
js_SuppressDeletedProperty(JSContext *cx, HandleObject obj, jsid id)
{
@ -1193,6 +1197,8 @@ js_SuppressDeletedElement(JSContext *cx, HandleObject obj, uint32_t index)
return js_SuppressDeletedProperty(cx, obj, id);
}
namespace {
class IndexRangePredicate {
uint32_t begin, end;
@ -1207,6 +1213,8 @@ class IndexRangePredicate {
bool matchesAtMostOne() { return false; }
};
} /* anonymous namespace */
bool
js_SuppressDeletedElements(JSContext *cx, HandleObject obj, uint32_t begin, uint32_t end)
{

View File

@ -85,6 +85,8 @@ ComputeAccurateDecimalInteger(ThreadSafeContext *cx,
return true;
}
namespace {
class BinaryDigitReader
{
const int base; /* Base of number; must be a power of 2 */
@ -122,6 +124,8 @@ class BinaryDigitReader
}
};
} /* anonymous namespace */
/*
* The fast result might also have been inaccurate for power-of-two bases. This
* happens if the addition in value * 2 + digit causes a round-down to an even

View File

@ -115,6 +115,8 @@ Quote(JSContext *cx, StringBuffer &sb, JSString *str)
return sb.append('"');
}
namespace {
class StringifyContext
{
public:
@ -134,6 +136,8 @@ class StringifyContext
uint32_t depth;
};
} /* anonymous namespace */
static bool Str(JSContext *cx, const Value &v, StringifyContext *scx);
static bool
@ -151,6 +155,8 @@ WriteIndent(JSContext *cx, StringifyContext *scx, uint32_t limit)
return true;
}
namespace {
template<typename KeyType>
class KeyStringifier {
};
@ -171,6 +177,8 @@ class KeyStringifier<HandleId> {
}
};
} /* anonymous namespace */
/*
* ES5 15.12.3 Str, steps 2-4, extracted to enable preprocessing of property
* values when stringifying objects in JO.

View File

@ -1087,6 +1087,8 @@ GetBlockChainAtPC(JSContext *cx, JSScript *script, jsbytecode *pc)
return blockChain;
}
namespace {
class PCStack
{
jsbytecode **stack;
@ -1100,6 +1102,8 @@ class PCStack
jsbytecode *operator[](int i) const;
};
} /* anonymous namespace */
PCStack::~PCStack()
{
js_free(stack);

View File

@ -746,6 +746,8 @@ FunctionProxyObject::constructOrUndefined() const
return getSlot(CONSTRUCT_SLOT);
}
namespace {
/* Derived class for all scripted indirect proxy handlers. */
class ScriptedIndirectProxyHandler : public BaseProxyHandler
{
@ -791,6 +793,8 @@ class ScriptedIndirectProxyHandler : public BaseProxyHandler
static ScriptedIndirectProxyHandler singleton;
};
} /* anonymous namespace */
static int sScriptedIndirectProxyHandlerFamily = 0;
ScriptedIndirectProxyHandler::ScriptedIndirectProxyHandler()

View File

@ -120,6 +120,8 @@ typedef AutoValueVector NodeVector;
return false; \
JS_END_MACRO
namespace {
/*
* Builder class that constructs JavaScript AST node objects. See:
*
@ -615,6 +617,8 @@ class NodeBuilder
bool propertyPattern(HandleValue key, HandleValue patt, TokenPos *pos, MutableHandleValue dst);
};
} /* anonymous namespace */
bool
NodeBuilder::newNode(ASTType type, TokenPos *pos, MutableHandleObject dst)
{

View File

@ -2979,6 +2979,8 @@ DebuggerScript_getOffsetLine(JSContext *cx, unsigned argc, Value *vp)
return true;
}
namespace {
class BytecodeRangeWithPosition : private BytecodeRange
{
public:
@ -3207,6 +3209,8 @@ class FlowGraphSummary {
Vector<Entry> entries_;
};
} /* anonymous namespace */
static bool
DebuggerScript_getAllOffsets(JSContext *cx, unsigned argc, Value *vp)
{

View File

@ -1004,6 +1004,8 @@ JS::FreeStackDescription(JSContext *cx, JS::StackDescription *desc)
js_delete(desc);
}
namespace {
class AutoPropertyDescArray
{
JSContext *cx_;
@ -1032,6 +1034,8 @@ class AutoPropertyDescArray
}
};
} /* anonymous namespace */
static const char *
FormatValue(JSContext *cx, const Value &vArg, JSAutoByteString &bytes)
{

View File

@ -1138,6 +1138,8 @@ ScopeIterKey::match(ScopeIterKey si1, ScopeIterKey si2)
/*****************************************************************************/
namespace {
/*
* DebugScopeProxy is the handler for DebugScopeObject proxy objects. Having a
* custom handler (rather than trying to reuse js::Wrapper) gives us several
@ -1532,6 +1534,8 @@ class DebugScopeProxy : public BaseProxyHandler
}
};
} /* anonymous namespace */
int DebugScopeProxy::family = 0;
DebugScopeProxy DebugScopeProxy::singleton;

View File

@ -966,6 +966,8 @@ JSStructuredCloneReader::checkDouble(double d)
return true;
}
namespace {
class Chars {
JSContext *cx;
jschar *p;
@ -987,6 +989,8 @@ class Chars {
void forget() { p = NULL; }
};
} /* anonymous namespace */
JSString *
JSStructuredCloneReader::readString(uint32_t nchars)
{

View File

@ -24,7 +24,7 @@ using namespace js;
// Once the worker's state is set to |TERMINATING|, the worker will
// exit as soon as its queue is empty.
const size_t WORKER_THREAD_STACK_SIZE = 1*1024*1024;
static const size_t WORKER_THREAD_STACK_SIZE = 1*1024*1024;
class js::ThreadPoolWorker : public Monitor
{

View File

@ -1407,8 +1407,6 @@ template<> inline const bool ElementTypeMayBeDouble<uint32_t>() { return true; }
template<> inline const bool ElementTypeMayBeDouble<float>() { return true; }
template<> inline const bool ElementTypeMayBeDouble<double>() { return true; }
template<typename NativeType> class TypedArrayObjectTemplate;
template<typename ElementType>
static inline JSObject *
NewArray(JSContext *cx, uint32_t nelements);
@ -1425,6 +1423,8 @@ InitArrayBufferViewDataPointer(JSObject *obj, ArrayBufferObject *buffer, size_t
PostBarrierTypedArrayObject(obj);
}
namespace {
template<typename NativeType>
class TypedArrayObjectTemplate : public TypedArrayObject
{
@ -2619,6 +2619,8 @@ class Uint8ClampedArrayObject : public TypedArrayObjectTemplate<uint8_clamped> {
static const JSFunctionSpec jsfuncs[];
};
} /* anonymous namespace */
template<typename T>
bool
ArrayBufferObject::createTypedArrayFromBufferImpl(JSContext *cx, CallArgs args)
@ -2682,6 +2684,8 @@ TypedArrayObjectTemplate<NativeType>::copyIndexToValue(JSObject *tarray, uint32_
vp.setInt32(getIndex(tarray, index));
}
namespace {
// and we need to specialize for 32-bit integers and floats
template<>
void
@ -2739,6 +2743,8 @@ TypedArrayObjectTemplate<double>::copyIndexToValue(JSObject *tarray, uint32_t in
vp.setDouble(JS_CANONICALIZE_NAN(val));
}
} /* anonymous namespace */
static NewObjectKind
DataViewNewObjectKind(JSContext *cx, uint32_t byteLength, JSObject *proto)
{