Bug 787246 - rm OffTheBooks/Foreground/UnwantedForeground gunk (r=billm)

This commit is contained in:
Luke Wagner 2012-08-31 15:01:33 -07:00
parent af7a42b5bb
commit 76b8fb7891
70 changed files with 444 additions and 639 deletions

View File

@ -34,26 +34,26 @@ using namespace js;
static void *
DefaultAllocTable(void *pool, size_t size)
{
return OffTheBooks::malloc_(size);
return js_malloc(size);
}
static void
DefaultFreeTable(void *pool, void *item, size_t size)
{
UnwantedForeground::free_(item);
js_free(item);
}
static JSHashEntry *
DefaultAllocEntry(void *pool, const void *key)
{
return (JSHashEntry*) OffTheBooks::malloc_(sizeof(JSHashEntry));
return (JSHashEntry*) js_malloc(sizeof(JSHashEntry));
}
static void
DefaultFreeEntry(void *pool, JSHashEntry *he, unsigned flag)
{
if (flag == HT_FREE_ENTRY)
UnwantedForeground::free_(he);
js_free(he);
}
static JSHashAllocOps defaultHashAllocOps = {

View File

@ -146,11 +146,6 @@ PrintBacktrace()
# define JS_OOM_POSSIBLY_FAIL_REPORT(cx) do {} while(0)
# endif /* DEBUG */
/*
* SpiderMonkey code should not be calling these allocation functions directly.
* Instead, all calls should go through JSRuntime, JSContext or OffTheBooks.
* However, js_free() can be called directly.
*/
static JS_INLINE void* js_malloc(size_t bytes)
{
JS_OOM_POSSIBLY_FAIL();
@ -381,82 +376,45 @@ JS_END_EXTERN_C
#include <new>
/*
* User guide to memory management within SpiderMonkey:
* Low-level memory management in SpiderMonkey:
*
* Quick tips:
* ** Do not use the standard malloc/free/realloc: SpiderMonkey allows these
* to be redefined (via JS_USE_CUSTOM_ALLOCATOR) and Gecko even #define's
* these symbols.
*
* Allocation:
* - Prefer to allocate using JSContext:
* cx->{malloc_,realloc_,calloc_,new_,array_new}
* ** Do not use the builtin C++ operator new and delete: these throw on
* error and we cannot override them not to.
*
* - If no JSContext is available, use a JSRuntime:
* rt->{malloc_,realloc_,calloc_,new_,array_new}
* Allocation:
*
* - As a last resort, use unaccounted allocation ("OffTheBooks"):
* js::OffTheBooks::{malloc_,realloc_,calloc_,new_,array_new}
* - If the lifetime of the allocation is tied to the lifetime of a GC-thing
* (that is, finalizing the GC-thing will free the allocation), call one of
* the following functions:
*
* Deallocation:
* - When the deallocation occurs on a slow path, use:
* Foreground::{free_,delete_,array_delete}
* JSContext::{malloc_,realloc_,calloc_,new_}
* JSRuntime::{malloc_,realloc_,calloc_,new_}
*
* - Otherwise deallocate on a background thread using a JSContext:
* cx->{free_,delete_,array_delete}
* These functions accumulate the number of bytes allocated which is used as
* part of the GC-triggering heuristic.
*
* - If no JSContext is available, use a JSRuntime:
* rt->{free_,delete_,array_delete}
* The difference between the JSContext and JSRuntime versions is that the
* cx version reports an out-of-memory error on OOM. (This follows from the
* general SpiderMonkey idiom that a JSContext-taking function reports its
* own errors.)
*
* - As a last resort, use UnwantedForeground deallocation:
* js::UnwantedForeground::{free_,delete_,array_delete}
* - Otherwise, use js_malloc/js_realloc/js_calloc/js_free/js_new
*
* General tips:
* Deallocation:
*
* - Mixing and matching these allocators is allowed (you may free memory
* allocated by any allocator, with any deallocator).
* - Ordinarily, use js_free/js_delete.
*
* - Never, ever use normal C/C++ memory management:
* malloc, free, new, new[], delete, operator new, etc.
* - For deallocations during GC finalization, use one of the following
* operations on the FreeOp provided to the finalizer:
*
* - Never, ever use low-level SpiderMonkey allocators:
* js_malloc(), js_free(), js_calloc(), js_realloc()
* Their use is reserved for the other memory managers.
* FreeOp::{free_,delete_}
*
* - Classes which have private constructors or destructors should have
* JS_DECLARE_ALLOCATION_FRIENDS_FOR_PRIVATE_CONSTRUCTOR added to their
* declaration.
*
* Details:
*
* Using vanilla new/new[] is unsafe in SpiderMonkey because they throw on
* failure instead of returning NULL, which is what SpiderMonkey expects.
* (Even overriding them is unsafe, as the system's C++ runtime library may
* throw, which we do not support. We also can't just use the 'nothrow'
* variant of new/new[], because we want to mediate *all* allocations
* within SpiderMonkey, to satisfy any embedders using
* JS_USE_CUSTOM_ALLOCATOR.)
*
* JSContexts and JSRuntimes keep track of memory allocated, and use this
* accounting to schedule GC. OffTheBooks does not. We'd like to remove
* OffTheBooks allocations as much as possible (bug 636558).
*
* On allocation failure, a JSContext correctly reports an error, which a
* JSRuntime and OffTheBooks does not.
*
* A JSContext deallocates in a background thread. A JSRuntime might
* deallocate in the background in the future, but does not now. Foreground
* deallocation is preferable on slow paths. UnwantedForeground deallocations
* occur where we have no JSContext or JSRuntime, and the deallocation is not
* on a slow path. We want to remove UnwantedForeground deallocations (bug
* 636561).
*
* JS_DECLARE_ALLOCATION_FRIENDS_FOR_PRIVATE_CONSTRUCTOR makes the allocation
* classes friends with your class, giving them access to private
* constructors and destructors.
*
* |make check| does a source level check on the number of uses OffTheBooks,
* UnwantedForeground, js_malloc, js_free etc, to prevent regressions. If you
* really must add one, update Makefile.in, and run |make check|.
*
* |make check| also statically prevents the use of vanilla new/new[].
* The advantage of these operations is that the memory is batched and freed
* on another thread.
*/
#define JS_NEW_BODY(allocator, t, parms) \
@ -464,190 +422,112 @@ JS_END_EXTERN_C
return memory ? new(memory) t parms : NULL;
/*
* Given a class which should provide new_() methods, add
* Given a class which should provide 'new' methods, add
* JS_DECLARE_NEW_METHODS (see JSContext for a usage example). This
* adds new_()s with up to 12 parameters. Add more versions of new_ below if
* adds news with up to 12 parameters. Add more versions of new below if
* you need more than 12 parameters.
*
* Note: Do not add a ; at the end of a use of JS_DECLARE_NEW_METHODS,
* or the build will break.
*/
#define JS_DECLARE_NEW_METHODS(ALLOCATOR, QUALIFIERS)\
#define JS_DECLARE_NEW_METHODS(NEWNAME, ALLOCATOR, QUALIFIERS)\
template <class T>\
QUALIFIERS T *new_() {\
QUALIFIERS T *NEWNAME() {\
JS_NEW_BODY(ALLOCATOR, T, ())\
}\
\
template <class T, class P1>\
QUALIFIERS T *new_(P1 p1) {\
QUALIFIERS T *NEWNAME(P1 p1) {\
JS_NEW_BODY(ALLOCATOR, T, (p1))\
}\
\
template <class T, class P1, class P2>\
QUALIFIERS T *new_(P1 p1, P2 p2) {\
QUALIFIERS T *NEWNAME(P1 p1, P2 p2) {\
JS_NEW_BODY(ALLOCATOR, T, (p1, p2))\
}\
\
template <class T, class P1, class P2, class P3>\
QUALIFIERS T *new_(P1 p1, P2 p2, P3 p3) {\
QUALIFIERS T *NEWNAME(P1 p1, P2 p2, P3 p3) {\
JS_NEW_BODY(ALLOCATOR, T, (p1, p2, p3))\
}\
\
template <class T, class P1, class P2, class P3, class P4>\
QUALIFIERS T *new_(P1 p1, P2 p2, P3 p3, P4 p4) {\
QUALIFIERS T *NEWNAME(P1 p1, P2 p2, P3 p3, P4 p4) {\
JS_NEW_BODY(ALLOCATOR, T, (p1, p2, p3, p4))\
}\
\
template <class T, class P1, class P2, class P3, class P4, class P5>\
QUALIFIERS T *new_(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) {\
QUALIFIERS T *NEWNAME(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) {\
JS_NEW_BODY(ALLOCATOR, T, (p1, p2, p3, p4, p5))\
}\
\
template <class T, class P1, class P2, class P3, class P4, class P5, class P6>\
QUALIFIERS T *new_(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) {\
QUALIFIERS T *NEWNAME(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) {\
JS_NEW_BODY(ALLOCATOR, T, (p1, p2, p3, p4, p5, p6))\
}\
\
template <class T, class P1, class P2, class P3, class P4, class P5, class P6, class P7>\
QUALIFIERS T *new_(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) {\
QUALIFIERS T *NEWNAME(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) {\
JS_NEW_BODY(ALLOCATOR, T, (p1, p2, p3, p4, p5, p6, p7))\
}\
\
template <class T, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8>\
QUALIFIERS T *new_(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) {\
QUALIFIERS T *NEWNAME(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) {\
JS_NEW_BODY(ALLOCATOR, T, (p1, p2, p3, p4, p5, p6, p7, p8))\
}\
\
template <class T, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9>\
QUALIFIERS T *new_(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9) {\
QUALIFIERS T *NEWNAME(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9) {\
JS_NEW_BODY(ALLOCATOR, T, (p1, p2, p3, p4, p5, p6, p7, p8, p9))\
}\
\
template <class T, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9, class P10>\
QUALIFIERS T *new_(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10) {\
QUALIFIERS T *NEWNAME(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10) {\
JS_NEW_BODY(ALLOCATOR, T, (p1, p2, p3, p4, p5, p6, p7, p8, p9, p10))\
}\
\
template <class T, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9, class P10, class P11>\
QUALIFIERS T *new_(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10, P11 p11) {\
QUALIFIERS T *NEWNAME(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10, P11 p11) {\
JS_NEW_BODY(ALLOCATOR, T, (p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11))\
}\
\
template <class T, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9, class P10, class P11, class P12>\
QUALIFIERS T *new_(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10, P11 p11, P12 p12) {\
QUALIFIERS T *NEWNAME(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10, P11 p11, P12 p12) {\
JS_NEW_BODY(ALLOCATOR, T, (p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12))\
}\
static const int JSMinAlignment = 8;\
template <class T>\
QUALIFIERS T *array_new(size_t n) {\
/* The length is stored just before the vector memory. */\
uint64_t numBytes64 = uint64_t(JSMinAlignment) + uint64_t(sizeof(T)) * uint64_t(n);\
size_t numBytes = size_t(numBytes64);\
if (numBytes64 != numBytes) {\
JS_ASSERT(0); /* we want to know if this happens in debug builds */\
return NULL;\
}\
void *memory = ALLOCATOR(numBytes);\
if (!memory)\
return NULL;\
*(size_t *)memory = n;\
memory = (void*)(uintptr_t(memory) + JSMinAlignment);\
return new(memory) T[n];\
}\
JS_DECLARE_NEW_METHODS(js_new, js_malloc, static JS_ALWAYS_INLINE)
#define JS_DECLARE_DELETE_METHODS(DEALLOCATOR, QUALIFIERS)\
template <class T>\
QUALIFIERS void delete_(T *p) {\
if (p) {\
p->~T();\
DEALLOCATOR(p);\
}\
}\
\
template <class T>\
QUALIFIERS void array_delete(T *p) {\
if (p) {\
void* p0 = (void *)(uintptr_t(p) - js::OffTheBooks::JSMinAlignment);\
size_t n = *(size_t *)p0;\
for (size_t i = 0; i < n; i++)\
(p + i)->~T();\
DEALLOCATOR(p0);\
}\
template <class T>
static JS_ALWAYS_INLINE void
js_delete(T *p)
{
if (p) {
p->~T();
js_free(p);
}
}
/*
* In general, all allocations should go through a JSContext or JSRuntime, so
* that the garbage collector knows how much memory has been allocated. In
* cases where it is difficult to use a JSContext or JSRuntime, OffTheBooks can
* be used, though this is undesirable.
*/
namespace js {
class OffTheBooks {
public:
JS_DECLARE_NEW_METHODS(::js_malloc, JS_ALWAYS_INLINE static)
static JS_INLINE void* malloc_(size_t bytes) {
return ::js_malloc(bytes);
}
static JS_INLINE void* calloc_(size_t bytes) {
return ::js_calloc(bytes);
}
static JS_INLINE void* realloc_(void* p, size_t bytes) {
return ::js_realloc(p, bytes);
}
};
/*
* We generally prefer deallocating using JSContext because it can happen in
* the background. On slow paths, we may prefer foreground allocation.
*/
class Foreground {
public:
/* See parentheses comment above. */
static JS_ALWAYS_INLINE void free_(void* p) {
::js_free(p);
}
JS_DECLARE_DELETE_METHODS(::js_free, JS_ALWAYS_INLINE static)
};
class UnwantedForeground : public Foreground {
};
template<typename T>
struct ScopedFreePtrTraits
{
typedef T* type;
static T* empty() { return NULL; }
static void release(T* ptr) { Foreground::free_(ptr); }
static void release(T* ptr) { js_free(ptr); }
};
SCOPED_TEMPLATE(ScopedFreePtr, ScopedFreePtrTraits)
template <typename T>
struct ScopedDeletePtrTraits : public ScopedFreePtrTraits<T>
{
static void release(T *ptr) { Foreground::delete_(ptr); }
static void release(T *ptr) { js_delete(ptr); }
};
SCOPED_TEMPLATE(ScopedDeletePtr, ScopedDeletePtrTraits)
} /* namespace js */
/*
* Note lack of ; in JSRuntime below. This is intentional so "calling" this
* looks "normal".
*/
#define JS_DECLARE_ALLOCATION_FRIENDS_FOR_PRIVATE_CONSTRUCTOR \
friend class js::OffTheBooks;\
friend class js::Foreground;\
friend class js::UnwantedForeground;\
friend struct ::JSContext;\
friend struct ::JSRuntime
/*
* The following classes are designed to cause assertions to detect
* inadvertent use of guard objects as temporaries. In other words,

View File

@ -512,37 +512,6 @@ ifeq ($(MOZ_DEBUG),1)
#check:: check-ooms
endif
## Prevent regressing in our deprecation of non-preferred memory management functions.
# We use all the files in the distribution so that different configurations
# don't give different results. We skip the contents of objdirs using |find|
# (it can't be done with %-expansion, because the files we want to skip aren't
# in the vpath).
ALL_FILES=$(shell find $(srcdir) \( -name "*.cpp" -o -name "*.h" \) ! -path "*/dist/*" ! -path "*/config/*")
check-malloc-function-usage: $(filter-out %jsalloc.h %jscntxt.h %jsutil.h, $(ALL_FILES))
# js_malloc and friends are only used by other memory managers, and should
# never be used elsewhere directly.
$(srcdir)/config/check_source_count.py "\bjs_malloc\b" 0 \
"in Makefile.in" "cx->malloc_ or rt->malloc_" $^
$(srcdir)/config/check_source_count.py "\bjs_calloc\b" 0 \
"in Makefile.in" "cx->calloc_ or rt->calloc_" $^
$(srcdir)/config/check_source_count.py "\bjs_realloc\b" 0 \
"in Makefile.in" "cx->realloc_ or rt->realloc_" $^
$(srcdir)/config/check_source_count.py "\bjs_free\b" 0 \
"in Makefile.in" "cx->free_" $^
# We desire these numbers to go down, not up. See "User guide to memory
# management within SpiderMonkey" in jsutil.h.
$(srcdir)/config/check_source_count.py OffTheBooks:: 71 \
"in Makefile.in" "{cx,rt}->{new_,array_new,malloc_,calloc_,realloc_}" $^
# This should go to zero, if possible.
$(srcdir)/config/check_source_count.py UnwantedForeground:: 31 \
"in Makefile.in" "{cx,rt}->{free_,delete_,array_delete}" $^
ifneq ($(OS_ARCH),WINNT) # FIXME: this should be made work on Windows too.
#check:: check-malloc-function-usage FIXME: disable on JM until closer to merge time.
endif
ifdef MOZ_VALGRIND
ifndef MOZ_ASAN
JITTEST_VALGRIND_FLAG = --valgrind

View File

@ -87,7 +87,6 @@ namespace JSC {
// These are reference-counted. A new one starts with a count of 1.
class ExecutablePool {
JS_DECLARE_ALLOCATION_FRIENDS_FOR_PRIVATE_CONSTRUCTOR;
friend class ExecutableAllocator;
private:
struct Allocation {
@ -123,11 +122,17 @@ public:
JS_ASSERT(m_refCount != 0);
// XXX: disabled, see bug 654820.
//JS_ASSERT_IF(willDestroy, m_refCount == 1);
if (--m_refCount == 0) {
js::UnwantedForeground::delete_(this);
}
if (--m_refCount == 0)
js_delete(this);
}
ExecutablePool(ExecutableAllocator* allocator, Allocation a)
: m_allocator(allocator), m_freePtr(a.pages), m_end(m_freePtr + a.size), m_allocation(a),
m_refCount(1), m_mjitCodeMethod(0), m_mjitCodeRegexp(0), m_destroy(false), m_gcNumber(0)
{ }
~ExecutablePool();
private:
// It should be impossible for us to roll over, because only small
// pools have multiple holders, and they have one holder per chunk
@ -138,13 +143,6 @@ private:
++m_refCount;
}
ExecutablePool(ExecutableAllocator* allocator, Allocation a)
: m_allocator(allocator), m_freePtr(a.pages), m_end(m_freePtr + a.size), m_allocation(a),
m_refCount(1), m_mjitCodeMethod(0), m_mjitCodeRegexp(0), m_destroy(false), m_gcNumber(0)
{ }
~ExecutablePool();
void* alloc(size_t n, CodeKind kind)
{
JS_ASSERT(n <= available());
@ -304,7 +302,7 @@ private:
if (!a.pages)
return NULL;
ExecutablePool *pool = js::OffTheBooks::new_<ExecutablePool>(this, a);
ExecutablePool *pool = js_new<ExecutablePool>(this, a);
if (!pool) {
systemRelease(a);
return NULL;

View File

@ -789,7 +789,7 @@ MapIteratorObject::create(JSContext *cx, HandleObject mapobj, ValueMap *data)
JSObject *iterobj = NewObjectWithGivenProto(cx, &MapIteratorClass, proto, global);
if (!iterobj) {
cx->delete_(range);
js_delete(range);
return NULL;
}
iterobj->setSlot(TargetSlot, ObjectValue(*mapobj));
@ -817,7 +817,7 @@ MapIteratorObject::next_impl(JSContext *cx, CallArgs args)
if (!range)
return js_ThrowStopIteration(cx);
if (range->empty()) {
cx->delete_(range);
js_delete(range);
thisobj.setReservedSlot(RangeSlot, PrivateValue(NULL));
return js_ThrowStopIteration(cx);
}
@ -1236,7 +1236,7 @@ SetIteratorObject::create(JSContext *cx, HandleObject setobj, ValueSet *data)
JSObject *iterobj = NewObjectWithGivenProto(cx, &SetIteratorClass, proto, global);
if (!iterobj) {
cx->delete_(range);
js_delete(range);
return NULL;
}
iterobj->setSlot(TargetSlot, ObjectValue(*setobj));
@ -1264,7 +1264,7 @@ SetIteratorObject::next_impl(JSContext *cx, CallArgs args)
if (!range)
return js_ThrowStopIteration(cx);
if (range->empty()) {
cx->delete_(range);
js_delete(range);
thisobj.setReservedSlot(RangeSlot, PrivateValue(NULL));
return js_ThrowStopIteration(cx);
}

View File

@ -2149,7 +2149,7 @@ ImplicitConvert(JSContext* cx,
return false;
char** charBuffer = static_cast<char**>(buffer);
*charBuffer = cx->array_new<char>(nbytes + 1);
*charBuffer = (char*)cx->malloc_(nbytes + 1);
if (!*charBuffer) {
JS_ReportAllocationOverflow(cx);
return false;
@ -2166,7 +2166,7 @@ ImplicitConvert(JSContext* cx,
// JSString's buffer, but this approach is safer if the caller happens
// to modify the string.)
jschar** jscharBuffer = static_cast<jschar**>(buffer);
*jscharBuffer = cx->array_new<jschar>(sourceLength + 1);
*jscharBuffer = (jschar*)cx->malloc_((sourceLength + 1) * sizeof(jschar));
if (!*jscharBuffer) {
JS_ReportAllocationOverflow(cx);
return false;
@ -2255,7 +2255,7 @@ ImplicitConvert(JSContext* cx,
// Convert into an intermediate, in case of failure.
size_t elementSize = CType::GetSize(baseType);
size_t arraySize = elementSize * targetLength;
AutoPtr<char>::Array intermediate(cx->array_new<char>(arraySize));
AutoPtr<char> intermediate((char*)cx->malloc_(arraySize));
if (!intermediate) {
JS_ReportAllocationOverflow(cx);
return false;
@ -2306,7 +2306,7 @@ ImplicitConvert(JSContext* cx,
// Convert into an intermediate, in case of failure.
size_t structSize = CType::GetSize(targetType);
AutoPtr<char>::Array intermediate(cx->array_new<char>(structSize));
AutoPtr<char> intermediate((char*)cx->malloc_(structSize));
if (!intermediate) {
JS_ReportAllocationOverflow(cx);
return false;
@ -3067,7 +3067,7 @@ CType::Finalize(JSFreeOp *fop, JSObject* obj)
slot = JS_GetReservedSlot(obj, SLOT_FFITYPE);
if (!JSVAL_IS_VOID(slot)) {
ffi_type* ffiType = static_cast<ffi_type*>(JSVAL_TO_PRIVATE(slot));
FreeOp::get(fop)->array_delete(ffiType->elements);
FreeOp::get(fop)->free_(ffiType->elements);
FreeOp::get(fop)->delete_(ffiType);
}
@ -4202,7 +4202,7 @@ ArrayType::BuildFFIType(JSContext* cx, JSObject* obj)
ffiType->type = FFI_TYPE_STRUCT;
ffiType->size = CType::GetSize(obj);
ffiType->alignment = CType::GetAlignment(obj);
ffiType->elements = cx->array_new<ffi_type*>(length + 1);
ffiType->elements = (ffi_type**)cx->malloc_((length + 1) * sizeof(ffi_type*));
if (!ffiType->elements) {
JS_ReportAllocationOverflow(cx);
return NULL;
@ -4644,9 +4644,9 @@ StructType::BuildFFIType(JSContext* cx, JSObject* obj)
}
ffiType->type = FFI_TYPE_STRUCT;
AutoPtr<ffi_type*>::Array elements;
AutoPtr<ffi_type*> elements;
if (len != 0) {
elements = cx->array_new<ffi_type*>(len + 1);
elements = (ffi_type**)cx->malloc_((len + 1) * sizeof(ffi_type*));
if (!elements) {
JS_ReportOutOfMemory(cx);
return NULL;
@ -4665,7 +4665,7 @@ StructType::BuildFFIType(JSContext* cx, JSObject* obj)
// Represent an empty struct as having a size of 1 byte, just like C++.
JS_ASSERT(structSize == 1);
JS_ASSERT(structAlign == 1);
elements = cx->array_new<ffi_type*>(2);
elements = (ffi_type**)cx->malloc_(2 * sizeof(ffi_type*));
if (!elements) {
JS_ReportOutOfMemory(cx);
return NULL;
@ -5012,14 +5012,14 @@ struct AutoValue
~AutoValue()
{
UnwantedForeground::array_delete(static_cast<char*>(mData));
js_free(mData);
}
bool SizeToType(JSContext* cx, JSObject* type)
{
// Allocate a minimum of sizeof(ffi_arg) to handle small integers.
size_t size = Align(CType::GetSize(type), sizeof(ffi_arg));
mData = cx->array_new<char>(size);
mData = js_malloc(size);
if (mData)
memset(mData, 0, size);
return mData != NULL;
@ -6068,11 +6068,11 @@ CData::Create(JSContext* cx,
} else {
// Initialize our own buffer.
size_t size = CType::GetSize(typeObj);
data = cx->array_new<char>(size);
data = (char*)cx->malloc_(size);
if (!data) {
// Report a catchable allocation error.
JS_ReportAllocationOverflow(cx);
Foreground::delete_(buffer);
js_free(buffer);
return NULL;
}
@ -6104,7 +6104,7 @@ CData::Finalize(JSFreeOp *fop, JSObject* obj)
char** buffer = static_cast<char**>(JSVAL_TO_PRIVATE(slot));
if (owns)
FreeOp::get(fop)->array_delete(*buffer);
FreeOp::get(fop)->free_(*buffer);
FreeOp::get(fop)->delete_(buffer);
}

View File

@ -20,34 +20,17 @@ namespace ctypes {
** Utility classes
*******************************************************************************/
template<class T>
class OperatorDelete
{
public:
static void destroy(T* ptr) { UnwantedForeground::delete_(ptr); }
};
template<class T>
class OperatorArrayDelete
{
public:
static void destroy(T* ptr) { UnwantedForeground::array_delete(ptr); }
};
// Class that takes ownership of a pointer T*, and calls cx->delete_() or
// cx->array_delete() upon destruction.
template<class T, class DeleteTraits = OperatorDelete<T> >
template<class T>
class AutoPtr {
private:
typedef AutoPtr<T, DeleteTraits> self_type;
typedef AutoPtr<T> self_type;
public:
// An AutoPtr variant that calls js_array_delete() instead.
typedef AutoPtr<T, OperatorArrayDelete<T> > Array;
AutoPtr() : mPtr(NULL) { }
explicit AutoPtr(T* ptr) : mPtr(ptr) { }
~AutoPtr() { DeleteTraits::destroy(mPtr); }
~AutoPtr() { js_delete(mPtr); }
T* operator->() { return mPtr; }
bool operator!() { return mPtr == NULL; }
@ -64,8 +47,8 @@ public:
private:
// Do not allow copy construction or assignment from another AutoPtr.
template<class U> AutoPtr(AutoPtr<T, U>&);
template<class U> self_type& operator=(AutoPtr<T, U>& rhs);
AutoPtr(AutoPtr<T>&);
self_type& operator=(AutoPtr<T>& rhs);
T* mPtr;
};
@ -311,7 +294,7 @@ struct ClosureInfo
if (closure)
ffi_closure_free(closure);
if (errResult)
rt->free_(errResult);
js_free(errResult);
};
};

View File

@ -306,7 +306,7 @@ class LifoAlloc
return static_cast<T *>(alloc(sizeof(T)));
}
JS_DECLARE_NEW_METHODS(alloc, JS_ALWAYS_INLINE)
JS_DECLARE_NEW_METHODS(new_, alloc, JS_ALWAYS_INLINE)
};
class LifoAllocScope

View File

@ -139,12 +139,10 @@ BytecodeEmitter::init()
BytecodeEmitter::~BytecodeEmitter()
{
JSContext *cx = sc->context;
cx->free_(prolog.base);
cx->free_(prolog.notes);
cx->free_(main.base);
cx->free_(main.notes);
js_free(prolog.base);
js_free(prolog.notes);
js_free(main.base);
js_free(main.notes);
}
static ptrdiff_t
@ -2391,7 +2389,7 @@ EmitSwitch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn)
release:
if (intmap && intmap != intmap_space)
cx->free_(intmap);
js_free(intmap);
if (!ok)
return false;

View File

@ -678,7 +678,7 @@ frontend::FoldConstants(JSContext *cx, ParseNode *pn, Parser *parser, bool inGen
chars[length] = 0;
JSString *str = js_NewString(cx, chars, length);
if (!str) {
cx->free_(chars);
js_free(chars);
return false;
}

View File

@ -36,7 +36,7 @@ void
ParseMapPool::purgeAll()
{
for (void **it = all.begin(), **end = all.end(); it != end; ++it)
cx->delete_<AtomMapT>(asAtomMap(*it));
js_delete<AtomMapT>(asAtomMap(*it));
all.clearAndFree();
recyclable.clearAndFree();

View File

@ -79,7 +79,7 @@ ParseContext::~ParseContext()
// die, make |*parserPC| point to this object's parent.
JS_ASSERT(*parserPC == this);
*parserPC = this->parent;
sc->context->delete_(funcStmts);
js_delete(funcStmts);
if (queuedStrictModeError) {
// If the parent context is looking for strict mode violations, pass
// ours up. Otherwise, free it.
@ -87,7 +87,7 @@ ParseContext::~ParseContext()
!parent->queuedStrictModeError)
parent->queuedStrictModeError = queuedStrictModeError;
else
sc->context->delete_(queuedStrictModeError);
js_delete(queuedStrictModeError);
}
}

View File

@ -342,7 +342,7 @@ struct Parser : private AutoGCRooter
void prepareNodeForMutation(ParseNode *pn) { return allocator.prepareNodeForMutation(pn); }
/* new_ methods for creating parse nodes. These report OOM on context. */
JS_DECLARE_NEW_METHODS(allocParseNode, inline)
JS_DECLARE_NEW_METHODS(new_, allocParseNode, inline)
ParseNode *cloneNode(const ParseNode &other) {
ParseNode *node = allocParseNode(sizeof(ParseNode));

View File

@ -218,9 +218,9 @@ TokenStream::TokenStream(JSContext *cx, const CompileOptions &options,
TokenStream::~TokenStream()
{
if (flags & TSF_OWNFILENAME)
cx->free_((void *) filename);
js_free((void *) filename);
if (sourceMap)
cx->free_(sourceMap);
js_free(sourceMap);
if (originPrincipals)
JS_DropPrincipals(cx->runtime, originPrincipals);
}
@ -441,19 +441,19 @@ CompileError::throwError()
CompileError::~CompileError()
{
cx->free_((void*)report.uclinebuf);
cx->free_((void*)report.linebuf);
cx->free_((void*)report.ucmessage);
cx->free_(message);
js_free((void*)report.uclinebuf);
js_free((void*)report.linebuf);
js_free((void*)report.ucmessage);
js_free(message);
message = NULL;
if (report.messageArgs) {
if (hasCharArgs) {
unsigned i = 0;
while (report.messageArgs[i])
cx->free_((void*)report.messageArgs[i++]);
js_free((void*)report.messageArgs[i++]);
}
cx->free_(report.messageArgs);
js_free(report.messageArgs);
}
PodZero(&report);
@ -725,7 +725,7 @@ TokenStream::getXMLEntity()
bytes = DeflateString(cx, bp + 1, (tb.end() - bp) - 1);
if (bytes) {
reportError(msg, bytes);
cx->free_(bytes);
js_free(bytes);
}
return false;
}
@ -1211,7 +1211,7 @@ TokenStream::getAtLine()
if (c == EOF || c == '\n') {
if (i > 0) {
if (flags & TSF_OWNFILENAME)
cx->free_((void *) filename);
js_free((void *) filename);
filename = JS_strdup(cx, filenameBuf);
if (!filename)
return false;
@ -1250,7 +1250,7 @@ TokenStream::getAtSourceMappingURL()
size_t sourceMapLength = tokenbuf.length();
if (sourceMap)
cx->free_(sourceMap);
js_free(sourceMap);
sourceMap = static_cast<jschar *>(cx->malloc_(sizeof(jschar) * (sourceMapLength + 1)));
if (!sourceMap)
return false;

View File

@ -799,7 +799,7 @@ ScriptAnalysis::analyzeLifetimes(JSContext *cx)
LifetimeVariable &var = *saved[i];
var.lifetime = alloc.new_<Lifetime>(offset, var.savedEnd, var.saved);
if (!var.lifetime) {
cx->free_(saved);
js_free(saved);
setOOM(cx);
return;
}
@ -866,7 +866,7 @@ ScriptAnalysis::analyzeLifetimes(JSContext *cx)
LoopAnalysis *nloop = alloc.new_<LoopAnalysis>();
if (!nloop) {
cx->free_(saved);
js_free(saved);
setOOM(cx);
return;
}
@ -916,7 +916,7 @@ ScriptAnalysis::analyzeLifetimes(JSContext *cx)
*/
var.lifetime = alloc.new_<Lifetime>(offset, var.savedEnd, var.saved);
if (!var.lifetime) {
cx->free_(saved);
js_free(saved);
setOOM(cx);
return;
}
@ -939,7 +939,7 @@ ScriptAnalysis::analyzeLifetimes(JSContext *cx)
offset--;
}
cx->free_(saved);
js_free(saved);
ranLifetimes_ = true;
}
@ -1207,7 +1207,7 @@ ScriptAnalysis::analyzeSSA(JSContext *cx)
JSContext *cx;
SSAValueInfo *values;
FreeSSAValues(JSContext *cx, SSAValueInfo *values) : cx(cx), values(values) {}
~FreeSSAValues() { cx->free_(values); }
~FreeSSAValues() { js_free(values); }
} free(cx, values);
SSAValueInfo *stack = values + numSlots;
@ -1853,7 +1853,7 @@ ScriptAnalysis::freezeNewValues(JSContext *cx, uint32_t offset)
unsigned count = pending->length();
if (count == 0) {
cx->delete_(pending);
js_delete(pending);
return;
}
@ -1868,7 +1868,7 @@ ScriptAnalysis::freezeNewValues(JSContext *cx, uint32_t offset)
code.newValues[count].slot = 0;
code.newValues[count].value.clear();
cx->delete_(pending);
js_delete(pending);
}
bool

View File

@ -436,7 +436,7 @@ JS_RemoveArgumentFormatter(JSContext *cx, const char *format)
while ((map = *mpp) != NULL) {
if (map->length == length && !strcmp(map->format, format)) {
*mpp = map->next;
cx->free_(map);
js_free(map);
return;
}
mpp = &map->next;
@ -905,7 +905,7 @@ JSRuntime::init(uint32_t maxbytes)
!atomsCompartment->init(NULL) ||
!compartments.append(atomsCompartment))
{
Foreground::delete_(atomsCompartment);
js_delete(atomsCompartment);
return false;
}
@ -938,7 +938,7 @@ JSRuntime::init(uint32_t maxbytes)
debugScopes = this->new_<DebugScopes>(this);
if (!debugScopes || !debugScopes->init()) {
Foreground::delete_(debugScopes);
js_delete(debugScopes);
return false;
}
@ -952,7 +952,7 @@ JSRuntime::~JSRuntime()
clearOwnerThread();
#endif
delete_(debugScopes);
js_delete(debugScopes);
/*
* Even though all objects in the compartment are dead, we may have keep
@ -992,12 +992,12 @@ JSRuntime::~JSRuntime()
PR_DestroyLock(gcLock);
#endif
delete_(bumpAlloc_);
delete_(mathCache_);
js_delete(bumpAlloc_);
js_delete(mathCache_);
#ifdef JS_METHODJIT
delete_(jaegerRuntime_);
js_delete(jaegerRuntime_);
#endif
delete_(execAlloc_); /* Delete after jaegerRuntime_. */
js_delete(execAlloc_); /* Delete after jaegerRuntime_. */
}
#ifdef JS_THREADSAFE
@ -1087,7 +1087,7 @@ JS_NewRuntime(uint32_t maxbytes)
js_NewRuntimeWasCalled = JS_TRUE;
}
JSRuntime *rt = OffTheBooks::new_<JSRuntime>();
JSRuntime *rt = js_new<JSRuntime>();
if (!rt)
return NULL;
@ -1104,7 +1104,7 @@ JS_PUBLIC_API(void)
JS_DestroyRuntime(JSRuntime *rt)
{
Probes::destroyRuntime(rt);
Foreground::delete_(rt);
js_delete(rt);
}
JS_PUBLIC_API(void)
@ -2310,7 +2310,7 @@ JS_realloc(JSContext *cx, void *p, size_t nbytes)
JS_PUBLIC_API(void)
JS_free(JSContext *cx, void *p)
{
return cx->free_(p);
return js_free(p);
}
JS_PUBLIC_API(void)
@ -2772,7 +2772,7 @@ DumpNotify(JSTracer *trc, void **thingp, JSGCTraceKind kind)
const char *edgeName = JS_GetTraceEdgeName(&dtrc->base, dtrc->buffer, sizeof(dtrc->buffer));
size_t edgeNameSize = strlen(edgeName) + 1;
size_t bytes = offsetof(JSHeapDumpNode, edgeName) + edgeNameSize;
JSHeapDumpNode *node = (JSHeapDumpNode *) OffTheBooks::malloc_(bytes);
JSHeapDumpNode *node = (JSHeapDumpNode *) js_malloc(bytes);
if (!node) {
dtrc->ok = false;
return;
@ -2916,7 +2916,7 @@ JS_DumpHeap(JSRuntime *rt, FILE *fp, void* startThing, JSGCTraceKind startKind,
for (;;) {
next = node->next;
parent = node->parent;
Foreground::free_(node);
js_free(node);
node = next;
if (node)
break;
@ -5227,7 +5227,7 @@ JS::Compile(JSContext *cx, HandleObject obj, CompileOptions options,
return NULL;
JSScript *script = Compile(cx, obj, options, chars, length);
cx->free_(chars);
js_free(chars);
return script;
}
@ -5395,7 +5395,7 @@ JS_BufferIsCompilableUnit(JSContext *cx, JSBool bytes_are_utf8, JSObject *objArg
JS_SetErrorReporter(cx, older);
}
}
cx->free_(chars);
js_free(chars);
JS_RestoreExceptionState(cx, exnState);
return result;
}
@ -5519,7 +5519,7 @@ JS::CompileFunction(JSContext *cx, HandleObject obj, CompileOptions options,
return NULL;
JSFunction *fun = CompileFunction(cx, obj, options, name, nargs, argnames, chars, length);
cx->free_(chars);
js_free(chars);
return fun;
}
@ -5715,7 +5715,7 @@ JS::Evaluate(JSContext *cx, HandleObject obj, CompileOptions options,
return false;
bool ok = Evaluate(cx, obj, options, chars, length, rval);
cx->free_(chars);
js_free(chars);
return ok;
}
@ -6020,7 +6020,7 @@ JS_NewStringCopyZ(JSContext *cx, const char *s)
return NULL;
str = js_NewString(cx, js, n);
if (!str)
cx->free_(js);
js_free(js);
return str;
}
@ -6461,7 +6461,7 @@ void
JSAutoStructuredCloneBuffer::clear()
{
if (data_) {
Foreground::free_(data_);
js_free(data_);
data_ = NULL;
nbytes_ = 0;
version_ = 0;
@ -6480,7 +6480,7 @@ JSAutoStructuredCloneBuffer::adopt(uint64_t *data, size_t nbytes, uint32_t versi
bool
JSAutoStructuredCloneBuffer::copy(const uint64_t *srcData, size_t nbytes, uint32_t version)
{
uint64_t *newData = static_cast<uint64_t *>(OffTheBooks::malloc_(nbytes));
uint64_t *newData = static_cast<uint64_t *>(js_malloc(nbytes));
if (!newData)
return false;
@ -6776,7 +6776,7 @@ JS_NewRegExpObject(JSContext *cx, JSObject *objArg, char *bytes, size_t length,
RegExpStatics *res = obj->asGlobal().getRegExpStatics();
RegExpObject *reobj = RegExpObject::create(cx, res, chars, length, RegExpFlag(flags), NULL);
cx->free_(chars);
js_free(chars);
return reobj;
}
@ -6835,7 +6835,7 @@ JS_NewRegExpObjectNoStatics(JSContext *cx, char *bytes, size_t length, unsigned
if (!chars)
return NULL;
RegExpObject *reobj = RegExpObject::createNoStatics(cx, chars, length, RegExpFlag(flags), NULL);
cx->free_(chars);
js_free(chars);
return reobj;
}
@ -6995,7 +6995,7 @@ JS_DropExceptionState(JSContext *cx, JSExceptionState *state)
assertSameCompartment(cx, state->exception);
JS_RemoveValueRoot(cx, &state->exception);
}
cx->free_(state);
js_free(state);
}
}

View File

@ -5762,7 +5762,7 @@ class JSAutoByteString {
}
~JSAutoByteString() {
js::UnwantedForeground::free_(mBytes);
js_free(mBytes);
}
/* Take ownership of the given byte array. */
@ -5779,7 +5779,7 @@ class JSAutoByteString {
}
void clear() {
js::UnwantedForeground::free_(mBytes);
js_free(mBytes);
mBytes = NULL;
}
@ -6038,17 +6038,17 @@ JS_ReportAllocationOverflow(JSContext *cx);
struct JSErrorReport {
const char *filename; /* source file name, URL, etc., or null */
JSPrincipals *originPrincipals; /* see 'originPrincipals' comment above */
unsigned lineno; /* source line number */
unsigned lineno; /* source line number */
const char *linebuf; /* offending source line without final \n */
const char *tokenptr; /* pointer to error token in linebuf */
const jschar *uclinebuf; /* unicode (original) line buffer */
const jschar *uctokenptr; /* unicode (original) token pointer */
unsigned flags; /* error/warning, etc. */
unsigned errorNumber; /* the error number, e.g. see js.msg */
unsigned flags; /* error/warning, etc. */
unsigned errorNumber; /* the error number, e.g. see js.msg */
const jschar *ucmessage; /* the (default) error message */
const jschar **messageArgs; /* arguments for the error message */
int16_t exnType; /* One of the JSExnType constants */
unsigned column; /* zero-based column index in line */
unsigned column; /* zero-based column index in line */
};
/*

View File

@ -1325,7 +1325,7 @@ JSObject::makeDenseArraySlow(JSContext *cx, HandleObject obj)
if (!AddLengthProperty(cx, obj)) {
obj->shape_ = oldShape;
if (obj->elements != emptyObjectElements)
cx->free_(obj->getElementsHeader());
js_free(obj->getElementsHeader());
obj->elements = elems;
return false;
}
@ -1345,7 +1345,7 @@ JSObject::makeDenseArraySlow(JSContext *cx, HandleObject obj)
if (!obj->addDataProperty(cx, id, next, JSPROP_ENUMERATE)) {
obj->shape_ = oldShape;
cx->free_(obj->getElementsHeader());
js_free(obj->getElementsHeader());
obj->elements = elems;
return false;
}
@ -1358,7 +1358,7 @@ JSObject::makeDenseArraySlow(JSContext *cx, HandleObject obj)
ObjectElements *oldheader = ObjectElements::fromElements(elems);
obj->getElementsHeader()->length = oldheader->length;
cx->free_(oldheader);
js_free(oldheader);
return true;
}
@ -3737,7 +3737,7 @@ js_ArrayInfo(JSContext *cx, unsigned argc, Value *vp)
if (arg.isPrimitive() ||
!(array = arg.toObjectOrNull())->isArray()) {
fprintf(stderr, "%s: not array\n", bytes);
cx->free_(bytes);
js_free(bytes);
continue;
}
fprintf(stderr, "%s: %s (len %u", bytes,
@ -3748,7 +3748,7 @@ js_ArrayInfo(JSContext *cx, unsigned argc, Value *vp)
array->getDenseArrayCapacity());
}
fputs(")\n", stderr);
cx->free_(bytes);
js_free(bytes);
}
args.rval().setUndefined();

View File

@ -384,7 +384,7 @@ js::Atomize(JSContext *cx, const char *bytes, size_t length, InternBehavior ib,
JSAtom *atom = AtomizeInline(cx, &chars, inflatedLength, ib, ocb);
if (ocb == TakeCharOwnership && chars)
cx->free_((void *)chars);
js_free((void *)chars);
return atom;
}
@ -506,7 +506,7 @@ js::XDRAtom(XDRState<mode> *xdr, JSAtom **atomp)
JS_ALWAYS_TRUE(xdr->codeChars(chars, nchars));
atom = AtomizeChars(cx, chars, nchars);
if (chars != stackChars)
Foreground::free_(chars);
js_free(chars);
#endif /* !IS_LITTLE_ENDIAN */
if (!atom)

View File

@ -607,7 +607,7 @@ class Chars {
jschar *p;
public:
Chars(JSContext *cx) : cx(cx), p(NULL) {}
~Chars() { if (p) cx->free_(p); }
~Chars() { if (p) js_free(p); }
bool allocate(size_t len) {
JS_ASSERT(!p);

View File

@ -185,7 +185,7 @@ JSRuntime::createExecutableAllocator(JSContext *cx)
JSC::AllocationBehavior randomize =
jitHardening ? JSC::AllocationCanRandomize : JSC::AllocationDeterministic;
execAlloc_ = new_<JSC::ExecutableAllocator>(randomize);
execAlloc_ = js_new<JSC::ExecutableAllocator>(randomize);
if (!execAlloc_)
js_ReportOutOfMemory(cx);
return execAlloc_;
@ -197,7 +197,7 @@ JSRuntime::createBumpPointerAllocator(JSContext *cx)
JS_ASSERT(!bumpAlloc_);
JS_ASSERT(cx->runtime == this);
bumpAlloc_ = new_<WTF::BumpPointerAllocator>();
bumpAlloc_ = js_new<WTF::BumpPointerAllocator>();
if (!bumpAlloc_)
js_ReportOutOfMemory(cx);
return bumpAlloc_;
@ -209,7 +209,7 @@ JSRuntime::createMathCache(JSContext *cx)
JS_ASSERT(!mathCache_);
JS_ASSERT(cx->runtime == this);
MathCache *newMathCache = new_<MathCache>();
MathCache *newMathCache = js_new<MathCache>();
if (!newMathCache) {
js_ReportOutOfMemory(cx);
return NULL;
@ -226,10 +226,10 @@ JSRuntime::createJaegerRuntime(JSContext *cx)
JS_ASSERT(!jaegerRuntime_);
JS_ASSERT(cx->runtime == this);
mjit::JaegerRuntime *jr = new_<mjit::JaegerRuntime>();
mjit::JaegerRuntime *jr = js_new<mjit::JaegerRuntime>();
if (!jr || !jr->init(cx)) {
js_ReportOutOfMemory(cx);
delete_(jr);
js_delete(jr);
return NULL;
}
@ -334,14 +334,14 @@ js::NewContext(JSRuntime *rt, size_t stackChunkSize)
{
JS_AbortIfWrongThread(rt);
JSContext *cx = OffTheBooks::new_<JSContext>(rt);
JSContext *cx = js_new<JSContext>(rt);
if (!cx)
return NULL;
JS_ASSERT(cx->findVersion() == JSVERSION_DEFAULT);
if (!cx->cycleDetectorSet.init()) {
Foreground::delete_(cx);
js_delete(cx);
return NULL;
}
@ -439,7 +439,7 @@ js::DestroyContext(JSContext *cx, DestroyContextMode mode)
PrepareForFullGC(rt);
GC(rt, GC_NORMAL, gcreason::DESTROY_CONTEXT);
}
Foreground::delete_(cx);
js_delete(cx);
}
namespace js {
@ -653,8 +653,8 @@ js_ReportErrorVA(JSContext *cx, unsigned flags, const char *format, va_list ap)
warning = JSREPORT_IS_WARNING(report.flags);
ReportError(cx, message, &report, NULL, NULL);
Foreground::free_(message);
Foreground::free_(ucmessage);
js_free(message);
js_free(ucmessage);
return warning;
}
@ -849,7 +849,7 @@ js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
reportp->ucmessage = out = (jschar *)
cx->malloc_((expandedLength + 1) * sizeof(jschar));
if (!out) {
cx->free_(buffer);
js_free(buffer);
goto error;
}
while (*fmt) {
@ -869,7 +869,7 @@ js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
}
JS_ASSERT(expandedArgs == argCount);
*out = 0;
cx->free_(buffer);
js_free(buffer);
*messagep = DeflateString(cx, reportp->ucmessage,
size_t(out - reportp->ucmessage));
if (!*messagep)
@ -910,17 +910,17 @@ error:
if (charArgs) {
i = 0;
while (reportp->messageArgs[i])
cx->free_((void *)reportp->messageArgs[i++]);
js_free((void *)reportp->messageArgs[i++]);
}
cx->free_((void *)reportp->messageArgs);
js_free((void *)reportp->messageArgs);
reportp->messageArgs = NULL;
}
if (reportp->ucmessage) {
cx->free_((void *)reportp->ucmessage);
js_free((void *)reportp->ucmessage);
reportp->ucmessage = NULL;
}
if (*messagep) {
cx->free_((void *)*messagep);
js_free((void *)*messagep);
*messagep = NULL;
}
return JS_FALSE;
@ -952,7 +952,7 @@ js_ReportErrorNumberVA(JSContext *cx, unsigned flags, JSErrorCallback callback,
ReportError(cx, message, &report, callback, userRef);
if (message)
cx->free_(message);
js_free(message);
if (report.messageArgs) {
/*
* js_ExpandErrorArguments owns its messageArgs only if it had to
@ -961,12 +961,12 @@ js_ReportErrorNumberVA(JSContext *cx, unsigned flags, JSErrorCallback callback,
if (charArgs) {
int i = 0;
while (report.messageArgs[i])
cx->free_((void *)report.messageArgs[i++]);
js_free((void *)report.messageArgs[i++]);
}
cx->free_((void *)report.messageArgs);
js_free((void *)report.messageArgs);
}
if (report.ucmessage)
cx->free_((void *)report.ucmessage);
js_free((void *)report.ucmessage);
return warning;
}
@ -980,7 +980,7 @@ js_ReportErrorAgain(JSContext *cx, const char *message, JSErrorReport *reportp)
return;
if (cx->lastMessage)
Foreground::free_(cx->lastMessage);
js_free(cx->lastMessage);
cx->lastMessage = JS_strdup(cx, message);
if (!cx->lastMessage)
return;
@ -1035,7 +1035,7 @@ js_ReportIsNullOrUndefined(JSContext *cx, int spindex, HandleValue v,
js_null_str, NULL);
}
cx->free_(bytes);
js_free(bytes);
return ok;
}
@ -1058,7 +1058,7 @@ js_ReportMissingArg(JSContext *cx, HandleValue v, unsigned arg)
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_MISSING_FUN_ARG, argbuf,
bytes ? bytes : "");
cx->free_(bytes);
js_free(bytes);
}
JSBool
@ -1077,7 +1077,7 @@ js_ReportValueErrorFlags(JSContext *cx, unsigned flags, const unsigned errorNumb
ok = JS_ReportErrorFlagsAndNumber(cx, flags, js_GetErrorMessage,
NULL, errorNumber, bytes, arg1, arg2);
cx->free_(bytes);
js_free(bytes);
return ok;
}
@ -1224,17 +1224,17 @@ JSContext::~JSContext()
{
/* Free the stuff hanging off of cx. */
if (parseMapPool_)
Foreground::delete_(parseMapPool_);
js_delete(parseMapPool_);
if (lastMessage)
Foreground::free_(lastMessage);
js_free(lastMessage);
/* Remove any argument formatters. */
JSArgumentFormatMap *map = argumentFormatMap;
while (map) {
JSArgumentFormatMap *temp = map;
map = map->next;
Foreground::free_(temp);
js_free(temp);
}
JS_ASSERT(!resolvingList);
@ -1382,11 +1382,11 @@ JSRuntime::onOutOfMemory(void *p, size_t nbytes, JSContext *cx)
ShrinkGCBuffers(this);
gcHelperThread.waitBackgroundSweepOrAllocEnd();
if (!p)
p = OffTheBooks::malloc_(nbytes);
p = js_malloc(nbytes);
else if (p == reinterpret_cast<void *>(1))
p = OffTheBooks::calloc_(nbytes);
p = js_calloc(nbytes);
else
p = OffTheBooks::realloc_(p, nbytes);
p = js_realloc(p, nbytes);
if (p)
return p;
if (cx)
@ -1398,7 +1398,7 @@ void
JSContext::purge()
{
if (!activeCompilations) {
Foreground::delete_(parseMapPool_);
js_delete(parseMapPool_);
parseMapPool_ = NULL;
}
}

View File

@ -341,7 +341,13 @@ class FreeOp : public JSFreeOp {
inline void free_(void* p);
JS_DECLARE_DELETE_METHODS(free_, inline)
template <class T>
inline void delete_(T *p) {
if (p) {
p->~T();
free_(p);
}
}
static void staticAsserts() {
/*
@ -934,13 +940,7 @@ struct JSRuntime : js::RuntimeFriendFields
return JS_LIKELY(!!p2) ? p2 : onOutOfMemory(p, bytes, cx);
}
inline void free_(void* p) {
/* FIXME: Making this free in the background is buggy. Can it work? */
js::Foreground::free_(p);
}
JS_DECLARE_NEW_METHODS(malloc_, JS_ALWAYS_INLINE)
JS_DECLARE_DELETE_METHODS(free_, JS_ALWAYS_INLINE)
JS_DECLARE_NEW_METHODS(new_, malloc_, JS_ALWAYS_INLINE)
void setGCMaxMallocBytes(size_t value);
@ -1120,7 +1120,7 @@ FreeOp::free_(void* p) {
runtime()->gcHelperThread.freeLater(p);
return;
}
runtime()->free_(p);
js_free(p);
}
} /* namespace js */
@ -1416,12 +1416,7 @@ struct JSContext : js::ContextFriendFields
return runtime->realloc_(p, oldBytes, newBytes, this);
}
inline void free_(void* p) {
runtime->free_(p);
}
JS_DECLARE_NEW_METHODS(malloc_, inline)
JS_DECLARE_DELETE_METHODS(free_, inline)
JS_DECLARE_NEW_METHODS(new_, malloc_, JS_ALWAYS_INLINE)
void purge();
@ -1617,7 +1612,6 @@ class AutoKeepAtoms {
};
class AutoReleasePtr {
JSContext *cx;
void *ptr;
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
@ -1625,20 +1619,20 @@ class AutoReleasePtr {
AutoReleasePtr operator=(const AutoReleasePtr &other) MOZ_DELETE;
public:
explicit AutoReleasePtr(JSContext *cx, void *ptr
explicit AutoReleasePtr(void *ptr
JS_GUARD_OBJECT_NOTIFIER_PARAM)
: cx(cx), ptr(ptr)
: ptr(ptr)
{
JS_GUARD_OBJECT_NOTIFIER_INIT;
}
~AutoReleasePtr() { cx->free_(ptr); }
void forget() { ptr = NULL; }
~AutoReleasePtr() { js_free(ptr); }
};
/*
* FIXME: bug 602774: cleaner API for AutoReleaseNullablePtr
*/
class AutoReleaseNullablePtr {
JSContext *cx;
void *ptr;
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
@ -1646,18 +1640,18 @@ class AutoReleaseNullablePtr {
AutoReleaseNullablePtr operator=(const AutoReleaseNullablePtr &other) MOZ_DELETE;
public:
explicit AutoReleaseNullablePtr(JSContext *cx, void *ptr
explicit AutoReleaseNullablePtr(void *ptr
JS_GUARD_OBJECT_NOTIFIER_PARAM)
: cx(cx), ptr(ptr)
: ptr(ptr)
{
JS_GUARD_OBJECT_NOTIFIER_INIT;
}
void reset(void *ptr2) {
if (ptr)
cx->free_(ptr);
js_free(ptr);
ptr = ptr2;
}
~AutoReleaseNullablePtr() { if (ptr) cx->free_(ptr); }
~AutoReleaseNullablePtr() { if (ptr) js_free(ptr); }
};
} /* namespace js */
@ -2013,7 +2007,7 @@ class RuntimeAllocPolicy
RuntimeAllocPolicy(JSContext *cx) : runtime(cx->runtime) {}
void *malloc_(size_t bytes) { return runtime->malloc_(bytes); }
void *realloc_(void *p, size_t bytes) { return runtime->realloc_(p, bytes); }
void free_(void *p) { runtime->free_(p); }
void free_(void *p) { js_free(p); }
void reportAllocOverflow() const {}
};
@ -2029,7 +2023,7 @@ class ContextAllocPolicy
JSContext *context() const { return cx; }
void *malloc_(size_t bytes) { return cx->malloc_(bytes); }
void *realloc_(void *p, size_t oldBytes, size_t bytes) { return cx->realloc_(p, oldBytes, bytes); }
void free_(void *p) { cx->free_(p); }
void free_(void *p) { js_free(p); }
void reportAllocOverflow() const { js_ReportAllocationOverflow(cx); }
};

View File

@ -176,7 +176,7 @@ class AutoPtr
public:
explicit AutoPtr(JSContext *cx) : cx(cx), value(NULL) {}
~AutoPtr() {
cx->delete_<T>(value);
js_delete<T>(value);
}
void operator=(T *ptr) { value = ptr; }
@ -551,7 +551,7 @@ JSContext::ensureParseMapPool()
{
if (parseMapPool_)
return true;
parseMapPool_ = js::OffTheBooks::new_<js::frontend::ParseMapPool>(this);
parseMapPool_ = js_new<js::frontend::ParseMapPool>(this);
return parseMapPool_;
}

View File

@ -76,9 +76,9 @@ JSCompartment::JSCompartment(JSRuntime *rt)
JSCompartment::~JSCompartment()
{
Foreground::delete_(watchpointMap);
Foreground::delete_(scriptCountsMap);
Foreground::delete_(debugScriptMap);
js_delete(watchpointMap);
js_delete(scriptCountsMap);
js_delete(debugScriptMap);
}
bool

View File

@ -362,7 +362,7 @@ JS_GetLinePCs(JSContext *cx, JSScript *script,
pcs = (jsbytecode**) cx->malloc_(len * sizeof(jsbytecode*));
if (!pcs) {
cx->free_(lines);
js_free(lines);
return JS_FALSE;
}
@ -391,12 +391,12 @@ JS_GetLinePCs(JSContext *cx, JSScript *script,
if (retLines)
*retLines = lines;
else
cx->free_(lines);
js_free(lines);
if (retPCs)
*retPCs = pcs;
else
cx->free_(pcs);
js_free(pcs);
return JS_TRUE;
}
@ -751,7 +751,7 @@ JS_EvaluateInStackFrame(JSContext *cx, JSStackFrame *fp,
length = (unsigned) len;
ok = JS_EvaluateUCInStackFrame(cx, fp, chars, length, filename, lineno,
rval);
cx->free_(chars);
js_free(chars);
return ok;
}
@ -896,7 +896,7 @@ JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda)
if (pd[i].flags & JSPD_ALIAS)
js_RemoveRoot(cx->runtime, &pd[i].alias);
}
cx->free_(pd);
js_free(pd);
pda->array = NULL;
pda->length = 0;
}
@ -1227,7 +1227,7 @@ struct RequiredStringArg {
}
~RequiredStringArg() {
if (mBytes)
mCx->free_(mBytes);
js_free(mBytes);
}
};
@ -1536,7 +1536,7 @@ js_StartVtune(const char *profileName)
status = VTStartSampling(&params);
if (params.tb5Filename != default_filename)
Foreground::free_(params.tb5Filename);
js_free(params.tb5Filename);
if (status != 0) {
if (status == VTAPI_MULTIPLE_RUNS)

View File

@ -78,13 +78,13 @@ using namespace js;
JS_PUBLIC_API(void *)
JS_DHashAllocTable(JSDHashTable *table, uint32_t nbytes)
{
return OffTheBooks::malloc_(nbytes);
return js_malloc(nbytes);
}
JS_PUBLIC_API(void)
JS_DHashFreeTable(JSDHashTable *table, void *ptr)
{
UnwantedForeground::free_(ptr);
js_free(ptr);
}
JS_PUBLIC_API(JSDHashNumber)
@ -147,7 +147,7 @@ JS_DHashFreeStringKey(JSDHashTable *table, JSDHashEntryHdr *entry)
{
const JSDHashEntryStub *stub = (const JSDHashEntryStub *)entry;
UnwantedForeground::free_((void *) stub->key);
js_free((void *) stub->key);
memset(entry, 0, table->entrySize);
}
@ -179,11 +179,11 @@ JS_NewDHashTable(const JSDHashTableOps *ops, void *data, uint32_t entrySize,
{
JSDHashTable *table;
table = (JSDHashTable *) OffTheBooks::malloc_(sizeof *table);
table = (JSDHashTable *) js_malloc(sizeof *table);
if (!table)
return NULL;
if (!JS_DHashTableInit(table, ops, data, entrySize, capacity)) {
Foreground::free_(table);
js_free(table);
return NULL;
}
return table;
@ -193,7 +193,7 @@ JS_PUBLIC_API(void)
JS_DHashTableDestroy(JSDHashTable *table)
{
JS_DHashTableFinish(table);
UnwantedForeground::free_(table);
js_free(table);
}
JS_PUBLIC_API(JSBool)

View File

@ -48,8 +48,8 @@ using namespace js;
* MALLOC gets declared external, and that doesn't work for class members, so
* wrap.
*/
inline void* dtoa_malloc(size_t size) { return OffTheBooks::malloc_(size); }
inline void dtoa_free(void* p) { return UnwantedForeground::free_(p); }
inline void* dtoa_malloc(size_t size) { return js_malloc(size); }
inline void dtoa_free(void* p) { return js_free(p); }
#define NO_GLOBAL_STATE
#define MALLOC dtoa_malloc
@ -301,7 +301,7 @@ js_dtobasestr(DtoaState *state, int base, double dinput)
JS_ASSERT(base >= 2 && base <= 36);
dval(d) = dinput;
buffer = (char*) OffTheBooks::malloc_(DTOBASESTR_BUFFER_SIZE);
buffer = (char*) js_malloc(DTOBASESTR_BUFFER_SIZE);
if (!buffer)
return NULL;
p = buffer;
@ -345,7 +345,7 @@ js_dtobasestr(DtoaState *state, int base, double dinput)
if (!b) {
nomem1:
Bfree(PASS_STATE b);
UnwantedForeground::free_(buffer);
js_free(buffer);
return NULL;
}
do {
@ -381,7 +381,7 @@ js_dtobasestr(DtoaState *state, int base, double dinput)
if (mlo != mhi)
Bfree(PASS_STATE mlo);
Bfree(PASS_STATE mhi);
UnwantedForeground::free_(buffer);
js_free(buffer);
return NULL;
}
JS_ASSERT(e < 0);

View File

@ -103,7 +103,7 @@ js_dtostr(DtoaState *state, char *buffer, size_t bufferSize, JSDToStrMode mode,
* not equal to itself).
*
* Return NULL if out of memory. If the result is not NULL, it must be
* released via cx->free_().
* released via js_free().
*/
char *
js_dtobasestr(DtoaState *state, int base, double d);

View File

@ -321,7 +321,7 @@ InitExnPrivate(JSContext *cx, HandleObject exnObject, HandleString message,
*/
priv->errorReport = CopyErrorReport(cx, report);
if (!priv->errorReport) {
cx->free_(priv);
js_free(priv);
return false;
}
} else {
@ -1179,19 +1179,8 @@ js_CopyErrorObject(JSContext *cx, HandleObject errobj, HandleObject scope)
JSExnPrivate *copy = (JSExnPrivate *)cx->malloc_(size);
if (!copy)
return NULL;
AutoReleasePtr autoFreePrivate(copy);
struct AutoFree {
JSContext *cx;
JSExnPrivate *p;
~AutoFree() {
if (p) {
cx->free_(p->errorReport);
cx->free_(p);
}
}
} autoFree = {cx, copy};
// Copy each field. Don't bother copying the stack elements.
if (priv->errorReport) {
copy->errorReport = CopyErrorReport(cx, priv->errorReport);
if (!copy->errorReport)
@ -1199,6 +1188,8 @@ js_CopyErrorObject(JSContext *cx, HandleObject errobj, HandleObject scope)
} else {
copy->errorReport = NULL;
}
AutoReleasePtr autoFreeErrorReport(copy->errorReport);
copy->message.init(priv->message);
if (!cx->compartment->wrap(cx, &copy->message))
return NULL;
@ -1220,6 +1211,7 @@ js_CopyErrorObject(JSContext *cx, HandleObject errobj, HandleObject scope)
if (!copyobj)
return NULL;
SetExnPrivate(cx, copyobj, copy);
autoFree.p = NULL;
autoFreePrivate.forget();
autoFreeErrorReport.forget();
return copyobj;
}

View File

@ -1273,7 +1273,7 @@ js_FinishGC(JSRuntime *rt)
/* Delete all remaining Compartments. */
for (CompartmentsIter c(rt); !c.done(); c.next())
Foreground::delete_(c.get());
js_delete(c.get());
rt->compartments.clear();
rt->atomsCompartment = NULL;
@ -3083,7 +3083,7 @@ GCHelperThread::replenishAndFreeLater(void *ptr)
do {
if (freeCursor && !freeVector.append(freeCursorEnd - FREE_ARRAY_LENGTH))
break;
freeCursor = (void **) OffTheBooks::malloc_(FREE_ARRAY_SIZE);
freeCursor = (void **) js_malloc(FREE_ARRAY_SIZE);
if (!freeCursor) {
freeCursorEnd = NULL;
break;
@ -3092,7 +3092,7 @@ GCHelperThread::replenishAndFreeLater(void *ptr)
*freeCursor++ = ptr;
return;
} while (false);
Foreground::free_(ptr);
js_free(ptr);
}
#ifdef JS_THREADSAFE
@ -4748,7 +4748,7 @@ NewCompartment(JSContext *cx, JSPrincipals *principals)
js_ReportOutOfMemory(cx);
}
Foreground::delete_(compartment);
js_delete(compartment);
return NULL;
}
@ -4942,7 +4942,7 @@ JS::CheckStackRoots(JSContext *cx)
* stack was last scanned, and update the last scanned state.
*/
if (stackEnd != oldStackEnd) {
rt->free_(oldStackData);
js_free(oldStackData);
oldStackCapacity = rt->nativeStackQuota / sizeof(uintptr_t);
oldStackData = (uintptr_t *) rt->malloc_(oldStackCapacity * sizeof(uintptr_t));
if (!oldStackData) {

View File

@ -633,8 +633,8 @@ class GCHelperThread {
static void freeElementsAndArray(void **array, void **end) {
JS_ASSERT(array <= end);
for (void **p = array; p != end; ++p)
js::Foreground::free_(*p);
js::Foreground::free_(array);
js_free(*p);
js_free(array);
}
static void threadMain(void* arg);

View File

@ -2165,14 +2165,14 @@ bool
TypeCompartment::growPendingArray(JSContext *cx)
{
unsigned newCapacity = js::Max(unsigned(100), pendingCapacity * 2);
PendingWork *newArray = (PendingWork *) OffTheBooks::calloc_(newCapacity * sizeof(PendingWork));
PendingWork *newArray = (PendingWork *) js_calloc(newCapacity * sizeof(PendingWork));
if (!newArray) {
cx->compartment->types.setPendingNukeTypes(cx);
return false;
}
PodCopy(newArray, pendingArray, pendingCount);
cx->free_(pendingArray);
js_free(pendingArray);
pendingArray = newArray;
pendingCapacity = newCapacity;
@ -3241,7 +3241,7 @@ TypeObject::clearNewScript(JSContext *cx)
/* We NULL out newScript *before* freeing it so the write barrier works. */
TypeNewScript *savedNewScript = newScript;
newScript = NULL;
cx->free_(savedNewScript);
js_free(savedNewScript);
markStateChange(cx);
}
@ -5930,8 +5930,8 @@ TypeCompartment::sweep(FreeOp *fop)
}
if (remove) {
Foreground::free_(key.ids);
Foreground::free_(entry.types);
js_free(key.ids);
js_free(entry.types);
e.removeFront();
}
}
@ -6015,16 +6015,16 @@ JSCompartment::sweepNewTypeObjectTable(TypeObjectSet &table)
TypeCompartment::~TypeCompartment()
{
if (pendingArray)
Foreground::free_(pendingArray);
js_free(pendingArray);
if (arrayTypeTable)
Foreground::delete_(arrayTypeTable);
js_delete(arrayTypeTable);
if (objectTypeTable)
Foreground::delete_(objectTypeTable);
js_delete(objectTypeTable);
if (allocationSiteTable)
Foreground::delete_(allocationSiteTable);
js_delete(allocationSiteTable);
}
/* static */ void
@ -6067,11 +6067,11 @@ TypeScript::destroy()
{
while (dynamicList) {
TypeResult *next = dynamicList->next;
Foreground::delete_(dynamicList);
js_delete(dynamicList);
dynamicList = next;
}
Foreground::free_(this);
js_free(this);
}
/* static */ void

View File

@ -595,7 +595,7 @@ GetIterator(JSContext *cx, HandleObject obj, unsigned flags, MutableHandleValue
if (!bytes)
return false;
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_NOT_ITERABLE, bytes);
cx->free_(bytes);
js_free(bytes);
return false;
}

View File

@ -83,12 +83,12 @@ ComputeAccurateDecimalInteger(JSContext *cx, const jschar *start, const jschar *
*dp = js_strtod_harder(cx->runtime->dtoaState, cstr, &estr, &err);
if (err == JS_DTOA_ENOMEM) {
JS_ReportOutOfMemory(cx);
cx->free_(cstr);
js_free(cstr);
return false;
}
if (err == JS_DTOA_ERANGE && *dp == HUGE_VAL)
*dp = js_PositiveInfinity;
cx->free_(cstr);
js_free(cstr);
return true;
}
@ -514,7 +514,7 @@ ToCStringBuf::ToCStringBuf() :dbuf(NULL)
ToCStringBuf::~ToCStringBuf()
{
if (dbuf)
UnwantedForeground::free_(dbuf);
js_free(dbuf);
}
JSFixedString *
@ -741,12 +741,12 @@ num_toLocaleString_impl(JSContext *cx, CallArgs args)
bool ok = !!cx->localeCallbacks->localeToUnicode(cx, buf, v.address());
if (ok)
args.rval().set(v);
cx->free_(buf);
js_free(buf);
return ok;
}
str = js_NewStringCopyN(cx, buf, buflen);
cx->free_(buf);
js_free(buf);
if (!str)
return false;
@ -1089,9 +1089,9 @@ InitRuntimeNumberState(JSRuntime *rt)
size_t decimalPointSize = strlen(decimalPoint) + 1;
size_t groupingSize = strlen(grouping) + 1;
char *storage = static_cast<char *>(OffTheBooks::malloc_(thousandsSeparatorSize +
decimalPointSize +
groupingSize));
char *storage = static_cast<char *>(js_malloc(thousandsSeparatorSize +
decimalPointSize +
groupingSize));
if (!storage)
return false;
@ -1116,7 +1116,7 @@ FinishRuntimeNumberState(JSRuntime *rt)
* strings.
*/
char *storage = const_cast<char *>(rt->thousandsSeparator);
Foreground::free_(storage);
js_free(storage);
}
} /* namespace js */
@ -1547,7 +1547,7 @@ js_strtod(JSContext *cx, const jschar *s, const jschar *send,
i = estr - cstr;
if (cstr != cbuf)
cx->free_(cstr);
js_free(cstr);
*ep = i ? s1 + i : s;
*dp = d;
return JS_TRUE;

View File

@ -2126,7 +2126,7 @@ NewObject(JSContext *cx, Class *clasp, types::TypeObject *type_, JSObject *paren
JSObject *obj = JSObject::create(cx, kind, shape, type, slots);
if (!obj) {
cx->free_(slots);
js_free(slots);
return NULL;
}
@ -2650,9 +2650,9 @@ struct JSObject::TradeGutsReserved {
~TradeGutsReserved()
{
if (newaslots)
cx->free_(newaslots);
js_free(newaslots);
if (newbslots)
cx->free_(newbslots);
js_free(newbslots);
}
};
@ -2840,9 +2840,9 @@ JSObject::TradeGuts(JSContext *cx, JSObject *a, JSObject *b, TradeGutsReserved &
/* Done with the dynamic slots. */
if (a->hasDynamicSlots())
cx->free_(a->slots);
js_free(a->slots);
if (b->hasDynamicSlots())
cx->free_(b->slots);
js_free(b->slots);
void *apriv = a->hasPrivate() ? a->getPrivate() : NULL;
void *bpriv = b->hasPrivate() ? b->getPrivate() : NULL;
@ -3375,7 +3375,7 @@ JSObject::shrinkSlots(JSContext *cx, uint32_t oldCount, uint32_t newCount)
size_t newSize = oldSize - (oldCount - newCount) * sizeof(Value);
if (newCount == 0) {
cx->free_(slots);
js_free(slots);
slots = NULL;
if (Probes::objectResizeActive())
Probes::resizeObject(cx, this, oldSize, newSize);

View File

@ -713,7 +713,7 @@ Sprinter::~Sprinter()
if (initialized)
checkInvariants();
#endif
context->free_(base);
js_free(base);
}
bool
@ -915,7 +915,7 @@ js::Sprint(Sprinter *sp, const char *format, ...)
return -1;
}
offset = sp->put(bp);
sp->context->free_(bp);
js_free(bp);
return offset;
}
@ -1106,11 +1106,10 @@ js_NewPrinter(JSContext *cx, const char *name, JSFunction *fun,
void
js_DestroyPrinter(JSPrinter *jp)
{
JSContext *cx = jp->sprinter.context;
jp->pool.freeAll();
Foreground::delete_(jp->localNames);
js_delete(jp->localNames);
jp->sprinter.Sprinter::~Sprinter();
cx->free_(jp);
js_free(jp);
}
JSString *
@ -1182,7 +1181,7 @@ js_printf(JSPrinter *jp, const char *format, ...)
/* Allocate temp space, convert format, and put. */
bp = JS_vsmprintf(format, ap); /* XXX vsaprintf */
if (fp) {
jp->sprinter.context->free_(fp);
js_free(fp);
format = NULL;
}
if (!bp) {
@ -1194,7 +1193,7 @@ js_printf(JSPrinter *jp, const char *format, ...)
cc = strlen(bp);
if (jp->sprinter.put(bp, (size_t)cc) < 0)
cc = -1;
jp->sprinter.context->free_(bp);
js_free(bp);
va_end(ap);
return cc;
@ -1379,7 +1378,7 @@ GetOff(SprintStack *ss, unsigned i)
if (off < 0)
off = 0;
ss->offsets[i] = off;
ss->sprinter.context->free_(bytes);
js_free(bytes);
return off;
}
@ -4290,7 +4289,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, int nb)
jsbytecode **argbytecodes = (jsbytecode **)
cx->malloc_((size_t)(argc + 1) * sizeof *argbytecodes);
if (!argbytecodes) {
cx->free_(argv);
js_free(argv);
return NULL;
}
@ -4338,8 +4337,8 @@ Decompile(SprintStack *ss, jsbytecode *pc, int nb)
}
ss->sprinter.put(rval);
cx->free_(argv);
cx->free_(argbytecodes);
js_free(argv);
js_free(argbytecodes);
break;
}
@ -4806,7 +4805,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, int nb)
if (!rval)
return NULL;
todo = ss->sprinter.put(rval);
cx->free_((void *)rval);
js_free((void *)rval);
break;
}
#endif /* JS_HAS_GENERATOR_EXPRS */
@ -4928,7 +4927,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, int nb)
cx->malloc_((size_t)j * sizeof *table);
if (tmp) {
MergeSort(table, size_t(j), tmp, CompareTableEntries);
Foreground::free_(tmp);
js_free(tmp);
ok = true;
} else {
ok = false;
@ -4937,7 +4936,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, int nb)
if (ok)
ok = DecompileSwitch(ss, table, (unsigned)j, pc, len, off, false);
cx->free_(table);
js_free(table);
if (!ok)
return NULL;
todo = -2;
@ -4980,7 +4979,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, int nb)
ok = DecompileSwitch(ss, table, (unsigned)npairs, pc, len, off,
JS_FALSE);
cx->free_(table);
js_free(table);
if (!ok)
return NULL;
todo = -2;
@ -5052,7 +5051,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, int nb)
ok = DecompileSwitch(ss, table, (unsigned)ncases, pc, len, off,
JS_TRUE);
cx->free_(table);
js_free(table);
if (!ok)
return NULL;
todo = -2;
@ -5371,7 +5370,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, int nb)
(*rval == '\0' ||
(ss->sprinter.put(" ", 1) >= 0 &&
ss->sprinter.put(rval)));
cx->free_((char *)rval);
js_free((char *)rval);
if (!ok)
return NULL;
ss->sprinter.put("?>", 2);
@ -5797,7 +5796,7 @@ class PCStack
PCStack::~PCStack()
{
cx->free_(stack);
js_free(stack);
}
bool
@ -6034,7 +6033,7 @@ ExpressionDecompiler::decompilePC(jsbytecode *pc)
ExpressionDecompiler::~ExpressionDecompiler()
{
cx->delete_<BindingVector>(localNames);
js_delete<BindingVector>(localNames);
}
bool
@ -6213,7 +6212,7 @@ js::DecompileValueGenerator(JSContext *cx, int spindex, HandleValue v,
if (result) {
if (strcmp(result, "(intermediate value)"))
return result;
cx->free_(result);
js_free(result);
}
}
if (!fallback) {
@ -6305,11 +6304,11 @@ DecompileExpression(JSContext *cx, JSScript *script, JSFunction *fun,
~Guard() {
if (printer)
js_DestroyPrinter(printer);
Foreground::free_(pcstack);
js_free(pcstack);
}
} g;
g.pcstack = (jsbytecode **)OffTheBooks::malloc_(StackDepth(script) * sizeof *g.pcstack);
g.pcstack = (jsbytecode **)js_malloc(StackDepth(script) * sizeof *g.pcstack);
if (!g.pcstack)
return NULL;

View File

@ -374,7 +374,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);
UnwantedForeground::free_(s);
js_free(s);
} else {
result = cvt_s(ss, NULL, width, prec, flags);
}
@ -592,7 +592,7 @@ static struct NumArgState* BuildArgArray( const char *fmt, va_list ap, int* rv,
if( *rv < 0 ){
if( nas != nasArray )
UnwantedForeground::free_( nas );
js_free( nas );
return NULL;
}
@ -629,7 +629,7 @@ static struct NumArgState* BuildArgArray( const char *fmt, va_list ap, int* rv,
default:
if( nas != nasArray )
UnwantedForeground::free_( nas );
js_free( nas );
*rv = -1;
return NULL;
}
@ -718,7 +718,7 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
if( nas[i-1].type == TYPE_UNKNOWN ){
if( nas && ( nas != nasArray ) )
UnwantedForeground::free_( nas );
js_free( nas );
return -1;
}
@ -999,7 +999,7 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
rv = (*ss->stuff)(ss, "\0", 1);
if( nas && ( nas != nasArray ) ){
UnwantedForeground::free_( nas );
js_free( nas );
}
return rv;
@ -1060,9 +1060,9 @@ static int GrowStuff(SprintfState *ss, const char *sp, uint32_t len)
/* Grow the buffer */
newlen = ss->maxlen + ((len > 32) ? len : 32);
if (ss->base) {
newbase = (char*) OffTheBooks::realloc_(ss->base, newlen);
newbase = (char*) js_realloc(ss->base, newlen);
} else {
newbase = (char*) OffTheBooks::malloc_(newlen);
newbase = (char*) js_malloc(newlen);
}
if (!newbase) {
/* Ran out of memory */
@ -1101,7 +1101,7 @@ JS_PUBLIC_API(char *) JS_smprintf(const char *fmt, ...)
*/
JS_PUBLIC_API(void) JS_smprintf_free(char *mem)
{
Foreground::free_(mem);
js_free(mem);
}
JS_PUBLIC_API(char *) JS_vsmprintf(const char *fmt, va_list ap)
@ -1116,7 +1116,7 @@ JS_PUBLIC_API(char *) JS_vsmprintf(const char *fmt, va_list ap)
rv = dosprintf(&ss, fmt, ap);
if (rv < 0) {
if (ss.base) {
Foreground::free_(ss.base);
js_free(ss.base);
}
return 0;
}
@ -1215,7 +1215,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) {
Foreground::free_(ss.base);
js_free(ss.base);
}
return 0;
}

