Bug 763384 - Don't treat regexp syntax errors as OOM errors (r=njn)

This commit is contained in:
Luke Wagner 2012-06-11 17:08:34 -07:00
parent ebf032432b
commit 28d1e3621d
3 changed files with 28 additions and 12 deletions

View File

@ -21,6 +21,7 @@
#include "jstypes.h"
#ifdef __cplusplus
# include "mozilla/Scoped.h"
/* The public JS engine namespace. */
namespace JS {}
@ -594,6 +595,15 @@ public:
class UnwantedForeground : public Foreground {
};
template <typename T>
struct ScopedDeletePtrTraits
{
typedef T *type;
static T *empty() { return NULL; }
static void release(T *ptr) { Foreground::delete_(ptr); }
};
SCOPED_TEMPLATE(ScopedDeletePtr, ScopedDeletePtrTraits)
} /* namespace js */
/*

View File

@ -0,0 +1,9 @@
var caught = false;
try {
''.match('(');
} catch (e) {
caught = true;
assertEq(e instanceof Error, true);
assertEq(('' + e).indexOf('SyntaxError') === -1, false);
}
assertEq(caught, true);

View File

@ -560,29 +560,26 @@ RegExpCompartment::get(JSContext *cx, JSAtom *keyAtom, JSAtom *source, RegExpFla
return true;
}
RegExpShared *shared = cx->runtime->new_<RegExpShared>(cx->runtime, flags);
ScopedDeletePtr<RegExpShared> shared(cx->new_<RegExpShared>(cx->runtime, flags));
if (!shared)
goto error;
return false;
if (!shared->compile(cx, source))
goto error;
return false;
/* Re-lookup in case there was a GC. */
if (!map_.relookupOrAdd(p, key, shared))
goto error;
if (!map_.relookupOrAdd(p, key, shared)) {
js_ReportOutOfMemory(cx);
return false;
}
/*
* Since 'error' deletes 'shared', only guard 'shared' on success. This is
* safe since 'shared' cannot be deleted by GC until after the call to
* map_.add() directly above.
* map_.relookupOrAdd() directly above.
*/
g->init(*shared);
g->init(*shared.forget());
return true;
error:
Foreground::delete_(shared);
js_ReportOutOfMemory(cx);
return false;
}
bool