mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
When finalizing, deallocate memory in a separate thread (505612, r=bent,brendan,waldo).
This commit is contained in:
parent
9e09ec6424
commit
e7f2714ea1
@ -144,6 +144,7 @@ CPPSRCS = \
|
||||
jsscope.cpp \
|
||||
jsscript.cpp \
|
||||
jsstr.cpp \
|
||||
jstask.cpp \
|
||||
jsutil.cpp \
|
||||
jsxdrapi.cpp \
|
||||
jsxml.cpp \
|
||||
@ -200,6 +201,7 @@ INSTALLED_HEADERS = \
|
||||
jsscript.h \
|
||||
jsstaticcheck.h \
|
||||
jsstr.h \
|
||||
jstask.h \
|
||||
jstracer.h \
|
||||
jstypes.h \
|
||||
jsutil.h \
|
||||
|
@ -79,6 +79,7 @@
|
||||
#include "jsscope.h"
|
||||
#include "jsscript.h"
|
||||
#include "jsstr.h"
|
||||
#include "jstask.h"
|
||||
#include "jstracer.h"
|
||||
#include "jsdbgapi.h"
|
||||
#include "prmjtime.h"
|
||||
@ -448,7 +449,7 @@ JS_AddArgumentFormatter(JSContext *cx, const char *format,
|
||||
goto out;
|
||||
mpp = &map->next;
|
||||
}
|
||||
map = (JSArgumentFormatMap *) JS_malloc(cx, sizeof *map);
|
||||
map = (JSArgumentFormatMap *) cx->malloc(sizeof *map);
|
||||
if (!map)
|
||||
return JS_FALSE;
|
||||
map->format = format;
|
||||
@ -471,7 +472,7 @@ JS_RemoveArgumentFormatter(JSContext *cx, const char *format)
|
||||
while ((map = *mpp) != NULL) {
|
||||
if (map->length == length && !strcmp(map->format, format)) {
|
||||
*mpp = map->next;
|
||||
JS_free(cx, map);
|
||||
cx->free(map);
|
||||
return;
|
||||
}
|
||||
mpp = &map->next;
|
||||
@ -773,7 +774,7 @@ JS_NewRuntime(uint32 maxbytes)
|
||||
}
|
||||
#endif /* DEBUG */
|
||||
|
||||
rt = (JSRuntime *) malloc(sizeof(JSRuntime));
|
||||
rt = (JSRuntime *) js_malloc(sizeof(JSRuntime));
|
||||
if (!rt)
|
||||
return NULL;
|
||||
|
||||
@ -817,6 +818,9 @@ JS_NewRuntime(uint32 maxbytes)
|
||||
rt->debuggerLock = JS_NEW_LOCK();
|
||||
if (!rt->debuggerLock)
|
||||
goto bad;
|
||||
rt->deallocatorThread = new JSBackgroundThread();
|
||||
if (!rt->deallocatorThread || !rt->deallocatorThread->init())
|
||||
goto bad;
|
||||
#endif
|
||||
if (!js_InitPropertyTree(rt))
|
||||
goto bad;
|
||||
@ -886,9 +890,13 @@ JS_DestroyRuntime(JSRuntime *rt)
|
||||
JS_DESTROY_CONDVAR(rt->titleSharingDone);
|
||||
if (rt->debuggerLock)
|
||||
JS_DESTROY_LOCK(rt->debuggerLock);
|
||||
if (rt->deallocatorThread) {
|
||||
rt->deallocatorThread->cancel();
|
||||
delete rt->deallocatorThread;
|
||||
}
|
||||
#endif
|
||||
js_FinishPropertyTree(rt);
|
||||
free(rt);
|
||||
js_free(rt);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
@ -1653,7 +1661,7 @@ NewIdArray(JSContext *cx, jsint length)
|
||||
JSIdArray *ida;
|
||||
|
||||
ida = (JSIdArray *)
|
||||
JS_malloc(cx, offsetof(JSIdArray, vector) + length * sizeof(jsval));
|
||||
cx->malloc(offsetof(JSIdArray, vector) + length * sizeof(jsval));
|
||||
if (ida)
|
||||
ida->length = length;
|
||||
return ida;
|
||||
@ -1831,41 +1839,19 @@ JS_ComputeThis(JSContext *cx, jsval *vp)
|
||||
JS_PUBLIC_API(void *)
|
||||
JS_malloc(JSContext *cx, size_t nbytes)
|
||||
{
|
||||
void *p;
|
||||
|
||||
JS_ASSERT(nbytes != 0);
|
||||
if (nbytes == 0)
|
||||
nbytes = 1;
|
||||
|
||||
p = malloc(nbytes);
|
||||
if (!p) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return NULL;
|
||||
}
|
||||
cx->updateMallocCounter(nbytes);
|
||||
|
||||
return p;
|
||||
return cx->malloc(nbytes);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void *)
|
||||
JS_realloc(JSContext *cx, void *p, size_t nbytes)
|
||||
{
|
||||
void *orig = p;
|
||||
p = realloc(p, nbytes);
|
||||
if (!p) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return NULL;
|
||||
}
|
||||
if (!orig)
|
||||
cx->updateMallocCounter(nbytes);
|
||||
return p;
|
||||
return cx->realloc(p, nbytes);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
JS_free(JSContext *cx, void *p)
|
||||
{
|
||||
if (p)
|
||||
free(p);
|
||||
return cx->free(p);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(char *)
|
||||
@ -1875,7 +1861,7 @@ JS_strdup(JSContext *cx, const char *s)
|
||||
void *p;
|
||||
|
||||
n = strlen(s) + 1;
|
||||
p = JS_malloc(cx, n);
|
||||
p = cx->malloc(n);
|
||||
if (!p)
|
||||
return NULL;
|
||||
return (char *)memcpy(p, s, n);
|
||||
@ -2260,7 +2246,7 @@ DumpNotify(JSTracer *trc, void *thing, uint32 kind)
|
||||
|
||||
edgeNameSize = strlen(edgeName) + 1;
|
||||
node = (JSHeapDumpNode *)
|
||||
JS_malloc(cx, offsetof(JSHeapDumpNode, edgeName) + edgeNameSize);
|
||||
cx->malloc(offsetof(JSHeapDumpNode, edgeName) + edgeNameSize);
|
||||
if (!node) {
|
||||
dtrc->ok = JS_FALSE;
|
||||
return;
|
||||
@ -2412,7 +2398,7 @@ JS_DumpHeap(JSContext *cx, FILE *fp, void* startThing, uint32 startKind,
|
||||
for (;;) {
|
||||
next = node->next;
|
||||
parent = node->parent;
|
||||
JS_free(cx, node);
|
||||
cx->free(node);
|
||||
node = next;
|
||||
if (node)
|
||||
break;
|
||||
@ -2679,7 +2665,7 @@ JS_SetScriptStackQuota(JSContext *cx, size_t quota)
|
||||
JS_PUBLIC_API(void)
|
||||
JS_DestroyIdArray(JSContext *cx, JSIdArray *ida)
|
||||
{
|
||||
JS_free(cx, ida);
|
||||
cx->free(ida);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
@ -4644,7 +4630,7 @@ JS_CompileScript(JSContext *cx, JSObject *obj,
|
||||
if (!chars)
|
||||
return NULL;
|
||||
script = JS_CompileUCScript(cx, obj, chars, length, filename, lineno);
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
return script;
|
||||
}
|
||||
|
||||
@ -4663,7 +4649,7 @@ JS_CompileScriptForPrincipals(JSContext *cx, JSObject *obj,
|
||||
return NULL;
|
||||
script = JS_CompileUCScriptForPrincipals(cx, obj, principals,
|
||||
chars, length, filename, lineno);
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
return script;
|
||||
}
|
||||
|
||||
@ -4748,7 +4734,7 @@ JS_BufferIsCompilableUnit(JSContext *cx, JSObject *obj,
|
||||
JS_SetErrorReporter(cx, older);
|
||||
}
|
||||
}
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
JS_RestoreExceptionState(cx, exnState);
|
||||
return result;
|
||||
}
|
||||
@ -4857,7 +4843,7 @@ JS_CompileFunction(JSContext *cx, JSObject *obj, const char *name,
|
||||
return NULL;
|
||||
fun = JS_CompileUCFunction(cx, obj, name, nargs, argnames, chars, length,
|
||||
filename, lineno);
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
return fun;
|
||||
}
|
||||
|
||||
@ -4878,7 +4864,7 @@ JS_CompileFunctionForPrincipals(JSContext *cx, JSObject *obj,
|
||||
fun = JS_CompileUCFunctionForPrincipals(cx, obj, principals, name,
|
||||
nargs, argnames, chars, length,
|
||||
filename, lineno);
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
return fun;
|
||||
}
|
||||
|
||||
@ -5088,7 +5074,7 @@ JS_EvaluateScript(JSContext *cx, JSObject *obj,
|
||||
if (!chars)
|
||||
return JS_FALSE;
|
||||
ok = JS_EvaluateUCScript(cx, obj, chars, length, filename, lineno, rval);
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@ -5110,7 +5096,7 @@ JS_EvaluateScriptForPrincipals(JSContext *cx, JSObject *obj,
|
||||
return JS_FALSE;
|
||||
ok = JS_EvaluateUCScriptForPrincipals(cx, obj, principals, chars, length,
|
||||
filename, lineno, rval);
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@ -5319,13 +5305,13 @@ JS_NewString(JSContext *cx, char *bytes, size_t nbytes)
|
||||
/* Free chars (but not bytes, which caller frees on error) if we fail. */
|
||||
str = js_NewString(cx, chars, length);
|
||||
if (!str) {
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Hand off bytes to the deflated string cache, if possible. */
|
||||
if (!js_SetStringBytes(cx, str, bytes, nbytes))
|
||||
JS_free(cx, bytes);
|
||||
cx->free(bytes);
|
||||
return str;
|
||||
}
|
||||
|
||||
@ -5341,7 +5327,7 @@ JS_NewStringCopyN(JSContext *cx, const char *s, size_t n)
|
||||
return NULL;
|
||||
str = js_NewString(cx, js, n);
|
||||
if (!str)
|
||||
JS_free(cx, js);
|
||||
cx->free(js);
|
||||
return str;
|
||||
}
|
||||
|
||||
@ -5361,7 +5347,7 @@ JS_NewStringCopyZ(JSContext *cx, const char *s)
|
||||
return NULL;
|
||||
str = js_NewString(cx, js, n);
|
||||
if (!str)
|
||||
JS_free(cx, js);
|
||||
cx->free(js);
|
||||
return str;
|
||||
}
|
||||
|
||||
@ -5449,7 +5435,7 @@ JS_GetStringChars(JSString *str)
|
||||
if (str->isDependent()) {
|
||||
n = str->dependentLength();
|
||||
size = (n + 1) * sizeof(jschar);
|
||||
s = (jschar *) malloc(size);
|
||||
s = (jschar *) js_malloc(size);
|
||||
if (s) {
|
||||
memcpy(s, str->dependentChars(), n * sizeof *s);
|
||||
s[n] = 0;
|
||||
@ -5727,7 +5713,7 @@ JS_NewRegExpObject(JSContext *cx, char *bytes, size_t length, uintN flags)
|
||||
if (!chars)
|
||||
return NULL;
|
||||
obj = js_NewRegExpObject(cx, NULL, chars, length, flags);
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
return obj;
|
||||
}
|
||||
|
||||
@ -5857,7 +5843,7 @@ JS_SaveExceptionState(JSContext *cx)
|
||||
JSExceptionState *state;
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
state = (JSExceptionState *) JS_malloc(cx, sizeof(JSExceptionState));
|
||||
state = (JSExceptionState *) cx->malloc(sizeof(JSExceptionState));
|
||||
if (state) {
|
||||
state->throwing = JS_GetPendingException(cx, &state->exception);
|
||||
if (state->throwing && JSVAL_IS_GCTHING(state->exception))
|
||||
@ -5886,7 +5872,7 @@ JS_DropExceptionState(JSContext *cx, JSExceptionState *state)
|
||||
if (state) {
|
||||
if (state->throwing && JSVAL_IS_GCTHING(state->exception))
|
||||
JS_RemoveRoot(cx, &state->exception);
|
||||
JS_free(cx, state);
|
||||
cx->free(state);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,12 +160,12 @@ JS_ArenaAllocate(JSArenaPool *pool, size_t nb)
|
||||
if (pool->quotap) {
|
||||
if (gross > *pool->quotap)
|
||||
return NULL;
|
||||
b = (JSArena *) malloc(gross);
|
||||
b = (JSArena *) js_malloc(gross);
|
||||
if (!b)
|
||||
return NULL;
|
||||
*pool->quotap -= gross;
|
||||
} else {
|
||||
b = (JSArena *) malloc(gross);
|
||||
b = (JSArena *) js_malloc(gross);
|
||||
if (!b)
|
||||
return NULL;
|
||||
}
|
||||
@ -227,12 +227,12 @@ JS_ArenaRealloc(JSArenaPool *pool, void *p, size_t size, size_t incr)
|
||||
growth = gross - (a->limit - (jsuword) a);
|
||||
if (growth > *pool->quotap)
|
||||
return NULL;
|
||||
a = (JSArena *) realloc(a, gross);
|
||||
a = (JSArena *) js_realloc(a, gross);
|
||||
if (!a)
|
||||
return NULL;
|
||||
*pool->quotap -= growth;
|
||||
} else {
|
||||
a = (JSArena *) realloc(a, gross);
|
||||
a = (JSArena *) js_realloc(a, gross);
|
||||
if (!a)
|
||||
return NULL;
|
||||
}
|
||||
@ -315,7 +315,7 @@ FreeArenaList(JSArenaPool *pool, JSArena *head)
|
||||
*pool->quotap += a->limit - (jsuword) a;
|
||||
JS_CLEAR_ARENA(a);
|
||||
JS_COUNT_ARENA(pool,--);
|
||||
free(a);
|
||||
js_free(a);
|
||||
} while ((a = *ap) != NULL);
|
||||
|
||||
pool->current = head;
|
||||
@ -354,7 +354,7 @@ JS_FinishArenaPool(JSArenaPool *pool)
|
||||
JSArenaStats *stats, **statsp;
|
||||
|
||||
if (pool->stats.name) {
|
||||
free(pool->stats.name);
|
||||
js_free(pool->stats.name);
|
||||
pool->stats.name = NULL;
|
||||
}
|
||||
for (statsp = &arena_stats_list; (stats = *statsp) != 0;
|
||||
|
@ -314,7 +314,7 @@ ResizeSlots(JSContext *cx, JSObject *obj, uint32 oldsize, uint32 size)
|
||||
|
||||
if (size == 0) {
|
||||
if (obj->dslots) {
|
||||
JS_free(cx, obj->dslots - 1);
|
||||
cx->free(obj->dslots - 1);
|
||||
obj->dslots = NULL;
|
||||
}
|
||||
return JS_TRUE;
|
||||
@ -330,7 +330,7 @@ ResizeSlots(JSContext *cx, JSObject *obj, uint32 oldsize, uint32 size)
|
||||
}
|
||||
|
||||
slots = obj->dslots ? obj->dslots - 1 : NULL;
|
||||
newslots = (jsval *) JS_realloc(cx, slots, (size + 1) * sizeof(jsval));
|
||||
newslots = (jsval *) cx->realloc(slots, (size + 1) * sizeof(jsval));
|
||||
if (!newslots)
|
||||
return JS_FALSE;
|
||||
|
||||
@ -1099,7 +1099,7 @@ array_enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
|
||||
if (obj->dslots[i] == JSVAL_HOLE) {
|
||||
if (!ii) {
|
||||
ii = (JSIndexIterState *)
|
||||
JS_malloc(cx, offsetof(JSIndexIterState, holes) +
|
||||
cx->malloc(offsetof(JSIndexIterState, holes) +
|
||||
JS_BITMAP_SIZE(capacity));
|
||||
if (!ii)
|
||||
return JS_FALSE;
|
||||
@ -1116,7 +1116,7 @@ array_enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
|
||||
break;
|
||||
}
|
||||
ii = (JSIndexIterState *)
|
||||
JS_malloc(cx, offsetof(JSIndexIterState, holes));
|
||||
cx->malloc(offsetof(JSIndexIterState, holes));
|
||||
if (!ii)
|
||||
return JS_FALSE;
|
||||
ii->hasHoles = JS_FALSE;
|
||||
@ -1157,7 +1157,7 @@ array_enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
|
||||
if (JSVAL_TAG(*statep) != JSVAL_BOOLEAN) {
|
||||
JS_ASSERT((*statep & INDEX_ITER_TAG) == INDEX_ITER_TAG);
|
||||
ii = (JSIndexIterState *) (*statep & ~INDEX_ITER_TAG);
|
||||
JS_free(cx, ii);
|
||||
cx->free(ii);
|
||||
}
|
||||
*statep = JSVAL_NULL;
|
||||
break;
|
||||
@ -1188,7 +1188,7 @@ static void
|
||||
array_finalize(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
if (obj->dslots)
|
||||
JS_free(cx, obj->dslots - 1);
|
||||
cx->free(obj->dslots - 1);
|
||||
obj->dslots = NULL;
|
||||
}
|
||||
|
||||
@ -1336,7 +1336,7 @@ BufferToString(JSContext *cx, JSTempVector<jschar> &buf, jsval *rval)
|
||||
jschar *chars = buf.extractRawBuffer();
|
||||
JSString *str = js_NewString(cx, chars, length);
|
||||
if (!str) {
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
return JS_FALSE;
|
||||
}
|
||||
*rval = STRING_TO_JSVAL(str);
|
||||
@ -1392,7 +1392,7 @@ array_toSource(JSContext *cx, uintN argc, jsval *vp)
|
||||
if (!(ok = buf.pushBack(arr, arr + 3)))
|
||||
goto done;
|
||||
if (sharpchars)
|
||||
JS_free(cx, sharpchars);
|
||||
cx->free(sharpchars);
|
||||
goto make_string;
|
||||
}
|
||||
#endif
|
||||
@ -2151,7 +2151,7 @@ array_sort(JSContext *cx, uintN argc, jsval *vp)
|
||||
return JS_FALSE;
|
||||
}
|
||||
#endif
|
||||
vec = (jsval *) JS_malloc(cx, 2 * (size_t) len * sizeof(jsval));
|
||||
vec = (jsval *) cx->malloc(2 * (size_t) len * sizeof(jsval));
|
||||
if (!vec)
|
||||
return JS_FALSE;
|
||||
|
||||
@ -2280,8 +2280,8 @@ array_sort(JSContext *cx, uintN argc, jsval *vp)
|
||||
} while (i != 0);
|
||||
|
||||
JS_ASSERT(tvr.u.array == vec);
|
||||
vec = (jsval *) JS_realloc(cx, vec,
|
||||
4 * (size_t) newlen * sizeof(jsval));
|
||||
vec = (jsval *) cx->realloc(vec,
|
||||
4 * (size_t) newlen * sizeof(jsval));
|
||||
if (!vec) {
|
||||
vec = tvr.u.array;
|
||||
ok = JS_FALSE;
|
||||
@ -2342,7 +2342,7 @@ array_sort(JSContext *cx, uintN argc, jsval *vp)
|
||||
|
||||
out:
|
||||
JS_POP_TEMP_ROOT(cx, &tvr);
|
||||
JS_free(cx, vec);
|
||||
cx->free(vec);
|
||||
if (!ok)
|
||||
return JS_FALSE;
|
||||
|
||||
@ -3507,7 +3507,7 @@ js_ArrayInfo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
if (JSVAL_IS_PRIMITIVE(argv[i]) ||
|
||||
!OBJ_IS_ARRAY(cx, (array = JSVAL_TO_OBJECT(argv[i])))) {
|
||||
fprintf(stderr, "%s: not array\n", bytes);
|
||||
JS_free(cx, bytes);
|
||||
cx->free(bytes);
|
||||
continue;
|
||||
}
|
||||
fprintf(stderr, "%s: %s (len %lu", bytes,
|
||||
@ -3519,7 +3519,7 @@ js_ArrayInfo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
js_DenseArrayCapacity(array));
|
||||
}
|
||||
fputs(")\n", stderr);
|
||||
JS_free(cx, bytes);
|
||||
cx->free(bytes);
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
@ -783,7 +783,7 @@ js_Atomize(JSContext *cx, const char *bytes, size_t length, uintN flags)
|
||||
str.initFlat(chars, inflatedLength);
|
||||
atom = js_AtomizeString(cx, &str, ATOM_TMPSTR | flags);
|
||||
if (chars != inflated && str.flatChars())
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
return atom;
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ static JSThread *
|
||||
NewThread(jsword id)
|
||||
{
|
||||
JS_ASSERT(js_CurrentThreadId() == id);
|
||||
JSThread *thread = (JSThread *) calloc(1, sizeof(JSThread));
|
||||
JSThread *thread = (JSThread *) js_calloc(sizeof(JSThread));
|
||||
if (!thread)
|
||||
return NULL;
|
||||
JS_INIT_CLIST(&thread->contextList);
|
||||
@ -158,7 +158,7 @@ DestroyThread(JSThread *thread)
|
||||
JS_ASSERT(JS_CLIST_IS_EMPTY(&thread->contextList));
|
||||
JS_ASSERT(!thread->titleToShare);
|
||||
FinishThreadData(&thread->data);
|
||||
free(thread);
|
||||
js_free(thread);
|
||||
}
|
||||
|
||||
JSBool
|
||||
@ -370,7 +370,7 @@ js_NewContext(JSRuntime *rt, size_t stackChunkSize)
|
||||
* runtime list. After that it can be accessed from another thread via
|
||||
* js_ContextIterator.
|
||||
*/
|
||||
cx = (JSContext *) calloc(1, sizeof *cx);
|
||||
cx = (JSContext *) js_calloc(sizeof *cx);
|
||||
if (!cx)
|
||||
return NULL;
|
||||
|
||||
@ -743,14 +743,14 @@ FreeContext(JSContext *cx)
|
||||
JS_FinishArenaPool(&cx->tempPool);
|
||||
|
||||
if (cx->lastMessage)
|
||||
free(cx->lastMessage);
|
||||
js_free(cx->lastMessage);
|
||||
|
||||
/* Remove any argument formatters. */
|
||||
map = cx->argumentFormatMap;
|
||||
while (map) {
|
||||
JSArgumentFormatMap *temp = map;
|
||||
map = map->next;
|
||||
JS_free(cx, temp);
|
||||
cx->free(temp);
|
||||
}
|
||||
|
||||
/* Destroy the busy array table. */
|
||||
@ -769,13 +769,13 @@ FreeContext(JSContext *cx)
|
||||
if (lrs) {
|
||||
while ((lrc = lrs->topChunk) != &lrs->firstChunk) {
|
||||
lrs->topChunk = lrc->down;
|
||||
JS_free(cx, lrc);
|
||||
cx->free(lrc);
|
||||
}
|
||||
JS_free(cx, lrs);
|
||||
cx->free(lrs);
|
||||
}
|
||||
|
||||
/* Finally, free cx itself. */
|
||||
free(cx);
|
||||
js_free(cx);
|
||||
}
|
||||
|
||||
JSBool
|
||||
@ -1013,7 +1013,7 @@ js_EnterLocalRootScope(JSContext *cx)
|
||||
|
||||
lrs = cx->localRootStack;
|
||||
if (!lrs) {
|
||||
lrs = (JSLocalRootStack *) JS_malloc(cx, sizeof *lrs);
|
||||
lrs = (JSLocalRootStack *) cx->malloc(sizeof *lrs);
|
||||
if (!lrs)
|
||||
return JS_FALSE;
|
||||
lrs->scopeMark = JSLRS_NULL_MARK;
|
||||
@ -1056,7 +1056,7 @@ js_LeaveLocalRootScopeWithResult(JSContext *cx, jsval rval)
|
||||
lrc = lrs->topChunk;
|
||||
JS_ASSERT(lrc != &lrs->firstChunk);
|
||||
lrs->topChunk = lrc->down;
|
||||
JS_free(cx, lrc);
|
||||
cx->free(lrc);
|
||||
--n;
|
||||
}
|
||||
|
||||
@ -1096,10 +1096,10 @@ js_LeaveLocalRootScopeWithResult(JSContext *cx, jsval rval)
|
||||
*/
|
||||
if (mark == 0) {
|
||||
cx->localRootStack = NULL;
|
||||
JS_free(cx, lrs);
|
||||
cx->free(lrs);
|
||||
} else if (m == 0) {
|
||||
lrs->topChunk = lrc->down;
|
||||
JS_free(cx, lrc);
|
||||
cx->free(lrc);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1158,7 +1158,7 @@ js_ForgetLocalRoot(JSContext *cx, jsval v)
|
||||
JS_ASSERT(n != 0);
|
||||
JS_ASSERT(lrc != &lrs->firstChunk);
|
||||
lrs->topChunk = lrc->down;
|
||||
JS_free(cx, lrc);
|
||||
cx->free(lrc);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1187,7 +1187,7 @@ js_PushLocalRoot(JSContext *cx, JSLocalRootStack *lrs, jsval v)
|
||||
* After lrs->firstChunk, trying to index at a power-of-two chunk
|
||||
* boundary: need a new chunk.
|
||||
*/
|
||||
lrc = (JSLocalRootChunk *) JS_malloc(cx, sizeof *lrc);
|
||||
lrc = (JSLocalRootChunk *) cx->malloc(sizeof *lrc);
|
||||
if (!lrc)
|
||||
return -1;
|
||||
lrc->down = lrs->topChunk;
|
||||
@ -1380,8 +1380,8 @@ js_ReportErrorVA(JSContext *cx, uintN flags, const char *format, va_list ap)
|
||||
}
|
||||
|
||||
ReportError(cx, message, &report);
|
||||
free(message);
|
||||
JS_free(cx, ucmessage);
|
||||
js_free(message);
|
||||
cx->free(ucmessage);
|
||||
return warning;
|
||||
}
|
||||
|
||||
@ -1432,7 +1432,7 @@ js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
|
||||
* pointers later.
|
||||
*/
|
||||
reportp->messageArgs = (const jschar **)
|
||||
JS_malloc(cx, sizeof(jschar *) * (argCount + 1));
|
||||
cx->malloc(sizeof(jschar *) * (argCount + 1));
|
||||
if (!reportp->messageArgs)
|
||||
return JS_FALSE;
|
||||
reportp->messageArgs[argCount] = NULL;
|
||||
@ -1476,9 +1476,9 @@ js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
|
||||
* is used once and only once in the expansion !!!
|
||||
*/
|
||||
reportp->ucmessage = out = (jschar *)
|
||||
JS_malloc(cx, (expandedLength + 1) * sizeof(jschar));
|
||||
cx->malloc((expandedLength + 1) * sizeof(jschar));
|
||||
if (!out) {
|
||||
JS_free (cx, buffer);
|
||||
cx->free(buffer);
|
||||
goto error;
|
||||
}
|
||||
while (*fmt) {
|
||||
@ -1498,7 +1498,7 @@ js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
|
||||
}
|
||||
JS_ASSERT(expandedArgs == argCount);
|
||||
*out = 0;
|
||||
JS_free (cx, buffer);
|
||||
cx->free(buffer);
|
||||
*messagep =
|
||||
js_DeflateString(cx, reportp->ucmessage,
|
||||
(size_t)(out - reportp->ucmessage));
|
||||
@ -1527,7 +1527,7 @@ js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
|
||||
const char *defaultErrorMessage
|
||||
= "No error message available for error number %d";
|
||||
size_t nbytes = strlen(defaultErrorMessage) + 16;
|
||||
*messagep = (char *)JS_malloc(cx, nbytes);
|
||||
*messagep = (char *)cx->malloc(nbytes);
|
||||
if (!*messagep)
|
||||
goto error;
|
||||
JS_snprintf(*messagep, nbytes, defaultErrorMessage, errorNumber);
|
||||
@ -1540,17 +1540,17 @@ error:
|
||||
if (charArgs) {
|
||||
i = 0;
|
||||
while (reportp->messageArgs[i])
|
||||
JS_free(cx, (void *)reportp->messageArgs[i++]);
|
||||
cx->free((void *)reportp->messageArgs[i++]);
|
||||
}
|
||||
JS_free(cx, (void *)reportp->messageArgs);
|
||||
cx->free((void *)reportp->messageArgs);
|
||||
reportp->messageArgs = NULL;
|
||||
}
|
||||
if (reportp->ucmessage) {
|
||||
JS_free(cx, (void *)reportp->ucmessage);
|
||||
cx->free((void *)reportp->ucmessage);
|
||||
reportp->ucmessage = NULL;
|
||||
}
|
||||
if (*messagep) {
|
||||
JS_free(cx, (void *)*messagep);
|
||||
cx->free((void *)*messagep);
|
||||
*messagep = NULL;
|
||||
}
|
||||
return JS_FALSE;
|
||||
@ -1581,7 +1581,7 @@ js_ReportErrorNumberVA(JSContext *cx, uintN flags, JSErrorCallback callback,
|
||||
ReportError(cx, message, &report);
|
||||
|
||||
if (message)
|
||||
JS_free(cx, message);
|
||||
cx->free(message);
|
||||
if (report.messageArgs) {
|
||||
/*
|
||||
* js_ExpandErrorArguments owns its messageArgs only if it had to
|
||||
@ -1590,12 +1590,12 @@ js_ReportErrorNumberVA(JSContext *cx, uintN flags, JSErrorCallback callback,
|
||||
if (charArgs) {
|
||||
int i = 0;
|
||||
while (report.messageArgs[i])
|
||||
JS_free(cx, (void *)report.messageArgs[i++]);
|
||||
cx->free((void *)report.messageArgs[i++]);
|
||||
}
|
||||
JS_free(cx, (void *)report.messageArgs);
|
||||
cx->free((void *)report.messageArgs);
|
||||
}
|
||||
if (report.ucmessage)
|
||||
JS_free(cx, (void *)report.ucmessage);
|
||||
cx->free((void *)report.ucmessage);
|
||||
|
||||
return warning;
|
||||
}
|
||||
@ -1609,7 +1609,7 @@ js_ReportErrorAgain(JSContext *cx, const char *message, JSErrorReport *reportp)
|
||||
return;
|
||||
|
||||
if (cx->lastMessage)
|
||||
free(cx->lastMessage);
|
||||
js_free(cx->lastMessage);
|
||||
cx->lastMessage = JS_strdup(cx, message);
|
||||
if (!cx->lastMessage)
|
||||
return;
|
||||
@ -1667,7 +1667,7 @@ js_ReportIsNullOrUndefined(JSContext *cx, intN spindex, jsval v,
|
||||
js_null_str, NULL);
|
||||
}
|
||||
|
||||
JS_free(cx, bytes);
|
||||
cx->free(bytes);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@ -1690,7 +1690,7 @@ js_ReportMissingArg(JSContext *cx, jsval *vp, uintN arg)
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_MISSING_FUN_ARG, argbuf,
|
||||
bytes ? bytes : "");
|
||||
JS_free(cx, bytes);
|
||||
cx->free(bytes);
|
||||
}
|
||||
|
||||
JSBool
|
||||
@ -1709,7 +1709,7 @@ js_ReportValueErrorFlags(JSContext *cx, uintN flags, const uintN errorNumber,
|
||||
|
||||
ok = JS_ReportErrorFlagsAndNumber(cx, flags, js_GetErrorMessage,
|
||||
NULL, errorNumber, bytes, arg1, arg2);
|
||||
JS_free(cx, bytes);
|
||||
cx->free(bytes);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
104
js/src/jscntxt.h
104
js/src/jscntxt.h
@ -57,6 +57,7 @@
|
||||
#include "jsregexp.h"
|
||||
#include "jsutil.h"
|
||||
#include "jsarray.h"
|
||||
#include "jstask.h"
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
@ -255,6 +256,13 @@ struct JSThreadData {
|
||||
* locks on each JS_malloc.
|
||||
*/
|
||||
size_t gcMallocBytes;
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
/*
|
||||
* Deallocator task for this thread.
|
||||
*/
|
||||
JSFreePointerListTask *deallocatorTask;
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
@ -699,6 +707,26 @@ struct JSRuntime {
|
||||
|
||||
void setGCTriggerFactor(uint32 factor);
|
||||
void setGCLastBytes(size_t lastBytes);
|
||||
|
||||
inline void* malloc(size_t bytes) {
|
||||
return ::js_malloc(bytes);
|
||||
}
|
||||
|
||||
inline void* calloc(size_t bytes) {
|
||||
return ::js_calloc(bytes);
|
||||
}
|
||||
|
||||
inline void* realloc(void* p, size_t bytes) {
|
||||
return ::js_realloc(p, bytes);
|
||||
}
|
||||
|
||||
inline void free(void* p) {
|
||||
::js_free(p);
|
||||
}
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
JSBackgroundThread *deallocatorThread;
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Common macros to access thread-local caches in JSThread or JSRuntime. */
|
||||
@ -1050,16 +1078,86 @@ struct JSContext {
|
||||
jsval *nativeVp;
|
||||
#endif
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
inline void createDeallocatorTask() {
|
||||
JSThreadData* tls = JS_THREAD_DATA(this);
|
||||
JS_ASSERT(!tls->deallocatorTask);
|
||||
if (runtime->deallocatorThread && !runtime->deallocatorThread->busy())
|
||||
tls->deallocatorTask = new JSFreePointerListTask();
|
||||
}
|
||||
|
||||
inline void submitDeallocatorTask() {
|
||||
JSThreadData* tls = JS_THREAD_DATA(this);
|
||||
if (tls->deallocatorTask) {
|
||||
runtime->deallocatorThread->schedule(tls->deallocatorTask);
|
||||
tls->deallocatorTask = NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Call this after succesful malloc of memory for GC-related things. */
|
||||
inline void
|
||||
updateMallocCounter(size_t nbytes)
|
||||
{
|
||||
inline void updateMallocCounter(size_t nbytes) {
|
||||
size_t *pbytes, bytes;
|
||||
|
||||
pbytes = &JS_THREAD_DATA(this)->gcMallocBytes;
|
||||
bytes = *pbytes;
|
||||
*pbytes = (size_t(-1) - bytes <= nbytes) ? size_t(-1) : bytes + nbytes;
|
||||
}
|
||||
|
||||
inline void* malloc(size_t bytes) {
|
||||
JS_ASSERT(bytes != 0);
|
||||
void *p = runtime->malloc(bytes);
|
||||
if (!p) {
|
||||
JS_ReportOutOfMemory(this);
|
||||
return NULL;
|
||||
}
|
||||
updateMallocCounter(bytes);
|
||||
return p;
|
||||
}
|
||||
|
||||
inline void* calloc(size_t bytes) {
|
||||
JS_ASSERT(bytes != 0);
|
||||
void *p = runtime->calloc(bytes);
|
||||
if (!p) {
|
||||
JS_ReportOutOfMemory(this);
|
||||
return NULL;
|
||||
}
|
||||
updateMallocCounter(bytes);
|
||||
return p;
|
||||
}
|
||||
|
||||
inline void* realloc(void* p, size_t bytes) {
|
||||
void *orig = p;
|
||||
p = runtime->realloc(p, bytes);
|
||||
if (!p) {
|
||||
JS_ReportOutOfMemory(this);
|
||||
return NULL;
|
||||
}
|
||||
if (!orig)
|
||||
updateMallocCounter(bytes);
|
||||
return p;
|
||||
}
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
inline void free(void* p) {
|
||||
if (!p)
|
||||
return;
|
||||
if (thread) {
|
||||
JSFreePointerListTask* task = JS_THREAD_DATA(this)->deallocatorTask;
|
||||
if (task) {
|
||||
task->add(p);
|
||||
return;
|
||||
}
|
||||
}
|
||||
runtime->free(p);
|
||||
}
|
||||
#else
|
||||
inline void free(void* p) {
|
||||
if (!p)
|
||||
return;
|
||||
runtime->free(p);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
|
@ -1961,7 +1961,7 @@ date_toSource(JSContext *cx, uintN argc, jsval *vp)
|
||||
|
||||
str = JS_NewString(cx, bytes, strlen(bytes));
|
||||
if (!str) {
|
||||
free(bytes);
|
||||
js_free(bytes);
|
||||
return JS_FALSE;
|
||||
}
|
||||
*vp = STRING_TO_JSVAL(str);
|
||||
|
@ -123,7 +123,7 @@ js_UntrapScriptCode(JSContext *cx, JSScript *script)
|
||||
continue;
|
||||
nbytes += (sn - notes + 1) * sizeof *sn;
|
||||
|
||||
code = (jsbytecode *) JS_malloc(cx, nbytes);
|
||||
code = (jsbytecode *) cx->malloc(nbytes);
|
||||
if (!code)
|
||||
break;
|
||||
memcpy(code, script->code, nbytes);
|
||||
@ -155,12 +155,12 @@ JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
|
||||
} else {
|
||||
sample = rt->debuggerMutations;
|
||||
DBG_UNLOCK(rt);
|
||||
trap = (JSTrap *) JS_malloc(cx, sizeof *trap);
|
||||
trap = (JSTrap *) cx->malloc(sizeof *trap);
|
||||
if (!trap)
|
||||
return JS_FALSE;
|
||||
trap->closure = NULL;
|
||||
if(!js_AddRoot(cx, &trap->closure, "trap->closure")) {
|
||||
JS_free(cx, trap);
|
||||
cx->free(trap);
|
||||
return JS_FALSE;
|
||||
}
|
||||
DBG_LOCK(rt);
|
||||
@ -184,7 +184,7 @@ JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
|
||||
DBG_UNLOCK(rt);
|
||||
if (junk) {
|
||||
js_RemoveRoot(rt, &junk->closure);
|
||||
JS_free(cx, junk);
|
||||
cx->free(junk);
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
@ -213,7 +213,7 @@ DestroyTrapAndUnlock(JSContext *cx, JSTrap *trap)
|
||||
DBG_UNLOCK(cx->runtime);
|
||||
|
||||
js_RemoveRoot(cx->runtime, &trap->closure);
|
||||
JS_free(cx, trap);
|
||||
cx->free(trap);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
@ -413,7 +413,7 @@ DropWatchPointAndUnlock(JSContext *cx, JSWatchPoint *wp, uintN flag)
|
||||
}
|
||||
}
|
||||
|
||||
JS_free(cx, wp);
|
||||
cx->free(wp);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@ -619,7 +619,7 @@ js_watch_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
if (nslots <= JS_ARRAY_LENGTH(smallv)) {
|
||||
argv = smallv;
|
||||
} else {
|
||||
argv = (jsval *) JS_malloc(cx, nslots * sizeof(jsval));
|
||||
argv = (jsval *) cx->malloc(nslots * sizeof(jsval));
|
||||
if (!argv) {
|
||||
DBG_LOCK(rt);
|
||||
DropWatchPointAndUnlock(cx, wp, JSWP_HELD);
|
||||
@ -651,7 +651,7 @@ js_watch_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
JSFUN_HEAVYWEIGHT_TEST(fun->flags) &&
|
||||
!js_GetCallObject(cx, &frame)) {
|
||||
if (argv != smallv)
|
||||
JS_free(cx, argv);
|
||||
cx->free(argv);
|
||||
DBG_LOCK(rt);
|
||||
DropWatchPointAndUnlock(cx, wp, JSWP_HELD);
|
||||
return JS_FALSE;
|
||||
@ -679,7 +679,7 @@ js_watch_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
|
||||
cx->fp = frame.down;
|
||||
if (argv != smallv)
|
||||
JS_free(cx, argv);
|
||||
cx->free(argv);
|
||||
}
|
||||
}
|
||||
DBG_LOCK(rt);
|
||||
@ -825,7 +825,7 @@ JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsval idval,
|
||||
goto out;
|
||||
}
|
||||
|
||||
wp = (JSWatchPoint *) JS_malloc(cx, sizeof *wp);
|
||||
wp = (JSWatchPoint *) cx->malloc(sizeof *wp);
|
||||
if (!wp) {
|
||||
ok = JS_FALSE;
|
||||
goto out;
|
||||
@ -1343,7 +1343,7 @@ JS_EvaluateInStackFrame(JSContext *cx, JSStackFrame *fp,
|
||||
length = (uintN) len;
|
||||
ok = JS_EvaluateUCInStackFrame(cx, fp, chars, length, filename, lineno,
|
||||
rval);
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
|
||||
return ok;
|
||||
}
|
||||
@ -1469,7 +1469,7 @@ JS_GetPropertyDescArray(JSContext *cx, JSObject *obj, JSPropertyDescArray *pda)
|
||||
}
|
||||
|
||||
n = scope->entryCount;
|
||||
pd = (JSPropertyDesc *) JS_malloc(cx, (size_t)n * sizeof(JSPropertyDesc));
|
||||
pd = (JSPropertyDesc *) cx->malloc((size_t)n * sizeof(JSPropertyDesc));
|
||||
if (!pd)
|
||||
return JS_FALSE;
|
||||
i = 0;
|
||||
@ -1511,7 +1511,7 @@ JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda)
|
||||
if (pd[i].flags & JSPD_ALIAS)
|
||||
js_RemoveRoot(cx->runtime, &pd[i].alias);
|
||||
}
|
||||
JS_free(cx, pd);
|
||||
cx->free(pd);
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
@ -1884,7 +1884,7 @@ js_DumpCallgrind(JSContext *cx, JSObject *obj,
|
||||
cstr = js_DeflateString(cx, str->chars(), str->length());
|
||||
if (cstr) {
|
||||
CALLGRIND_DUMP_STATS_AT(cstr);
|
||||
JS_free(cx, cstr);
|
||||
cx->free(cstr);
|
||||
return JS_TRUE;
|
||||
}
|
||||
}
|
||||
@ -1962,7 +1962,7 @@ js_StartVtune(JSContext *cx, JSObject *obj,
|
||||
status = VTStartSampling(¶ms);
|
||||
|
||||
if (params.tb5Filename != default_filename)
|
||||
JS_free(cx, params.tb5Filename);
|
||||
cx->free(params.tb5Filename);
|
||||
|
||||
if (status != 0) {
|
||||
if (status == VTAPI_MULTIPLE_RUNS)
|
||||
|
@ -111,13 +111,13 @@
|
||||
JS_PUBLIC_API(void *)
|
||||
JS_DHashAllocTable(JSDHashTable *table, uint32 nbytes)
|
||||
{
|
||||
return malloc(nbytes);
|
||||
return js_malloc(nbytes);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
JS_DHashFreeTable(JSDHashTable *table, void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
js_free(ptr);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSDHashNumber)
|
||||
@ -180,7 +180,7 @@ JS_DHashFreeStringKey(JSDHashTable *table, JSDHashEntryHdr *entry)
|
||||
{
|
||||
const JSDHashEntryStub *stub = (const JSDHashEntryStub *)entry;
|
||||
|
||||
free((void *) stub->key);
|
||||
js_free((void *) stub->key);
|
||||
memset(entry, 0, table->entrySize);
|
||||
}
|
||||
|
||||
@ -212,11 +212,11 @@ JS_NewDHashTable(const JSDHashTableOps *ops, void *data, uint32 entrySize,
|
||||
{
|
||||
JSDHashTable *table;
|
||||
|
||||
table = (JSDHashTable *) malloc(sizeof *table);
|
||||
table = (JSDHashTable *) js_malloc(sizeof *table);
|
||||
if (!table)
|
||||
return NULL;
|
||||
if (!JS_DHashTableInit(table, ops, data, entrySize, capacity)) {
|
||||
free(table);
|
||||
js_free(table);
|
||||
return NULL;
|
||||
}
|
||||
return table;
|
||||
@ -226,7 +226,7 @@ JS_PUBLIC_API(void)
|
||||
JS_DHashTableDestroy(JSDHashTable *table)
|
||||
{
|
||||
JS_DHashTableFinish(table);
|
||||
free(table);
|
||||
js_free(table);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
|
@ -368,7 +368,7 @@ JS_dtobasestr(int base, double dinput)
|
||||
JS_ASSERT(base >= 2 && base <= 36);
|
||||
|
||||
dval(d) = dinput;
|
||||
buffer = (char*) malloc(DTOBASESTR_BUFFER_SIZE);
|
||||
buffer = (char*) js_malloc(DTOBASESTR_BUFFER_SIZE);
|
||||
if (buffer) {
|
||||
p = buffer;
|
||||
if (dval(d) < 0.0
|
||||
@ -412,7 +412,7 @@ JS_dtobasestr(int base, double dinput)
|
||||
nomem1:
|
||||
Bfree(b);
|
||||
UNLOCK_DTOA();
|
||||
free(buffer);
|
||||
js_free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
do {
|
||||
@ -449,7 +449,7 @@ JS_dtobasestr(int base, double dinput)
|
||||
Bfree(mlo);
|
||||
Bfree(mhi);
|
||||
UNLOCK_DTOA();
|
||||
free(buffer);
|
||||
js_free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
JS_ASSERT(e < 0);
|
||||
|
@ -112,10 +112,10 @@ JSCodeGenerator::~JSCodeGenerator()
|
||||
|
||||
/* NB: non-null only after OOM. */
|
||||
if (spanDeps)
|
||||
JS_free(compiler->context, spanDeps);
|
||||
compiler->context->free(spanDeps);
|
||||
|
||||
if (upvarMap.vector)
|
||||
JS_free(compiler->context, upvarMap.vector);
|
||||
compiler->context->free(upvarMap.vector);
|
||||
}
|
||||
|
||||
static ptrdiff_t
|
||||
@ -549,7 +549,7 @@ AddSpanDep(JSContext *cx, JSCodeGenerator *cg, jsbytecode *pc, jsbytecode *pc2,
|
||||
if ((index & (index - 1)) == 0 &&
|
||||
(!(sdbase = cg->spanDeps) || index >= SPANDEPS_MIN)) {
|
||||
size = sdbase ? SPANDEPS_SIZE(index) : SPANDEPS_SIZE_MIN / 2;
|
||||
sdbase = (JSSpanDep *) JS_realloc(cx, sdbase, size + size);
|
||||
sdbase = (JSSpanDep *) cx->realloc(sdbase, size + size);
|
||||
if (!sdbase)
|
||||
return JS_FALSE;
|
||||
cg->spanDeps = sdbase;
|
||||
@ -1165,7 +1165,7 @@ OptimizeSpanDeps(JSContext *cx, JSCodeGenerator *cg)
|
||||
* can span top-level statements, because JS lacks goto.
|
||||
*/
|
||||
size = SPANDEPS_SIZE(JS_BIT(JS_CeilingLog2(cg->numSpanDeps)));
|
||||
JS_free(cx, cg->spanDeps);
|
||||
cx->free(cg->spanDeps);
|
||||
cg->spanDeps = NULL;
|
||||
FreeJumpTargets(cg, cg->jumpTargets);
|
||||
cg->jumpTargets = NULL;
|
||||
@ -1899,7 +1899,7 @@ MakeUpvarForEval(JSParseNode *pn, JSCodeGenerator *cg)
|
||||
JS_ASSERT(ALE_INDEX(ale) <= length);
|
||||
if (ALE_INDEX(ale) == length) {
|
||||
length = 2 * JS_MAX(2, length);
|
||||
vector = (uint32 *) JS_realloc(cx, vector, length * sizeof *vector);
|
||||
vector = (uint32 *) cx->realloc(vector, length * sizeof *vector);
|
||||
if (!vector)
|
||||
return false;
|
||||
cg->upvarMap.vector = vector;
|
||||
@ -2197,7 +2197,7 @@ BindNameToSlot(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
|
||||
if (!vector) {
|
||||
uint32 length = cg->lexdeps.count;
|
||||
|
||||
vector = (uint32 *) calloc(length, sizeof *vector);
|
||||
vector = (uint32 *) js_calloc(length * sizeof *vector);
|
||||
if (!vector) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return JS_FALSE;
|
||||
@ -3144,9 +3144,8 @@ EmitSwitch(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn,
|
||||
/* Just grab 8K for the worst-case bitmap. */
|
||||
intmap_bitlen = JS_BIT(16);
|
||||
intmap = (jsbitmap *)
|
||||
JS_malloc(cx,
|
||||
(JS_BIT(16) >> JS_BITS_PER_WORD_LOG2)
|
||||
* sizeof(jsbitmap));
|
||||
cx->malloc((JS_BIT(16) >> JS_BITS_PER_WORD_LOG2)
|
||||
* sizeof(jsbitmap));
|
||||
if (!intmap) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return JS_FALSE;
|
||||
@ -3163,7 +3162,7 @@ EmitSwitch(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn,
|
||||
|
||||
release:
|
||||
if (intmap && intmap != intmap_space)
|
||||
JS_free(cx, intmap);
|
||||
cx->free(intmap);
|
||||
if (!ok)
|
||||
return JS_FALSE;
|
||||
|
||||
@ -3307,7 +3306,7 @@ EmitSwitch(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn,
|
||||
*/
|
||||
if (tableLength != 0) {
|
||||
tableSize = (size_t)tableLength * sizeof *table;
|
||||
table = (JSParseNode **) JS_malloc(cx, tableSize);
|
||||
table = (JSParseNode **) cx->malloc(tableSize);
|
||||
if (!table)
|
||||
return JS_FALSE;
|
||||
memset(table, 0, tableSize);
|
||||
@ -3475,7 +3474,7 @@ EmitSwitch(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn,
|
||||
|
||||
out:
|
||||
if (table)
|
||||
JS_free(cx, table);
|
||||
cx->free(table);
|
||||
if (ok) {
|
||||
ok = js_PopStatementCG(cx, cg);
|
||||
|
||||
|
@ -164,7 +164,7 @@ CopyErrorReport(JSContext *cx, JSErrorReport *report)
|
||||
*/
|
||||
mallocSize = sizeof(JSErrorReport) + argsArraySize + argsCopySize +
|
||||
ucmessageSize + uclinebufSize + linebufSize + filenameSize;
|
||||
cursor = (uint8 *)JS_malloc(cx, mallocSize);
|
||||
cursor = (uint8 *)cx->malloc(mallocSize);
|
||||
if (!cursor)
|
||||
return NULL;
|
||||
|
||||
@ -301,7 +301,7 @@ InitExnPrivate(JSContext *cx, JSObject *exnObject, JSString *message,
|
||||
js_ReportAllocationOverflow(cx);
|
||||
return JS_FALSE;
|
||||
}
|
||||
priv = (JSExnPrivate *)JS_malloc(cx, size);
|
||||
priv = (JSExnPrivate *)cx->malloc(size);
|
||||
if (!priv)
|
||||
return JS_FALSE;
|
||||
|
||||
@ -417,8 +417,8 @@ exn_finalize(JSContext *cx, JSObject *obj)
|
||||
priv = GetExnPrivate(cx, obj);
|
||||
if (priv) {
|
||||
if (priv->errorReport)
|
||||
JS_free(cx, priv->errorReport);
|
||||
JS_free(cx, priv);
|
||||
cx->free(priv->errorReport);
|
||||
cx->free(priv);
|
||||
}
|
||||
}
|
||||
|
||||
@ -586,7 +586,7 @@ StackTraceToString(JSContext *cx, JSExnPrivate *priv)
|
||||
if (stackmax >= STACK_LENGTH_LIMIT) \
|
||||
goto done; \
|
||||
stackmax = stackmax ? 2 * stackmax : 64; \
|
||||
ptr_ = JS_realloc(cx, stackbuf, (stackmax+1) * sizeof(jschar)); \
|
||||
ptr_ = cx->realloc(stackbuf, (stackmax+1) * sizeof(jschar)); \
|
||||
if (!ptr_) \
|
||||
goto bad; \
|
||||
stackbuf = (jschar *) ptr_; \
|
||||
@ -608,7 +608,7 @@ StackTraceToString(JSContext *cx, JSExnPrivate *priv)
|
||||
goto done; \
|
||||
} \
|
||||
stackmax = JS_BIT(JS_CeilingLog2(stacklen + length_)); \
|
||||
ptr_ = JS_realloc(cx, stackbuf, (stackmax+1) * sizeof(jschar)); \
|
||||
ptr_ = cx->realloc(stackbuf, (stackmax+1) * sizeof(jschar)); \
|
||||
if (!ptr_) \
|
||||
goto bad; \
|
||||
stackbuf = (jschar *) ptr_; \
|
||||
@ -659,7 +659,7 @@ StackTraceToString(JSContext *cx, JSExnPrivate *priv)
|
||||
* don't use JS_realloc here; simply let the oversized allocation
|
||||
* be owned by the string in that rare case.
|
||||
*/
|
||||
void *shrunk = JS_realloc(cx, stackbuf, (stacklen+1) * sizeof(jschar));
|
||||
void *shrunk = cx->realloc(stackbuf, (stacklen+1) * sizeof(jschar));
|
||||
if (shrunk)
|
||||
stackbuf = (jschar *) shrunk;
|
||||
}
|
||||
@ -671,7 +671,7 @@ StackTraceToString(JSContext *cx, JSExnPrivate *priv)
|
||||
|
||||
bad:
|
||||
if (stackbuf)
|
||||
JS_free(cx, stackbuf);
|
||||
cx->free(stackbuf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -800,7 +800,7 @@ exn_toString(JSContext *cx, uintN argc, jsval *vp)
|
||||
name_length = name->length();
|
||||
message_length = message->length();
|
||||
length = (name_length ? name_length + 2 : 0) + message_length;
|
||||
cp = chars = (jschar *) JS_malloc(cx, (length + 1) * sizeof(jschar));
|
||||
cp = chars = (jschar *) cx->malloc((length + 1) * sizeof(jschar));
|
||||
if (!chars)
|
||||
return JS_FALSE;
|
||||
|
||||
@ -815,7 +815,7 @@ exn_toString(JSContext *cx, uintN argc, jsval *vp)
|
||||
|
||||
result = js_NewString(cx, chars, length);
|
||||
if (!result) {
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
return JS_FALSE;
|
||||
}
|
||||
} else {
|
||||
@ -915,7 +915,7 @@ exn_toSource(JSContext *cx, uintN argc, jsval *vp)
|
||||
}
|
||||
}
|
||||
|
||||
cp = chars = (jschar *) JS_malloc(cx, (length + 1) * sizeof(jschar));
|
||||
cp = chars = (jschar *) cx->malloc((length + 1) * sizeof(jschar));
|
||||
if (!chars) {
|
||||
ok = JS_FALSE;
|
||||
goto out;
|
||||
@ -955,7 +955,7 @@ exn_toSource(JSContext *cx, uintN argc, jsval *vp)
|
||||
|
||||
result = js_NewString(cx, chars, length);
|
||||
if (!result) {
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
ok = JS_FALSE;
|
||||
goto out;
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ static char*
|
||||
js_combinePath(JSContext *cx, const char *base, const char *name)
|
||||
{
|
||||
int len = strlen(base);
|
||||
char* result = JS_malloc(cx, len + strlen(name) + 2);
|
||||
char* result = cx->malloc(len + strlen(name) + 2);
|
||||
|
||||
if (!result)
|
||||
return NULL;
|
||||
@ -335,7 +335,7 @@ js_fileBaseName(JSContext *cx, const char *pathname)
|
||||
}
|
||||
|
||||
/* Allocate and copy. */
|
||||
result = JS_malloc(cx, aux - index + 1);
|
||||
result = cx->malloc(aux - index + 1);
|
||||
if (!result)
|
||||
return NULL;
|
||||
strncpy(result, pathname + index + 1, aux - index);
|
||||
@ -366,7 +366,7 @@ js_fileDirectoryName(JSContext *cx, const char *pathname)
|
||||
|
||||
if (cp < pathname && end != pathname) {
|
||||
/* There were just /s, return the root. */
|
||||
result = JS_malloc(cx, 1 + 1); /* The separator + trailing NUL. */
|
||||
result = cx->malloc(1 + 1); /* The separator + trailing NUL. */
|
||||
result[0] = FILESEPARATOR;
|
||||
result[1] = '\0';
|
||||
return result;
|
||||
@ -388,7 +388,7 @@ js_fileDirectoryName(JSContext *cx, const char *pathname)
|
||||
}
|
||||
|
||||
pathsize = end - pathname + 1;
|
||||
result = JS_malloc(cx, pathsize + 1);
|
||||
result = cx->malloc(pathsize + 1);
|
||||
if (!result)
|
||||
return NULL;
|
||||
|
||||
@ -401,7 +401,7 @@ js_fileDirectoryName(JSContext *cx, const char *pathname)
|
||||
|
||||
/* Return everything up to and including the seperator. */
|
||||
pathsize = cp - pathname + 1;
|
||||
result = JS_malloc(cx, pathsize + 1);
|
||||
result = cx->malloc(pathsize + 1);
|
||||
if (!result)
|
||||
return NULL;
|
||||
|
||||
@ -462,7 +462,7 @@ js_canonicalPath(JSContext *cx, char *oldpath)
|
||||
while (j >= 0 && path[j] == ' ')
|
||||
j--;
|
||||
|
||||
tmp = JS_malloc(cx, j-i+2);
|
||||
tmp = cx->malloc(j-i+2);
|
||||
if (!tmp)
|
||||
return NULL;
|
||||
|
||||
@ -478,7 +478,7 @@ js_canonicalPath(JSContext *cx, char *oldpath)
|
||||
/* file:// support. */
|
||||
if (!strncmp(path, URL_PREFIX, strlen(URL_PREFIX))) {
|
||||
tmp = js_canonicalPath(cx, path + strlen(URL_PREFIX));
|
||||
JS_free(cx, path);
|
||||
cx->free(path);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@ -486,7 +486,7 @@ js_canonicalPath(JSContext *cx, char *oldpath)
|
||||
tmp = js_absolutePath(cx, path);
|
||||
if (!tmp)
|
||||
return NULL;
|
||||
JS_free(cx, path);
|
||||
cx->free(path);
|
||||
path = tmp;
|
||||
}
|
||||
|
||||
@ -505,7 +505,7 @@ js_canonicalPath(JSContext *cx, char *oldpath)
|
||||
back--;
|
||||
} else {
|
||||
tmp = result;
|
||||
result = JS_malloc(cx, strlen(base) + 1 + strlen(tmp) + 1);
|
||||
result = cx->malloc(strlen(base) + 1 + strlen(tmp) + 1);
|
||||
if (!result)
|
||||
goto out;
|
||||
|
||||
@ -516,18 +516,18 @@ js_canonicalPath(JSContext *cx, char *oldpath)
|
||||
result[c + 1] = '\0';
|
||||
strcat(result, tmp);
|
||||
}
|
||||
JS_free(cx, tmp);
|
||||
cx->free(tmp);
|
||||
}
|
||||
}
|
||||
JS_free(cx, current);
|
||||
JS_free(cx, base);
|
||||
cx->free(current);
|
||||
cx->free(base);
|
||||
current = dir;
|
||||
base = js_fileBaseName(cx, current);
|
||||
dir = js_fileDirectoryName(cx, current);
|
||||
}
|
||||
|
||||
tmp = result;
|
||||
result = JS_malloc(cx, strlen(dir)+1+strlen(tmp)+1);
|
||||
result = cx->malloc(strlen(dir) + 1 + strlen(tmp) + 1);
|
||||
if (!result)
|
||||
goto out;
|
||||
|
||||
@ -543,13 +543,13 @@ js_canonicalPath(JSContext *cx, char *oldpath)
|
||||
|
||||
out:
|
||||
if (tmp)
|
||||
JS_free(cx, tmp);
|
||||
cx->free(tmp);
|
||||
if (dir)
|
||||
JS_free(cx, dir);
|
||||
cx->free(dir);
|
||||
if (base)
|
||||
JS_free(cx, base);
|
||||
cx->free(base);
|
||||
if (current)
|
||||
JS_free(cx, current);
|
||||
cx->free(current);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -753,7 +753,7 @@ js_FileHasOption(JSContext *cx, const char *oldoptions, const char *name)
|
||||
break;
|
||||
current = comma + 1;
|
||||
}
|
||||
JS_free(cx, options);
|
||||
cx->free(options);
|
||||
return found;
|
||||
}
|
||||
|
||||
@ -838,20 +838,20 @@ js_FileRead(JSContext *cx, JSFile *file, jschar *buf, int32 len, int32 mode)
|
||||
|
||||
switch (mode) {
|
||||
case ASCII:
|
||||
aux = (unsigned char*)JS_malloc(cx, len);
|
||||
aux = (unsigned char*)cx->malloc(len);
|
||||
if (!aux)
|
||||
return 0;
|
||||
|
||||
count = js_BufferedRead(file, aux, len);
|
||||
if (count == -1) {
|
||||
JS_free(cx, aux);
|
||||
cx->free(aux);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
buf[i] = (jschar)aux[i];
|
||||
|
||||
JS_free(cx, aux);
|
||||
cx->free(aux);
|
||||
break;
|
||||
|
||||
case UTF8:
|
||||
@ -977,7 +977,7 @@ js_FileWrite(JSContext *cx, JSFile *file, jschar *buf, int32 len, int32 mode)
|
||||
|
||||
switch (mode) {
|
||||
case ASCII:
|
||||
aux = (unsigned char*)JS_malloc(cx, len);
|
||||
aux = (unsigned char*)cx->malloc(len);
|
||||
if (!aux)
|
||||
return 0;
|
||||
|
||||
@ -989,21 +989,21 @@ js_FileWrite(JSContext *cx, JSFile *file, jschar *buf, int32 len, int32 mode)
|
||||
: fwrite(aux, 1, len, file->nativehandle);
|
||||
|
||||
if (count==-1) {
|
||||
JS_free(cx, aux);
|
||||
cx->free(aux);
|
||||
return 0;
|
||||
}
|
||||
|
||||
JS_free(cx, aux);
|
||||
cx->free(aux);
|
||||
break;
|
||||
|
||||
case UTF8:
|
||||
utfbuf = (unsigned char*)JS_malloc(cx, len*3);
|
||||
utfbuf = (unsigned char*)cx->malloc(len*3);
|
||||
if (!utfbuf) return 0;
|
||||
i = 0;
|
||||
for (count = 0;count<len;count++) {
|
||||
j = one_ucs2_to_utf8_char(utfbuf+i, utfbuf+len*3, buf[count]);
|
||||
if (j==-1) {
|
||||
JS_free(cx, utfbuf);
|
||||
cx->free(utfbuf);
|
||||
return 0;
|
||||
}
|
||||
i+=j;
|
||||
@ -1013,10 +1013,10 @@ js_FileWrite(JSContext *cx, JSFile *file, jschar *buf, int32 len, int32 mode)
|
||||
: fwrite(utfbuf, 1, i, file->nativehandle);
|
||||
|
||||
if (j<i) {
|
||||
JS_free(cx, utfbuf);
|
||||
cx->free(utfbuf);
|
||||
return 0;
|
||||
}
|
||||
JS_free(cx, utfbuf);
|
||||
cx->free(utfbuf);
|
||||
break;
|
||||
|
||||
case UCS2:
|
||||
@ -1179,13 +1179,13 @@ js_parent(JSContext *cx, JSFile *file, jsval *resultp)
|
||||
} else {
|
||||
JSObject *obj = js_NewFileObject(cx, str);
|
||||
if (!obj) {
|
||||
JS_free(cx, str);
|
||||
cx->free(str);
|
||||
return JS_FALSE;
|
||||
}
|
||||
*resultp = OBJECT_TO_JSVAL(obj);
|
||||
}
|
||||
|
||||
JS_free(cx, str);
|
||||
cx->free(str);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
@ -1206,7 +1206,7 @@ js_name(JSContext *cx, JSFile *file, jsval *vp)
|
||||
|
||||
str = JS_NewString(cx, name, strlen(name));
|
||||
if (!str) {
|
||||
JS_free(cx, name);
|
||||
cx->free(name);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@ -1353,7 +1353,7 @@ file_open(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
pipemode[i++] = '\0';
|
||||
file->nativehandle = POPEN(&file->path[1], pipemode);
|
||||
} else if(file->path[len-1] == PIPE_SYMBOL) {
|
||||
char *command = JS_malloc(cx, len);
|
||||
char *command = cx->malloc(len);
|
||||
|
||||
strncpy(command, file->path, len-1);
|
||||
command[len-1] = '\0';
|
||||
@ -1364,7 +1364,7 @@ file_open(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
#endif
|
||||
pipemode[i++] = '\0';
|
||||
file->nativehandle = POPEN(command, pipemode);
|
||||
JS_free(cx, command);
|
||||
cx->free(command);
|
||||
}
|
||||
/* set the flags */
|
||||
file->isNative = JS_TRUE;
|
||||
@ -1377,7 +1377,7 @@ file_open(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
}
|
||||
|
||||
js_ResetBuffers(file);
|
||||
JS_free(cx, mode);
|
||||
cx->free(mode);
|
||||
mode = NULL;
|
||||
|
||||
/* Set the open flag and return result */
|
||||
@ -1396,7 +1396,7 @@ good:
|
||||
|
||||
out:
|
||||
if(mode)
|
||||
JS_free(cx, mode);
|
||||
cx->free(mode);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@ -1511,13 +1511,13 @@ file_copyTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
goto out;
|
||||
}
|
||||
|
||||
buffer = JS_malloc(cx, size);
|
||||
buffer = cx->malloc(size);
|
||||
|
||||
count = INT_TO_JSVAL(PR_Read(file->handle, buffer, size));
|
||||
|
||||
/* reading panic */
|
||||
if (count!=size) {
|
||||
JS_free(cx, buffer);
|
||||
cx->free(buffer);
|
||||
JS_ReportErrorNumber(cx, JSFile_GetErrorMessage, NULL,
|
||||
JSFILEMSG_COPY_READ_ERROR, file->path);
|
||||
goto out;
|
||||
@ -1527,13 +1527,13 @@ file_copyTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
|
||||
/* writing panic */
|
||||
if (count!=size) {
|
||||
JS_free(cx, buffer);
|
||||
cx->free(buffer);
|
||||
JS_ReportErrorNumber(cx, JSFile_GetErrorMessage, NULL,
|
||||
JSFILEMSG_COPY_WRITE_ERROR, file->path);
|
||||
goto out;
|
||||
}
|
||||
|
||||
JS_free(cx, buffer);
|
||||
cx->free(buffer);
|
||||
|
||||
if(!fileInitiallyOpen){
|
||||
if(!file_close(cx, obj, 0, NULL, rval)) goto out;
|
||||
@ -1577,7 +1577,7 @@ file_renameTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval
|
||||
|
||||
if (PR_Rename(file->path, dest)==PR_SUCCESS){
|
||||
/* copy the new filename */
|
||||
JS_free(cx, file->path);
|
||||
cx->free(file->path);
|
||||
file->path = dest;
|
||||
*rval = JSVAL_TRUE;
|
||||
return JS_TRUE;
|
||||
@ -1729,17 +1729,17 @@ file_read(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
|
||||
/* want = (want>262144)?262144:want; * arbitrary size limitation */
|
||||
|
||||
buf = JS_malloc(cx, want*sizeof buf[0]);
|
||||
buf = cx->malloc(want*sizeof buf[0]);
|
||||
if (!buf) goto out;
|
||||
|
||||
count = js_FileRead(cx, file, buf, want, file->type);
|
||||
if (count>0) {
|
||||
str = JS_NewUCStringCopyN(cx, buf, count);
|
||||
*rval = STRING_TO_JSVAL(str);
|
||||
JS_free(cx, buf);
|
||||
cx->free(buf);
|
||||
return JS_TRUE;
|
||||
} else {
|
||||
JS_free(cx, buf);
|
||||
cx->free(buf);
|
||||
goto out;
|
||||
}
|
||||
out:
|
||||
@ -1760,7 +1760,7 @@ file_readln(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
SECURITY_CHECK(cx, NULL, "readln", file);
|
||||
JSFILE_CHECK_READ;
|
||||
|
||||
buf = JS_malloc(cx, MAX_LINE_LENGTH * sizeof data);
|
||||
buf = cx->malloc(MAX_LINE_LENGTH * sizeof data);
|
||||
if (!buf)
|
||||
return JS_FALSE;
|
||||
|
||||
@ -1792,8 +1792,7 @@ file_readln(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
|
||||
default:
|
||||
if (--room < 0) {
|
||||
tmp = JS_realloc(cx, buf,
|
||||
(offset + MAX_LINE_LENGTH) * sizeof data);
|
||||
tmp = cx->realloc(buf, (offset + MAX_LINE_LENGTH) * sizeof data);
|
||||
if (!tmp)
|
||||
goto out;
|
||||
|
||||
@ -1814,7 +1813,7 @@ eof:
|
||||
|
||||
done:
|
||||
buf[offset] = 0;
|
||||
tmp = JS_realloc(cx, buf, (offset + 1) * sizeof data);
|
||||
tmp = cx->realloc(buf, (offset + 1) * sizeof data);
|
||||
if (!tmp)
|
||||
goto out;
|
||||
|
||||
@ -1827,7 +1826,7 @@ done:
|
||||
|
||||
out:
|
||||
if (buf)
|
||||
JS_free(cx, buf);
|
||||
cx->free(buf);
|
||||
|
||||
return JS_FALSE;
|
||||
}
|
||||
@ -1980,7 +1979,7 @@ file_list(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
filePath = js_combinePath(cx, file->path, (char*)entry->name);
|
||||
|
||||
eachFile = js_NewFileObject(cx, filePath);
|
||||
JS_free(cx, filePath);
|
||||
cx->free(filePath);
|
||||
if (!eachFile){
|
||||
JS_ReportWarning(cx, "File %s cannot be retrieved", filePath);
|
||||
continue;
|
||||
@ -2017,7 +2016,7 @@ file_mkdir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
char *dir = js_fileDirectoryName(cx, file->path);
|
||||
JSObject *dirObj = js_NewFileObject(cx, dir);
|
||||
|
||||
JS_free(cx, dir);
|
||||
cx->free(dir);
|
||||
|
||||
/* call file_mkdir with the right set of parameters if needed */
|
||||
if (file_mkdir(cx, dirObj, argc, argv, rval))
|
||||
@ -2031,12 +2030,12 @@ file_mkdir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
fullName = js_combinePath(cx, file->path, dirName);
|
||||
if (PR_MkDir(fullName, 0755)==PR_SUCCESS){
|
||||
*rval = JSVAL_TRUE;
|
||||
JS_free(cx, fullName);
|
||||
cx->free(fullName);
|
||||
return JS_TRUE;
|
||||
}else{
|
||||
JS_ReportErrorNumber(cx, JSFile_GetErrorMessage, NULL,
|
||||
JSFILEMSG_OP_FAILED, "mkdir", fullName);
|
||||
JS_free(cx, fullName);
|
||||
cx->free(fullName);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
@ -2077,7 +2076,7 @@ file_toURL(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
return JS_FALSE;
|
||||
str = js_NewString(cx, urlChars, len);
|
||||
if (!str) {
|
||||
JS_free(cx, urlChars);
|
||||
cx->free(urlChars);
|
||||
return JS_FALSE;
|
||||
}
|
||||
*rval = STRING_TO_JSVAL(str);
|
||||
@ -2104,9 +2103,9 @@ file_finalize(JSContext *cx, JSObject *obj)
|
||||
}
|
||||
|
||||
if (file->path)
|
||||
JS_free(cx, file->path);
|
||||
cx->free(file->path);
|
||||
|
||||
JS_free(cx, file);
|
||||
cx->free(file);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2118,7 +2117,7 @@ file_init(JSContext *cx, JSObject *obj, char *bytes)
|
||||
{
|
||||
JSFile *file;
|
||||
|
||||
file = JS_malloc(cx, sizeof *file);
|
||||
file = cx->malloc(sizeof *file);
|
||||
if (!file)
|
||||
return NULL;
|
||||
memset(file, 0 , sizeof *file);
|
||||
@ -2130,7 +2129,7 @@ file_init(JSContext *cx, JSObject *obj, char *bytes)
|
||||
if (!JS_SetPrivate(cx, obj, file)) {
|
||||
JS_ReportErrorNumber(cx, JSFile_GetErrorMessage, NULL,
|
||||
JSFILEMSG_CANNOT_SET_PRIVATE_FILE, file->path);
|
||||
JS_free(cx, file);
|
||||
cx->free(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -2176,7 +2175,7 @@ js_NewFileObjectFromFILE(JSContext *cx, FILE *nativehandle, char *filename,
|
||||
|
||||
/* free result of RESOLVE_PATH from file_init. */
|
||||
JS_ASSERT(file->path != NULL);
|
||||
JS_free(cx, file->path);
|
||||
cx->free(file->path);
|
||||
|
||||
file->path = strdup(filename);
|
||||
file->isOpen = open;
|
||||
@ -2399,7 +2398,7 @@ file_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
case FILE_MODE:
|
||||
SECURITY_CHECK(cx, NULL, "mode", file);
|
||||
JSFILE_CHECK_OPEN("mode");
|
||||
bytes = JS_malloc(cx, MODE_SIZE);
|
||||
bytes = cx->malloc(MODE_SIZE);
|
||||
bytes[0] = '\0';
|
||||
flag = JS_FALSE;
|
||||
|
||||
@ -2439,7 +2438,7 @@ file_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
flag = JS_TRUE;
|
||||
}
|
||||
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, bytes));
|
||||
JS_free(cx, bytes);
|
||||
cx->free(bytes);
|
||||
break;
|
||||
case FILE_CREATED:
|
||||
SECURITY_CHECK(cx, NULL, "creationTime", file);
|
||||
@ -2575,7 +2574,7 @@ file_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
bytes = js_combinePath(cx, file->path, prop_name);
|
||||
*vp = OBJECT_TO_JSVAL(js_NewFileObject(cx, bytes));
|
||||
PR_CloseDir(dir);
|
||||
JS_free(cx, bytes);
|
||||
cx->free(bytes);
|
||||
return !JSVAL_IS_NULL(*vp);
|
||||
}
|
||||
}
|
||||
@ -2717,10 +2716,10 @@ js_InitFileClass(JSContext *cx, JSObject* obj)
|
||||
/* Define CURRENTDIR property. We are doing this to get a
|
||||
slash at the end of the current dir */
|
||||
afile = js_NewFileObject(cx, CURRENT_DIR);
|
||||
currentdir = JS_malloc(cx, MAX_PATH_LENGTH);
|
||||
currentdir = getcwd(currentdir, MAX_PATH_LENGTH);
|
||||
currentdir = cx->malloc(MAX_PATH_LENGTH);
|
||||
currentdir = getcwd(currentdir, MAX_PATH_LENGTH);
|
||||
afile = js_NewFileObject(cx, currentdir);
|
||||
JS_free(cx, currentdir);
|
||||
cx->free(currentdir);
|
||||
vp = OBJECT_TO_JSVAL(afile);
|
||||
JS_DefinePropertyWithTinyId(cx, ctor, CURRENTDIR_PROPERTY, 0, vp,
|
||||
JS_PropertyStub, file_currentDirSetter,
|
||||
|
@ -136,7 +136,7 @@ MarkArgDeleted(JSContext *cx, JSStackFrame *fp, uintN slot)
|
||||
bitmap = (jsbitmap *) &bmapint;
|
||||
} else {
|
||||
nbytes = JS_HOWMANY(nbits, JS_BITS_PER_WORD) * sizeof(jsbitmap);
|
||||
bitmap = (jsbitmap *) JS_malloc(cx, nbytes);
|
||||
bitmap = (jsbitmap *) cx->malloc(nbytes);
|
||||
if (!bitmap)
|
||||
return JS_FALSE;
|
||||
memset(bitmap, 0, nbytes);
|
||||
@ -311,7 +311,7 @@ js_PutArgsObject(JSContext *cx, JSStackFrame *fp)
|
||||
if (!JSVAL_IS_VOID(bmapval)) {
|
||||
JS_SetReservedSlot(cx, argsobj, 0, JSVAL_VOID);
|
||||
if (fp->argc > JSVAL_INT_BITS)
|
||||
JS_free(cx, JSVAL_TO_PRIVATE(bmapval));
|
||||
cx->free(JSVAL_TO_PRIVATE(bmapval));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -2758,10 +2758,10 @@ FreeLocalNameHash(JSContext *cx, JSLocalNameMap *map)
|
||||
|
||||
for (dup = map->lastdup; dup; dup = next) {
|
||||
next = dup->link;
|
||||
JS_free(cx, dup);
|
||||
cx->free(dup);
|
||||
}
|
||||
JS_DHashTableFinish(&map->names);
|
||||
JS_free(cx, map);
|
||||
cx->free(map);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
@ -2789,7 +2789,7 @@ HashLocalName(JSContext *cx, JSLocalNameMap *map, JSAtom *name,
|
||||
if (entry->name) {
|
||||
JS_ASSERT(entry->name == name);
|
||||
JS_ASSERT(entry->localKind == JSLOCAL_ARG);
|
||||
dup = (JSNameIndexPair *) JS_malloc(cx, sizeof *dup);
|
||||
dup = (JSNameIndexPair *) cx->malloc(sizeof *dup);
|
||||
if (!dup)
|
||||
return JS_FALSE;
|
||||
dup->name = entry->name;
|
||||
@ -2835,7 +2835,7 @@ js_AddLocal(JSContext *cx, JSFunction *fun, JSAtom *atom, JSLocalKind kind)
|
||||
if (n > 1) {
|
||||
array = fun->u.i.names.array;
|
||||
} else {
|
||||
array = (jsuword *) JS_malloc(cx, MAX_ARRAY_LOCALS * sizeof *array);
|
||||
array = (jsuword *) cx->malloc(MAX_ARRAY_LOCALS * sizeof *array);
|
||||
if (!array)
|
||||
return JS_FALSE;
|
||||
array[0] = fun->u.i.names.taggedAtom;
|
||||
@ -2860,7 +2860,7 @@ js_AddLocal(JSContext *cx, JSFunction *fun, JSAtom *atom, JSLocalKind kind)
|
||||
}
|
||||
} else if (n == MAX_ARRAY_LOCALS) {
|
||||
array = fun->u.i.names.array;
|
||||
map = (JSLocalNameMap *) JS_malloc(cx, sizeof *map);
|
||||
map = (JSLocalNameMap *) cx->malloc(sizeof *map);
|
||||
if (!map)
|
||||
return JS_FALSE;
|
||||
if (!JS_DHashTableInit(&map->names, JS_DHashGetStubOps(),
|
||||
@ -2868,7 +2868,7 @@ js_AddLocal(JSContext *cx, JSFunction *fun, JSAtom *atom, JSLocalKind kind)
|
||||
JS_DHASH_DEFAULT_CAPACITY(MAX_ARRAY_LOCALS
|
||||
* 2))) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
JS_free(cx, map);
|
||||
cx->free(map);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@ -2901,7 +2901,7 @@ js_AddLocal(JSContext *cx, JSFunction *fun, JSAtom *atom, JSLocalKind kind)
|
||||
* to replace fun->u.i.names with the built map.
|
||||
*/
|
||||
fun->u.i.names.map = map;
|
||||
JS_free(cx, array);
|
||||
cx->free(array);
|
||||
} else {
|
||||
if (*indexp == JS_BITMASK(16)) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
@ -3123,7 +3123,7 @@ DestroyLocalNames(JSContext *cx, JSFunction *fun)
|
||||
if (n <= 1)
|
||||
return;
|
||||
if (n <= MAX_ARRAY_LOCALS)
|
||||
JS_free(cx, fun->u.i.names.array);
|
||||
cx->free(fun->u.i.names.array);
|
||||
else
|
||||
FreeLocalNameHash(cx, fun->u.i.names.map);
|
||||
}
|
||||
@ -3139,8 +3139,8 @@ js_FreezeLocalNames(JSContext *cx, JSFunction *fun)
|
||||
n = fun->nargs + fun->u.i.nvars + fun->u.i.nupvars;
|
||||
if (2 <= n && n < MAX_ARRAY_LOCALS) {
|
||||
/* Shrink over-allocated array ignoring realloc failures. */
|
||||
array = (jsuword *) JS_realloc(cx, fun->u.i.names.array,
|
||||
n * sizeof *array);
|
||||
array = (jsuword *) cx->realloc(fun->u.i.names.array,
|
||||
n * sizeof *array);
|
||||
if (array)
|
||||
fun->u.i.names.array = array;
|
||||
}
|
||||
|
@ -76,6 +76,7 @@
|
||||
#include "jsscript.h"
|
||||
#include "jsstaticcheck.h"
|
||||
#include "jsstr.h"
|
||||
#include "jstask.h"
|
||||
#include "jstracer.h"
|
||||
|
||||
#if JS_HAS_XML_SUPPORT
|
||||
@ -722,7 +723,7 @@ FreePtrTable(JSPtrTable *table, const JSPtrTableInfo *info)
|
||||
{
|
||||
if (table->array) {
|
||||
JS_ASSERT(table->count > 0);
|
||||
free(table->array);
|
||||
js_free(table->array);
|
||||
table->array = NULL;
|
||||
table->count = 0;
|
||||
}
|
||||
@ -756,8 +757,8 @@ AddToPtrTable(JSContext *cx, JSPtrTable *table, const JSPtrTableInfo *info,
|
||||
if (capacity > (size_t)-1 / sizeof table->array[0])
|
||||
goto bad;
|
||||
}
|
||||
array = (void **) realloc(table->array,
|
||||
capacity * sizeof table->array[0]);
|
||||
array = (void **) js_realloc(table->array,
|
||||
capacity * sizeof table->array[0]);
|
||||
if (!array)
|
||||
goto bad;
|
||||
#ifdef DEBUG
|
||||
@ -796,11 +797,11 @@ ShrinkPtrTable(JSPtrTable *table, const JSPtrTableInfo *info,
|
||||
array = table->array;
|
||||
JS_ASSERT(array);
|
||||
if (capacity == 0) {
|
||||
free(array);
|
||||
js_free(array);
|
||||
table->array = NULL;
|
||||
return;
|
||||
}
|
||||
array = (void **) realloc(array, capacity * sizeof array[0]);
|
||||
array = (void **) js_realloc(array, capacity * sizeof array[0]);
|
||||
if (array)
|
||||
table->array = array;
|
||||
}
|
||||
@ -881,7 +882,7 @@ NewGCChunk(void)
|
||||
*
|
||||
* bytes to ensure that we always have room to store the gap.
|
||||
*/
|
||||
p = malloc((js_gcArenasPerChunk + 1) << GC_ARENA_SHIFT);
|
||||
p = js_malloc((js_gcArenasPerChunk + 1) << GC_ARENA_SHIFT);
|
||||
if (!p)
|
||||
return 0;
|
||||
|
||||
@ -913,11 +914,11 @@ DestroyGCChunk(jsuword chunk)
|
||||
#endif
|
||||
|
||||
#if HAS_POSIX_MEMALIGN
|
||||
free((void *) chunk);
|
||||
js_free((void *) chunk);
|
||||
#else
|
||||
/* See comments in NewGCChunk. */
|
||||
JS_ASSERT(*GetMallocedChunkGapPtr(chunk) < GC_ARENA_SIZE);
|
||||
free((void *) (chunk - *GetMallocedChunkGapPtr(chunk)));
|
||||
js_free((void *) (chunk - *GetMallocedChunkGapPtr(chunk)));
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -3270,7 +3271,10 @@ js_FinalizeStringRT(JSRuntime *rt, JSString *str, intN type, JSContext *cx)
|
||||
JS_ASSERT(type < 0);
|
||||
rt->unitStrings[*chars] = NULL;
|
||||
} else if (type < 0) {
|
||||
free(chars);
|
||||
if (cx)
|
||||
cx->free(chars);
|
||||
else
|
||||
rt->free(chars);
|
||||
} else {
|
||||
JS_ASSERT((uintN) type < JS_ARRAY_LENGTH(str_finalizers));
|
||||
finalizer = str_finalizers[type];
|
||||
@ -3556,6 +3560,10 @@ js_GC(JSContext *cx, JSGCInvocationKind gckind)
|
||||
|
||||
rt->gcMarkingTracer = NULL;
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
cx->createDeallocatorTask();
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Sweep phase.
|
||||
*
|
||||
@ -3734,6 +3742,10 @@ js_GC(JSContext *cx, JSGCInvocationKind gckind)
|
||||
*/
|
||||
DestroyGCArenas(rt, emptyArenas);
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
cx->submitDeallocatorTask();
|
||||
#endif
|
||||
|
||||
if (rt->gcCallback)
|
||||
(void) rt->gcCallback(cx, JSGC_FINALIZE_END);
|
||||
#ifdef DEBUG_srcnotesize
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include "jsdhash.h"
|
||||
#include "jsbit.h"
|
||||
#include "jsutil.h"
|
||||
#include "jstask.h"
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
@ -341,6 +342,28 @@ js_AddAsGCBytes(JSContext *cx, size_t sz);
|
||||
extern void
|
||||
js_RemoveAsGCBytes(JSRuntime* rt, size_t sz);
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
class JSFreePointerListTask : public JSBackgroundTask {
|
||||
void *head;
|
||||
public:
|
||||
JSFreePointerListTask() : head(NULL) {}
|
||||
|
||||
void add(void* ptr) {
|
||||
*(void**)ptr = head;
|
||||
head = ptr;
|
||||
}
|
||||
|
||||
void run() {
|
||||
void *ptr = head;
|
||||
while (ptr) {
|
||||
void *next = *(void **)ptr;
|
||||
js_free(ptr);
|
||||
ptr = next;
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Free the chars held by str when it is finalized by the GC. When type is
|
||||
* less then zero, it denotes an internal string. Otherwise it denotes the
|
||||
|
@ -73,7 +73,7 @@ DefaultAllocTable(void *pool, size_t size)
|
||||
static void
|
||||
DefaultFreeTable(void *pool, void *item, size_t size)
|
||||
{
|
||||
free(item);
|
||||
js_free(item);
|
||||
}
|
||||
|
||||
static JSHashEntry *
|
||||
@ -86,7 +86,7 @@ static void
|
||||
DefaultFreeEntry(void *pool, JSHashEntry *he, uintN flag)
|
||||
{
|
||||
if (flag == HT_FREE_ENTRY)
|
||||
free(he);
|
||||
js_free(he);
|
||||
}
|
||||
|
||||
static JSHashAllocOps defaultHashAllocOps = {
|
||||
|
@ -2145,7 +2145,7 @@ js_TraceOpcode(JSContext *cx)
|
||||
fprintf(tracefp, "%s %s",
|
||||
(n == -ndefs) ? " output:" : ",",
|
||||
bytes);
|
||||
JS_free(cx, bytes);
|
||||
cx->free(bytes);
|
||||
}
|
||||
}
|
||||
fprintf(tracefp, " @ %u\n", (uintN) (regs->sp - StackBase(fp)));
|
||||
@ -2177,7 +2177,7 @@ js_TraceOpcode(JSContext *cx)
|
||||
fprintf(tracefp, "%s %s",
|
||||
(n == -nuses) ? " inputs:" : ",",
|
||||
bytes);
|
||||
JS_free(cx, bytes);
|
||||
cx->free(bytes);
|
||||
}
|
||||
}
|
||||
fprintf(tracefp, " @ %u\n", (uintN) (regs->sp - StackBase(fp)));
|
||||
@ -2264,7 +2264,7 @@ js_DumpOpMeters()
|
||||
|
||||
# define SIGNIFICANT(count,total) (200. * (count) >= (total))
|
||||
|
||||
graph = (Edge *) calloc(nedges, sizeof graph[0]);
|
||||
graph = (Edge *) js_calloc(nedges * sizeof graph[0]);
|
||||
for (i = nedges = 0; i < JSOP_LIMIT; i++) {
|
||||
from = js_CodeName[i];
|
||||
for (j = 0; j < JSOP_LIMIT; j++) {
|
||||
@ -2293,7 +2293,7 @@ js_DumpOpMeters()
|
||||
graph[i].from, graph[i].to,
|
||||
(unsigned long)graph[i].count, style);
|
||||
}
|
||||
free(graph);
|
||||
js_free(graph);
|
||||
fputs("}\n", fp);
|
||||
fclose(fp);
|
||||
|
||||
|
@ -649,7 +649,7 @@ generator_finalize(JSContext *cx, JSObject *obj)
|
||||
*/
|
||||
JS_ASSERT(gen->state == JSGEN_NEWBORN || gen->state == JSGEN_CLOSED ||
|
||||
gen->state == JSGEN_OPEN);
|
||||
JS_free(cx, gen);
|
||||
cx->free(gen);
|
||||
}
|
||||
}
|
||||
|
||||
@ -716,7 +716,7 @@ js_NewGenerator(JSContext *cx, JSStackFrame *fp)
|
||||
|
||||
/* Allocate obj's private data struct. */
|
||||
gen = (JSGenerator *)
|
||||
JS_malloc(cx, sizeof(JSGenerator) + (nslots - 1) * sizeof(jsval));
|
||||
cx->malloc(sizeof(JSGenerator) + (nslots - 1) * sizeof(jsval));
|
||||
if (!gen)
|
||||
goto bad;
|
||||
|
||||
@ -783,7 +783,7 @@ js_NewGenerator(JSContext *cx, JSStackFrame *fp)
|
||||
gen->state = JSGEN_NEWBORN;
|
||||
|
||||
if (!JS_SetPrivate(cx, obj, gen)) {
|
||||
JS_free(cx, gen);
|
||||
cx->free(gen);
|
||||
goto bad;
|
||||
}
|
||||
return obj;
|
||||
|
@ -896,7 +896,7 @@ DestroyFatlock(JSFatLock *fl)
|
||||
{
|
||||
PR_DestroyLock(fl->slock);
|
||||
PR_DestroyCondVar(fl->svar);
|
||||
free(fl);
|
||||
js_free(fl);
|
||||
}
|
||||
|
||||
static JSFatLock *
|
||||
@ -990,7 +990,7 @@ js_SetupLocks(int listc, int globc)
|
||||
global_locks_log2 = JS_CeilingLog2(globc);
|
||||
global_locks_mask = JS_BITMASK(global_locks_log2);
|
||||
global_lock_count = JS_BIT(global_locks_log2);
|
||||
global_locks = (PRLock **) malloc(global_lock_count * sizeof(PRLock*));
|
||||
global_locks = (PRLock **) js_malloc(global_lock_count * sizeof(PRLock*));
|
||||
if (!global_locks)
|
||||
return JS_FALSE;
|
||||
for (i = 0; i < global_lock_count; i++) {
|
||||
@ -1001,7 +1001,7 @@ js_SetupLocks(int listc, int globc)
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
fl_list_table = (JSFatLockTable *) malloc(i * sizeof(JSFatLockTable));
|
||||
fl_list_table = (JSFatLockTable *) js_malloc(i * sizeof(JSFatLockTable));
|
||||
if (!fl_list_table) {
|
||||
js_CleanupLocks();
|
||||
return JS_FALSE;
|
||||
@ -1023,7 +1023,7 @@ js_CleanupLocks()
|
||||
if (global_locks) {
|
||||
for (i = 0; i < global_lock_count; i++)
|
||||
PR_DestroyLock(global_locks[i]);
|
||||
free(global_locks);
|
||||
js_free(global_locks);
|
||||
global_locks = NULL;
|
||||
global_lock_count = 1;
|
||||
global_locks_log2 = 0;
|
||||
@ -1036,7 +1036,7 @@ js_CleanupLocks()
|
||||
DeleteListOfFatlocks(fl_list_table[i].taken);
|
||||
fl_list_table[i].taken = NULL;
|
||||
}
|
||||
free(fl_list_table);
|
||||
js_free(fl_list_table);
|
||||
fl_list_table = NULL;
|
||||
fl_list_table_len = 0;
|
||||
}
|
||||
|
@ -384,7 +384,7 @@ num_toString(JSContext *cx, uintN argc, jsval *vp)
|
||||
return JS_FALSE;
|
||||
}
|
||||
str = JS_NewStringCopyZ(cx, dStr);
|
||||
free(dStr);
|
||||
js_free(dStr);
|
||||
}
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
@ -460,7 +460,7 @@ num_toLocaleString(JSContext *cx, uintN argc, jsval *vp)
|
||||
}
|
||||
tmpGroup--;
|
||||
|
||||
buf = (char *)JS_malloc(cx, size + 1);
|
||||
buf = (char *)cx->malloc(size + 1);
|
||||
if (!buf)
|
||||
return JS_FALSE;
|
||||
|
||||
@ -492,7 +492,7 @@ num_toLocaleString(JSContext *cx, uintN argc, jsval *vp)
|
||||
|
||||
str = JS_NewString(cx, buf, size);
|
||||
if (!str) {
|
||||
JS_free(cx, buf);
|
||||
cx->free(buf);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@ -739,9 +739,9 @@ js_FinishRuntimeNumberState(JSContext *cx)
|
||||
rt->jsNegativeInfinity = NULL;
|
||||
rt->jsPositiveInfinity = NULL;
|
||||
|
||||
JS_free(cx, (void *)rt->thousandsSeparator);
|
||||
JS_free(cx, (void *)rt->decimalSeparator);
|
||||
JS_free(cx, (void *)rt->numGrouping);
|
||||
cx->free((void *)rt->thousandsSeparator);
|
||||
cx->free((void *)rt->decimalSeparator);
|
||||
cx->free((void *)rt->numGrouping);
|
||||
rt->thousandsSeparator = rt->decimalSeparator = rt->numGrouping = NULL;
|
||||
}
|
||||
|
||||
@ -852,7 +852,7 @@ NumberToStringWithBase(JSContext *cx, jsdouble d, jsint base)
|
||||
return NULL;
|
||||
s = JS_NewStringCopyZ(cx, numStr);
|
||||
if (!(numStr >= buf && numStr < buf + sizeof buf))
|
||||
free(numStr);
|
||||
js_free(numStr);
|
||||
return s;
|
||||
}
|
||||
|
||||
@ -1251,7 +1251,7 @@ js_strtod(JSContext *cx, const jschar *s, const jschar *send,
|
||||
|
||||
/* Use cbuf to avoid malloc */
|
||||
if (length >= sizeof cbuf) {
|
||||
cstr = (char *) JS_malloc(cx, length + 1);
|
||||
cstr = (char *) cx->malloc(length + 1);
|
||||
if (!cstr)
|
||||
return JS_FALSE;
|
||||
} else {
|
||||
@ -1292,7 +1292,7 @@ js_strtod(JSContext *cx, const jschar *s, const jschar *send,
|
||||
|
||||
i = estr - cstr;
|
||||
if (cstr != cbuf)
|
||||
JS_free(cx, cstr);
|
||||
cx->free(cstr);
|
||||
*ep = i ? s1 + i : s;
|
||||
*dp = d;
|
||||
return JS_TRUE;
|
||||
@ -1405,7 +1405,7 @@ js_strtointeger(JSContext *cx, const jschar *s, const jschar *send,
|
||||
*/
|
||||
size_t i;
|
||||
size_t length = s1 - start;
|
||||
char *cstr = (char *) JS_malloc(cx, length + 1);
|
||||
char *cstr = (char *) cx->malloc(length + 1);
|
||||
char *estr;
|
||||
int err=0;
|
||||
|
||||
@ -1418,12 +1418,12 @@ js_strtointeger(JSContext *cx, const jschar *s, const jschar *send,
|
||||
value = JS_strtod(cstr, &estr, &err);
|
||||
if (err == JS_DTOA_ENOMEM) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
JS_free(cx, cstr);
|
||||
cx->free(cstr);
|
||||
return JS_FALSE;
|
||||
}
|
||||
if (err == JS_DTOA_ERANGE && value == HUGE_VAL)
|
||||
value = *cx->runtime->jsPositiveInfinity;
|
||||
JS_free(cx, cstr);
|
||||
cx->free(cstr);
|
||||
} else if ((base & (base - 1)) == 0) {
|
||||
/*
|
||||
* The number may also be inaccurate for power-of-two bases. This
|
||||
|
@ -560,7 +560,7 @@ out:
|
||||
ida = JS_Enumerate(cx, obj);
|
||||
if (!ida) {
|
||||
if (*sp) {
|
||||
JS_free(cx, *sp);
|
||||
cx->free(*sp);
|
||||
*sp = NULL;
|
||||
}
|
||||
goto bad;
|
||||
@ -704,7 +704,7 @@ obj_toSource(JSContext *cx, uintN argc, jsval *vp)
|
||||
|
||||
if (!chars) {
|
||||
/* If outermost, allocate 4 + 1 for "({})" and the terminator. */
|
||||
chars = (jschar *) malloc(((outermost ? 4 : 2) + 1) * sizeof(jschar));
|
||||
chars = (jschar *) js_malloc(((outermost ? 4 : 2) + 1) * sizeof(jschar));
|
||||
nchars = 0;
|
||||
if (!chars)
|
||||
goto error;
|
||||
@ -715,9 +715,9 @@ obj_toSource(JSContext *cx, uintN argc, jsval *vp)
|
||||
MAKE_SHARP(he);
|
||||
nchars = js_strlen(chars);
|
||||
chars = (jschar *)
|
||||
realloc((ochars = chars), (nchars + 2 + 1) * sizeof(jschar));
|
||||
js_realloc((ochars = chars), (nchars + 2 + 1) * sizeof(jschar));
|
||||
if (!chars) {
|
||||
free(ochars);
|
||||
js_free(ochars);
|
||||
goto error;
|
||||
}
|
||||
if (outermost) {
|
||||
@ -958,11 +958,11 @@ obj_toSource(JSContext *cx, uintN argc, jsval *vp)
|
||||
|
||||
/* Allocate 1 + 1 at end for closing brace and terminating 0. */
|
||||
chars = (jschar *)
|
||||
realloc((ochars = chars), curlen * sizeof(jschar));
|
||||
js_realloc((ochars = chars), curlen * sizeof(jschar));
|
||||
if (!chars) {
|
||||
/* Save code space on error: let JS_free ignore null vsharp. */
|
||||
JS_free(cx, vsharp);
|
||||
free(ochars);
|
||||
cx->free(vsharp);
|
||||
js_free(ochars);
|
||||
goto error;
|
||||
}
|
||||
|
||||
@ -1005,7 +1005,7 @@ obj_toSource(JSContext *cx, uintN argc, jsval *vp)
|
||||
nchars += vlength;
|
||||
|
||||
if (vsharp)
|
||||
JS_free(cx, vsharp);
|
||||
cx->free(vsharp);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1019,7 +1019,7 @@ obj_toSource(JSContext *cx, uintN argc, jsval *vp)
|
||||
|
||||
if (!ok) {
|
||||
if (chars)
|
||||
free(chars);
|
||||
js_free(chars);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -1031,7 +1031,7 @@ obj_toSource(JSContext *cx, uintN argc, jsval *vp)
|
||||
make_string:
|
||||
str = js_NewString(cx, chars, nchars);
|
||||
if (!str) {
|
||||
free(chars);
|
||||
js_free(chars);
|
||||
ok = JS_FALSE;
|
||||
goto out;
|
||||
}
|
||||
@ -1042,8 +1042,8 @@ obj_toSource(JSContext *cx, uintN argc, jsval *vp)
|
||||
return ok;
|
||||
|
||||
overflow:
|
||||
JS_free(cx, vsharp);
|
||||
free(chars);
|
||||
cx->free(vsharp);
|
||||
js_free(chars);
|
||||
chars = NULL;
|
||||
goto error;
|
||||
}
|
||||
@ -1064,7 +1064,7 @@ obj_toString(JSContext *cx, uintN argc, jsval *vp)
|
||||
obj = js_GetWrappedObject(cx, obj);
|
||||
clazz = OBJ_GET_CLASS(cx, obj)->name;
|
||||
nchars = 9 + strlen(clazz); /* 9 for "[object ]" */
|
||||
chars = (jschar *) JS_malloc(cx, (nchars + 1) * sizeof(jschar));
|
||||
chars = (jschar *) cx->malloc((nchars + 1) * sizeof(jschar));
|
||||
if (!chars)
|
||||
return JS_FALSE;
|
||||
|
||||
@ -1079,7 +1079,7 @@ obj_toString(JSContext *cx, uintN argc, jsval *vp)
|
||||
|
||||
str = js_NewString(cx, chars, nchars);
|
||||
if (!str) {
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
return JS_FALSE;
|
||||
}
|
||||
*vp = STRING_TO_JSVAL(str);
|
||||
@ -2986,7 +2986,7 @@ AllocSlots(JSContext *cx, JSObject *obj, size_t nslots)
|
||||
JS_ASSERT(nslots > JS_INITIAL_NSLOTS);
|
||||
|
||||
jsval* slots;
|
||||
slots = (jsval*) JS_malloc(cx, SLOTS_TO_DYNAMIC_WORDS(nslots) * sizeof(jsval));
|
||||
slots = (jsval*) cx->malloc(SLOTS_TO_DYNAMIC_WORDS(nslots) * sizeof(jsval));
|
||||
if (!slots)
|
||||
return true;
|
||||
|
||||
@ -3044,7 +3044,7 @@ js_GrowSlots(JSContext *cx, JSObject *obj, size_t nslots)
|
||||
|
||||
size_t oslots = size_t(slots[-1]);
|
||||
|
||||
slots = (jsval*) JS_realloc(cx, slots - 1, nwords * sizeof(jsval));
|
||||
slots = (jsval*) cx->realloc(slots - 1, nwords * sizeof(jsval));
|
||||
*slots++ = nslots;
|
||||
obj->dslots = slots;
|
||||
|
||||
@ -3069,11 +3069,11 @@ js_ShrinkSlots(JSContext *cx, JSObject *obj, size_t nslots)
|
||||
JS_ASSERT(nslots <= size_t(slots[-1]));
|
||||
|
||||
if (nslots <= JS_INITIAL_NSLOTS) {
|
||||
JS_free(cx, slots - 1);
|
||||
cx->free(slots - 1);
|
||||
obj->dslots = NULL;
|
||||
} else {
|
||||
size_t nwords = SLOTS_TO_DYNAMIC_WORDS(nslots);
|
||||
slots = (jsval*) JS_realloc(cx, slots - 1, nwords * sizeof(jsval));
|
||||
slots = (jsval*) cx->realloc(slots - 1, nwords * sizeof(jsval));
|
||||
*slots++ = nslots;
|
||||
obj->dslots = slots;
|
||||
}
|
||||
@ -4965,7 +4965,7 @@ js_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
|
||||
}
|
||||
|
||||
allocated = NativeEnumeratorSize(length);
|
||||
ne = (JSNativeEnumerator *) JS_malloc(cx, allocated);
|
||||
ne = (JSNativeEnumerator *) cx->malloc(allocated);
|
||||
if (!ne) {
|
||||
JS_UNLOCK_SCOPE(cx, scope);
|
||||
return JS_FALSE;
|
||||
@ -4997,7 +4997,7 @@ js_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
|
||||
JS_LOCK_GC(cx->runtime);
|
||||
if (!js_AddAsGCBytes(cx, allocated)) {
|
||||
/* js_AddAsGCBytes releases the GC lock on failures. */
|
||||
JS_free(cx, ne);
|
||||
cx->free(ne);
|
||||
return JS_FALSE;
|
||||
}
|
||||
ne->next = cx->runtime->nativeEnumerators;
|
||||
@ -5090,7 +5090,7 @@ js_TraceNativeEnumerators(JSTracer *trc)
|
||||
} else if (doGC) {
|
||||
js_RemoveAsGCBytes(rt, NativeEnumeratorSize(ne->length));
|
||||
*nep = ne->next;
|
||||
JS_free(trc->context, ne);
|
||||
trc->context->free(ne);
|
||||
continue;
|
||||
}
|
||||
nep = &ne->next;
|
||||
|
@ -38,7 +38,7 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <string.h> /* memset */
|
||||
#include <string.h>
|
||||
#include "jsapi.h"
|
||||
#include "jsarena.h"
|
||||
#include "jsarray.h"
|
||||
@ -740,10 +740,9 @@ js_BeginJSONParse(JSContext *cx, jsval *rootVal)
|
||||
if (!arr)
|
||||
return NULL;
|
||||
|
||||
JSONParser *jp = (JSONParser*) JS_malloc(cx, sizeof(JSONParser));
|
||||
JSONParser *jp = (JSONParser*) cx->calloc(sizeof(JSONParser));
|
||||
if (!jp)
|
||||
return NULL;
|
||||
memset(jp, 0, sizeof *jp);
|
||||
|
||||
jp->objectStack = arr;
|
||||
if (!js_AddRoot(cx, &jp->objectStack, "JSON parse stack"))
|
||||
@ -798,7 +797,7 @@ js_FinishJSONParse(JSContext *cx, JSONParser *jp, jsval reviver)
|
||||
|
||||
JSBool ok = *jp->statep == JSON_PARSE_STATE_FINISHED;
|
||||
jsval *vp = jp->rootVal;
|
||||
JS_free(cx, jp);
|
||||
cx->free(jp);
|
||||
|
||||
if (!early_ok)
|
||||
return JS_FALSE;
|
||||
|
@ -604,7 +604,7 @@ Sprint(Sprinter *sp, const char *format, ...)
|
||||
return -1;
|
||||
}
|
||||
offset = SprintCString(sp, bp);
|
||||
free(bp);
|
||||
js_free(bp);
|
||||
return offset;
|
||||
}
|
||||
|
||||
@ -737,7 +737,7 @@ JS_NEW_PRINTER(JSContext *cx, const char *name, JSFunction *fun,
|
||||
{
|
||||
JSPrinter *jp;
|
||||
|
||||
jp = (JSPrinter *) JS_malloc(cx, sizeof(JSPrinter));
|
||||
jp = (JSPrinter *) cx->malloc(sizeof(JSPrinter));
|
||||
if (!jp)
|
||||
return NULL;
|
||||
INIT_SPRINTER(cx, &jp->sprinter, &jp->pool, 0);
|
||||
@ -764,7 +764,7 @@ void
|
||||
js_DestroyPrinter(JSPrinter *jp)
|
||||
{
|
||||
JS_FinishArenaPool(&jp->pool);
|
||||
JS_free(jp->sprinter.context, jp);
|
||||
jp->sprinter.context->free(jp);
|
||||
}
|
||||
|
||||
JSString *
|
||||
@ -832,7 +832,7 @@ js_printf(JSPrinter *jp, const char *format, ...)
|
||||
/* Allocate temp space, convert format, and put. */
|
||||
bp = JS_vsmprintf(format, ap); /* XXX vsaprintf */
|
||||
if (fp) {
|
||||
JS_free(jp->sprinter.context, fp);
|
||||
jp->sprinter.context->free(fp);
|
||||
format = NULL;
|
||||
}
|
||||
if (!bp) {
|
||||
@ -843,7 +843,7 @@ js_printf(JSPrinter *jp, const char *format, ...)
|
||||
cc = strlen(bp);
|
||||
if (SprintPut(&jp->sprinter, bp, (size_t)cc) < 0)
|
||||
cc = -1;
|
||||
free(bp);
|
||||
js_free(bp);
|
||||
|
||||
va_end(ap);
|
||||
return cc;
|
||||
@ -929,7 +929,7 @@ GetOff(SprintStack *ss, uintN i)
|
||||
if (off < 0)
|
||||
off = 0;
|
||||
ss->offsets[i] = off;
|
||||
JS_free(ss->sprinter.context, bytes);
|
||||
ss->sprinter.context->free(bytes);
|
||||
return off;
|
||||
}
|
||||
if (!ss->sprinter.base && SprintPut(&ss->sprinter, "", 0) >= 0) {
|
||||
@ -2508,14 +2508,14 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
||||
len = 0;
|
||||
|
||||
if (!Decompile(ss, done, pc - done, JSOP_POP)) {
|
||||
JS_free(cx, (char *)lval);
|
||||
cx->free((char *)lval);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Pop Decompile result and print comma expression. */
|
||||
rval = POP_STR();
|
||||
todo = Sprint(&ss->sprinter, "%s, %s", lval, rval);
|
||||
JS_free(cx, (char *)lval);
|
||||
cx->free((char *)lval);
|
||||
break;
|
||||
|
||||
case SRC_HIDDEN:
|
||||
@ -2547,7 +2547,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
||||
/* Set saveop to reflect what we will push. */
|
||||
saveop = JSOP_LEAVEBLOCKEXPR;
|
||||
if (!Decompile(ss, pc, len, saveop)) {
|
||||
JS_free(cx, (char *)lval);
|
||||
cx->free((char *)lval);
|
||||
return NULL;
|
||||
}
|
||||
rval = PopStr(ss, JSOP_SETNAME);
|
||||
@ -2556,7 +2556,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
||||
? "let (%s) (%s)"
|
||||
: "let (%s) %s",
|
||||
lval, rval);
|
||||
JS_free(cx, (char *)lval);
|
||||
cx->free((char *)lval);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -2620,7 +2620,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
||||
if ((size_t)argc <= JS_ARRAY_LENGTH(smallv)) {
|
||||
atomv = smallv;
|
||||
} else {
|
||||
atomv = (JSAtom **) JS_malloc(cx, argc * sizeof(JSAtom *));
|
||||
atomv = (JSAtom **) cx->malloc(argc * sizeof(JSAtom *));
|
||||
if (!atomv)
|
||||
return NULL;
|
||||
}
|
||||
@ -2755,7 +2755,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
||||
#undef LOCAL_ASSERT_OUT
|
||||
enterblock_out:
|
||||
if (atomv != smallv)
|
||||
JS_free(cx, atomv);
|
||||
cx->free(atomv);
|
||||
if (!ok)
|
||||
return NULL;
|
||||
}
|
||||
@ -3280,7 +3280,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
||||
DECOMPILE_CODE(pc + oplen, len - oplen);
|
||||
lval = JS_strdup(cx, POP_STR());
|
||||
if (!lval) {
|
||||
JS_free(cx, (void *)xval);
|
||||
cx->free((void *)xval);
|
||||
return NULL;
|
||||
}
|
||||
pc += len;
|
||||
@ -3291,8 +3291,8 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
||||
rval = POP_STR();
|
||||
todo = Sprint(&ss->sprinter, "%s ? %s : %s",
|
||||
xval, lval, rval);
|
||||
JS_free(cx, (void *)xval);
|
||||
JS_free(cx, (void *)lval);
|
||||
cx->free((void *)xval);
|
||||
cx->free((void *)lval);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -3319,7 +3319,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
||||
pc += len;
|
||||
len = done - pc;
|
||||
if (!Decompile(ss, pc, len, op)) {
|
||||
JS_free(cx, (char *)lval);
|
||||
cx->free((char *)lval);
|
||||
return NULL;
|
||||
}
|
||||
rval = POP_STR();
|
||||
@ -3332,14 +3332,14 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
||||
todo = Sprint(&ss->sprinter, "%s %s\n", lval, xval);
|
||||
tail = Sprint(&ss->sprinter, "%*s%s",
|
||||
jp->indent + 4, "", rval);
|
||||
JS_free(cx, (char *)rval);
|
||||
cx->free((char *)rval);
|
||||
}
|
||||
if (tail < 0)
|
||||
todo = -1;
|
||||
} else {
|
||||
todo = Sprint(&ss->sprinter, "%s %s %s", lval, xval, rval);
|
||||
}
|
||||
JS_free(cx, (char *)lval);
|
||||
cx->free((char *)lval);
|
||||
break;
|
||||
|
||||
case JSOP_AND:
|
||||
@ -3532,7 +3532,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
||||
#endif
|
||||
argc = GET_ARGC(pc);
|
||||
argv = (char **)
|
||||
JS_malloc(cx, (size_t)(argc + 1) * sizeof *argv);
|
||||
cx->malloc((size_t)(argc + 1) * sizeof *argv);
|
||||
if (!argv)
|
||||
return NULL;
|
||||
|
||||
@ -3590,8 +3590,8 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
||||
ok = JS_FALSE;
|
||||
|
||||
for (i = 0; i <= argc; i++)
|
||||
JS_free(cx, argv[i]);
|
||||
JS_free(cx, argv);
|
||||
cx->free(argv[i]);
|
||||
cx->free(argv);
|
||||
if (!ok)
|
||||
return NULL;
|
||||
#if JS_HAS_LVALUE_RETURN
|
||||
@ -4095,7 +4095,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
||||
if (!rval)
|
||||
return NULL;
|
||||
todo = SprintCString(&ss->sprinter, rval);
|
||||
JS_free(cx, (void *)rval);
|
||||
cx->free((void *)rval);
|
||||
break;
|
||||
}
|
||||
#endif /* JS_HAS_GENERATOR_EXPRS */
|
||||
@ -4166,7 +4166,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
||||
ok = JS_TRUE;
|
||||
} else {
|
||||
table = (TableEntry *)
|
||||
JS_malloc(cx, (size_t)n * sizeof *table);
|
||||
cx->malloc((size_t)n * sizeof *table);
|
||||
if (!table)
|
||||
return NULL;
|
||||
for (i = j = 0; i < n; i++) {
|
||||
@ -4186,12 +4186,12 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
||||
pc2 += jmplen;
|
||||
}
|
||||
tmp = (TableEntry *)
|
||||
JS_malloc(cx, (size_t)j * sizeof *table);
|
||||
cx->malloc((size_t)j * sizeof *table);
|
||||
if (tmp) {
|
||||
VOUCH_DOES_NOT_REQUIRE_STACK();
|
||||
ok = js_MergeSort(table, (size_t)j, sizeof(TableEntry),
|
||||
CompareOffsets, NULL, tmp);
|
||||
JS_free(cx, tmp);
|
||||
cx->free(tmp);
|
||||
} else {
|
||||
ok = JS_FALSE;
|
||||
}
|
||||
@ -4201,7 +4201,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
||||
ok = DecompileSwitch(ss, table, (uintN)j, pc, len, off,
|
||||
JS_FALSE);
|
||||
}
|
||||
JS_free(cx, table);
|
||||
cx->free(table);
|
||||
if (!ok)
|
||||
return NULL;
|
||||
todo = -2;
|
||||
@ -4227,7 +4227,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
||||
pc2 += UINT16_LEN;
|
||||
|
||||
table = (TableEntry *)
|
||||
JS_malloc(cx, (size_t)npairs * sizeof *table);
|
||||
cx->malloc((size_t)npairs * sizeof *table);
|
||||
if (!table)
|
||||
return NULL;
|
||||
for (k = 0; k < npairs; k++) {
|
||||
@ -4248,7 +4248,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
||||
|
||||
ok = DecompileSwitch(ss, table, (uintN)npairs, pc, len, off,
|
||||
JS_FALSE);
|
||||
JS_free(cx, table);
|
||||
cx->free(table);
|
||||
if (!ok)
|
||||
return NULL;
|
||||
todo = -2;
|
||||
@ -4292,7 +4292,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
||||
* and the distance to its statements in table[i].offset.
|
||||
*/
|
||||
table = (TableEntry *)
|
||||
JS_malloc(cx, (size_t)ncases * sizeof *table);
|
||||
cx->malloc((size_t)ncases * sizeof *table);
|
||||
if (!table)
|
||||
return NULL;
|
||||
pc2 = pc;
|
||||
@ -4322,7 +4322,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
||||
|
||||
ok = DecompileSwitch(ss, table, (uintN)ncases, pc, len, off,
|
||||
JS_TRUE);
|
||||
JS_free(cx, table);
|
||||
cx->free(table);
|
||||
if (!ok)
|
||||
return NULL;
|
||||
todo = -2;
|
||||
@ -4370,7 +4370,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
||||
break;
|
||||
}
|
||||
|
||||
argv = (char **) JS_malloc(cx, size_t(argc) * sizeof *argv);
|
||||
argv = (char **) cx->malloc(size_t(argc) * sizeof *argv);
|
||||
if (!argv)
|
||||
return NULL;
|
||||
|
||||
@ -4394,8 +4394,8 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
||||
}
|
||||
|
||||
for (i = 0; i < argc; i++)
|
||||
JS_free(cx, argv[i]);
|
||||
JS_free(cx, argv);
|
||||
cx->free(argv[i]);
|
||||
cx->free(argv);
|
||||
if (!ok)
|
||||
return NULL;
|
||||
|
||||
@ -4728,7 +4728,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
||||
(*rval == '\0' ||
|
||||
(SprintPut(&ss->sprinter, " ", 1) >= 0 &&
|
||||
SprintCString(&ss->sprinter, rval)));
|
||||
JS_free(cx, (char *)rval);
|
||||
cx->free((char *)rval);
|
||||
if (!ok)
|
||||
return NULL;
|
||||
SprintPut(&ss->sprinter, "?>", 2);
|
||||
@ -4836,7 +4836,7 @@ DecompileCode(JSPrinter *jp, JSScript *script, jsbytecode *pc, uintN len,
|
||||
|
||||
ok = Decompile(&ss, pc, len, JSOP_NOP) != NULL;
|
||||
if (code != oldcode) {
|
||||
JS_free(cx, jp->script->code);
|
||||
cx->free(jp->script->code);
|
||||
jp->script->code = oldcode;
|
||||
jp->script->main = oldmain;
|
||||
}
|
||||
@ -5055,7 +5055,7 @@ js_DecompileValueGenerator(JSContext *cx, intN spindex, jsval v,
|
||||
* populated interpreter's stack with its current content.
|
||||
*/
|
||||
pcstack = (jsbytecode **)
|
||||
JS_malloc(cx, StackDepth(script) * sizeof *pcstack);
|
||||
cx->malloc(StackDepth(script) * sizeof *pcstack);
|
||||
if (!pcstack)
|
||||
return NULL;
|
||||
pcdepth = ReconstructPCStack(cx, script, pc, pcstack);
|
||||
@ -5096,7 +5096,7 @@ js_DecompileValueGenerator(JSContext *cx, intN spindex, jsval v,
|
||||
}
|
||||
|
||||
release_pcstack:
|
||||
JS_free(cx, pcstack);
|
||||
cx->free(pcstack);
|
||||
if (pcdepth < 0)
|
||||
goto do_fallback;
|
||||
}
|
||||
@ -5232,7 +5232,7 @@ DecompileExpression(JSContext *cx, JSScript *script, JSFunction *fun,
|
||||
}
|
||||
|
||||
pcstack = (jsbytecode **)
|
||||
JS_malloc(cx, StackDepth(script) * sizeof *pcstack);
|
||||
cx->malloc(StackDepth(script) * sizeof *pcstack);
|
||||
if (!pcstack) {
|
||||
name = NULL;
|
||||
goto out;
|
||||
@ -5259,12 +5259,12 @@ DecompileExpression(JSContext *cx, JSScript *script, JSFunction *fun,
|
||||
|
||||
out:
|
||||
if (code != oldcode) {
|
||||
JS_free(cx, script->code);
|
||||
cx->free(script->code);
|
||||
script->code = oldcode;
|
||||
script->main = oldmain;
|
||||
}
|
||||
|
||||
JS_free(cx, pcstack);
|
||||
cx->free(pcstack);
|
||||
return name;
|
||||
}
|
||||
|
||||
@ -5339,7 +5339,7 @@ SimulateImacroCFG(JSContext *cx, JSScript *script,
|
||||
jsbytecode **pcstack)
|
||||
{
|
||||
size_t nbytes = StackDepth(script) * sizeof *pcstack;
|
||||
jsbytecode** tmp_pcstack = (jsbytecode **) JS_malloc(cx, nbytes);
|
||||
jsbytecode** tmp_pcstack = (jsbytecode **) cx->malloc(nbytes);
|
||||
if (!tmp_pcstack)
|
||||
return -1;
|
||||
memcpy(tmp_pcstack, pcstack, nbytes);
|
||||
@ -5379,11 +5379,11 @@ SimulateImacroCFG(JSContext *cx, JSScript *script,
|
||||
|
||||
success:
|
||||
memcpy(pcstack, tmp_pcstack, nbytes);
|
||||
JS_free(cx, tmp_pcstack);
|
||||
cx->free(tmp_pcstack);
|
||||
return pcdepth;
|
||||
|
||||
failure:
|
||||
JS_free(cx, tmp_pcstack);
|
||||
cx->free(tmp_pcstack);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -9036,12 +9036,12 @@ js_FoldConstants(JSContext *cx, JSParseNode *pn, JSTreeContext *tc, bool inCond)
|
||||
}
|
||||
|
||||
/* Allocate a new buffer and string descriptor for the result. */
|
||||
chars = (jschar *) JS_malloc(cx, (length + 1) * sizeof(jschar));
|
||||
chars = (jschar *) cx->malloc((length + 1) * sizeof(jschar));
|
||||
if (!chars)
|
||||
return JS_FALSE;
|
||||
str = js_NewString(cx, chars, length);
|
||||
if (!str) {
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
@ -412,7 +412,7 @@ static int cvt_ws(SprintfState *ss, const jschar *ws, int width, int prec,
|
||||
if (!s)
|
||||
return -1; /* JSStuffFunc error indicator. */
|
||||
result = cvt_s(ss, s, width, prec, flags);
|
||||
free(s);
|
||||
js_free(s);
|
||||
} else {
|
||||
result = cvt_s(ss, NULL, width, prec, flags);
|
||||
}
|
||||
@ -630,7 +630,7 @@ static struct NumArgState* BuildArgArray( const char *fmt, va_list ap, int* rv,
|
||||
|
||||
if( *rv < 0 ){
|
||||
if( nas != nasArray )
|
||||
free( nas );
|
||||
js_free( nas );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -667,7 +667,7 @@ static struct NumArgState* BuildArgArray( const char *fmt, va_list ap, int* rv,
|
||||
|
||||
default:
|
||||
if( nas != nasArray )
|
||||
free( nas );
|
||||
js_free( nas );
|
||||
*rv = -1;
|
||||
return NULL;
|
||||
}
|
||||
@ -756,7 +756,7 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
|
||||
|
||||
if( nas[i-1].type == TYPE_UNKNOWN ){
|
||||
if( nas && ( nas != nasArray ) )
|
||||
free( nas );
|
||||
js_free( nas );
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1037,7 +1037,7 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
|
||||
rv = (*ss->stuff)(ss, "\0", 1);
|
||||
|
||||
if( nas && ( nas != nasArray ) ){
|
||||
free( nas );
|
||||
js_free( nas );
|
||||
}
|
||||
|
||||
return rv;
|
||||
@ -1098,9 +1098,9 @@ static int GrowStuff(SprintfState *ss, const char *sp, JSUint32 len)
|
||||
/* Grow the buffer */
|
||||
newlen = ss->maxlen + ((len > 32) ? len : 32);
|
||||
if (ss->base) {
|
||||
newbase = (char*) realloc(ss->base, newlen);
|
||||
newbase = (char*) js_realloc(ss->base, newlen);
|
||||
} else {
|
||||
newbase = (char*) malloc(newlen);
|
||||
newbase = (char*) js_malloc(newlen);
|
||||
}
|
||||
if (!newbase) {
|
||||
/* Ran out of memory */
|
||||
@ -1139,7 +1139,7 @@ JS_PUBLIC_API(char *) JS_smprintf(const char *fmt, ...)
|
||||
*/
|
||||
JS_PUBLIC_API(void) JS_smprintf_free(char *mem)
|
||||
{
|
||||
free(mem);
|
||||
js_free(mem);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(char *) JS_vsmprintf(const char *fmt, va_list ap)
|
||||
@ -1154,7 +1154,7 @@ JS_PUBLIC_API(char *) JS_vsmprintf(const char *fmt, va_list ap)
|
||||
rv = dosprintf(&ss, fmt, ap);
|
||||
if (rv < 0) {
|
||||
if (ss.base) {
|
||||
free(ss.base);
|
||||
js_free(ss.base);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -1253,7 +1253,7 @@ JS_PUBLIC_API(char *) JS_vsprintf_append(char *last, const char *fmt, va_list ap
|
||||
rv = dosprintf(&ss, fmt, ap);
|
||||
if (rv < 0) {
|
||||
if (ss.base) {
|
||||
free(ss.base);
|
||||
js_free(ss.base);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -145,7 +145,6 @@ typedef struct JSObject JSObject;
|
||||
typedef struct JSObjectMap JSObjectMap;
|
||||
typedef struct JSObjectOps JSObjectOps;
|
||||
typedef struct JSRuntime JSRuntime;
|
||||
typedef struct JSRuntime JSTaskState; /* XXX deprecated name */
|
||||
typedef struct JSScript JSScript;
|
||||
typedef struct JSStackFrame JSStackFrame;
|
||||
typedef struct JSString JSString;
|
||||
|
@ -585,12 +585,12 @@ ParseRegExp(CompilerState *state)
|
||||
}
|
||||
|
||||
operatorStack = (REOpData *)
|
||||
JS_malloc(state->context, sizeof(REOpData) * operatorStackSize);
|
||||
state->context->malloc(sizeof(REOpData) * operatorStackSize);
|
||||
if (!operatorStack)
|
||||
return JS_FALSE;
|
||||
|
||||
operandStack = (RENode **)
|
||||
JS_malloc(state->context, sizeof(RENode *) * operandStackSize);
|
||||
state->context->malloc(sizeof(RENode *) * operandStackSize);
|
||||
if (!operandStack)
|
||||
goto out;
|
||||
|
||||
@ -682,8 +682,8 @@ pushOperand:
|
||||
RENode **tmp;
|
||||
operandStackSize += operandStackSize;
|
||||
tmp = (RENode **)
|
||||
JS_realloc(state->context, operandStack,
|
||||
sizeof(RENode *) * operandStackSize);
|
||||
state->context->realloc(operandStack,
|
||||
sizeof(RENode *) * operandStackSize);
|
||||
if (!tmp)
|
||||
goto out;
|
||||
operandStack = tmp;
|
||||
@ -817,8 +817,8 @@ pushOperator:
|
||||
REOpData *tmp;
|
||||
operatorStackSize += operatorStackSize;
|
||||
tmp = (REOpData *)
|
||||
JS_realloc(state->context, operatorStack,
|
||||
sizeof(REOpData) * operatorStackSize);
|
||||
state->context->realloc(operatorStack,
|
||||
sizeof(REOpData) * operatorStackSize);
|
||||
if (!tmp)
|
||||
goto out;
|
||||
operatorStack = tmp;
|
||||
@ -831,9 +831,9 @@ pushOperator:
|
||||
}
|
||||
out:
|
||||
if (operatorStack)
|
||||
JS_free(state->context, operatorStack);
|
||||
state->context->free(operatorStack);
|
||||
if (operandStack)
|
||||
JS_free(state->context, operandStack);
|
||||
state->context->free(operandStack);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -1647,9 +1647,8 @@ EmitREBytecode(CompilerState *state, JSRegExp *re, size_t treeDepth,
|
||||
emitStateStack = NULL;
|
||||
} else {
|
||||
emitStateStack =
|
||||
(EmitStateStackEntry *)JS_malloc(state->context,
|
||||
sizeof(EmitStateStackEntry) *
|
||||
treeDepth);
|
||||
(EmitStateStackEntry *)
|
||||
state->context->malloc(sizeof(EmitStateStackEntry) * treeDepth);
|
||||
if (!emitStateStack)
|
||||
return NULL;
|
||||
}
|
||||
@ -1951,7 +1950,7 @@ EmitREBytecode(CompilerState *state, JSRegExp *re, size_t treeDepth,
|
||||
|
||||
cleanup:
|
||||
if (emitStateStack)
|
||||
JS_free(state->context, emitStateStack);
|
||||
state->context->free(emitStateStack);
|
||||
return pc;
|
||||
|
||||
jump_too_big:
|
||||
@ -3228,7 +3227,7 @@ js_NewRegExp(JSContext *cx, JSTokenStream *ts,
|
||||
goto out;
|
||||
|
||||
resize = offsetof(JSRegExp, program) + state.progLength + 1;
|
||||
re = (JSRegExp *) JS_malloc(cx, resize);
|
||||
re = (JSRegExp *) cx->malloc(resize);
|
||||
if (!re)
|
||||
goto out;
|
||||
|
||||
@ -3237,7 +3236,7 @@ js_NewRegExp(JSContext *cx, JSTokenStream *ts,
|
||||
re->classCount = state.classCount;
|
||||
if (re->classCount) {
|
||||
re->classList = (RECharSet *)
|
||||
JS_malloc(cx, re->classCount * sizeof(RECharSet));
|
||||
cx->malloc(re->classCount * sizeof(RECharSet));
|
||||
if (!re->classList) {
|
||||
js_DestroyRegExp(cx, re);
|
||||
re = NULL;
|
||||
@ -3266,7 +3265,7 @@ js_NewRegExp(JSContext *cx, JSTokenStream *ts,
|
||||
JSRegExp *tmp;
|
||||
JS_ASSERT((size_t)(endPC - re->program) < state.progLength + 1);
|
||||
resize = offsetof(JSRegExp, program) + (endPC - re->program);
|
||||
tmp = (JSRegExp *) JS_realloc(cx, re, resize);
|
||||
tmp = (JSRegExp *) cx->realloc(re, resize);
|
||||
if (tmp)
|
||||
re = tmp;
|
||||
}
|
||||
@ -3606,7 +3605,7 @@ ProcessCharSet(JSContext *cx, JSRegExp *re, RECharSet *charSet)
|
||||
JS_ASSERT(end[0] == ']');
|
||||
|
||||
byteLength = (charSet->length >> 3) + 1;
|
||||
charSet->u.bits = (uint8 *)JS_malloc(cx, byteLength);
|
||||
charSet->u.bits = (uint8 *)cx->malloc(byteLength);
|
||||
if (!charSet->u.bits) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return JS_FALSE;
|
||||
@ -3800,12 +3799,12 @@ js_DestroyRegExp(JSContext *cx, JSRegExp *re)
|
||||
uintN i;
|
||||
for (i = 0; i < re->classCount; i++) {
|
||||
if (re->classList[i].converted)
|
||||
JS_free(cx, re->classList[i].u.bits);
|
||||
cx->free(re->classList[i].u.bits);
|
||||
re->classList[i].u.bits = NULL;
|
||||
}
|
||||
JS_free(cx, re->classList);
|
||||
cx->free(re->classList);
|
||||
}
|
||||
JS_free(cx, re);
|
||||
cx->free(re);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4870,12 +4869,12 @@ js_ExecuteRegExp(JSContext *cx, JSRegExp *re, JSString *str, size_t *indexp,
|
||||
if (!morepar) {
|
||||
res->moreLength = 10;
|
||||
morepar = (JSSubString*)
|
||||
JS_malloc(cx, 10 * sizeof(JSSubString));
|
||||
cx->malloc(10 * sizeof(JSSubString));
|
||||
} else if (morenum >= res->moreLength) {
|
||||
res->moreLength += 10;
|
||||
morepar = (JSSubString*)
|
||||
JS_realloc(cx, morepar,
|
||||
res->moreLength * sizeof(JSSubString));
|
||||
cx->realloc(morepar,
|
||||
res->moreLength * sizeof(JSSubString));
|
||||
}
|
||||
if (!morepar) {
|
||||
cx->weakRoots.newborn[GCX_OBJECT] = NULL;
|
||||
@ -5114,7 +5113,7 @@ js_FreeRegExpStatics(JSContext *cx)
|
||||
JSRegExpStatics *res = &cx->regExpStatics;
|
||||
|
||||
if (res->moreParens) {
|
||||
JS_free(cx, res->moreParens);
|
||||
cx->free(res->moreParens);
|
||||
res->moreParens = NULL;
|
||||
}
|
||||
JS_FinishArenaPool(&cx->regexpPool);
|
||||
@ -5365,7 +5364,7 @@ js_regexp_toString(JSContext *cx, JSObject *obj, jsval *vp)
|
||||
nflags = 0;
|
||||
for (flags = re->flags; flags != 0; flags &= flags - 1)
|
||||
nflags++;
|
||||
chars = (jschar*) JS_malloc(cx, (length + nflags + 1) * sizeof(jschar));
|
||||
chars = (jschar*) cx->malloc((length + nflags + 1) * sizeof(jschar));
|
||||
if (!chars) {
|
||||
JS_UNLOCK_OBJ(cx, obj);
|
||||
return JS_FALSE;
|
||||
@ -5389,7 +5388,7 @@ js_regexp_toString(JSContext *cx, JSObject *obj, jsval *vp)
|
||||
|
||||
str = js_NewString(cx, chars, length);
|
||||
if (!str) {
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
return JS_FALSE;
|
||||
}
|
||||
*vp = STRING_TO_JSVAL(str);
|
||||
@ -5472,15 +5471,15 @@ regexp_compile_sub(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
if (*cp == '/' && (cp == start || cp[-1] != '\\')) {
|
||||
nbytes = (++length + 1) * sizeof(jschar);
|
||||
if (!nstart) {
|
||||
nstart = (jschar *) JS_malloc(cx, nbytes);
|
||||
nstart = (jschar *) cx->malloc(nbytes);
|
||||
if (!nstart)
|
||||
return JS_FALSE;
|
||||
ncp = nstart + (cp - start);
|
||||
js_strncpy(nstart, start, cp - start);
|
||||
} else {
|
||||
tmp = (jschar *) JS_realloc(cx, nstart, nbytes);
|
||||
tmp = (jschar *) cx->realloc(nstart, nbytes);
|
||||
if (!tmp) {
|
||||
JS_free(cx, nstart);
|
||||
cx->free(nstart);
|
||||
return JS_FALSE;
|
||||
}
|
||||
ncp = tmp + (ncp - nstart);
|
||||
@ -5498,7 +5497,7 @@ regexp_compile_sub(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
*ncp = 0;
|
||||
str = js_NewString(cx, nstart, length);
|
||||
if (!str) {
|
||||
JS_free(cx, nstart);
|
||||
cx->free(nstart);
|
||||
return JS_FALSE;
|
||||
}
|
||||
argv[0] = STRING_TO_JSVAL(str);
|
||||
|
@ -258,7 +258,7 @@ void
|
||||
js_CloseTokenStream(JSContext *cx, JSTokenStream *ts)
|
||||
{
|
||||
if (ts->flags & TSF_OWNFILENAME)
|
||||
JS_free(cx, (void *) ts->filename);
|
||||
cx->free((void *) ts->filename);
|
||||
}
|
||||
|
||||
JS_FRIEND_API(int)
|
||||
@ -562,7 +562,7 @@ js_ReportCompileErrorNumber(JSContext *cx, JSTokenStream *ts, JSParseNode *pn,
|
||||
}
|
||||
report.lineno = ts->lineno;
|
||||
linelength = ts->linebuf.limit - ts->linebuf.base;
|
||||
linechars = (jschar *)JS_malloc(cx, (linelength + 1) * sizeof(jschar));
|
||||
linechars = (jschar *)cx->malloc((linelength + 1) * sizeof(jschar));
|
||||
if (!linechars) {
|
||||
warning = JS_FALSE;
|
||||
goto out;
|
||||
@ -651,21 +651,21 @@ js_ReportCompileErrorNumber(JSContext *cx, JSTokenStream *ts, JSParseNode *pn,
|
||||
|
||||
out:
|
||||
if (linebytes)
|
||||
JS_free(cx, linebytes);
|
||||
cx->free(linebytes);
|
||||
if (linechars)
|
||||
JS_free(cx, linechars);
|
||||
cx->free(linechars);
|
||||
if (message)
|
||||
JS_free(cx, message);
|
||||
cx->free(message);
|
||||
if (report.ucmessage)
|
||||
JS_free(cx, (void *)report.ucmessage);
|
||||
cx->free((void *)report.ucmessage);
|
||||
|
||||
if (report.messageArgs) {
|
||||
if (!(flags & JSREPORT_UC)) {
|
||||
i = 0;
|
||||
while (report.messageArgs[i])
|
||||
JS_free(cx, (void *)report.messageArgs[i++]);
|
||||
cx->free((void *)report.messageArgs[i++]);
|
||||
}
|
||||
JS_free(cx, (void *)report.messageArgs);
|
||||
cx->free((void *)report.messageArgs);
|
||||
}
|
||||
|
||||
if (!JSREPORT_IS_WARNING(flags)) {
|
||||
@ -698,7 +698,7 @@ GrowStringBuffer(JSStringBuffer *sb, size_t amount)
|
||||
|
||||
/* Now do the full overflow check. */
|
||||
if (size_t(offset) < newlength && newlength < ~size_t(0) / sizeof(jschar)) {
|
||||
jschar *bp = (jschar *) realloc(sb->base, newlength * sizeof(jschar));
|
||||
jschar *bp = (jschar *) js_realloc(sb->base, newlength * sizeof(jschar));
|
||||
if (bp) {
|
||||
sb->base = bp;
|
||||
sb->ptr = bp + offset;
|
||||
@ -709,7 +709,7 @@ GrowStringBuffer(JSStringBuffer *sb, size_t amount)
|
||||
}
|
||||
|
||||
/* Either newlength overflow or realloc failure: poison the well. */
|
||||
free(sb->base);
|
||||
js_free(sb->base);
|
||||
sb->base = STRING_BUFFER_ERROR_BASE;
|
||||
return false;
|
||||
}
|
||||
@ -719,7 +719,7 @@ FreeStringBuffer(JSStringBuffer *sb)
|
||||
{
|
||||
JS_ASSERT(STRING_BUFFER_OK(sb));
|
||||
if (sb->base)
|
||||
free(sb->base);
|
||||
js_free(sb->base);
|
||||
}
|
||||
|
||||
void
|
||||
@ -924,7 +924,7 @@ bad:
|
||||
if (bytes) {
|
||||
js_ReportCompileErrorNumber(cx, ts, NULL, JSREPORT_ERROR,
|
||||
msg, bytes);
|
||||
JS_free(cx, bytes);
|
||||
cx->free(bytes);
|
||||
}
|
||||
return JS_FALSE;
|
||||
}
|
||||
@ -1788,7 +1788,7 @@ retry:
|
||||
if (c == '\n') {
|
||||
if (i > 0) {
|
||||
if (ts->flags & TSF_OWNFILENAME)
|
||||
JS_free(cx, (void *) ts->filename);
|
||||
cx->free((void *) ts->filename);
|
||||
ts->filename = JS_strdup(cx, filename);
|
||||
if (!ts->filename)
|
||||
goto error;
|
||||
|
@ -166,7 +166,7 @@ JSScope::createTable(JSContext *cx, bool report)
|
||||
sizeLog2 = MIN_SCOPE_SIZE_LOG2;
|
||||
}
|
||||
|
||||
table = (JSScopeProperty **) calloc(JS_BIT(sizeLog2), sizeof(JSScopeProperty *));
|
||||
table = (JSScopeProperty **) js_calloc(JS_BIT(sizeLog2) * sizeof(JSScopeProperty *));
|
||||
if (!table) {
|
||||
if (report)
|
||||
JS_ReportOutOfMemory(cx);
|
||||
@ -188,7 +188,7 @@ JSScope::create(JSContext *cx, JSObjectOps *ops, JSClass *clasp, JSObject *obj)
|
||||
JS_ASSERT(OPS_IS_NATIVE(ops));
|
||||
JS_ASSERT(obj);
|
||||
|
||||
JSScope *scope = (JSScope *) JS_malloc(cx, sizeof(JSScope));
|
||||
JSScope *scope = (JSScope *) cx->malloc(sizeof(JSScope));
|
||||
if (!scope)
|
||||
return NULL;
|
||||
|
||||
@ -213,7 +213,7 @@ JSScope::createEmptyScope(JSContext *cx, JSClass *clasp)
|
||||
{
|
||||
JS_ASSERT(!emptyScope);
|
||||
|
||||
JSScope *scope = (JSScope *) JS_malloc(cx, sizeof(JSScope));
|
||||
JSScope *scope = (JSScope *) cx->malloc(sizeof(JSScope));
|
||||
if (!scope)
|
||||
return NULL;
|
||||
|
||||
@ -252,13 +252,13 @@ JSScope::destroy(JSContext *cx, JSScope *scope)
|
||||
js_FinishTitle(cx, &scope->title);
|
||||
#endif
|
||||
if (scope->table)
|
||||
JS_free(cx, scope->table);
|
||||
cx->free(scope->table);
|
||||
if (scope->emptyScope)
|
||||
scope->emptyScope->drop(cx, NULL);
|
||||
|
||||
LIVE_SCOPE_METER(cx, cx->runtime->liveScopeProps -= scope->entryCount);
|
||||
JS_RUNTIME_UNMETER(cx->runtime, liveScopes);
|
||||
JS_free(cx, scope);
|
||||
cx->free(scope);
|
||||
}
|
||||
|
||||
#ifdef JS_DUMP_PROPTREE_STATS
|
||||
@ -401,11 +401,9 @@ JSScope::changeTable(JSContext *cx, int change)
|
||||
oldsize = JS_BIT(oldlog2);
|
||||
newsize = JS_BIT(newlog2);
|
||||
nbytes = SCOPE_TABLE_NBYTES(newsize);
|
||||
newtable = (JSScopeProperty **) calloc(nbytes, 1);
|
||||
if (!newtable) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
newtable = (JSScopeProperty **) cx->calloc(nbytes);
|
||||
if (!newtable)
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Now that we have newtable allocated, update members. */
|
||||
hashShift = JS_DHASH_BITS - newlog2;
|
||||
@ -428,7 +426,7 @@ JSScope::changeTable(JSContext *cx, int change)
|
||||
}
|
||||
|
||||
/* Finally, free the old table storage. */
|
||||
JS_free(cx, oldtable);
|
||||
cx->free(oldtable);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -578,7 +576,7 @@ NewPropTreeKidsChunk(JSRuntime *rt)
|
||||
{
|
||||
PropTreeKidsChunk *chunk;
|
||||
|
||||
chunk = (PropTreeKidsChunk *) calloc(1, sizeof *chunk);
|
||||
chunk = (PropTreeKidsChunk *) js_calloc(sizeof *chunk);
|
||||
if (!chunk)
|
||||
return NULL;
|
||||
JS_ASSERT(((jsuword)chunk & CHUNKY_KIDS_TAG) == 0);
|
||||
@ -592,7 +590,7 @@ DestroyPropTreeKidsChunk(JSRuntime *rt, PropTreeKidsChunk *chunk)
|
||||
JS_RUNTIME_UNMETER(rt, propTreeKidsChunks);
|
||||
if (chunk->table)
|
||||
JS_DHashTableDestroy(chunk->table);
|
||||
free(chunk);
|
||||
js_free(chunk);
|
||||
}
|
||||
|
||||
/* NB: Called with rt->gcLock held. */
|
||||
@ -1215,7 +1213,7 @@ JSScope::add(JSContext *cx, jsid id,
|
||||
splen = entryCount;
|
||||
JS_ASSERT(splen != 0);
|
||||
spvec = (JSScopeProperty **)
|
||||
JS_malloc(cx, SCOPE_TABLE_NBYTES(splen));
|
||||
cx->malloc(SCOPE_TABLE_NBYTES(splen));
|
||||
if (!spvec)
|
||||
goto fail_overwrite;
|
||||
i = splen;
|
||||
@ -1248,7 +1246,7 @@ JSScope::add(JSContext *cx, jsid id,
|
||||
} else {
|
||||
sprop = GetPropertyTreeChild(cx, sprop, spvec[i]);
|
||||
if (!sprop) {
|
||||
JS_free(cx, spvec);
|
||||
cx->free(spvec);
|
||||
goto fail_overwrite;
|
||||
}
|
||||
|
||||
@ -1257,7 +1255,7 @@ JSScope::add(JSContext *cx, jsid id,
|
||||
SPROP_STORE_PRESERVING_COLLISION(spp2, sprop);
|
||||
}
|
||||
} while (++i < splen);
|
||||
JS_free(cx, spvec);
|
||||
cx->free(spvec);
|
||||
|
||||
/*
|
||||
* Now sprop points to the last property in this scope, where
|
||||
@ -1558,7 +1556,7 @@ JSScope::clear(JSContext *cx)
|
||||
LIVE_SCOPE_METER(cx, cx->runtime->liveScopeProps -= entryCount);
|
||||
|
||||
if (table)
|
||||
free(table);
|
||||
js_free(table);
|
||||
clearMiddleDelete();
|
||||
js_LeaveTraceIfGlobalObject(cx, object);
|
||||
initMinimal(cx);
|
||||
|
@ -140,7 +140,7 @@ script_toSource(JSContext *cx, uintN argc, jsval *vp)
|
||||
}
|
||||
|
||||
/* Allocate the source string and copy into it. */
|
||||
t = (jschar *) JS_malloc(cx, (n + 1) * sizeof(jschar));
|
||||
t = (jschar *) cx->malloc((n + 1) * sizeof(jschar));
|
||||
if (!t)
|
||||
return JS_FALSE;
|
||||
for (i = 0; i < j; i++)
|
||||
@ -154,7 +154,7 @@ script_toSource(JSContext *cx, uintN argc, jsval *vp)
|
||||
/* Create and return a JS string for t. */
|
||||
str = JS_NewUCString(cx, t, n);
|
||||
if (!str) {
|
||||
JS_free(cx, t);
|
||||
cx->free(t);
|
||||
return JS_FALSE;
|
||||
}
|
||||
*vp = STRING_TO_JSVAL(str);
|
||||
@ -533,7 +533,7 @@ js_XDRScript(JSXDRState *xdr, JSScript **scriptp, JSBool *hasMagic)
|
||||
ok = JS_XDRBytes(xdr, (char *) code, length * sizeof(jsbytecode));
|
||||
|
||||
if (code != script->code)
|
||||
JS_free(cx, code);
|
||||
cx->free(code);
|
||||
|
||||
if (!ok)
|
||||
goto error;
|
||||
@ -576,7 +576,7 @@ js_XDRScript(JSXDRState *xdr, JSScript **scriptp, JSBool *hasMagic)
|
||||
filename = js_SaveScriptFilename(cx, filename);
|
||||
if (!filename)
|
||||
goto error;
|
||||
JS_free(cx, (void *) script->filename);
|
||||
cx->free((void *) script->filename);
|
||||
script->filename = filename;
|
||||
filenameWasSaved = JS_TRUE;
|
||||
}
|
||||
@ -665,7 +665,7 @@ js_XDRScript(JSXDRState *xdr, JSScript **scriptp, JSBool *hasMagic)
|
||||
if (xdr->mode == JSXDR_DECODE) {
|
||||
JS_POP_TEMP_ROOT(cx, &tvr);
|
||||
if (script->filename && !filenameWasSaved) {
|
||||
JS_free(cx, (void *) script->filename);
|
||||
cx->free((void *) script->filename);
|
||||
script->filename = NULL;
|
||||
}
|
||||
js_DestroyScript(cx, script);
|
||||
@ -783,7 +783,7 @@ script_thaw(JSContext *cx, uintN argc, jsval *vp)
|
||||
|
||||
/* Swap bytes in Unichars to keep frozen strings machine-independent. */
|
||||
from = (jschar *)buf;
|
||||
to = (jschar *) JS_malloc(cx, len * sizeof(jschar));
|
||||
to = (jschar *) cx->malloc(len * sizeof(jschar));
|
||||
if (!to) {
|
||||
JS_XDRDestroy(xdr);
|
||||
return JS_FALSE;
|
||||
@ -839,7 +839,7 @@ out:
|
||||
JS_XDRMemSetData(xdr, NULL, 0);
|
||||
JS_XDRDestroy(xdr);
|
||||
#if IS_BIG_ENDIAN
|
||||
JS_free(cx, buf);
|
||||
cx->free(buf);
|
||||
#endif
|
||||
*vp = JSVAL_TRUE;
|
||||
return ok;
|
||||
@ -995,13 +995,13 @@ typedef struct ScriptFilenameEntry {
|
||||
static void *
|
||||
js_alloc_table_space(void *priv, size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
return js_malloc(size);
|
||||
}
|
||||
|
||||
static void
|
||||
js_free_table_space(void *priv, void *item, size_t size)
|
||||
{
|
||||
free(item);
|
||||
js_free(item);
|
||||
}
|
||||
|
||||
static JSHashEntry *
|
||||
@ -1010,7 +1010,7 @@ js_alloc_sftbl_entry(void *priv, const void *key)
|
||||
size_t nbytes = offsetof(ScriptFilenameEntry, filename) +
|
||||
strlen((const char *) key) + 1;
|
||||
|
||||
return (JSHashEntry *) malloc(JS_MAX(nbytes, sizeof(JSHashEntry)));
|
||||
return (JSHashEntry *) js_malloc(JS_MAX(nbytes, sizeof(JSHashEntry)));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1018,7 +1018,7 @@ js_free_sftbl_entry(void *priv, JSHashEntry *he, uintN flag)
|
||||
{
|
||||
if (flag != HT_FREE_ENTRY)
|
||||
return;
|
||||
free(he);
|
||||
js_free(he);
|
||||
}
|
||||
|
||||
static JSHashAllocOps sftbl_alloc_ops = {
|
||||
@ -1080,7 +1080,7 @@ js_FreeRuntimeScriptState(JSRuntime *rt)
|
||||
while (!JS_CLIST_IS_EMPTY(&rt->scriptFilenamePrefixes)) {
|
||||
sfp = (ScriptFilenamePrefix *) rt->scriptFilenamePrefixes.next;
|
||||
JS_REMOVE_LINK(&sfp->links);
|
||||
free(sfp);
|
||||
js_free(sfp);
|
||||
}
|
||||
js_FinishRuntimeScriptState(rt);
|
||||
}
|
||||
@ -1143,7 +1143,7 @@ SaveScriptFilename(JSRuntime *rt, const char *filename, uint32 flags)
|
||||
|
||||
if (!sfp) {
|
||||
/* No such prefix: add one now. */
|
||||
sfp = (ScriptFilenamePrefix *) malloc(sizeof(ScriptFilenamePrefix));
|
||||
sfp = (ScriptFilenamePrefix *) js_malloc(sizeof(ScriptFilenamePrefix));
|
||||
if (!sfp)
|
||||
return NULL;
|
||||
JS_INSERT_AFTER(&sfp->links, link);
|
||||
@ -1384,7 +1384,7 @@ js_NewScript(JSContext *cx, uint32 length, uint32 nsrcnotes, uint32 natoms,
|
||||
if (ntrynotes != 0)
|
||||
size += sizeof(JSTryNoteArray) + ntrynotes * sizeof(JSTryNote);
|
||||
|
||||
script = (JSScript *) JS_malloc(cx, size);
|
||||
script = (JSScript *) cx->malloc(size);
|
||||
if (!script)
|
||||
return NULL;
|
||||
memset(script, 0, sizeof(JSScript));
|
||||
@ -1536,7 +1536,7 @@ js_NewScriptFromCG(JSContext *cx, JSCodeGenerator *cg)
|
||||
memcpy(JS_SCRIPT_UPVARS(script)->vector, cg->upvarMap.vector,
|
||||
cg->upvarList.count * sizeof(uint32));
|
||||
cg->upvarList.clear();
|
||||
JS_free(cx, cg->upvarMap.vector);
|
||||
cx->free(cg->upvarMap.vector);
|
||||
cg->upvarMap.vector = NULL;
|
||||
}
|
||||
|
||||
@ -1648,7 +1648,7 @@ js_DestroyScript(JSContext *cx, JSScript *script)
|
||||
}
|
||||
}
|
||||
|
||||
JS_free(cx, script);
|
||||
cx->free(script);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -145,7 +145,7 @@ js_ConcatStrings(JSContext *cx, JSString *left, JSString *right)
|
||||
|
||||
if (!left->isMutable()) {
|
||||
/* We must copy if left does not own a buffer to realloc. */
|
||||
s = (jschar *) JS_malloc(cx, (ln + rn + 1) * sizeof(jschar));
|
||||
s = (jschar *) cx->malloc((ln + rn + 1) * sizeof(jschar));
|
||||
if (!s)
|
||||
return NULL;
|
||||
js_strncpy(s, ls, ln);
|
||||
@ -153,7 +153,7 @@ js_ConcatStrings(JSContext *cx, JSString *left, JSString *right)
|
||||
} else {
|
||||
/* We can realloc left's space and make it depend on our result. */
|
||||
JS_ASSERT(left->isFlat());
|
||||
s = (jschar *) JS_realloc(cx, ls, (ln + rn + 1) * sizeof(jschar));
|
||||
s = (jschar *) cx->realloc(ls, (ln + rn + 1) * sizeof(jschar));
|
||||
if (!s)
|
||||
return NULL;
|
||||
|
||||
@ -173,9 +173,9 @@ js_ConcatStrings(JSContext *cx, JSString *left, JSString *right)
|
||||
if (!str) {
|
||||
/* Out of memory: clean up any space we (re-)allocated. */
|
||||
if (!ldep) {
|
||||
JS_free(cx, s);
|
||||
cx->free(s);
|
||||
} else {
|
||||
s = (jschar *) JS_realloc(cx, ls, (ln + 1) * sizeof(jschar));
|
||||
s = (jschar *) cx->realloc(ls, (ln + 1) * sizeof(jschar));
|
||||
if (s)
|
||||
left->mChars = s;
|
||||
}
|
||||
@ -210,7 +210,7 @@ js_UndependString(JSContext *cx, JSString *str)
|
||||
if (str->isDependent()) {
|
||||
n = str->dependentLength();
|
||||
size = (n + 1) * sizeof(jschar);
|
||||
s = (jschar *) JS_malloc(cx, size);
|
||||
s = (jschar *) cx->malloc(size);
|
||||
if (!s)
|
||||
return NULL;
|
||||
|
||||
@ -402,7 +402,7 @@ js_str_escape(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
newchars = (jschar *) JS_malloc(cx, (newlength + 1) * sizeof(jschar));
|
||||
newchars = (jschar *) cx->malloc((newlength + 1) * sizeof(jschar));
|
||||
if (!newchars)
|
||||
return JS_FALSE;
|
||||
for (i = 0, ni = 0; i < length; i++) {
|
||||
@ -430,7 +430,7 @@ js_str_escape(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval
|
||||
|
||||
str = js_NewString(cx, newchars, newlength);
|
||||
if (!str) {
|
||||
JS_free(cx, newchars);
|
||||
cx->free(newchars);
|
||||
return JS_FALSE;
|
||||
}
|
||||
*rval = STRING_TO_JSVAL(str);
|
||||
@ -464,7 +464,7 @@ str_unescape(JSContext *cx, uintN argc, jsval *vp)
|
||||
str->getCharsAndLength(chars, length);
|
||||
|
||||
/* Don't bother allocating less space for the new string. */
|
||||
newchars = (jschar *) JS_malloc(cx, (length + 1) * sizeof(jschar));
|
||||
newchars = (jschar *) cx->malloc((length + 1) * sizeof(jschar));
|
||||
if (!newchars)
|
||||
return JS_FALSE;
|
||||
ni = i = 0;
|
||||
@ -493,7 +493,7 @@ str_unescape(JSContext *cx, uintN argc, jsval *vp)
|
||||
|
||||
str = js_NewString(cx, newchars, ni);
|
||||
if (!str) {
|
||||
JS_free(cx, newchars);
|
||||
cx->free(newchars);
|
||||
return JS_FALSE;
|
||||
}
|
||||
*vp = STRING_TO_JSVAL(str);
|
||||
@ -695,7 +695,7 @@ str_toSource(JSContext *cx, uintN argc, jsval *vp)
|
||||
j = JS_snprintf(buf, sizeof buf, "(new %s(", js_StringClass.name);
|
||||
str->getCharsAndLength(s, k);
|
||||
n = j + k + 2;
|
||||
t = (jschar *) JS_malloc(cx, (n + 1) * sizeof(jschar));
|
||||
t = (jschar *) cx->malloc((n + 1) * sizeof(jschar));
|
||||
if (!t)
|
||||
return JS_FALSE;
|
||||
for (i = 0; i < j; i++)
|
||||
@ -707,7 +707,7 @@ str_toSource(JSContext *cx, uintN argc, jsval *vp)
|
||||
t[i] = 0;
|
||||
str = js_NewString(cx, t, n);
|
||||
if (!str) {
|
||||
JS_free(cx, t);
|
||||
cx->free(t);
|
||||
return JS_FALSE;
|
||||
}
|
||||
*vp = STRING_TO_JSVAL(str);
|
||||
@ -799,7 +799,7 @@ js_toLowerCase(JSContext *cx, JSString *str)
|
||||
jschar *news;
|
||||
|
||||
str->getCharsAndLength(s, n);
|
||||
news = (jschar *) JS_malloc(cx, (n + 1) * sizeof(jschar));
|
||||
news = (jschar *) cx->malloc((n + 1) * sizeof(jschar));
|
||||
if (!news)
|
||||
return NULL;
|
||||
for (i = 0; i < n; i++)
|
||||
@ -807,7 +807,7 @@ js_toLowerCase(JSContext *cx, JSString *str)
|
||||
news[n] = 0;
|
||||
str = js_NewString(cx, news, n);
|
||||
if (!str) {
|
||||
JS_free(cx, news);
|
||||
cx->free(news);
|
||||
return NULL;
|
||||
}
|
||||
return str;
|
||||
@ -850,7 +850,7 @@ js_toUpperCase(JSContext *cx, JSString *str)
|
||||
jschar *news;
|
||||
|
||||
str->getCharsAndLength(s, n);
|
||||
news = (jschar *) JS_malloc(cx, (n + 1) * sizeof(jschar));
|
||||
news = (jschar *) cx->malloc((n + 1) * sizeof(jschar));
|
||||
if (!news)
|
||||
return NULL;
|
||||
for (i = 0; i < n; i++)
|
||||
@ -858,7 +858,7 @@ js_toUpperCase(JSContext *cx, JSString *str)
|
||||
news[n] = 0;
|
||||
str = js_NewString(cx, news, n);
|
||||
if (!str) {
|
||||
JS_free(cx, news);
|
||||
cx->free(news);
|
||||
return NULL;
|
||||
}
|
||||
return str;
|
||||
@ -1659,7 +1659,7 @@ find_replen(JSContext *cx, ReplaceData *rdata, size_t *sizep)
|
||||
lambda_out:
|
||||
js_FreeStack(cx, mark);
|
||||
if (freeMoreParens)
|
||||
JS_free(cx, cx->regExpStatics.moreParens);
|
||||
cx->free(cx->regExpStatics.moreParens);
|
||||
cx->regExpStatics = save;
|
||||
return ok;
|
||||
}
|
||||
@ -1716,7 +1716,7 @@ replace_destroy(JSContext *cx, GlobData *data)
|
||||
ReplaceData *rdata;
|
||||
|
||||
rdata = (ReplaceData *)data;
|
||||
JS_free(cx, rdata->chars);
|
||||
cx->free(rdata->chars);
|
||||
rdata->chars = NULL;
|
||||
}
|
||||
|
||||
@ -1741,9 +1741,9 @@ replace_glob(JSContext *cx, jsint count, GlobData *data)
|
||||
growth = leftlen + replen;
|
||||
chars = (jschar *)
|
||||
(rdata->chars
|
||||
? JS_realloc(cx, rdata->chars, (rdata->length + growth + 1)
|
||||
? cx->realloc(rdata->chars, (rdata->length + growth + 1)
|
||||
* sizeof(jschar))
|
||||
: JS_malloc(cx, (growth + 1) * sizeof(jschar)));
|
||||
: cx->malloc((growth + 1) * sizeof(jschar)));
|
||||
if (!chars)
|
||||
return JS_FALSE;
|
||||
rdata->chars = chars;
|
||||
@ -1826,7 +1826,7 @@ js_StringReplaceHelper(JSContext *cx, uintN argc, JSObject *lambda,
|
||||
if (!ok)
|
||||
goto out;
|
||||
length += leftlen;
|
||||
chars = (jschar *) JS_malloc(cx, (length + 1) * sizeof(jschar));
|
||||
chars = (jschar *) cx->malloc((length + 1) * sizeof(jschar));
|
||||
if (!chars) {
|
||||
ok = JS_FALSE;
|
||||
goto out;
|
||||
@ -1840,9 +1840,9 @@ js_StringReplaceHelper(JSContext *cx, uintN argc, JSObject *lambda,
|
||||
rightlen = cx->regExpStatics.rightContext.length;
|
||||
length = rdata.length + rightlen;
|
||||
chars = (jschar *)
|
||||
JS_realloc(cx, rdata.chars, (length + 1) * sizeof(jschar));
|
||||
cx->realloc(rdata.chars, (length + 1) * sizeof(jschar));
|
||||
if (!chars) {
|
||||
JS_free(cx, rdata.chars);
|
||||
cx->free(rdata.chars);
|
||||
ok = JS_FALSE;
|
||||
goto out;
|
||||
}
|
||||
@ -1852,7 +1852,7 @@ js_StringReplaceHelper(JSContext *cx, uintN argc, JSObject *lambda,
|
||||
|
||||
str = js_NewString(cx, chars, length);
|
||||
if (!str) {
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
ok = JS_FALSE;
|
||||
goto out;
|
||||
}
|
||||
@ -2266,7 +2266,7 @@ tagify(JSContext *cx, const char *begin, JSString *param, const char *end,
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
tagbuf = (jschar *) JS_malloc(cx, (taglen + 1) * sizeof(jschar));
|
||||
tagbuf = (jschar *) cx->malloc((taglen + 1) * sizeof(jschar));
|
||||
if (!tagbuf)
|
||||
return JS_FALSE;
|
||||
|
||||
@ -2294,7 +2294,7 @@ tagify(JSContext *cx, const char *begin, JSString *param, const char *end,
|
||||
|
||||
str = js_NewString(cx, tagbuf, taglen);
|
||||
if (!str) {
|
||||
free((char *)tagbuf);
|
||||
js_free((char *)tagbuf);
|
||||
return JS_FALSE;
|
||||
}
|
||||
*vp = STRING_TO_JSVAL(str);
|
||||
@ -2531,13 +2531,13 @@ str_fromCharCode(JSContext *cx, uintN argc, jsval *vp)
|
||||
*vp = STRING_TO_JSVAL(str);
|
||||
return JS_TRUE;
|
||||
}
|
||||
chars = (jschar *) JS_malloc(cx, (argc + 1) * sizeof(jschar));
|
||||
chars = (jschar *) cx->malloc((argc + 1) * sizeof(jschar));
|
||||
if (!chars)
|
||||
return JS_FALSE;
|
||||
for (i = 0; i < argc; i++) {
|
||||
code = js_ValueToUint16(cx, &argv[i]);
|
||||
if (JSVAL_IS_NULL(argv[i])) {
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
return JS_FALSE;
|
||||
}
|
||||
chars[i] = (jschar)code;
|
||||
@ -2545,7 +2545,7 @@ str_fromCharCode(JSContext *cx, uintN argc, jsval *vp)
|
||||
chars[i] = 0;
|
||||
str = js_NewString(cx, chars, argc);
|
||||
if (!str) {
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
return JS_FALSE;
|
||||
}
|
||||
*vp = STRING_TO_JSVAL(str);
|
||||
@ -2621,9 +2621,8 @@ js_GetUnitStringForChar(JSContext *cx, jschar c)
|
||||
JS_ASSERT(c < UNIT_STRING_LIMIT);
|
||||
rt = cx->runtime;
|
||||
if (!rt->unitStrings) {
|
||||
sp = (JSString **) calloc(UNIT_STRING_LIMIT * sizeof(JSString *) +
|
||||
UNIT_STRING_LIMIT * 2 * sizeof(jschar),
|
||||
1);
|
||||
sp = (JSString **) js_calloc(UNIT_STRING_LIMIT * sizeof(JSString *) +
|
||||
UNIT_STRING_LIMIT * 2 * sizeof(jschar));
|
||||
if (!sp) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return NULL;
|
||||
@ -2639,7 +2638,7 @@ js_GetUnitStringForChar(JSContext *cx, jschar c)
|
||||
JS_UNLOCK_GC(rt);
|
||||
} else {
|
||||
JS_UNLOCK_GC(rt);
|
||||
free(sp);
|
||||
js_free(sp);
|
||||
}
|
||||
}
|
||||
if (!rt->unitStrings[c]) {
|
||||
@ -2676,7 +2675,7 @@ js_GetUnitString(JSContext *cx, JSString *str, size_t index)
|
||||
void
|
||||
js_FinishUnitStrings(JSRuntime *rt)
|
||||
{
|
||||
free(rt->unitStrings);
|
||||
js_free(rt->unitStrings);
|
||||
rt->unitStrings = NULL;
|
||||
}
|
||||
|
||||
@ -2832,14 +2831,14 @@ js_NewStringCopyN(JSContext *cx, const jschar *s, size_t n)
|
||||
jschar *news;
|
||||
JSString *str;
|
||||
|
||||
news = (jschar *) JS_malloc(cx, (n + 1) * sizeof(jschar));
|
||||
news = (jschar *) cx->malloc((n + 1) * sizeof(jschar));
|
||||
if (!news)
|
||||
return NULL;
|
||||
js_strncpy(news, s, n);
|
||||
news[n] = 0;
|
||||
str = js_NewString(cx, news, n);
|
||||
if (!str)
|
||||
JS_free(cx, news);
|
||||
cx->free(news);
|
||||
return str;
|
||||
}
|
||||
|
||||
@ -2852,13 +2851,13 @@ js_NewStringCopyZ(JSContext *cx, const jschar *s)
|
||||
|
||||
n = js_strlen(s);
|
||||
m = (n + 1) * sizeof(jschar);
|
||||
news = (jschar *) JS_malloc(cx, m);
|
||||
news = (jschar *) cx->malloc(m);
|
||||
if (!news)
|
||||
return NULL;
|
||||
memcpy(news, s, m);
|
||||
str = js_NewString(cx, news, n);
|
||||
if (!str)
|
||||
JS_free(cx, news);
|
||||
cx->free(news);
|
||||
return str;
|
||||
}
|
||||
|
||||
@ -2876,7 +2875,7 @@ js_PurgeDeflatedStringCache(JSRuntime *rt, JSString *str)
|
||||
#ifdef DEBUG
|
||||
rt->deflatedStringCacheBytes -= str->length();
|
||||
#endif
|
||||
free(he->value);
|
||||
js_free(he->value);
|
||||
JS_HashTableRawRemove(rt->deflatedStringCache, hep, he);
|
||||
}
|
||||
JS_RELEASE_LOCK(rt->deflatedStringCacheLock);
|
||||
@ -3121,7 +3120,7 @@ js_InflateString(JSContext *cx, const char *bytes, size_t *lengthp)
|
||||
if (js_CStringsAreUTF8) {
|
||||
if (!js_InflateStringToBuffer(cx, bytes, nbytes, NULL, &nchars))
|
||||
goto bad;
|
||||
chars = (jschar *) JS_malloc(cx, (nchars + 1) * sizeof (jschar));
|
||||
chars = (jschar *) cx->malloc((nchars + 1) * sizeof (jschar));
|
||||
if (!chars)
|
||||
goto bad;
|
||||
#ifdef DEBUG
|
||||
@ -3131,7 +3130,7 @@ js_InflateString(JSContext *cx, const char *bytes, size_t *lengthp)
|
||||
JS_ASSERT(ok);
|
||||
} else {
|
||||
nchars = nbytes;
|
||||
chars = (jschar *) JS_malloc(cx, (nchars + 1) * sizeof(jschar));
|
||||
chars = (jschar *) cx->malloc((nchars + 1) * sizeof(jschar));
|
||||
if (!chars)
|
||||
goto bad;
|
||||
for (i = 0; i < nchars; i++)
|
||||
@ -3166,7 +3165,7 @@ js_DeflateString(JSContext *cx, const jschar *chars, size_t nchars)
|
||||
nbytes = js_GetDeflatedStringLength(cx, chars, nchars);
|
||||
if (nbytes == (size_t) -1)
|
||||
return NULL;
|
||||
bytes = (char *) (cx ? JS_malloc(cx, nbytes + 1) : malloc(nbytes + 1));
|
||||
bytes = (char *) (cx ? cx->malloc(nbytes + 1) : js_malloc(nbytes + 1));
|
||||
if (!bytes)
|
||||
return NULL;
|
||||
#ifdef DEBUG
|
||||
@ -3176,7 +3175,7 @@ js_DeflateString(JSContext *cx, const jschar *chars, size_t nchars)
|
||||
JS_ASSERT(ok);
|
||||
} else {
|
||||
nbytes = nchars;
|
||||
bytes = (char *) (cx ? JS_malloc(cx, nbytes + 1) : malloc(nbytes + 1));
|
||||
bytes = (char *) (cx ? cx->malloc(nbytes + 1) : js_malloc(nbytes + 1));
|
||||
if (!bytes)
|
||||
return NULL;
|
||||
for (i = 0; i < nbytes; i++)
|
||||
@ -3491,9 +3490,9 @@ js_GetStringBytes(JSContext *cx, JSString *str)
|
||||
str->setDeflated();
|
||||
} else {
|
||||
if (cx)
|
||||
JS_free(cx, bytes);
|
||||
cx->free(bytes);
|
||||
else
|
||||
free(bytes);
|
||||
js_free(bytes);
|
||||
bytes = NULL;
|
||||
}
|
||||
}
|
||||
@ -4836,8 +4835,8 @@ AddCharsToURI(JSContext *cx, JSCharBuffer *buf,
|
||||
if (!buf->chars ||
|
||||
JS_HOWMANY(total, URI_CHUNK) > JS_HOWMANY(buf->length + 1, URI_CHUNK)) {
|
||||
total = JS_ROUNDUP(total, URI_CHUNK);
|
||||
newchars = (jschar *) JS_realloc(cx, buf->chars,
|
||||
total * sizeof(jschar));
|
||||
newchars = (jschar *) cx->realloc(buf->chars,
|
||||
total * sizeof(jschar));
|
||||
if (!newchars)
|
||||
return JS_FALSE;
|
||||
buf->chars = newchars;
|
||||
@ -4860,7 +4859,7 @@ TransferBufferToString(JSContext *cx, JSCharBuffer *cb, jsval *rval)
|
||||
* don't worry about that case here.
|
||||
*/
|
||||
n = cb->length;
|
||||
chars = (jschar *) JS_realloc(cx, cb->chars, (n + 1) * sizeof(jschar));
|
||||
chars = (jschar *) cx->realloc(cb->chars, (n + 1) * sizeof(jschar));
|
||||
if (!chars)
|
||||
chars = cb->chars;
|
||||
str = js_NewString(cx, chars, n);
|
||||
@ -4953,7 +4952,7 @@ Encode(JSContext *cx, JSString *str, const jschar *unescapedSet,
|
||||
return JS_TRUE;
|
||||
|
||||
bad:
|
||||
JS_free(cx, cb.chars);
|
||||
cx->free(cb.chars);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@ -5048,7 +5047,7 @@ Decode(JSContext *cx, JSString *str, const jschar *reservedSet, jsval *rval)
|
||||
/* FALL THROUGH */
|
||||
|
||||
bad:
|
||||
JS_free(cx, cb.chars);
|
||||
cx->free(cb.chars);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
126
js/src/jstask.cpp
Normal file
126
js/src/jstask.cpp
Normal file
@ -0,0 +1,126 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* vim: set ts=4 sw=4 et tw=99 ft=cpp:
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla SpiderMonkey JavaScript 1.9.1 code, released
|
||||
* June 30, 2009.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Andreas Gal <gal@mozilla.com>
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "jstask.h"
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
static void start(void* arg) {
|
||||
((JSBackgroundThread*)arg)->work();
|
||||
}
|
||||
|
||||
JSBackgroundThread::JSBackgroundThread()
|
||||
: thread(NULL), stack(NULL), lock(NULL), wakeup(NULL), shutdown(false)
|
||||
{
|
||||
}
|
||||
|
||||
JSBackgroundThread::~JSBackgroundThread()
|
||||
{
|
||||
if (wakeup)
|
||||
PR_DestroyCondVar(wakeup);
|
||||
if (lock)
|
||||
PR_DestroyLock(lock);
|
||||
/* PR_DestroyThread is not necessary. */
|
||||
}
|
||||
|
||||
bool
|
||||
JSBackgroundThread::init()
|
||||
{
|
||||
if (!(lock = PR_NewLock()))
|
||||
return false;
|
||||
if (!(wakeup = PR_NewCondVar(lock)))
|
||||
return false;
|
||||
thread = PR_CreateThread(PR_USER_THREAD, start, this, PR_PRIORITY_LOW,
|
||||
PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
|
||||
return !!thread;
|
||||
}
|
||||
|
||||
void
|
||||
JSBackgroundThread::cancel()
|
||||
{
|
||||
PR_Lock(lock);
|
||||
if (shutdown) {
|
||||
PR_Unlock(lock);
|
||||
return;
|
||||
}
|
||||
shutdown = true;
|
||||
PR_NotifyCondVar(wakeup);
|
||||
PR_Unlock(lock);
|
||||
PR_JoinThread(thread);
|
||||
}
|
||||
|
||||
void
|
||||
JSBackgroundThread::work()
|
||||
{
|
||||
PR_Lock(lock);
|
||||
do {
|
||||
PR_WaitCondVar(wakeup, PR_INTERVAL_NO_TIMEOUT);
|
||||
JSBackgroundTask* t;
|
||||
while ((t = stack) != NULL) {
|
||||
stack = t->next;
|
||||
PR_Unlock(lock);
|
||||
t->run();
|
||||
delete t;
|
||||
PR_Lock(lock);
|
||||
}
|
||||
} while (!shutdown);
|
||||
PR_Unlock(lock);
|
||||
}
|
||||
|
||||
bool
|
||||
JSBackgroundThread::busy()
|
||||
{
|
||||
return !!stack; // we tolerate some racing here
|
||||
}
|
||||
|
||||
void
|
||||
JSBackgroundThread::schedule(JSBackgroundTask* task)
|
||||
{
|
||||
PR_Lock(lock);
|
||||
if (shutdown) {
|
||||
PR_Unlock(lock);
|
||||
task->run();
|
||||
delete task;
|
||||
return;
|
||||
}
|
||||
task->next = stack;
|
||||
stack = task;
|
||||
PR_NotifyCondVar(wakeup);
|
||||
PR_Unlock(lock);
|
||||
}
|
||||
|
||||
#endif
|
84
js/src/jstask.h
Normal file
84
js/src/jstask.h
Normal file
@ -0,0 +1,84 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* vim: set ts=4 sw=4 et tw=99 ft=cpp:
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla SpiderMonkey JavaScript 1.9 code, released
|
||||
* June 30, 2009.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Andreas Gal <gal@mozilla.com>
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef jstask_h___
|
||||
#define jstask_h___
|
||||
|
||||
class JSBackgroundTask {
|
||||
friend class JSBackgroundThread;
|
||||
JSBackgroundTask* next;
|
||||
public:
|
||||
virtual void run() = 0;
|
||||
};
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
|
||||
#include "prthread.h"
|
||||
#include "prlock.h"
|
||||
#include "prcvar.h"
|
||||
|
||||
class JSBackgroundThread {
|
||||
PRThread* thread;
|
||||
JSBackgroundTask* stack;
|
||||
PRLock* lock;
|
||||
PRCondVar* wakeup;
|
||||
bool shutdown;
|
||||
|
||||
public:
|
||||
JSBackgroundThread();
|
||||
~JSBackgroundThread();
|
||||
|
||||
bool init();
|
||||
void cancel();
|
||||
void work();
|
||||
bool busy();
|
||||
void schedule(JSBackgroundTask* task);
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
class JSBackgroundThread {
|
||||
public:
|
||||
void schedule(JSBackgroundTask* task) {
|
||||
task->run();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* jstask_h___ */
|
@ -3616,11 +3616,11 @@ TraceRecorder::compile(JSTraceMonitor* tm)
|
||||
/* :TODO: windows support */
|
||||
#if defined DEBUG && !defined WIN32
|
||||
const char* filename = cx->fp->script->filename;
|
||||
char* label = (char*)malloc((filename ? strlen(filename) : 7) + 16);
|
||||
char* label = (char*)js_malloc((filename ? strlen(filename) : 7) + 16);
|
||||
sprintf(label, "%s:%u", filename ? filename : "<stdin>",
|
||||
js_FramePCToLineNumber(cx, cx->fp));
|
||||
fragmento->labels->add(fragment, sizeof(Fragment), 0, label);
|
||||
free(label);
|
||||
js_free(label);
|
||||
#endif
|
||||
AUDIT(traceCompleted);
|
||||
}
|
||||
@ -12445,7 +12445,7 @@ js_StartTraceVis(JSContext *cx, JSObject *obj,
|
||||
if (!filename)
|
||||
goto error;
|
||||
ok = JS_StartTraceVis(filename);
|
||||
JS_free(cx, filename);
|
||||
cx->free(filename);
|
||||
} else {
|
||||
ok = JS_StartTraceVis();
|
||||
}
|
||||
|
@ -297,7 +297,7 @@ CallTree(void **bp)
|
||||
return NULL;
|
||||
|
||||
/* Create a new callsite record. */
|
||||
site = (JSCallsite *) malloc(sizeof(JSCallsite));
|
||||
site = (JSCallsite *) js_malloc(sizeof(JSCallsite));
|
||||
if (!site)
|
||||
return NULL;
|
||||
|
||||
|
@ -44,6 +44,8 @@
|
||||
#ifndef jsutil_h___
|
||||
#define jsutil_h___
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
/*
|
||||
@ -176,9 +178,30 @@ JS_Backtrace(int skip);
|
||||
|
||||
extern JS_FRIEND_API(void)
|
||||
JS_DumpBacktrace(JSCallsite *trace);
|
||||
|
||||
#endif
|
||||
|
||||
static JS_INLINE void* js_malloc(size_t bytes) {
|
||||
if (bytes < sizeof(void*)) /* for asyncFree */
|
||||
bytes = sizeof(void*);
|
||||
return malloc(bytes);
|
||||
}
|
||||
|
||||
static JS_INLINE void* js_calloc(size_t bytes) {
|
||||
if (bytes < sizeof(void*)) /* for asyncFree */
|
||||
bytes = sizeof(void*);
|
||||
return calloc(bytes, 1);
|
||||
}
|
||||
|
||||
static JS_INLINE void* js_realloc(void* p, size_t bytes) {
|
||||
if (bytes < sizeof(void*)) /* for asyncFree */
|
||||
bytes = sizeof(void*);
|
||||
return realloc(p, bytes);
|
||||
}
|
||||
|
||||
static JS_INLINE void js_free(void* p) {
|
||||
free(p);
|
||||
}
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsutil_h___ */
|
||||
|
@ -90,7 +90,7 @@ typedef struct JSXDRMemState {
|
||||
if (MEM_LIMIT(xdr) && \
|
||||
MEM_COUNT(xdr) + bytes > MEM_LIMIT(xdr)) { \
|
||||
uint32 limit_ = JS_ROUNDUP(MEM_COUNT(xdr) + bytes, MEM_BLOCK);\
|
||||
void *data_ = JS_realloc((xdr)->cx, MEM_BASE(xdr), limit_); \
|
||||
void *data_ = (xdr)->cx->realloc(MEM_BASE(xdr), limit_); \
|
||||
if (!data_) \
|
||||
return 0; \
|
||||
MEM_BASE(xdr) = (char *) data_; \
|
||||
@ -216,7 +216,7 @@ mem_tell(JSXDRState *xdr)
|
||||
static void
|
||||
mem_finalize(JSXDRState *xdr)
|
||||
{
|
||||
JS_free(xdr->cx, MEM_BASE(xdr));
|
||||
xdr->cx->free(MEM_BASE(xdr));
|
||||
}
|
||||
|
||||
static JSXDROps xdrmem_ops = {
|
||||
@ -239,13 +239,13 @@ JS_XDRInitBase(JSXDRState *xdr, JSXDRMode mode, JSContext *cx)
|
||||
JS_PUBLIC_API(JSXDRState *)
|
||||
JS_XDRNewMem(JSContext *cx, JSXDRMode mode)
|
||||
{
|
||||
JSXDRState *xdr = (JSXDRState *) JS_malloc(cx, sizeof(JSXDRMemState));
|
||||
JSXDRState *xdr = (JSXDRState *) cx->malloc(sizeof(JSXDRMemState));
|
||||
if (!xdr)
|
||||
return NULL;
|
||||
JS_XDRInitBase(xdr, mode, cx);
|
||||
if (mode == JSXDR_ENCODE) {
|
||||
if (!(MEM_BASE(xdr) = (char *) JS_malloc(cx, MEM_BLOCK))) {
|
||||
JS_free(cx, xdr);
|
||||
if (!(MEM_BASE(xdr) = (char *) cx->malloc(MEM_BLOCK))) {
|
||||
cx->free(xdr);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
@ -299,11 +299,11 @@ JS_XDRDestroy(JSXDRState *xdr)
|
||||
JSContext *cx = xdr->cx;
|
||||
xdr->ops->finalize(xdr);
|
||||
if (xdr->registry) {
|
||||
JS_free(cx, xdr->registry);
|
||||
cx->free(xdr->registry);
|
||||
if (xdr->reghash)
|
||||
JS_DHashTableDestroy((JSDHashTable *) xdr->reghash);
|
||||
}
|
||||
JS_free(cx, xdr);
|
||||
cx->free(xdr);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
@ -381,18 +381,18 @@ JS_XDRCString(JSXDRState *xdr, char **sp)
|
||||
len = strlen(*sp);
|
||||
JS_XDRUint32(xdr, &len);
|
||||
if (xdr->mode == JSXDR_DECODE) {
|
||||
if (!(*sp = (char *) JS_malloc(xdr->cx, len + 1)))
|
||||
if (!(*sp = (char *) xdr->cx->malloc(len + 1)))
|
||||
return JS_FALSE;
|
||||
}
|
||||
if (!JS_XDRBytes(xdr, *sp, len)) {
|
||||
if (xdr->mode == JSXDR_DECODE)
|
||||
JS_free(xdr->cx, *sp);
|
||||
xdr->cx->free(*sp);
|
||||
return JS_FALSE;
|
||||
}
|
||||
if (xdr->mode == JSXDR_DECODE) {
|
||||
(*sp)[len] = '\0';
|
||||
} else if (xdr->mode == JSXDR_FREE) {
|
||||
JS_free(xdr->cx, *sp);
|
||||
xdr->cx->free(*sp);
|
||||
*sp = NULL;
|
||||
}
|
||||
return JS_TRUE;
|
||||
@ -452,7 +452,7 @@ JS_XDRString(JSXDRState *xdr, JSString **strp)
|
||||
return JS_FALSE;
|
||||
|
||||
if (xdr->mode == JSXDR_DECODE) {
|
||||
chars = (jschar *) JS_malloc(xdr->cx, (nchars + 1) * sizeof(jschar));
|
||||
chars = (jschar *) xdr->cx->malloc((nchars + 1) * sizeof(jschar));
|
||||
if (!chars)
|
||||
return JS_FALSE;
|
||||
} else {
|
||||
@ -471,7 +471,7 @@ JS_XDRString(JSXDRState *xdr, JSString **strp)
|
||||
|
||||
bad:
|
||||
if (xdr->mode == JSXDR_DECODE)
|
||||
JS_free(xdr->cx, chars);
|
||||
xdr->cx->free(chars);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@ -662,7 +662,7 @@ js_XDRStringAtom(JSXDRState *xdr, JSAtom **atomp)
|
||||
* This is very uncommon. Don't use the tempPool arena for this as
|
||||
* most allocations here will be bigger than tempPool's arenasize.
|
||||
*/
|
||||
chars = (jschar *) JS_malloc(cx, nchars * sizeof(jschar));
|
||||
chars = (jschar *) cx->malloc(nchars * sizeof(jschar));
|
||||
if (!chars)
|
||||
return JS_FALSE;
|
||||
}
|
||||
@ -670,7 +670,7 @@ js_XDRStringAtom(JSXDRState *xdr, JSAtom **atomp)
|
||||
if (XDRChars(xdr, chars, nchars))
|
||||
atom = js_AtomizeChars(cx, chars, nchars, 0);
|
||||
if (chars != stackChars)
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
|
||||
if (!atom)
|
||||
return JS_FALSE;
|
||||
@ -709,7 +709,7 @@ JS_XDRRegisterClass(JSXDRState *xdr, JSClass *clasp, uint32 *idp)
|
||||
if (numclasses == maxclasses) {
|
||||
maxclasses = (maxclasses == 0) ? CLASS_REGISTRY_MIN : maxclasses << 1;
|
||||
registry = (JSClass **)
|
||||
JS_realloc(xdr->cx, xdr->registry, maxclasses * sizeof(JSClass *));
|
||||
xdr->cx->realloc(xdr->registry, maxclasses * sizeof(JSClass *));
|
||||
if (!registry)
|
||||
return JS_FALSE;
|
||||
xdr->registry = registry;
|
||||
|
@ -460,7 +460,7 @@ qname_toString(JSContext *cx, uintN argc, jsval *vp)
|
||||
|
||||
if (str && clasp == &js_AttributeNameClass) {
|
||||
length = str->length();
|
||||
chars = (jschar *) JS_malloc(cx, (length + 2) * sizeof(jschar));
|
||||
chars = (jschar *) cx->malloc((length + 2) * sizeof(jschar));
|
||||
if (!chars)
|
||||
return JS_FALSE;
|
||||
*chars = '@';
|
||||
@ -468,7 +468,7 @@ qname_toString(JSContext *cx, uintN argc, jsval *vp)
|
||||
chars[++length] = 0;
|
||||
str = js_NewString(cx, chars, length);
|
||||
if (!str) {
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
@ -933,7 +933,7 @@ XMLArraySetCapacity(JSContext *cx, JSXMLArray *array, uint32 capacity)
|
||||
if (capacity == 0) {
|
||||
/* We could let realloc(p, 0) free this, but purify gets confused. */
|
||||
if (array->vector)
|
||||
free(array->vector);
|
||||
cx->free(array->vector);
|
||||
vector = NULL;
|
||||
} else {
|
||||
if (
|
||||
@ -941,7 +941,7 @@ XMLArraySetCapacity(JSContext *cx, JSXMLArray *array, uint32 capacity)
|
||||
(size_t)capacity > ~(size_t)0 / sizeof(void *) ||
|
||||
#endif
|
||||
!(vector = (void **)
|
||||
realloc(array->vector, capacity * sizeof(void *)))) {
|
||||
js_realloc(array->vector, capacity * sizeof(void *)))) {
|
||||
if (cx)
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return JS_FALSE;
|
||||
@ -975,7 +975,7 @@ XMLArrayFinish(JSContext *cx, JSXMLArray *array)
|
||||
{
|
||||
JSXMLArrayCursor *cursor;
|
||||
|
||||
JS_free(cx, array->vector);
|
||||
cx->free(array->vector);
|
||||
|
||||
while ((cursor = array->cursors) != NULL)
|
||||
XMLArrayCursorFinish(cursor);
|
||||
@ -1039,7 +1039,7 @@ XMLArrayAddMember(JSContext *cx, JSXMLArray *array, uint32 index, void *elt)
|
||||
(size_t)capacity > ~(size_t)0 / sizeof(void *) ||
|
||||
#endif
|
||||
!(vector = (void **)
|
||||
realloc(array->vector, capacity * sizeof(void *)))) {
|
||||
js_realloc(array->vector, capacity * sizeof(void *)))) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return JS_FALSE;
|
||||
}
|
||||
@ -1120,10 +1120,10 @@ XMLArrayTruncate(JSContext *cx, JSXMLArray *array, uint32 length)
|
||||
|
||||
if (length == 0) {
|
||||
if (array->vector)
|
||||
free(array->vector);
|
||||
cx->free(array->vector);
|
||||
vector = NULL;
|
||||
} else {
|
||||
vector = (void **) realloc(array->vector, length * sizeof(void *));
|
||||
vector = (void **) js_realloc(array->vector, length * sizeof(void *));
|
||||
if (!vector)
|
||||
return;
|
||||
}
|
||||
@ -1854,7 +1854,7 @@ ParseXMLSource(JSContext *cx, JSString *src)
|
||||
length = constrlen(prefix) + urilen + constrlen(middle) + srclen +
|
||||
constrlen(suffix);
|
||||
|
||||
chars = (jschar *) JS_malloc(cx, (length + 1) * sizeof(jschar));
|
||||
chars = (jschar *) cx->malloc((length + 1) * sizeof(jschar));
|
||||
if (!chars)
|
||||
return NULL;
|
||||
|
||||
@ -1905,7 +1905,7 @@ ParseXMLSource(JSContext *cx, JSString *src)
|
||||
}
|
||||
}
|
||||
|
||||
JS_free(cx, chars);
|
||||
cx->free(chars);
|
||||
return xml;
|
||||
|
||||
#undef constrlen
|
||||
@ -2138,7 +2138,7 @@ MakeXMLSpecialString(JSContext *cx, JSStringBuffer *sb,
|
||||
prefixlength + length + ((length2 != 0) ? 1 + length2 : 0) +
|
||||
suffixlength;
|
||||
bp = base = (jschar *)
|
||||
JS_realloc(cx, sb->base, (newlength + 1) * sizeof(jschar));
|
||||
cx->realloc(sb->base, (newlength + 1) * sizeof(jschar));
|
||||
if (!bp) {
|
||||
js_FinishStringBuffer(sb);
|
||||
return NULL;
|
||||
@ -2159,7 +2159,7 @@ MakeXMLSpecialString(JSContext *cx, JSStringBuffer *sb,
|
||||
|
||||
str = js_NewString(cx, base, newlength);
|
||||
if (!str)
|
||||
free(base);
|
||||
cx->free(base);
|
||||
return str;
|
||||
}
|
||||
|
||||
@ -2210,7 +2210,7 @@ AppendAttributeValue(JSContext *cx, JSStringBuffer *sb, JSString *valstr)
|
||||
valstr = js_EscapeAttributeValue(cx, valstr, JS_TRUE);
|
||||
if (!valstr) {
|
||||
if (STRING_BUFFER_OK(sb)) {
|
||||
free(sb->base);
|
||||
cx->free(sb->base);
|
||||
sb->base = STRING_BUFFER_ERROR_BASE;
|
||||
}
|
||||
return;
|
||||
@ -2482,7 +2482,7 @@ GeneratePrefix(JSContext *cx, JSString *uri, JSXMLArray *decls)
|
||||
if (STARTS_WITH_XML(cp, length) || !IsXMLName(cp, length)) {
|
||||
newlength = length + 2 + (size_t) log10((double) decls->length);
|
||||
bp = (jschar *)
|
||||
JS_malloc(cx, (newlength + 1) * sizeof(jschar));
|
||||
cx->malloc((newlength + 1) * sizeof(jschar));
|
||||
if (!bp)
|
||||
return NULL;
|
||||
|
||||
@ -2507,7 +2507,7 @@ GeneratePrefix(JSContext *cx, JSString *uri, JSXMLArray *decls)
|
||||
if (bp == cp) {
|
||||
newlength = length + 2 + (size_t) log10((double) n);
|
||||
bp = (jschar *)
|
||||
JS_malloc(cx, (newlength + 1) * sizeof(jschar));
|
||||
cx->malloc((newlength + 1) * sizeof(jschar));
|
||||
if (!bp)
|
||||
return NULL;
|
||||
js_strncpy(bp, cp, length);
|
||||
@ -2534,7 +2534,7 @@ GeneratePrefix(JSContext *cx, JSString *uri, JSXMLArray *decls)
|
||||
} else {
|
||||
prefix = js_NewString(cx, bp, newlength);
|
||||
if (!prefix)
|
||||
JS_free(cx, bp);
|
||||
cx->free(bp);
|
||||
}
|
||||
return prefix;
|
||||
}
|
||||
@ -5132,7 +5132,7 @@ xml_enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
|
||||
if (length == 0) {
|
||||
cursor = NULL;
|
||||
} else {
|
||||
cursor = (JSXMLArrayCursor *) JS_malloc(cx, sizeof *cursor);
|
||||
cursor = (JSXMLArrayCursor *) cx->malloc(sizeof *cursor);
|
||||
if (!cursor)
|
||||
return JS_FALSE;
|
||||
XMLArrayCursorInit(cursor, &xml->xml_kids);
|
||||
@ -5155,7 +5155,7 @@ xml_enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
|
||||
cursor = (JSXMLArrayCursor *) JSVAL_TO_PRIVATE(*statep);
|
||||
if (cursor) {
|
||||
XMLArrayCursorFinish(cursor);
|
||||
JS_free(cx, cursor);
|
||||
cx->free(cursor);
|
||||
}
|
||||
*statep = JSVAL_NULL;
|
||||
break;
|
||||
@ -5266,7 +5266,7 @@ js_EnumerateXMLValues(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
|
||||
if (length == 0) {
|
||||
cursor = NULL;
|
||||
} else {
|
||||
cursor = (JSXMLArrayCursor *) JS_malloc(cx, sizeof *cursor);
|
||||
cursor = (JSXMLArrayCursor *) cx->malloc(sizeof *cursor);
|
||||
if (!cursor)
|
||||
return JS_FALSE;
|
||||
XMLArrayCursorInit(cursor, &xml->xml_kids);
|
||||
@ -5301,7 +5301,7 @@ js_EnumerateXMLValues(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
|
||||
if (cursor) {
|
||||
destroy:
|
||||
XMLArrayCursorFinish(cursor);
|
||||
JS_free(cx, cursor);
|
||||
cx->free(cursor);
|
||||
}
|
||||
*statep = JSVAL_NULL;
|
||||
break;
|
||||
@ -7801,7 +7801,7 @@ js_AddAttributePart(JSContext *cx, JSBool isName, JSString *str, JSString *str2)
|
||||
|
||||
str2->getCharsAndLength(chars2, len2);
|
||||
newlen = (isName) ? len + 1 + len2 : len + 2 + len2 + 1;
|
||||
chars = (jschar *) JS_realloc(cx, chars, (newlen+1) * sizeof(jschar));
|
||||
chars = (jschar *) cx->realloc(chars, (newlen+1) * sizeof(jschar));
|
||||
if (!chars)
|
||||
return NULL;
|
||||
|
||||
@ -8114,7 +8114,7 @@ xmlfilter_finalize(JSContext *cx, JSObject *obj)
|
||||
return;
|
||||
|
||||
XMLArrayCursorFinish(&filter->cursor);
|
||||
JS_free(cx, filter);
|
||||
cx->free(filter);
|
||||
}
|
||||
|
||||
JSClass js_XMLFilterClass = {
|
||||
@ -8169,7 +8169,7 @@ js_StepXMLListFilter(JSContext *cx, JSBool initialized)
|
||||
if (!filterobj)
|
||||
return JS_FALSE;
|
||||
|
||||
filter = (JSXMLFilter *) JS_malloc(cx, sizeof *filter);
|
||||
filter = (JSXMLFilter *) cx->malloc(sizeof *filter);
|
||||
if (!filter)
|
||||
return JS_FALSE;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user