View File

@ -46,9 +46,9 @@ PropertyTree::newShape(JSContext *cx)
static KidsHash *
HashChildren(Shape *kid1, Shape *kid2)
{
KidsHash *hash = OffTheBooks::new_<KidsHash>();
KidsHash *hash = js_new<KidsHash>();
if (!hash || !hash->init(2)) {
Foreground::delete_(hash);
js_delete(hash);
return NULL;
}
@ -125,7 +125,7 @@ Shape::removeChild(Shape *child)
Shape *otherChild = r.front();
JS_ASSERT((r.popFront(), r.empty())); /* No more elements! */
kidp->setShape(otherChild);
js::UnwantedForeground::delete_(hash);
js_delete(hash);
}
}

View File

@ -3285,7 +3285,7 @@ reflect_parse(JSContext *cx, uint32_t argc, jsval *vp)
return JS_FALSE;
char *filename = NULL;
AutoReleaseNullablePtr filenamep(cx, filename);
AutoReleaseNullablePtr filenamep(filename);
uint32_t lineno = 1;
bool loc = true;

View File

@ -128,7 +128,7 @@ Shape::hashify(JSContext *cx)
return false;
if (!table->init(rt, self)) {
rt->free_(table);
js_free(table);
return false;
}
@ -255,7 +255,7 @@ ShapeTable::change(int log2Delta, JSContext *cx)
}
/* Finally, free the old entries storage. */
cx->free_(oldTable);
js_free(oldTable);
return true;
}

