Bug 639469 - Use mozilla::ArrayLength and mozilla::ArrayEnd in preference to JS_ARRAY_LENGTH whenever possible. r=cjones

This commit is contained in:
Jeff Walden 2011-10-10 23:00:28 -07:00
Родитель 0f30b277bf
Коммит 52fd4e450f
30 изменённых файлов: 177 добавлений и 92 удалений

Просмотреть файл

@ -11,6 +11,8 @@
#include "vm/String-inl.h"
using namespace mozilla;
template<size_t N> JSFlatString *
NewString(JSContext *cx, const jschar (&chars)[N])
{
@ -51,7 +53,7 @@ static const struct TestPair {
BEGIN_TEST(testIndexToString)
{
for (size_t i = 0, sz = JS_ARRAY_LENGTH(tests); i < sz; i++) {
for (size_t i = 0, sz = ArrayLength(tests); i < sz; i++) {
uint32 u = tests[i].num;
JSString *str = js::IndexToString(cx, u);
CHECK(str);
@ -70,7 +72,7 @@ END_TEST(testIndexToString)
BEGIN_TEST(testStringIsIndex)
{
for (size_t i = 0, sz = JS_ARRAY_LENGTH(tests); i < sz; i++) {
for (size_t i = 0, sz = ArrayLength(tests); i < sz; i++) {
uint32 u = tests[i].num;
JSFlatString *str = js::IndexToString(cx, u);
CHECK(str);

Просмотреть файл

@ -1,11 +1,13 @@
#include "tests.h"
#include "jsatom.h"
using namespace mozilla;
BEGIN_TEST(testAtomizedIsNotInterned)
{
/* Try to pick a string that won't be interned by other tests in this runtime. */
static const char someChars[] = "blah blah blah? blah blah blah";
JSAtom *atom = js_Atomize(cx, someChars, JS_ARRAY_LENGTH(someChars));
JSAtom *atom = js_Atomize(cx, someChars, ArrayLength(someChars));
CHECK(!JS_StringHasBeenInterned(cx, atom));
CHECK(JS_InternJSString(cx, atom));
CHECK(JS_StringHasBeenInterned(cx, atom));

Просмотреть файл

@ -38,6 +38,8 @@
*
* ***** END LICENSE BLOCK ***** */
#include "mozilla/Util.h"
#include "jsapi.h"
#include "jsprvtd.h"
#include "jsalloc.h"

Просмотреть файл

@ -245,7 +245,7 @@ BigIndexToId(JSContext *cx, JSObject *obj, jsuint index, JSBool createAtom,
JS_ASSERT(index > JSID_INT_MAX);
jschar buf[10];
jschar *start = JS_ARRAY_END(buf);
jschar *start = ArrayEnd(buf);
do {
--start;
*start = (jschar)('0' + index % 10);
@ -261,13 +261,13 @@ BigIndexToId(JSContext *cx, JSObject *obj, jsuint index, JSBool createAtom,
*/
JSAtom *atom;
if (!createAtom && (obj->isSlowArray() || obj->isArguments() || obj->isObject())) {
atom = js_GetExistingStringAtom(cx, start, JS_ARRAY_END(buf) - start);
atom = js_GetExistingStringAtom(cx, start, ArrayEnd(buf) - start);
if (!atom) {
*idp = JSID_VOID;
return JS_TRUE;
}
} else {
atom = js_AtomizeChars(cx, start, JS_ARRAY_END(buf) - start);
atom = js_AtomizeChars(cx, start, ArrayEnd(buf) - start);
if (!atom)
return JS_FALSE;
}

Просмотреть файл

@ -44,6 +44,7 @@
#include <string.h>
#include "mozilla/RangedPtr.h"
#include "mozilla/Util.h"
#include "jstypes.h"
#include "jsstdint.h"
@ -68,6 +69,7 @@
#include "vm/String-inl.h"
using namespace mozilla;
using namespace js;
using namespace js::gc;
@ -363,7 +365,7 @@ js_InitCommonAtoms(JSContext *cx)
{
JSAtomState *state = &cx->runtime->atomState;
JSAtom **atoms = state->commonAtomsStart();
for (size_t i = 0; i < JS_ARRAY_LENGTH(js_common_atom_names); i++, atoms++) {
for (size_t i = 0; i < ArrayLength(js_common_atom_names); i++, atoms++) {
JSAtom *atom = js_Atomize(cx, js_common_atom_names[i], strlen(js_common_atom_names[i]),
InternAtom);
if (!atom)
@ -677,7 +679,7 @@ IndexToIdSlow(JSContext *cx, uint32 index, jsid *idp)
JS_ASSERT(index > JSID_INT_MAX);
jschar buf[UINT32_CHAR_BUFFER_LENGTH];
RangedPtr<jschar> end(buf + JS_ARRAY_LENGTH(buf), buf, buf + JS_ARRAY_LENGTH(buf));
RangedPtr<jschar> end(buf + ArrayLength(buf), buf, buf + ArrayLength(buf));
RangedPtr<jschar> start = BackfillIndexInCharBuffer(index, end);
JSAtom *atom = js_AtomizeChars(cx, start.get(), end - start);

Просмотреть файл

@ -64,6 +64,7 @@
#include "assembler/jit/ExecutableAllocator.h"
#endif
using namespace mozilla;
using namespace js;
using namespace js::gc;
@ -122,7 +123,7 @@ JSCompartment::~JSCompartment()
Foreground::delete_(watchpointMap);
#ifdef DEBUG
for (size_t i = 0; i != JS_ARRAY_LENGTH(evalCache); ++i)
for (size_t i = 0; i < ArrayLength(evalCache); ++i)
JS_ASSERT(!evalCache[i]);
#endif
}
@ -662,7 +663,7 @@ JSCompartment::purge(JSContext *cx)
* not null when we have script owned by an object and not from the eval
* cache.
*/
for (size_t i = 0; i != JS_ARRAY_LENGTH(evalCache); ++i) {
for (size_t i = 0; i < ArrayLength(evalCache); ++i) {
for (JSScript **listHeadp = &evalCache[i]; *listHeadp; ) {
JSScript *script = *listHeadp;
JS_ASSERT(GetGCThingTraceKind(script) == JSTRACE_SCRIPT);

Просмотреть файл

@ -56,6 +56,9 @@
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "mozilla/Util.h"
#include "jstypes.h"
#include "jsstdint.h"
#include "jsprf.h"
@ -79,6 +82,7 @@
#include "vm/Stack-inl.h"
using namespace mozilla;
using namespace js;
using namespace js::types;
@ -1038,7 +1042,7 @@ date_parseString(JSLinearString *str, jsdouble *result, JSContext *cx)
}
if (i <= st + 1)
goto syntax;
for (k = JS_ARRAY_LENGTH(wtb); --k >= 0;)
for (k = ArrayLength(wtb); --k >= 0;)
if (date_regionMatches(wtb[k], 0, s, st, i-st, 1)) {
int action = ttb[k];
if (action != 0) {

Просмотреть файл

@ -46,6 +46,7 @@
#endif
#include <new>
#include <string.h>
#include "jstypes.h"
#include "jsstdint.h"
#include "jsutil.h"

Просмотреть файл

@ -43,6 +43,9 @@
*/
#include <stdlib.h>
#include <string.h>
#include "mozilla/Util.h"
#include "jstypes.h"
#include "jsstdint.h"
#include "jsutil.h"
@ -70,6 +73,7 @@
#include "vm/Stack-inl.h"
using namespace mozilla;
using namespace js;
using namespace js::gc;
using namespace js::types;
@ -860,7 +864,7 @@ exn_toSource(JSContext *cx, uintN argc, Value *vp)
vp->setString(name);
{
AutoArrayRooter tvr(cx, JS_ARRAY_LENGTH(localroots), localroots);
AutoArrayRooter tvr(cx, ArrayLength(localroots), localroots);
#ifdef __GNUC__
message = filename = NULL;
@ -1155,7 +1159,7 @@ js_ErrorToException(JSContext *cx, const char *message, JSErrorReport *reportp,
/* Protect the newly-created strings below from nesting GCs. */
PodArrayZero(tv);
AutoArrayRooter tvr(cx, JS_ARRAY_LENGTH(tv), tv);
AutoArrayRooter tvr(cx, ArrayLength(tv), tv);
/*
* Try to get an appropriate prototype by looking up the corresponding
@ -1220,7 +1224,7 @@ js_ReportUncaughtException(JSContext *cx)
return false;
PodArrayZero(roots);
AutoArrayRooter tvr(cx, JS_ARRAY_LENGTH(roots), roots);
AutoArrayRooter tvr(cx, ArrayLength(roots), roots);
/*
* Because js_ValueToString below could error and an exception object

Просмотреть файл

@ -42,6 +42,9 @@
* JS function support.
*/
#include <string.h>
#include "mozilla/Util.h"
#include "jstypes.h"
#include "jsstdint.h"
#include "jsutil.h"
@ -95,6 +98,7 @@
#include "vm/ArgumentsObject-inl.h"
#include "vm/Stack-inl.h"
using namespace mozilla;
using namespace js;
using namespace js::gc;
using namespace js::types;
@ -1373,7 +1377,7 @@ fun_getProperty(JSContext *cx, JSObject *obj, jsid id, Value *vp)
/* NB: no sentinels at ends -- use JS_ARRAY_LENGTH to bound loops.
/* NB: no sentinels at ends -- use ArrayLength to bound loops.
* Properties censored into [[ThrowTypeError]] in strict mode. */
static const uint16 poisonPillProps[] = {
ATOM_OFFSET(arguments),
@ -1402,7 +1406,7 @@ fun_enumerate(JSContext *cx, JSObject *obj)
if (!obj->hasProperty(cx, id, &found, JSRESOLVE_QUALIFIED))
return false;
for (uintN i = 0; i < JS_ARRAY_LENGTH(poisonPillProps); i++) {
for (uintN i = 0; i < ArrayLength(poisonPillProps); i++) {
const uint16 offset = poisonPillProps[i];
id = ATOM_TO_JSID(OFFSET_TO_ATOM(cx->runtime, offset));
if (!obj->hasProperty(cx, id, &found, JSRESOLVE_QUALIFIED))
@ -1508,7 +1512,7 @@ fun_resolve(JSContext *cx, JSObject *obj, jsid id, uintN flags,
return true;
}
for (uintN i = 0; i < JS_ARRAY_LENGTH(poisonPillProps); i++) {
for (uintN i = 0; i < ArrayLength(poisonPillProps); i++) {
const uint16 offset = poisonPillProps[i];
if (JSID_IS_ATOM(id, OFFSET_TO_ATOM(cx->runtime, offset))) {

Просмотреть файл

@ -50,6 +50,9 @@
*/
#include <math.h>
#include <string.h> /* for memset used when DEBUG */
#include "mozilla/Util.h"
#include "jstypes.h"
#include "jsstdint.h"
#include "jsutil.h"
@ -102,6 +105,7 @@
# include <valgrind/memcheck.h>
#endif
using namespace mozilla;
using namespace js;
using namespace js::gc;
@ -548,7 +552,7 @@ Chunk::init()
/* Assemble all arenas into a linked list and mark them as not allocated. */
ArenaHeader **prevp = &info.emptyArenaListHead;
Arena *end = &arenas[JS_ARRAY_LENGTH(arenas)];
Arena *end = &arenas[ArrayLength(arenas)];
for (Arena *a = &arenas[0]; a != end; ++a) {
*prevp = &a->aheader;
a->aheader.setAsNotAllocated();
@ -940,7 +944,7 @@ MarkThreadDataConservatively(JSTracer *trc, ThreadData *td)
JS_ASSERT(stackMin <= stackEnd);
MarkRangeConservatively(trc, stackMin, stackEnd);
MarkRangeConservatively(trc, ctd->registerSnapshot.words,
JS_ARRAY_END(ctd->registerSnapshot.words));
ArrayEnd(ctd->registerSnapshot.words));
}
void

Просмотреть файл

@ -45,6 +45,8 @@
*/
#include <setjmp.h>
#include "mozilla/Util.h"
#include "jsalloc.h"
#include "jstypes.h"
#include "jsprvtd.h"
@ -1111,7 +1113,7 @@ struct ArenaLists {
void checkEmptyFreeLists() {
#ifdef DEBUG
for (size_t i = 0; i != JS_ARRAY_LENGTH(freeLists); ++i)
for (size_t i = 0; i < mozilla::ArrayLength(freeLists); ++i)
JS_ASSERT(freeLists[i].isEmpty());
#endif
}

Просмотреть файл

@ -36,6 +36,8 @@
*
* ***** END LICENSE BLOCK ***** */
#include "mozilla/Util.h"
#include "jstypes.h"
#include "jscntxt.h"
#include "jsgcstats.h"
@ -46,6 +48,7 @@
#include "jsgcinlines.h"
using namespace mozilla;
using namespace js;
using namespace js::gc;
@ -61,7 +64,7 @@ void
ConservativeGCStats::dump(FILE *fp)
{
size_t words = 0;
for (size_t i = 0; i != JS_ARRAY_LENGTH(counter); ++i)
for (size_t i = 0; i < ArrayLength(counter); ++i)
words += counter[i];
#define ULSTAT(x) ((unsigned long)(x))

Просмотреть файл

@ -39,6 +39,8 @@
#ifndef jsgcstats_h___
#define jsgcstats_h___
#include "mozilla/Util.h"
#if !defined JS_DUMP_CONSERVATIVE_GC_ROOTS && defined DEBUG
# define JS_DUMP_CONSERVATIVE_GC_ROOTS 1
#endif
@ -69,7 +71,7 @@ struct ConservativeGCStats
thing start pointers */
void add(const ConservativeGCStats &another) {
for (size_t i = 0; i != JS_ARRAY_LENGTH(counter); ++i)
for (size_t i = 0; i < mozilla::ArrayLength(counter); ++i)
counter[i] += another.counter[i];
}

Просмотреть файл

@ -42,6 +42,9 @@
* JavaScript iterators.
*/
#include <string.h> /* for memcpy */
#include "mozilla/Util.h"
#include "jstypes.h"
#include "jsstdint.h"
#include "jsutil.h"
@ -80,6 +83,7 @@
#include "vm/Stack-inl.h"
#include "vm/String-inl.h"
using namespace mozilla;
using namespace js;
using namespace js::gc;
@ -161,7 +165,7 @@ static inline bool
NewKeyValuePair(JSContext *cx, jsid id, const Value &val, Value *rval)
{
Value vec[2] = { IdToValue(id), val };
AutoArrayRooter tvr(cx, JS_ARRAY_LENGTH(vec), vec);
AutoArrayRooter tvr(cx, ArrayLength(vec), vec);
JSObject *aobj = NewDenseCopiedArray(cx, 2, vec);
if (!aobj)

Просмотреть файл

@ -43,6 +43,9 @@
*/
#include <stdlib.h>
#include <string.h>
#include "mozilla/Util.h"
#include "jstypes.h"
#include "jsstdint.h"
#include "jsutil.h"
@ -108,6 +111,7 @@
#include "jsautooplen.h"
using namespace mozilla;
using namespace js;
using namespace js::gc;
using namespace js::types;
@ -512,7 +516,7 @@ obj_toSource(JSContext *cx, uintN argc, Value *vp)
Value localroot[4];
PodArrayZero(localroot);
AutoArrayRooter tvr(cx, JS_ARRAY_LENGTH(localroot), localroot);
AutoArrayRooter tvr(cx, ArrayLength(localroot), localroot);
/* If outermost, we need parentheses to be an expression, not a block. */
JSBool outermost = (cx->sharpObjectMap.depth == 0);
@ -1407,7 +1411,7 @@ obj_watch_handler(JSContext *cx, JSObject *obj, jsid id, jsval old,
return true;
Value argv[] = { IdToValue(id), old, *nvp };
return Invoke(cx, ObjectValue(*obj), ObjectOrNullValue(callable), JS_ARRAY_LENGTH(argv), argv, nvp);
return Invoke(cx, ObjectValue(*obj), ObjectOrNullValue(callable), ArrayLength(argv), argv, nvp);
}
static JSBool

Просмотреть файл

@ -48,6 +48,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mozilla/Util.h"
#include "jstypes.h"
#include "jsstdint.h"
#include "jsutil.h"
@ -80,6 +83,7 @@
#include "vm/RegExpObject-inl.h"
using namespace mozilla;
using namespace js;
using namespace js::gc;
@ -2757,7 +2761,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
LOAD_OBJECT(0);
argc = OBJ_BLOCK_COUNT(cx, obj);
if ((size_t)argc <= JS_ARRAY_LENGTH(smallv)) {
if ((size_t)argc <= ArrayLength(smallv)) {
atomv = smallv;
} else {
atomv = (JSAtom **) cx->malloc_(argc * sizeof(JSAtom *));

Просмотреть файл

@ -42,6 +42,9 @@
*/
#include <stdlib.h>
#include <string.h> /* for jsparse.h */
#include "mozilla/Util.h"
#include "jspubtd.h"
#include "jsatom.h"
#include "jsobj.h"
@ -66,6 +69,7 @@
#include "jsscriptinlines.h"
using namespace mozilla;
using namespace js;
namespace js {
@ -230,7 +234,7 @@ class NodeBuilder
if (!newNodeLoc(pos, &loc))
return false;
Value argv[] = { loc };
return Invoke(cx, userv, fun, JS_ARRAY_LENGTH(argv), argv, dst);
return Invoke(cx, userv, fun, ArrayLength(argv), argv, dst);
}
Value argv[] = { NullValue() }; /* no zero-length arrays allowed! */
@ -243,11 +247,11 @@ class NodeBuilder
if (!newNodeLoc(pos, &loc))
return false;
Value argv[] = { v1, loc };
return Invoke(cx, userv, fun, JS_ARRAY_LENGTH(argv), argv, dst);
return Invoke(cx, userv, fun, ArrayLength(argv), argv, dst);
}
Value argv[] = { v1 };
return Invoke(cx, userv, fun, JS_ARRAY_LENGTH(argv), argv, dst);
return Invoke(cx, userv, fun, ArrayLength(argv), argv, dst);
}
bool callback(Value fun, Value v1, Value v2, TokenPos *pos, Value *dst) {
@ -256,11 +260,11 @@ class NodeBuilder
if (!newNodeLoc(pos, &loc))
return false;
Value argv[] = { v1, v2, loc };
return Invoke(cx, userv, fun, JS_ARRAY_LENGTH(argv), argv, dst);
return Invoke(cx, userv, fun, ArrayLength(argv), argv, dst);
}
Value argv[] = { v1, v2 };
return Invoke(cx, userv, fun, JS_ARRAY_LENGTH(argv), argv, dst);
return Invoke(cx, userv, fun, ArrayLength(argv), argv, dst);
}
bool callback(Value fun, Value v1, Value v2, Value v3, TokenPos *pos, Value *dst) {
@ -269,11 +273,11 @@ class NodeBuilder
if (!newNodeLoc(pos, &loc))
return false;
Value argv[] = { v1, v2, v3, loc };
return Invoke(cx, userv, fun, JS_ARRAY_LENGTH(argv), argv, dst);
return Invoke(cx, userv, fun, ArrayLength(argv), argv, dst);
}
Value argv[] = { v1, v2, v3 };
return Invoke(cx, userv, fun, JS_ARRAY_LENGTH(argv), argv, dst);
return Invoke(cx, userv, fun, ArrayLength(argv), argv, dst);
}
bool callback(Value fun, Value v1, Value v2, Value v3, Value v4, TokenPos *pos, Value *dst) {
@ -282,11 +286,11 @@ class NodeBuilder
if (!newNodeLoc(pos, &loc))
return false;
Value argv[] = { v1, v2, v3, v4, loc };
return Invoke(cx, userv, fun, JS_ARRAY_LENGTH(argv), argv, dst);
return Invoke(cx, userv, fun, ArrayLength(argv), argv, dst);
}
Value argv[] = { v1, v2, v3, v4 };
return Invoke(cx, userv, fun, JS_ARRAY_LENGTH(argv), argv, dst);
return Invoke(cx, userv, fun, ArrayLength(argv), argv, dst);
}
bool callback(Value fun, Value v1, Value v2, Value v3, Value v4, Value v5,
@ -296,11 +300,11 @@ class NodeBuilder
if (!newNodeLoc(pos, &loc))
return false;
Value argv[] = { v1, v2, v3, v4, v5, loc };
return Invoke(cx, userv, fun, JS_ARRAY_LENGTH(argv), argv, dst);
return Invoke(cx, userv, fun, ArrayLength(argv), argv, dst);
}
Value argv[] = { v1, v2, v3, v4, v5 };
return Invoke(cx, userv, fun, JS_ARRAY_LENGTH(argv), argv, dst);
return Invoke(cx, userv, fun, ArrayLength(argv), argv, dst);
}
Value opt(Value v) {

Просмотреть файл

@ -39,6 +39,8 @@
*
* ***** END LICENSE BLOCK ***** */
#include "mozilla/Util.h"
#include "jsstdint.h"
#include "jsprf.h"
#include <math.h> // standard headers next
@ -116,6 +118,8 @@
#include <elf.h>
#endif
using namespace mozilla;
#ifdef DEBUG
namespace js {
static const char*
@ -13843,13 +13847,13 @@ TraceRecorder::record_JSOP_FUNAPPLY()
RETURN_STOP_A("arguments parameter of apply is not a dense array or argments object");
}
if (length >= JS_ARRAY_LENGTH(funapply_imacro_table))
if (length >= ArrayLength(funapply_imacro_table))
RETURN_STOP_A("too many arguments to apply");
return InjectStatus(callImacro(funapply_imacro_table[length]));
}
if (argc >= JS_ARRAY_LENGTH(funcall_imacro_table))
if (argc >= ArrayLength(funcall_imacro_table))
RETURN_STOP_A("too many arguments to call");
return InjectStatus(callImacro(funcall_imacro_table[argc]));

Просмотреть файл

@ -39,6 +39,8 @@
#include <string.h>
#include "mozilla/Util.h"
#include "jstypes.h"
#include "jsstdint.h"
#include "jsutil.h"
@ -68,6 +70,7 @@
#include "jsobjinlines.h"
#include "jstypedarrayinlines.h"
using namespace mozilla;
using namespace js;
using namespace js::gc;
using namespace js::types;
@ -2409,7 +2412,7 @@ js_CreateTypedArrayWithBuffer(JSContext *cx, jsint atype, JSObject *bufArg,
argc++;
}
AutoArrayRooter tvr(cx, JS_ARRAY_LENGTH(vals), vals);
AutoArrayRooter tvr(cx, ArrayLength(vals), vals);
return TypedArrayConstruct(cx, atype, argc, &vals[0]);
}

Просмотреть файл

@ -37,6 +37,8 @@
*
* ***** END LICENSE BLOCK ***** */
#include "mozilla/Util.h"
#include "jsversion.h"
#if JS_HAS_XDR
@ -58,6 +60,7 @@
#include "jsobjinlines.h"
using namespace mozilla;
using namespace js;
#ifdef DEBUG
@ -641,7 +644,7 @@ js_XDRAtom(JSXDRState *xdr, JSAtom **atomp)
return JS_FALSE;
atom = NULL;
cx = xdr->cx;
if (nchars <= JS_ARRAY_LENGTH(stackChars)) {
if (nchars <= ArrayLength(stackChars)) {
chars = stackChars;
} else {
/*

Просмотреть файл

@ -44,6 +44,9 @@
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "mozilla/Util.h"
#include "jstypes.h"
#include "jsstdint.h"
#include "jsprf.h"
@ -81,6 +84,7 @@
#include <string.h> /* for #ifdef DEBUG memset calls */
#endif
using namespace mozilla;
using namespace js;
using namespace js::gc;
using namespace js::types;
@ -3763,7 +3767,7 @@ GetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
return GetXMLFunction(cx, obj, funid, vp);
jsval roots[2] = { OBJECT_TO_JSVAL(nameqn), JSVAL_NULL };
AutoArrayRooter tvr(cx, JS_ARRAY_LENGTH(roots), roots);
AutoArrayRooter tvr(cx, ArrayLength(roots), roots);
listobj = js_NewXMLObject(cx, JSXML_CLASS_LIST);
if (!listobj)
@ -3864,7 +3868,7 @@ PutProperty(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
roots[OBJ_ROOT] = OBJECT_TO_JSVAL(obj);
roots[ID_ROOT] = IdToJsval(id);
roots[VAL_ROOT] = *vp;
AutoArrayRooter tvr(cx, JS_ARRAY_LENGTH(roots), roots);
AutoArrayRooter tvr(cx, ArrayLength(roots), roots);
if (js_IdIsIndex(id, &index)) {
if (xml->xml_class != JSXML_CLASS_LIST) {

Просмотреть файл

@ -40,6 +40,8 @@
#if !defined jsjaeger_regstate_h__ && defined JS_METHODJIT
#define jsjaeger_regstate_h__
#include "mozilla/Util.h"
#include "assembler/assembler/MacroAssembler.h"
namespace js {
@ -336,8 +338,8 @@ struct Registers {
JSC::SparcRegisters::o5
};
#endif
JS_ASSERT(numArgRegs(conv) == JS_ARRAY_LENGTH(regs));
if (i > JS_ARRAY_LENGTH(regs))
JS_ASSERT(numArgRegs(conv) == mozilla::ArrayLength(regs));
if (i > mozilla::ArrayLength(regs))
return false;
*reg = regs[i];
return true;

Просмотреть файл

@ -48,6 +48,9 @@
#include <string.h>
#include <signal.h>
#include <locale.h>
#include "mozilla/Util.h"
#include "jstypes.h"
#include "jsstdint.h"
#include "jsutil.h"
@ -114,6 +117,7 @@
#include "jswin.h"
#endif
using namespace mozilla;
using namespace js;
using namespace js::cli;
@ -606,7 +610,7 @@ cleanup:
* JSContext option name to flag map. The option names are in alphabetical
* order for better reporting.
*/
static const struct {
static const struct JSOption {
const char *name;
uint32 flag;
} js_options[] = {
@ -625,7 +629,7 @@ static const struct {
static uint32
MapContextOptionNameToFlag(JSContext* cx, const char* name)
{
for (size_t i = 0; i != JS_ARRAY_LENGTH(js_options); ++i) {
for (size_t i = 0; i < ArrayLength(js_options); ++i) {
if (strcmp(name, js_options[i].name) == 0)
return js_options[i].flag;
}
@ -633,13 +637,13 @@ MapContextOptionNameToFlag(JSContext* cx, const char* name)
char* msg = JS_sprintf_append(NULL,
"unknown option name '%s'."
" The valid names are ", name);
for (size_t i = 0; i != JS_ARRAY_LENGTH(js_options); ++i) {
for (size_t i = 0; i < ArrayLength(js_options); ++i) {
if (!msg)
break;
msg = JS_sprintf_append(msg, "%s%s", js_options[i].name,
(i + 2 < JS_ARRAY_LENGTH(js_options)
(i + 2 < ArrayLength(js_options)
? ", "
: i + 2 == JS_ARRAY_LENGTH(js_options)
: i + 2 == ArrayLength(js_options)
? " and "
: "."));
}
@ -741,7 +745,7 @@ Options(JSContext *cx, uintN argc, jsval *vp)
names = NULL;
found = JS_FALSE;
for (size_t i = 0; i != JS_ARRAY_LENGTH(js_options); i++) {
for (size_t i = 0; i < ArrayLength(js_options); i++) {
if (js_options[i].flag & optset) {
found = JS_TRUE;
names = JS_sprintf_append(names, "%s%s",
@ -1217,20 +1221,20 @@ GC(JSContext *cx, uintN argc, jsval *vp)
return true;
}
static const struct ParamPair {
const char *name;
JSGCParamKey param;
} paramMap[] = {
{"maxBytes", JSGC_MAX_BYTES },
{"maxMallocBytes", JSGC_MAX_MALLOC_BYTES},
{"gcStackpoolLifespan", JSGC_STACKPOOL_LIFESPAN},
{"gcBytes", JSGC_BYTES},
{"gcNumber", JSGC_NUMBER},
};
static JSBool
GCParameter(JSContext *cx, uintN argc, jsval *vp)
{
static const struct {
const char *name;
JSGCParamKey param;
} paramMap[] = {
{"maxBytes", JSGC_MAX_BYTES },
{"maxMallocBytes", JSGC_MAX_MALLOC_BYTES},
{"gcStackpoolLifespan", JSGC_STACKPOOL_LIFESPAN},
{"gcBytes", JSGC_BYTES},
{"gcNumber", JSGC_NUMBER},
};
JSString *str;
if (argc == 0) {
str = JS_ValueToString(cx, JSVAL_VOID);
@ -1248,7 +1252,7 @@ GCParameter(JSContext *cx, uintN argc, jsval *vp)
size_t paramIndex = 0;
for (;; paramIndex++) {
if (paramIndex == JS_ARRAY_LENGTH(paramMap)) {
if (paramIndex == ArrayLength(paramMap)) {
JS_ReportError(cx,
"the first argument argument must be maxBytes, "
"maxMallocBytes, gcStackpoolLifespan, gcBytes or "
@ -1412,6 +1416,18 @@ CountHeapNotify(JSTracer *trc, void *thing, JSGCTraceKind kind)
countTracer->traceList = node;
}
static const struct TraceKindPair {
const char *name;
int32 kind;
} traceKindNames[] = {
{ "all", -1 },
{ "object", JSTRACE_OBJECT },
{ "string", JSTRACE_STRING },
#if JS_HAS_XML_SUPPORT
{ "xml", JSTRACE_XML },
#endif
};
static JSBool
CountHeap(JSContext *cx, uintN argc, jsval *vp)
{
@ -1424,18 +1440,6 @@ CountHeap(JSContext *cx, uintN argc, jsval *vp)
JSCountHeapNode *node;
size_t counter;
static const struct {
const char *name;
int32 kind;
} traceKindNames[] = {
{ "all", -1 },
{ "object", JSTRACE_OBJECT },
{ "string", JSTRACE_STRING },
#if JS_HAS_XML_SUPPORT
{ "xml", JSTRACE_XML },
#endif
};
startThing = NULL;
startTraceKind = JSTRACE_OBJECT;
if (argc > 0) {
@ -1464,7 +1468,7 @@ CountHeap(JSContext *cx, uintN argc, jsval *vp)
traceKind = traceKindNames[i].kind;
break;
}
if (++i == JS_ARRAY_LENGTH(traceKindNames)) {
if (++i == ArrayLength(traceKindNames)) {
JSAutoByteString bytes(cx, str);
if (!!bytes)
JS_ReportError(cx, "trace kind name '%s' is unknown", bytes.ptr());
@ -1988,7 +1992,7 @@ TryNotes(JSContext *cx, JSScript *script, Sprinter *sp)
tnlimit = tn + script->trynotes()->length;
Sprint(sp, "\nException table:\nkind stack start end\n");
do {
JS_ASSERT(tn->kind < JS_ARRAY_LENGTH(TryNoteNames));
JS_ASSERT(tn->kind < ArrayLength(TryNoteNames));
Sprint(sp, " %-7s %6u %8u %8u\n",
TryNoteNames[tn->kind], tn->stackDepth,
tn->start, tn->start + tn->length);
@ -4477,7 +4481,7 @@ CheckHelpMessages()
const char *lp;
/* Messages begin with "function_name(" prefix and don't end with \n. */
for (m = shell_help_messages; m != JS_ARRAY_END(shell_help_messages) - EXTERNAL_FUNCTION_COUNT; ++m) {
for (m = shell_help_messages; m < ArrayEnd(shell_help_messages) - EXTERNAL_FUNCTION_COUNT; ++m) {
lp = strchr(*m, '(');
JS_ASSERT(lp);
JS_ASSERT(memcmp(shell_functions[m - shell_help_messages].name,
@ -4506,7 +4510,7 @@ Help(JSContext *cx, uintN argc, jsval *vp)
fprintf(gOutFile, "%s\n", JS_GetImplementationVersion());
if (argc == 0) {
fputs(shell_help_header, gOutFile);
for (i = 0; i < JS_ARRAY_LENGTH(shell_help_messages); ++i)
for (i = 0; i < ArrayLength(shell_help_messages); ++i)
fprintf(gOutFile, "%s\n", shell_help_messages[i]);
} else {
did_header = 0;
@ -4526,7 +4530,7 @@ Help(JSContext *cx, uintN argc, jsval *vp)
JSAutoByteString funcName(cx, str);
if (!funcName)
return JS_FALSE;
for (j = 0; j < JS_ARRAY_LENGTH(shell_help_messages); ++j) {
for (j = 0; j < ArrayLength(shell_help_messages); ++j) {
/* Help messages are required to be formatted "functionName(..." */
const char *msg = shell_help_messages[j];
const char *p = strchr(msg, '(');

Просмотреть файл

@ -41,6 +41,8 @@
#ifndef RegExpObject_inl_h___
#define RegExpObject_inl_h___
#include "mozilla/Util.h"
#include "RegExpObject.h"
#include "RegExpStatics.h"
@ -403,12 +405,13 @@ RegExpPrivate::compile(JSContext *cx, TokenStream *ts)
static const jschar prefix[] = {'^', '(', '?', ':'};
static const jschar postfix[] = {')'};
using mozilla::ArrayLength;
StringBuffer sb(cx);
if (!sb.reserve(JS_ARRAY_LENGTH(prefix) + source->length() + JS_ARRAY_LENGTH(postfix)))
if (!sb.reserve(ArrayLength(prefix) + source->length() + ArrayLength(postfix)))
return false;
sb.infallibleAppend(prefix, JS_ARRAY_LENGTH(prefix));
sb.infallibleAppend(prefix, ArrayLength(prefix));
sb.infallibleAppend(source->chars(), source->length());
sb.infallibleAppend(postfix, JS_ARRAY_LENGTH(postfix));
sb.infallibleAppend(postfix, ArrayLength(postfix));
JSLinearString *fakeySource = sb.finishString();
if (!fakeySource)

Просмотреть файл

@ -41,6 +41,8 @@
#ifndef String_h_
#define String_h_
#include "mozilla/Util.h"
#include "jsapi.h"
#include "jscell.h"
@ -633,7 +635,7 @@ class JSExternalString : public JSFixedString
static intN changeFinalizer(JSStringFinalizeOp oldop,
JSStringFinalizeOp newop) {
for (uintN i = 0; i != JS_ARRAY_LENGTH(str_finalizers); i++) {
for (uintN i = 0; i < mozilla::ArrayLength(str_finalizers); i++) {
if (str_finalizers[i] == oldop) {
str_finalizers[i] = newop;
return intN(i);

Просмотреть файл

@ -46,6 +46,9 @@
/* XPConnect JavaScript interactive shell. */
#include <stdio.h>
#include "mozilla/Util.h"
#include "jsapi.h"
#include "jscntxt.h"
#include "jsdbgapi.h"
@ -106,6 +109,8 @@
#include "nsICrashReporter.h"
#endif
using namespace mozilla;
class XPCShellDirProvider : public nsIDirectoryServiceProvider2
{
public:
@ -727,7 +732,7 @@ static const struct {
static uint32
MapContextOptionNameToFlag(JSContext* cx, const char* name)
{
for (size_t i = 0; i != JS_ARRAY_LENGTH(js_options); ++i) {
for (size_t i = 0; i < ArrayLength(js_options); ++i) {
if (strcmp(name, js_options[i].name) == 0)
return js_options[i].flag;
}
@ -735,13 +740,13 @@ MapContextOptionNameToFlag(JSContext* cx, const char* name)
char* msg = JS_sprintf_append(NULL,
"unknown option name '%s'."
" The valid names are ", name);
for (size_t i = 0; i != JS_ARRAY_LENGTH(js_options); ++i) {
for (size_t i = 0; i < ArrayLength(js_options); ++i) {
if (!msg)
break;
msg = JS_sprintf_append(msg, "%s%s", js_options[i].name,
(i + 2 < JS_ARRAY_LENGTH(js_options)
(i + 2 < ArrayLength(js_options)
? ", "
: i + 2 == JS_ARRAY_LENGTH(js_options)
: i + 2 == ArrayLength(js_options)
? " and "
: "."));
}
@ -781,7 +786,7 @@ Options(JSContext *cx, uintN argc, jsval *vp)
names = NULL;
found = JS_FALSE;
for (size_t i = 0; i != JS_ARRAY_LENGTH(js_options); i++) {
for (size_t i = 0; i < ArrayLength(js_options); i++) {
if (js_options[i].flag & optset) {
found = JS_TRUE;
names = JS_sprintf_append(names, "%s%s",

Просмотреть файл

@ -853,7 +853,7 @@ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb)
"Shape",
"TypeObject",
};
JS_STATIC_ASSERT(JS_ARRAY_LENGTH(trace_types) == JSTRACE_LAST + 1);
JS_STATIC_ASSERT(NS_ARRAY_LENGTH(trace_types) == JSTRACE_LAST + 1);
JS_snprintf(name, sizeof(name), "JS %s", trace_types[traceKind]);
}

Просмотреть файл

@ -41,6 +41,8 @@
/* Per JSRuntime object */
#include "mozilla/Util.h"
#include "xpcprivate.h"
#include "xpcpublic.h"
#include "WrapperFactory.h"
@ -1644,7 +1646,7 @@ CollectCompartmentStatsForRuntime(JSRuntime *rt, IterateData *data)
PRInt64 used = stats.gcHeapArenaHeaders +
stats.gcHeapArenaPadding +
stats.gcHeapArenaUnused;
for (size_t i = 0; i != JS_ARRAY_LENGTH(stats.gcHeapKinds); ++i)
for (size_t i = 0; i != ArrayLength(stats.gcHeapKinds); ++i)
used += stats.gcHeapKinds[i];
data->gcHeapChunkDirtyUnused -= used;

Просмотреть файл

@ -37,6 +37,8 @@
*
* ***** END LICENSE BLOCK ***** */
#include "mozilla/Util.h"
#include "jsapi.h"
#include "jscntxt.h" /* for error messages */
#include "nsCOMPtr.h"
@ -45,6 +47,8 @@
#include "xpcquickstubs.h"
#include "XPCWrapper.h"
using namespace mozilla;
static inline QITableEntry *
GetOffsets(nsISupports *identity, XPCWrappedNativeProto* proto)
{
@ -220,7 +224,7 @@ ReifyPropertyOps(JSContext *cx, JSObject *obj, jsid id, uintN orig_attrs,
{
// Generate both getter and setter and stash them in the prototype.
jsval roots[2] = { JSVAL_NULL, JSVAL_NULL };
js::AutoArrayRooter tvr(cx, JS_ARRAY_LENGTH(roots), roots);
js::AutoArrayRooter tvr(cx, ArrayLength(roots), roots);
uintN attrs = JSPROP_SHARED | (orig_attrs & JSPROP_ENUMERATE);
JSObject *getterobj;