Bug 817452 - Remove AutoRelease[Nullable]Ptr. r=njn

This commit is contained in:
Benjamin Peterson 2012-12-05 00:09:15 -05:00
parent 3a7d1398ef
commit b90a600d03
4 changed files with 5 additions and 52 deletions

View File

@ -1846,49 +1846,6 @@ class AutoKeepAtoms {
~AutoKeepAtoms() { JS_UNKEEP_ATOMS(rt); } ~AutoKeepAtoms() { JS_UNKEEP_ATOMS(rt); }
}; };
class AutoReleasePtr {
void *ptr;
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
AutoReleasePtr(const AutoReleasePtr &other) MOZ_DELETE;
AutoReleasePtr operator=(const AutoReleasePtr &other) MOZ_DELETE;
public:
explicit AutoReleasePtr(void *ptr
JS_GUARD_OBJECT_NOTIFIER_PARAM)
: ptr(ptr)
{
JS_GUARD_OBJECT_NOTIFIER_INIT;
}
void forget() { ptr = NULL; }
~AutoReleasePtr() { js_free(ptr); }
};
/*
* FIXME: bug 602774: cleaner API for AutoReleaseNullablePtr
*/
class AutoReleaseNullablePtr {
void *ptr;
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
AutoReleaseNullablePtr(const AutoReleaseNullablePtr &other) MOZ_DELETE;
AutoReleaseNullablePtr operator=(const AutoReleaseNullablePtr &other) MOZ_DELETE;
public:
explicit AutoReleaseNullablePtr(void *ptr
JS_GUARD_OBJECT_NOTIFIER_PARAM)
: ptr(ptr)
{
JS_GUARD_OBJECT_NOTIFIER_INIT;
}
void reset(void *ptr2) {
if (ptr)
js_free(ptr);
ptr = ptr2;
}
~AutoReleaseNullablePtr() { if (ptr) js_free(ptr); }
};
} /* namespace js */ } /* namespace js */
class JSAutoResolveFlags class JSAutoResolveFlags

View File

@ -1147,10 +1147,9 @@ js_CopyErrorObject(JSContext *cx, HandleObject errobj, HandleObject scope)
size_t size = offsetof(JSExnPrivate, stackElems) + size_t size = offsetof(JSExnPrivate, stackElems) +
priv->stackDepth * sizeof(JSStackTraceElem); priv->stackDepth * sizeof(JSStackTraceElem);
JSExnPrivate *copy = (JSExnPrivate *)cx->malloc_(size); js::ScopedFreePtr<JSExnPrivate> copy(static_cast<JSExnPrivate *>(cx->malloc_(size)));
if (!copy) if (!copy)
return NULL; return NULL;
AutoReleasePtr autoFreePrivate(copy);
if (priv->errorReport) { if (priv->errorReport) {
copy->errorReport = CopyErrorReport(cx, priv->errorReport); copy->errorReport = CopyErrorReport(cx, priv->errorReport);
@ -1159,7 +1158,7 @@ js_CopyErrorObject(JSContext *cx, HandleObject errobj, HandleObject scope)
} else { } else {
copy->errorReport = NULL; copy->errorReport = NULL;
} }
AutoReleasePtr autoFreeErrorReport(copy->errorReport); js::ScopedFreePtr<JSErrorReport> autoFreeErrorReport(copy->errorReport);
copy->message.init(priv->message); copy->message.init(priv->message);
if (!cx->compartment->wrap(cx, &copy->message)) if (!cx->compartment->wrap(cx, &copy->message))
@ -1182,7 +1181,7 @@ js_CopyErrorObject(JSContext *cx, HandleObject errobj, HandleObject scope)
if (!copyobj) if (!copyobj)
return NULL; return NULL;
SetExnPrivate(copyobj, copy); SetExnPrivate(copyobj, copy);
autoFreePrivate.forget(); copy.forget();
autoFreeErrorReport.forget(); autoFreeErrorReport.forget();
return copyobj; return copyobj;
} }

View File

@ -3398,8 +3398,7 @@ reflect_parse(JSContext *cx, uint32_t argc, jsval *vp)
if (!src) if (!src)
return JS_FALSE; return JS_FALSE;
char *filename = NULL; js::ScopedFreePtr<char> filename;
AutoReleaseNullablePtr filenamep(filename);
uint32_t lineno = 1; uint32_t lineno = 1;
bool loc = true; bool loc = true;
@ -3446,7 +3445,6 @@ reflect_parse(JSContext *cx, uint32_t argc, jsval *vp)
filename = DeflateString(cx, chars, length); filename = DeflateString(cx, chars, length);
if (!filename) if (!filename)
return JS_FALSE; return JS_FALSE;
filenamep.reset(filename);
} }
/* config.line */ /* config.line */

View File

@ -488,10 +488,9 @@ ReferenceFinder::addReferrer(jsval referrer_, Path *path)
if (!context->compartment->wrap(context, referrer.address())) if (!context->compartment->wrap(context, referrer.address()))
return false; return false;
char *pathName = path->computeName(context); js::ScopedFreePtr<char> pathName(path->computeName(context));
if (!pathName) if (!pathName)
return false; return false;
AutoReleasePtr releasePathName(pathName);
/* Find the property of the results object named |pathName|. */ /* Find the property of the results object named |pathName|. */
RootedValue valRoot(context); RootedValue valRoot(context);