View File

@ -130,7 +130,7 @@ struct ShapeTable {
}
~ShapeTable() {
js::UnwantedForeground::free_(entries);
js_free(entries);
}
/* By definition, hashShift = HASH_BITS - log2(capacity). */

View File

@ -777,8 +777,8 @@ JSScript::initScriptCounts(JSContext *cx)
if (!map) {
map = cx->new_<ScriptCountsMap>();
if (!map || !map->init()) {
cx->free_(cursor);
cx->delete_(map);
js_free(cursor);
js_delete(map);
return false;
}
compartment()->scriptCountsMap = map;
@ -802,8 +802,8 @@ JSScript::initScriptCounts(JSContext *cx)
}
if (!map->putNew(this, scriptCounts)) {
cx->free_(cursor);
cx->delete_(map);
js_free(cursor);
js_delete(map);
return false;
}
hasScriptCounts = true; // safe to set this; we can't fail after this point
@ -1057,7 +1057,7 @@ void
SourceDataCache::put(ScriptSource *ss, JSFixedString *str)
{
if (!map_) {
map_ = OffTheBooks::new_<Map>();
map_ = js_new<Map>();
if (!map_)
return;
if (!map_->init()) {
@ -1072,7 +1072,7 @@ SourceDataCache::put(ScriptSource *ss, JSFixedString *str)
void
SourceDataCache::purge()
{
Foreground::delete_(map_);
js_delete(map_);
map_ = NULL;
}
@ -1093,13 +1093,13 @@ ScriptSource::substring(JSContext *cx, uint32_t start, uint32_t stop)
if (!DecompressString(data.compressed, compressedLength_,
reinterpret_cast<unsigned char *>(decompressed), nbytes)) {
JS_ReportOutOfMemory(cx);
cx->free_(decompressed);
js_free(decompressed);
return NULL;
}
decompressed[length_] = 0;
cached = js_NewString(cx, decompressed, length_);
if (!cached) {
cx->free_(decompressed);
js_free(decompressed);
return NULL;
}
cx->runtime->sourceDataCache.put(this, cached);
@ -1173,12 +1173,12 @@ void
ScriptSource::destroy(JSRuntime *rt)
{
JS_ASSERT(ready());
rt->free_(data.compressed);
rt->free_(sourceMap_);
js_free(data.compressed);
js_free(sourceMap_);
#ifdef DEBUG
ready_ = false;
#endif
rt->free_(this);
js_free(this);
}
size_t
@ -1227,7 +1227,7 @@ ScriptSource::performXDR(XDRState<mode> *xdr)
}
if (!xdr->codeBytes(data.compressed, byteLen)) {
if (mode == XDR_DECODE) {
xdr->cx()->free_(data.compressed);
js_free(data.compressed);
data.compressed = NULL;
}
return false;
@ -1254,7 +1254,7 @@ ScriptSource::performXDR(XDRState<mode> *xdr)
}
if (!xdr->codeChars(sourceMap_, sourceMapLen)) {
if (mode == XDR_DECODE) {
xdr->cx()->free_(sourceMap_);
js_free(sourceMap_);
sourceMap_ = NULL;
}
return false;
@ -1277,7 +1277,7 @@ ScriptSource::setSourceMap(JSContext *cx, jschar *sourceMapURL, const char *file
if (hasSourceMap()) {
if (!JS_ReportErrorFlagsAndNumber(cx, JSREPORT_WARNING, js_GetErrorMessage, NULL,
JSMSG_ALREADY_HAS_SOURCEMAP, filename)) {
cx->free_(sourceMapURL);
js_free(sourceMapURL);
return false;
}
}
@ -1314,7 +1314,7 @@ js::SaveScriptFilename(JSContext *cx, const char *filename)
strcpy(entry->filename, filename);
if (!rt->scriptFilenameTable.add(p, entry)) {
Foreground::free_(entry);
js_free(entry);
JS_ReportOutOfMemory(cx);
return NULL;
}
@ -1345,7 +1345,7 @@ js::SweepScriptFilenames(JSRuntime *rt)
if (entry->marked) {
entry->marked = false;
} else if (!rt->gcKeepAtoms) {
Foreground::free_(entry);
js_free(entry);
e.removeFront();
}
}
@ -1356,7 +1356,7 @@ js::FreeScriptFilenames(JSRuntime *rt)
{
ScriptFilenameTable &table = rt->scriptFilenameTable;
for (ScriptFilenameTable::Enum e(table); !e.empty(); e.popFront())
Foreground::free_(e.front());
js_free(e.front());
table.clear();
}
@ -2126,7 +2126,7 @@ js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun,
options, src->staticLevel,
src->scriptSource(), src->sourceStart, src->sourceEnd);
if (!dst) {
Foreground::free_(data);
js_free(data);
return NULL;
}
@ -2256,16 +2256,16 @@ JSScript::ensureHasDebugScript(JSContext *cx)
if (!map) {
map = cx->new_<DebugScriptMap>();
if (!map || !map->init()) {
cx->free_(debug);
cx->delete_(map);
js_free(debug);
js_delete(map);
return false;
}
compartment()->debugScriptMap = map;
}
if (!map->putNew(this, debug)) {
cx->free_(debug);
cx->delete_(map);
js_free(debug);
js_delete(map);
return false;
}
hasDebugScript = true; // safe to set this; we can't fail after this point
@ -2307,7 +2307,7 @@ JSScript::tryNewStepMode(JSContext *cx, uint32_t newValue)
recompileForStepMode(cx->runtime->defaultFreeOp());
if (!stepModeEnabled() && !debug->numSites)
cx->free_(releaseDebugScript());
js_free(releaseDebugScript());
}
return true;

View File

@ -192,7 +192,7 @@ str_escape(JSContext *cx, unsigned argc, Value *vp)
JSString *retstr = js_NewString(cx, newchars, newlength);
if (!retstr) {
cx->free_(newchars);
js_free(newchars);
return false;
}
@ -624,7 +624,7 @@ js_toLowerCase(JSContext *cx, JSString *str)
news[n] = 0;
str = js_NewString(cx, news, n);
if (!str) {
cx->free_(news);
js_free(news);
return NULL;
}
return str;
@ -691,7 +691,7 @@ js_toUpperCase(JSContext *cx, JSString *str)
news[n] = 0;
str = js_NewString(cx, news, n);
if (!str) {
cx->free_(news);
js_free(news);
return NULL;
}
return str;
@ -3192,7 +3192,7 @@ js::str_fromCharCode(JSContext *cx, unsigned argc, Value *vp)
for (unsigned i = 0; i < args.length(); i++) {
uint16_t code;
if (!ToUint16(cx, args[i], &code)) {
cx->free_(chars);
js_free(chars);
return JS_FALSE;
}
chars[i] = (jschar)code;
@ -3200,7 +3200,7 @@ js::str_fromCharCode(JSContext *cx, unsigned argc, Value *vp)
chars[args.length()] = 0;
JSString *str = js_NewString(cx, chars, args.length());
if (!str) {
cx->free_(chars);
js_free(chars);
return JS_FALSE;
}
@ -3343,7 +3343,7 @@ js_NewStringCopyN(JSContext *cx, const jschar *s, size_t n)
news[n] = 0;
JSFixedString *str = js_NewString(cx, news, n);
if (!str)
cx->free_(news);
js_free(news);
return str;
}
@ -3358,7 +3358,7 @@ js_NewStringCopyN(JSContext *cx, const char *s, size_t n)
return NULL;
JSFixedString *str = js_NewString(cx, chars, n);
if (!str)
cx->free_(chars);
js_free(chars);
return str;
}
@ -3376,7 +3376,7 @@ js_NewStringCopyZ(JSContext *cx, const jschar *s)
js_memcpy(news, s, m);
JSFixedString *str = js_NewString(cx, news, n);
if (!str)
cx->free_(news);
js_free(news);
return str;
}
@ -3654,13 +3654,13 @@ DeflateString(JSContext *cx, const jschar *chars, size_t nchars)
nbytes = GetDeflatedStringLength(cx, chars, nchars);
if (nbytes == (size_t) -1)
return NULL;
bytes = (char *) (cx ? cx->malloc_(nbytes + 1) : OffTheBooks::malloc_(nbytes + 1));
bytes = (char *) (cx ? cx->malloc_(nbytes + 1) : js_malloc(nbytes + 1));
if (!bytes)
return NULL;
JS_ALWAYS_TRUE(DeflateStringToBuffer(cx, chars, nchars, bytes, &nbytes));
} else {
nbytes = nchars;
bytes = (char *) (cx ? cx->malloc_(nbytes + 1) : OffTheBooks::malloc_(nbytes + 1));
bytes = (char *) (cx ? cx->malloc_(nbytes + 1) : js_malloc(nbytes + 1));
if (!bytes)
return NULL;
for (i = 0; i < nbytes; i++)

View File

@ -211,7 +211,7 @@ AllocateArrayBufferContents(JSContext *maybecx, uint32_t nbytes, uint8_t *conten
{
uint32_t size = nbytes + sizeof(ObjectElements);
ObjectElements *newheader =
static_cast<ObjectElements *>(maybecx ? maybecx->calloc_(size) : OffTheBooks::calloc_(size));
static_cast<ObjectElements *>(maybecx ? maybecx->calloc_(size) : js_calloc(size));
if (!newheader) {
if (maybecx)
js_ReportOutOfMemory(maybecx);
@ -2181,7 +2181,7 @@ class TypedArrayTemplate
break;
}
UnwantedForeground::free_(srcbuf);
js_free(srcbuf);
return true;
}

View File

@ -33,13 +33,13 @@ using namespace js;
static void *
zlib_alloc(void *cx, uInt items, uInt size)
{
return OffTheBooks::malloc_(items * size);
return js_malloc(items * size);
}
static void
zlib_free(void *cx, void *addr)
{
Foreground::free_(addr);
js_free(addr);
}
bool

View File

@ -242,7 +242,7 @@ WeakMap_set_impl(JSContext *cx, CallArgs args)
if (!map) {
map = cx->new_<ObjectValueMap>(cx, thisObj.get());
if (!map->init()) {
cx->delete_(map);
js_delete(map);
JS_ReportOutOfMemory(cx);
return false;
}

View File

@ -378,14 +378,14 @@ ConvertQNameToString(JSContext *cx, JSObject *obj)
*chars = '@';
const jschar *strChars = str->getChars(cx);
if (!strChars) {
cx->free_(chars);
js_free(chars);
return NULL;
}
js_strncpy(chars + 1, strChars, length);
chars[++length] = 0;
str = js_NewString(cx, chars, length);
if (!str) {
cx->free_(chars);
js_free(chars);
return NULL;
}
}
@ -862,7 +862,7 @@ ReallocateVector(HeapPtr<T> *vector, size_t count)
#endif
size_t size = count * sizeof(HeapPtr<T>);
return (HeapPtr<T> *) OffTheBooks::realloc_(vector, size);
return (HeapPtr<T> *) js_realloc(vector, size);
}
/* NB: called with null cx from the GC, via xml_trace => JSXMLArray::trim. */
@ -874,9 +874,9 @@ JSXMLArray<T>::setCapacity(JSContext *cx, uint32_t newCapacity)
/* We could let realloc(p, 0) free this, but purify gets confused. */
if (vector) {
if (cx)
cx->free_(vector);
js_free(vector);
else
Foreground::free_(vector);
js_free(vector);
}
vector = NULL;
} else {
@ -1062,7 +1062,7 @@ XMLArrayTruncate(JSContext *cx, JSXMLArray<T> *array, uint32_t length)
if (length == 0) {
if (array->vector)
cx->free_(array->vector);
js_free(array->vector);
vector = NULL;
} else {
vector = ReallocateVector(array->vector, length);
@ -1733,7 +1733,7 @@ ParseXMLSource(JSContext *cx, HandleString src)
offset += dstlen;
srcp = src->getChars(cx);
if (!srcp) {
cx->free_(chars);
js_free(chars);
return NULL;
}
js_strncpy(chars + offset, srcp, srclen);
@ -1765,7 +1765,7 @@ ParseXMLSource(JSContext *cx, HandleString src)
if (parser.init()) {
JSObject *scopeChain = GetCurrentScopeChain(cx);
if (!scopeChain) {
cx->free_(chars);
js_free(chars);
return NULL;
}
@ -1779,7 +1779,7 @@ ParseXMLSource(JSContext *cx, HandleString src)
}
}
cx->free_(chars);
js_free(chars);
return xml;
#undef constrlen
@ -2360,7 +2360,7 @@ GeneratePrefix(JSContext *cx, JSLinearString *uri, JSXMLArray<JSObject> *decls)
} else {
prefix = js_NewString(cx, bp, newlength);
if (!prefix)
cx->free_(bp);
js_free(bp);
}
return prefix;
}
@ -5102,7 +5102,7 @@ xml_enumerate(JSContext *cx, HandleObject obj, JSIterateOp enum_op, Value *state
if (!statep->isInt32(0)) {
cursor = (JSXMLArrayCursor<JSXML> *) statep->toPrivate();
if (cursor)
cx->delete_(cursor);
js_delete(cursor);
}
statep->setNull();
break;

View File

@ -384,7 +384,7 @@ mjit::Compiler::pushActiveFrame(JSScript *script, uint32_t argc)
if (cx->runtime->profilingScripts && !script->hasScriptCounts)
script->initScriptCounts(cx);
ActiveFrame *newa = OffTheBooks::new_<ActiveFrame>(cx);
ActiveFrame *newa = js_new<ActiveFrame>(cx);
if (!newa) {
js_ReportOutOfMemory(cx);
return Compile_Error;
@ -435,7 +435,7 @@ mjit::Compiler::pushActiveFrame(JSScript *script, uint32_t argc)
return Compile_Error;
}
newa->jumpMap = (Label *)OffTheBooks::malloc_(sizeof(Label) * script->length);
newa->jumpMap = (Label *)js_malloc(sizeof(Label) * script->length);
if (!newa->jumpMap) {
js_ReportOutOfMemory(cx);
return Compile_Error;
@ -525,7 +525,7 @@ mjit::Compiler::performCompilation()
if (outerScript->hasScriptCounts || Probes::wantNativeAddressInfo(cx)) {
size_t length = ssa.frameLength(ssa.numFrames() - 1);
pcLengths = (PCLengthEntry *) OffTheBooks::calloc_(sizeof(pcLengths[0]) * length);
pcLengths = (PCLengthEntry *) js_calloc(sizeof(pcLengths[0]) * length);
if (!pcLengths)
return Compile_Error;
}
@ -568,20 +568,20 @@ mjit::Compiler::ActiveFrame::ActiveFrame(JSContext *cx)
mjit::Compiler::ActiveFrame::~ActiveFrame()
{
js::Foreground::free_(jumpMap);
js_free(jumpMap);
if (varTypes)
js::Foreground::free_(varTypes);
js_free(varTypes);
}
mjit::Compiler::~Compiler()
{
if (outer)
cx->delete_(outer);
js_delete(outer);
for (unsigned i = 0; i < inlineFrames.length(); i++)
cx->delete_(inlineFrames[i]);
js_delete(inlineFrames[i]);
while (loop) {
LoopState *nloop = loop->outer;
cx->delete_(loop);
js_delete(loop);
loop = nloop;
}
}
@ -611,8 +611,7 @@ mjit::Compiler::prepareInferenceTypes(JSScript *script, ActiveFrame *a)
* only if a variable has the same value on all incoming edges.
*/
a->varTypes = (VarType *)
OffTheBooks::calloc_(TotalSlots(script) * sizeof(VarType));
a->varTypes = (VarType *)js_calloc(TotalSlots(script) * sizeof(VarType));
if (!a->varTypes) {
js_ReportOutOfMemory(cx);
return Compile_Error;
@ -857,7 +856,7 @@ MakeJITScript(JSContext *cx, JSScript *script)
size_t dataSize = sizeof(JITScript)
+ (chunks.length() * sizeof(ChunkDescriptor))
+ (edges.length() * sizeof(CrossChunkEdge));
uint8_t *cursor = (uint8_t *) OffTheBooks::calloc_(dataSize);
uint8_t *cursor = (uint8_t *) js_calloc(dataSize);
if (!cursor)
return NULL;
@ -1355,7 +1354,7 @@ mjit::Compiler::finishThisUp()
#endif
0;
uint8_t *cursor = (uint8_t *)OffTheBooks::calloc_(dataSize);
uint8_t *cursor = (uint8_t *)js_calloc(dataSize);
if (!cursor) {
execPool->release();
js_ReportOutOfMemory(cx);
@ -1808,7 +1807,7 @@ mjit::Compiler::finishThisUp()
if (!Probes::registerMJITCode(cx, chunk,
a, (JSActiveFrame**) inlineFrames.begin())) {
execPool->release();
cx->free_(chunk);
js_free(chunk);
js_ReportOutOfMemory(cx);
return Compile_Error;
}
@ -1826,14 +1825,14 @@ mjit::Compiler::finishThisUp()
JSOp op = JSOp(script->code[edge.source]);
if (op == JSOP_TABLESWITCH) {
if (edge.jumpTableEntries)
cx->free_(edge.jumpTableEntries);
js_free(edge.jumpTableEntries);
CrossChunkEdge::JumpTableEntryVector *jumpTableEntries = NULL;
bool failed = false;
for (unsigned j = 0; j < chunkJumps.length(); j++) {
ChunkJumpTableEdge nedge = chunkJumps[j];
if (nedge.edge.source == edge.source && nedge.edge.target == edge.target) {
if (!jumpTableEntries) {
jumpTableEntries = OffTheBooks::new_<CrossChunkEdge::JumpTableEntryVector>();
jumpTableEntries = js_new<CrossChunkEdge::JumpTableEntryVector>();
if (!jumpTableEntries)
failed = true;
}
@ -1844,7 +1843,7 @@ mjit::Compiler::finishThisUp()
}
if (failed) {
execPool->release();
cx->free_(chunk);
js_free(chunk);
js_ReportOutOfMemory(cx);
return Compile_Error;
}
@ -4618,7 +4617,7 @@ mjit::Compiler::inlineScriptedFunction(uint32_t argc, bool callingNew)
frame.popn(argc + 2);
if (entrySnapshot)
cx->array_delete(entrySnapshot);
js_free(entrySnapshot);
if (exitState)
frame.discardForJoin(exitState, analysis->getCode(PC).stackDepth - (argc + 2));
@ -6895,7 +6894,7 @@ mjit::Compiler::startLoop(jsbytecode *head, Jump entry, jsbytecode *entryTarget)
loop->clearLoopRegisters();
}
LoopState *nloop = OffTheBooks::new_<LoopState>(cx, &ssa, this, &frame);
LoopState *nloop = js_new<LoopState>(cx, &ssa, this, &frame);
if (!nloop || !nloop->init(head, entry, entryTarget)) {
js_ReportOutOfMemory(cx);
return false;
@ -7032,7 +7031,7 @@ mjit::Compiler::finishLoop(jsbytecode *head)
loop->flushLoop(stubcc);
LoopState *nloop = loop->outer;
cx->delete_(loop);
js_delete(loop);
loop = nloop;
frame.setLoop(loop);

View File

@ -31,10 +31,10 @@ FrameState::~FrameState()
ActiveFrame *parent = a->parent;
if (a->script->hasAnalysis())
a->script->analysis()->clearAllocations();
cx->free_(a);
js_free(a);
a = parent;
}
cx->free_(entries);
js_free(entries);
}
void
@ -63,7 +63,7 @@ FrameState::pushActiveFrame(JSScript *script, uint32_t argc)
size_t totalBytes = sizeof(FrameEntry) * nentries + // entries[]
sizeof(FrameEntry *) * nentries + // tracker.entries
sizeof(StackEntryExtra) * nentries; // extraArray
uint8_t *cursor = (uint8_t *)OffTheBooks::calloc_(totalBytes);
uint8_t *cursor = (uint8_t *)js_calloc(totalBytes);
if (!cursor)
return false;
@ -89,7 +89,7 @@ FrameState::pushActiveFrame(JSScript *script, uint32_t argc)
/* We should have already checked that argc == nargs */
JS_ASSERT_IF(a, argc == script->function()->nargs);
ActiveFrame *newa = OffTheBooks::new_<ActiveFrame>();
ActiveFrame *newa = js_new<ActiveFrame>();
if (!newa)
return false;
@ -147,7 +147,7 @@ FrameState::popActiveFrame()
}
ActiveFrame *parent = a->parent;
cx->delete_(a);
js_delete(a);
a = parent;
}
@ -474,7 +474,7 @@ FrameEntry *
FrameState::snapshotState()
{
/* Everything can be recovered from a copy of the frame entries. */
FrameEntry *snapshot = cx->array_new<FrameEntry>(nentries);
FrameEntry *snapshot = (FrameEntry *)js_malloc(nentries * sizeof(FrameEntry));
if (!snapshot)
return NULL;
PodCopy(snapshot, entries, nentries);
@ -2858,7 +2858,7 @@ FrameState::getTemporaryCopies(Uses uses)
FrameEntry *nfe = tracker[i];
if (!deadEntry(nfe, uses.nuses) && nfe->isCopy() && nfe->copyOf() == fe) {
if (!res)
res = OffTheBooks::new_< Vector<TemporaryCopy> >(cx);
res = js_new< Vector<TemporaryCopy> >(cx);
res->append(TemporaryCopy(addressOf(nfe), addressOf(fe)));
}
}

View File

@ -23,7 +23,7 @@ ImmutableSync::ImmutableSync()
ImmutableSync::~ImmutableSync()
{
if (cx)
cx->free_(entries);
js_free(entries);
}
bool
@ -32,7 +32,7 @@ ImmutableSync::init(JSContext *cx, const FrameState &frame, uint32_t nentries)
this->cx = cx;
this->frame = &frame;
entries = (SyncEntry *)OffTheBooks::calloc_(sizeof(SyncEntry) * nentries);
entries = (SyncEntry *)js_calloc(sizeof(SyncEntry) * nentries);
return !!entries;
}

View File

@ -1438,7 +1438,7 @@ LoopState::restoreInvariants(jsbytecode *pc, Assembler &masm,
}
if (temporaryCopies)
cx->delete_(temporaryCopies);
js_delete(temporaryCopies);
}
/* Loop analysis methods. */

View File

@ -1260,7 +1260,7 @@ JITChunk::~JITChunk()
rootedRegExps()[i]->decRef();
if (pcLengths)
Foreground::free_(pcLengths);
js_free(pcLengths);
}
void

View File

@ -2377,7 +2377,7 @@ GetElementIC::attachGetProp(VMFrame &f, HandleObject obj, HandleValue v, HandleP
JaegerSpew(JSpew_PICs, "generated %s stub at %p for atom %p (\"%s\") shape %p (%s: %d)\n",
js_CodeName[JSOp(*f.pc())], cs.executableAddress(), (void*)name, chars,
(void*)holder->lastProperty(), cx->fp()->script()->filename, CurrentLine(cx));
cx->free_(chars);
js_free(chars);
#endif
// Update the inline guards, if needed.

View File

@ -129,11 +129,11 @@ class BasePolyIC : public BaseIC {
if (isOnePool()) {
JSC::ExecutablePool *oldPool = u.execPool;
JS_ASSERT(!isTagged(oldPool));
ExecPoolVector *execPools = OffTheBooks::new_<ExecPoolVector>(SystemAllocPolicy());
ExecPoolVector *execPools = js_new<ExecPoolVector>(SystemAllocPolicy());
if (!execPools)
return false;
if (!execPools->append(oldPool) || !execPools->append(pool)) {
Foreground::delete_(execPools);
js_delete(execPools);
return false;
}
u.taggedExecPools = tag(execPools);
@ -154,7 +154,7 @@ class BasePolyIC : public BaseIC {
ExecPoolVector *execPools = multiplePools();
for (size_t i = 0; i < execPools->length(); i++)
(*execPools)[i]->release();
Foreground::delete_(execPools);
js_delete(execPools);
u.execPool = NULL;
}
JS_ASSERT(areZeroPools());

View File

@ -234,7 +234,7 @@ namespace JS {
#define initCtr(flag) ((eventsMeasured & flag) ? 0 : -1)
PerfMeasurement::PerfMeasurement(PerfMeasurement::EventMask toMeasure)
: impl(OffTheBooks::new_<Impl>()),
: impl(js_new<Impl>()),
eventsMeasured(impl ? static_cast<Impl*>(impl)->init(toMeasure)
: EventMask(0)),
cpu_cycles(initCtr(CPU_CYCLES)),
@ -255,7 +255,7 @@ PerfMeasurement::PerfMeasurement(PerfMeasurement::EventMask toMeasure)
PerfMeasurement::~PerfMeasurement()
{
js::Foreground::delete_(static_cast<Impl*>(impl));
js_delete(static_cast<Impl*>(impl));
}
void

View File

@ -491,7 +491,7 @@ ReferenceFinder::addReferrer(jsval referrer_, Path *path)
char *pathName = path->computeName(context);
if (!pathName)
return false;
AutoReleasePtr releasePathName(context, pathName);
AutoReleasePtr releasePathName(pathName);
/* Find the property of the results object named |pathName|. */
JS::RootedValue valRoot(context);

View File

@ -442,9 +442,9 @@ OptionParser::getMultiStringOption(const char *longflag) const
OptionParser::~OptionParser()
{
for (Option **it = options.begin(), **end = options.end(); it != end; ++it)
Foreground::delete_<Option>(*it);
js_delete<Option>(*it);
for (Option **it = arguments.begin(), **end = arguments.end(); it != end; ++it)
Foreground::delete_<Option>(*it);
js_delete<Option>(*it);
}
Option *
@ -534,8 +534,7 @@ OptionParser::addIntOption(char shortflag, const char *longflag, const char *met
{
if (!options.reserve(options.length() + 1))
return false;
IntOption *io = OffTheBooks::new_<IntOption>(shortflag, longflag, help, metavar,
defaultValue);
IntOption *io = js_new<IntOption>(shortflag, longflag, help, metavar, defaultValue);
if (!io)
return false;
options.infallibleAppend(io);
@ -547,7 +546,7 @@ OptionParser::addBoolOption(char shortflag, const char *longflag, const char *he
{
if (!options.reserve(options.length() + 1))
return false;
BoolOption *bo = OffTheBooks::new_<BoolOption>(shortflag, longflag, help);
BoolOption *bo = js_new<BoolOption>(shortflag, longflag, help);
if (!bo)
return false;
options.infallibleAppend(bo);
@ -560,7 +559,7 @@ OptionParser::addStringOption(char shortflag, const char *longflag, const char *
{
if (!options.reserve(options.length() + 1))
return false;
StringOption *so = OffTheBooks::new_<StringOption>(shortflag, longflag, help, metavar);
StringOption *so = js_new<StringOption>(shortflag, longflag, help, metavar);
if (!so)
return false;
options.infallibleAppend(so);
@ -573,8 +572,7 @@ OptionParser::addMultiStringOption(char shortflag, const char *longflag, const c
{
if (!options.reserve(options.length() + 1))
return false;
MultiStringOption *mso = OffTheBooks::new_<MultiStringOption>(shortflag, longflag, help,
metavar);
MultiStringOption *mso = js_new<MultiStringOption>(shortflag, longflag, help, metavar);
if (!mso)
return false;
options.infallibleAppend(mso);
@ -588,7 +586,7 @@ OptionParser::addOptionalStringArg(const char *name, const char *help)
{
if (!arguments.reserve(arguments.length() + 1))
return false;
StringOption *so = OffTheBooks::new_<StringOption>(1, name, help, (const char *) NULL);
StringOption *so = js_new<StringOption>(1, name, help, (const char *) NULL);
if (!so)
return false;
arguments.infallibleAppend(so);
@ -601,8 +599,7 @@ OptionParser::addOptionalMultiStringArg(const char *name, const char *help)
JS_ASSERT_IF(!arguments.empty(), !arguments.back()->isVariadic());
if (!arguments.reserve(arguments.length() + 1))
return false;
MultiStringOption *mso = OffTheBooks::new_<MultiStringOption>(1, name, help,
(const char *) NULL);
MultiStringOption *mso = js_new<MultiStringOption>(1, name, help, (const char *) NULL);
if (!mso)
return false;
arguments.infallibleAppend(mso);

View File

@ -1819,7 +1819,7 @@ Debugger::construct(JSContext *cx, unsigned argc, Value *vp)
return false;
obj->setPrivate(dbg);
if (!dbg->init(cx)) {
cx->delete_(dbg);
js_delete(dbg);
return false;
}

View File

@ -227,7 +227,7 @@ intrinsic_ThrowError(JSContext *cx, unsigned argc, Value *vp)
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, errorNumber,
errorArgs[0], errorArgs[1], errorArgs[2]);
for (unsigned i = 0; i < 3; i++)
cx->free_(errorArgs[i]);
js_free(errorArgs[i]);
return false;
}
@ -305,7 +305,7 @@ GlobalObject::initFunctionAndObjectClasses(JSContext *cx)
return NULL;
ScriptSource *ss = cx->new_<ScriptSource>();
if (!ss) {
cx->free_(source);
js_free(source);
return NULL;
}
ScriptSourceHolder ssh(cx->runtime, ss);

View File

@ -546,7 +546,7 @@ RegExpCompartment::sweep(JSRuntime *rt)
/* See the comment on RegExpShared lifetime in RegExpObject.h. */
RegExpShared *shared = e.front().value;
if (shared->activeUseCount == 0 && shared->gcNumberWhenUsed < rt->gcStartNumber) {
Foreground::delete_(shared);
js_delete(shared);
e.removeFront();
}
}

View File

@ -104,7 +104,7 @@ class RegExpCode
codeBlock.release();
#endif
if (byteCode)
Foreground::delete_<BytecodePattern>(byteCode);
js_delete<BytecodePattern>(byteCode);
}
static bool checkSyntax(JSContext *cx, frontend::TokenStream *tokenStream,
@ -167,17 +167,15 @@ class RegExpShared
friend class RegExpGuard;
detail::RegExpCode code;
unsigned parenCount;
unsigned parenCount;
RegExpFlag flags;
size_t activeUseCount; /* See comment above. */
uint64_t gcNumberWhenUsed; /* See comment above. */
bool compile(JSContext *cx, JSAtom *source);
RegExpShared(JSRuntime *rt, RegExpFlag flags);
JS_DECLARE_ALLOCATION_FRIENDS_FOR_PRIVATE_CONSTRUCTOR;
public:
RegExpShared(JSRuntime *rt, RegExpFlag flags);
/* Called when a RegExpShared is installed into a RegExpObject. */
inline void prepareForUse(JSContext *cx);

View File

@ -31,12 +31,12 @@ SPSProfiler::~SPSProfiler()
{
if (strings.initialized()) {
for (ProfileStringMap::Enum e(strings); !e.empty(); e.popFront())
rt->array_delete(e.front().value);
js_free(const_cast<char *>(e.front().value));
}
#ifdef JS_METHODJIT
if (jminfo.initialized()) {
for (JITInfoMap::Enum e(jminfo); !e.empty(); e.popFront())
rt->delete_(e.front().value);
js_delete(e.front().value);
}
#endif
}
@ -76,7 +76,7 @@ SPSProfiler::profileString(JSContext *cx, JSScript *script, JSFunction *maybeFun
if (str == NULL)
return NULL;
if (!strings.add(s, script, str)) {
rt->array_delete(str);
js_free(const_cast<char *>(str));
return NULL;
}
return str;
@ -97,7 +97,7 @@ SPSProfiler::onScriptFinalized(JSScript *script)
if (ProfileStringMap::Ptr entry = strings.lookup(script)) {
const char *tofree = entry->value;
strings.remove(entry);
rt->array_delete(tofree);
js_free(const_cast<char *>(tofree));
}
}
@ -191,7 +191,7 @@ SPSProfiler::allocProfileString(JSContext *cx, JSScript *script, JSFunction *may
return NULL;
size_t len = buf.length();
char *cstr = rt->array_new<char>(len + 1);
char *cstr = (char *)js_malloc((len + 1) * sizeof(char));
if (cstr == NULL)
return NULL;
@ -379,7 +379,7 @@ SPSProfiler::unregisterScript(JSScript *script, mjit::JITChunk *chunk)
}
if (info->chunks.length() == 0) {
jminfo.remove(ptr);
rt->delete_(info);
js_delete(info);
}
}
#endif

View File

@ -130,7 +130,7 @@ AllocChars(JSContext *maybecx, size_t length, jschar **chars, size_t *capacity)
JS_STATIC_ASSERT(JSString::MAX_LENGTH * sizeof(jschar) < UINT32_MAX);
size_t bytes = numChars * sizeof(jschar);
*chars = (jschar *)(maybecx ? maybecx->malloc_(bytes) : OffTheBooks::malloc_(bytes));
*chars = (jschar *)(maybecx ? maybecx->malloc_(bytes) : js_malloc(bytes));
return *chars != NULL;
}

View File

@ -29,7 +29,7 @@ StringBuffer::extractWellSized()
JSContext *cx = context();
jschar *tmp = (jschar *)cx->realloc_(buf, bytes);
if (!tmp) {
cx->free_(buf);
js_free(buf);
return NULL;
}
buf = tmp;
@ -62,7 +62,7 @@ StringBuffer::finishString()
JSFixedString *str = js_NewString(cx, buf, length);
if (!str)
cx->free_(buf);
js_free(buf);
return str;
}

View File

@ -32,7 +32,7 @@ namespace js {
void
XDRBuffer::freeBuffer()
{
Foreground::free_(base);
js_free(base);
#ifdef DEBUG
memset(this, 0xe2, sizeof *this);
#endif
@ -51,7 +51,7 @@ XDRBuffer::grow(size_t n)
return false;
}
void *data = OffTheBooks::realloc_(base, newCapacity);
void *data = js_realloc(base, newCapacity);
if (!data) {
js_ReportOutOfMemory(cx());
return false;

View File

@ -2630,7 +2630,7 @@ static const char _wordcharData[65536] = {
CharacterClass* digitsCreate()
{
// FIXME: bug 574459 -- no NULL check
CharacterClass* characterClass = js::OffTheBooks::new_<CharacterClass>((CharacterClassTable*)NULL);
CharacterClass* characterClass = js_new<CharacterClass>((CharacterClassTable*)NULL);
characterClass->m_ranges.append(CharacterRange(0x30, 0x39));
return characterClass;
}
@ -2638,7 +2638,7 @@ CharacterClass* digitsCreate()
CharacterClass* nondigitsCreate()
{
// FIXME: bug 574459 -- no NULL check
CharacterClass* characterClass = js::OffTheBooks::new_<CharacterClass>((CharacterClassTable*)NULL);
CharacterClass* characterClass = js_new<CharacterClass>((CharacterClassTable*)NULL);
characterClass->m_ranges.append(CharacterRange(0x00, 0x2f));
characterClass->m_ranges.append(CharacterRange(0x3a, 0x7f));
characterClass->m_rangesUnicode.append(CharacterRange(0x0080, 0xffff));
@ -2648,7 +2648,7 @@ CharacterClass* nondigitsCreate()
CharacterClass* newlineCreate()
{
// FIXME: bug 574459 -- no NULL check
CharacterClass* characterClass = js::OffTheBooks::new_<CharacterClass>((CharacterClassTable*)NULL);
CharacterClass* characterClass = js_new<CharacterClass>((CharacterClassTable*)NULL);
characterClass->m_matches.append(0x0a);
characterClass->m_matches.append(0x0d);
characterClass->m_matchesUnicode.append(0x2028);
@ -2659,7 +2659,7 @@ CharacterClass* newlineCreate()
CharacterClass* spacesCreate()
{
// FIXME: bug 574459 -- no NULL check
CharacterClass* characterClass = js::OffTheBooks::new_<CharacterClass>(CharacterClassTable::create(_spacesData, false));
CharacterClass* characterClass = js_new<CharacterClass>(CharacterClassTable::create(_spacesData, false));
characterClass->m_ranges.append(CharacterRange(0x09, 0x0d));
characterClass->m_matches.append(0x20);
characterClass->m_matchesUnicode.append(0x00a0);
@ -2677,7 +2677,7 @@ CharacterClass* spacesCreate()
CharacterClass* nonspacesCreate()
{
// FIXME: bug 574459 -- no NULL check
CharacterClass* characterClass = js::OffTheBooks::new_<CharacterClass>(CharacterClassTable::create(_spacesData, true));
CharacterClass* characterClass = js_new<CharacterClass>(CharacterClassTable::create(_spacesData, true));
characterClass->m_ranges.append(CharacterRange(0x00, 0x08));
characterClass->m_ranges.append(CharacterRange(0x0e, 0x1f));
characterClass->m_ranges.append(CharacterRange(0x21, 0x7f));
@ -2696,7 +2696,7 @@ CharacterClass* nonspacesCreate()
CharacterClass* nonwordcharCreate()
{
// FIXME: bug 574459 -- no NULL check
CharacterClass* characterClass = js::OffTheBooks::new_<CharacterClass>(CharacterClassTable::create(_wordcharData, true));
CharacterClass* characterClass = js_new<CharacterClass>(CharacterClassTable::create(_wordcharData, true));
characterClass->m_ranges.append(CharacterRange(0x00, 0x2f));
characterClass->m_ranges.append(CharacterRange(0x3a, 0x40));
characterClass->m_ranges.append(CharacterRange(0x5b, 0x5e));
@ -2709,7 +2709,7 @@ CharacterClass* nonwordcharCreate()
CharacterClass* wordcharCreate()
{
// FIXME: bug 574459 -- no NULL check
CharacterClass* characterClass = js::OffTheBooks::new_<CharacterClass>(CharacterClassTable::create(_wordcharData, false));
CharacterClass* characterClass = js_new<CharacterClass>(CharacterClassTable::create(_wordcharData, false));
characterClass->m_ranges.append(CharacterRange(0x30, 0x39));
characterClass->m_ranges.append(CharacterRange(0x41, 0x5a));
characterClass->m_matches.append(0x5f);

View File

@ -1422,7 +1422,7 @@ public:
emitDisjunction(m_pattern.m_body);
regexEnd();
return adoptPtr(js::OffTheBooks::new_<BytecodePattern>(m_bodyDisjunction.release(), m_allParenthesesInfo, Ref<YarrPattern>(m_pattern), allocator));
return adoptPtr(js_new<BytecodePattern>(m_bodyDisjunction.release(), m_allParenthesesInfo, Ref<YarrPattern>(m_pattern), allocator));
}
void checkInput(unsigned count)
@ -1648,7 +1648,7 @@ public:
unsigned subpatternId = parenthesesBegin.atom.subpatternId;
unsigned numSubpatterns = lastSubpatternId - subpatternId + 1;
ByteDisjunction* parenthesesDisjunction = js::OffTheBooks::new_<ByteDisjunction>(numSubpatterns, callFrameSize);
ByteDisjunction* parenthesesDisjunction = js_new<ByteDisjunction>(numSubpatterns, callFrameSize);
parenthesesDisjunction->terms.append(ByteTerm::SubpatternBegin());
for (unsigned termInParentheses = beginTerm + 1; termInParentheses < endTerm; ++termInParentheses)
@ -1711,7 +1711,7 @@ public:
void regexBegin(unsigned numSubpatterns, unsigned callFrameSize, bool onceThrough)
{
m_bodyDisjunction = adoptPtr(js::OffTheBooks::new_<ByteDisjunction>(numSubpatterns, callFrameSize));
m_bodyDisjunction = adoptPtr(js_new<ByteDisjunction>(numSubpatterns, callFrameSize));
m_bodyDisjunction->terms.append(ByteTerm::BodyAlternativeBegin(onceThrough));
m_bodyDisjunction->terms[0].frameLocation = 0;
m_currentAlternativeIndex = 0;

View File

@ -150,7 +150,7 @@ public:
CharacterClass* charClass()
{
CharacterClass* characterClass = js::OffTheBooks::new_<CharacterClass>(PassRefPtr<CharacterClassTable>(0));
CharacterClass* characterClass = js_new<CharacterClass>(PassRefPtr<CharacterClassTable>(0));
characterClass->m_matches.append(m_matches);
characterClass->m_ranges.append(m_ranges);
@ -249,7 +249,7 @@ public:
, m_characterClassConstructor(pattern.m_ignoreCase)
, m_invertParentheticalAssertion(false)
{
m_pattern.m_body = js::OffTheBooks::new_<PatternDisjunction>();
m_pattern.m_body = js_new<PatternDisjunction>();
m_alternative = m_pattern.m_body->addNewAlternative();
m_pattern.m_disjunctions.append(m_pattern.m_body);
}
@ -263,7 +263,7 @@ public:
m_pattern.reset();
m_characterClassConstructor.reset();
m_pattern.m_body = js::OffTheBooks::new_<PatternDisjunction>();
m_pattern.m_body = js_new<PatternDisjunction>();
m_alternative = m_pattern.m_body->addNewAlternative();
m_pattern.m_disjunctions.append(m_pattern.m_body);
}
@ -366,7 +366,7 @@ public:
if (capture)
m_pattern.m_numSubpatterns++;
PatternDisjunction* parenthesesDisjunction = js::OffTheBooks::new_<PatternDisjunction>(m_alternative);
PatternDisjunction* parenthesesDisjunction = js_new<PatternDisjunction>(m_alternative);
m_pattern.m_disjunctions.append(parenthesesDisjunction);
m_alternative->m_terms.append(PatternTerm(PatternTerm::TypeParenthesesSubpattern, subpatternId, parenthesesDisjunction, capture, false));
m_alternative = parenthesesDisjunction->addNewAlternative();
@ -374,7 +374,7 @@ public:
void atomParentheticalAssertionBegin(bool invert = false)
{
PatternDisjunction* parenthesesDisjunction = js::OffTheBooks::new_<PatternDisjunction>(m_alternative);
PatternDisjunction* parenthesesDisjunction = js_new<PatternDisjunction>(m_alternative);
m_pattern.m_disjunctions.append(parenthesesDisjunction);
m_alternative->m_terms.append(PatternTerm(PatternTerm::TypeParentheticalAssertion, m_pattern.m_numSubpatterns + 1, parenthesesDisjunction, false, invert));
m_alternative = parenthesesDisjunction->addNewAlternative();
@ -448,7 +448,7 @@ public:
PatternAlternative* alternative = disjunction->m_alternatives[alt];
if (!filterStartsWithBOL || !alternative->m_startsWithBOL) {
if (!newDisjunction) {
newDisjunction = js::OffTheBooks::new_<PatternDisjunction>();
newDisjunction = js_new<PatternDisjunction>();
newDisjunction->m_parent = disjunction->m_parent;
}
PatternAlternative* newAlternative = newDisjunction->addNewAlternative();

View File

@ -66,15 +66,13 @@ struct CharacterRange {
};
struct CharacterClassTable : RefCounted<CharacterClassTable> {
friend class js::OffTheBooks;
const char* m_table;
bool m_inverted;
static PassRefPtr<CharacterClassTable> create(const char* table, bool inverted)
{
return adoptRef(js::OffTheBooks::new_<CharacterClassTable>(table, inverted));
return adoptRef(js_new<CharacterClassTable>(table, inverted));
}
private:
CharacterClassTable(const char* table, bool inverted)
: m_table(table)
, m_inverted(inverted)
@ -94,7 +92,7 @@ public:
}
~CharacterClass()
{
js::Foreground::delete_(m_table.get());
js_delete(m_table.get());
}
Vector<UChar> m_matches;
Vector<CharacterRange> m_ranges;
@ -299,7 +297,7 @@ public:
PatternAlternative* addNewAlternative()
{
PatternAlternative* alternative = js::OffTheBooks::new_<PatternAlternative>(this);
PatternAlternative* alternative = js_new<PatternAlternative>(this);
m_alternatives.append(alternative);
return alternative;
}

View File

@ -80,7 +80,7 @@ class OwnPtr {
~OwnPtr() {
if (ptr)
js::Foreground::delete_(ptr);
js_delete(ptr);
}
OwnPtr<T> &operator=(PassOwnPtr<T> p) {
@ -192,7 +192,7 @@ class Vector {
void deleteAllValues() {
for (T *p = impl.begin(); p != impl.end(); ++p)
js::Foreground::delete_(*p);
js_delete(*p);
}
};
@ -218,7 +218,7 @@ class Vector<OwnPtr<T> > {
void clear() {
for (T **p = impl.begin(); p != impl.end(); ++p)
js::Foreground::delete_(*p);
delete_(*p);
return impl.clear();
}
};