Skip to content

Commit

Permalink
Bug 933834 - Rename and handlify JS_ValueToString. r=terrence,bz
Browse files Browse the repository at this point in the history
  • Loading branch information
evilpie committed Nov 16, 2013
1 parent ab661fa commit bc757ef
Show file tree
Hide file tree
Showing 42 changed files with 267 additions and 321 deletions.
6 changes: 3 additions & 3 deletions caps/src/nsScriptSecurityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ IDToString(JSContext *cx, jsid id_)
if (JSID_IS_STRING(id))
return JS_GetInternedStringChars(JSID_TO_STRING(id));

JS::Value idval;
if (!JS_IdToValue(cx, id, &idval))
JS::Rooted<JS::Value> idval(cx);
if (!JS_IdToValue(cx, id, idval.address()))
return nullptr;
JSString *str = JS_ValueToString(cx, idval);
JSString *str = JS::ToString(cx, idval);
if(!str)
return nullptr;
return JS_GetStringCharsZ(cx, str);
Expand Down
6 changes: 3 additions & 3 deletions content/base/src/nsDOMBlobBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ nsDOMMultipartFile::ParseBlobArrayArgument(JSContext* aCx, JS::Value& aValue,
}

// coerce it to a string
JSString* str = JS_ValueToString(aCx, element);
JSString* str = JS::ToString(aCx, element);
NS_ENSURE_TRUE(str, NS_ERROR_TYPE_ERR);
blobSet.AppendString(str, aNativeEOL, aCx);
}
Expand Down Expand Up @@ -342,7 +342,7 @@ nsDOMMultipartFile::InitChromeFile(JSContext* aCx,
mIsFromNsiFile = true;
} else {
// It's a string
JSString* str = JS_ValueToString(aCx, aArgv[0]);
JSString* str = JS::ToString(aCx, JS::Handle<JS::Value>::fromMarkedLocation(&aArgv[0]));
NS_ENSURE_TRUE(str, NS_ERROR_XPC_BAD_CONVERT_JS);

nsDependentJSString xpcomStr;
Expand Down Expand Up @@ -397,7 +397,7 @@ nsDOMMultipartFile::InitFile(JSContext* aCx,
}

// File name
JSString* str = JS_ValueToString(aCx, aArgv[1]);
JSString* str = JS::ToString(aCx, JS::Handle<JS::Value>::fromMarkedLocation(&aArgv[1]));
NS_ENSURE_TRUE(str, NS_ERROR_XPC_BAD_CONVERT_JS);

nsDependentJSString xpcomStr;
Expand Down
4 changes: 2 additions & 2 deletions content/xslt/src/xslt/txMozillaXSLTProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1444,8 +1444,8 @@ txVariable::Convert(nsIVariant *aValue, txAExprResult** aResult)
JS::Rooted<JSObject*> jsobj(cx, holder->GetJSObject());
NS_ENSURE_STATE(jsobj);

JS::Rooted<JSString*> str(cx,
JS_ValueToString(cx, OBJECT_TO_JSVAL(jsobj)));
JS::Rooted<JS::Value> v(cx, JS::ObjectValue(*jsobj));
JS::Rooted<JSString*> str(cx, JS::ToString(cx, v));
NS_ENSURE_TRUE(str, NS_ERROR_FAILURE);

nsDependentJSString value;
Expand Down
2 changes: 1 addition & 1 deletion dom/audiochannel/AudioChannelService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ AudioChannelService::Observe(nsISupports* aSubject, const char* aTopic, const PR
return NS_OK;
}

JS::Rooted<JSString*> jsKey(cx, JS_ValueToString(cx, key));
JS::Rooted<JSString*> jsKey(cx, JS::ToString(cx, key));
if (!jsKey) {
return NS_OK;
}
Expand Down
31 changes: 13 additions & 18 deletions dom/base/nsDOMClassInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,10 +616,10 @@ IdToString(JSContext *cx, jsid id)
{
if (JSID_IS_STRING(id))
return JSID_TO_STRING(id);
jsval idval;
if (!::JS_IdToValue(cx, id, &idval))
JS::Rooted<JS::Value> idval(cx);
if (!::JS_IdToValue(cx, id, idval.address()))
return nullptr;
return JS_ValueToString(cx, idval);
return JS::ToString(cx, idval);
}

static inline nsresult
Expand Down Expand Up @@ -3292,7 +3292,7 @@ LocationSetterGuts(JSContext *cx, JSObject *obj, JS::MutableHandle<JS::Value> vp
NS_ENSURE_SUCCESS(rv, rv);

// Grab the value we're being set to before we stomp on |vp|
JS::Rooted<JSString*> val(cx, ::JS_ValueToString(cx, vp));
JS::Rooted<JSString*> val(cx, JS::ToString(cx, vp));
NS_ENSURE_TRUE(val, NS_ERROR_UNEXPECTED);

// Make sure |val| stays alive below
Expand Down Expand Up @@ -4198,9 +4198,10 @@ nsHTMLDocumentSH::ReleaseDocument(JSFreeOp *fop, JSObject *obj)
bool
nsHTMLDocumentSH::CallToGetPropMapper(JSContext *cx, unsigned argc, jsval *vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
// Handle document.all("foo") style access to document.all.

if (argc != 1) {
if (args.length() != 1) {
// XXX: Should throw NS_ERROR_XPC_NOT_ENOUGH_ARGS for argc < 1,
// and create a new NS_ERROR_XPC_TOO_MANY_ARGS for argc > 1? IE
// accepts nothing other than one arg.
Expand All @@ -4210,18 +4211,17 @@ nsHTMLDocumentSH::CallToGetPropMapper(JSContext *cx, unsigned argc, jsval *vp)
}

// Convert all types to string.
JS::Rooted<JSString*> str(cx, ::JS_ValueToString(cx, JS_ARGV(cx, vp)[0]));
JS::Rooted<JSString*> str(cx, JS::ToString(cx, args[0]));
if (!str) {
return false;
}

// If we are called via document.all(id) instead of document.all.item(i) or
// another method, use the document.all callee object as self.
JSObject *self;
JS::Value callee = JS_CALLEE(cx, vp);
if (callee.isObject() &&
JS_GetClass(&callee.toObject()) == &sHTMLDocumentAllClass) {
self = JSVAL_TO_OBJECT(JS_CALLEE(cx, vp));
if (args.calleev().isObject() &&
JS_GetClass(&args.calleev().toObject()) == &sHTMLDocumentAllClass) {
self = &args.calleev().toObject();
} else {
self = JS_THIS_OBJECT(cx, vp);
if (!self)
Expand All @@ -4235,13 +4235,7 @@ nsHTMLDocumentSH::CallToGetPropMapper(JSContext *cx, unsigned argc, jsval *vp)
return false;
}

JS::Rooted<JS::Value> value(cx);
if (!::JS_GetUCProperty(cx, self, chars, length, &value)) {
return false;
}

*vp = value;
return true;
return ::JS_GetUCProperty(cx, self, chars, length, args.rval());
}

// StringArray helper
Expand Down Expand Up @@ -4436,7 +4430,8 @@ nsStorage2SH::SetProperty(nsIXPConnectWrappedNative *wrapper,
nsDependentJSString keyStr;
NS_ENSURE_TRUE(keyStr.init(cx, key), NS_ERROR_UNEXPECTED);

JSString *value = ::JS_ValueToString(cx, *vp);
JS::Rooted<JS::Value> val(cx, *vp);
JSString *value = JS::ToString(cx, val);
NS_ENSURE_TRUE(value, NS_ERROR_UNEXPECTED);

nsDependentJSString valueStr;
Expand Down
23 changes: 13 additions & 10 deletions dom/base/nsJSEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1536,16 +1536,16 @@ TraceMallocEnable(JSContext *cx, unsigned argc, JS::Value *vp)
static bool
TraceMallocOpenLogFile(JSContext *cx, unsigned argc, JS::Value *vp)
{
int fd;
JSString *str;
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);

if (!CheckUniversalXPConnectForTraceMalloc(cx))
return false;

int fd;
if (argc == 0) {
fd = -1;
} else {
str = JS_ValueToString(cx, JS_ARGV(cx, vp)[0]);
JSString *str = JS::ToString(cx, args[0]);
if (!str)
return false;
JSAutoByteString filename(cx, str);
Expand All @@ -1557,7 +1557,7 @@ TraceMallocOpenLogFile(JSContext *cx, unsigned argc, JS::Value *vp)
return false;
}
}
JS_SET_RVAL(cx, vp, INT_TO_JSVAL(fd));
args.rva().setInt32(fd);
return true;
}

Expand Down Expand Up @@ -1608,27 +1608,29 @@ TraceMallocCloseLogFD(JSContext *cx, unsigned argc, JS::Value *vp)
static bool
TraceMallocLogTimestamp(JSContext *cx, unsigned argc, JS::Value *vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
if (!CheckUniversalXPConnectForTraceMalloc(cx))
return false;

JSString *str = JS_ValueToString(cx, argc ? JS_ARGV(cx, vp)[0] : JSVAL_VOID);
JSString *str = JS::ToString(cx, args.get(0));
if (!str)
return false;
JSAutoByteString caption(cx, str);
if (!caption)
return false;
NS_TraceMallocLogTimestamp(caption.ptr());
JS_SET_RVAL(cx, vp, JSVAL_VOID);
args.rval().setUndefined();
return true;
}

static bool
TraceMallocDumpAllocations(JSContext *cx, unsigned argc, JS::Value *vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
if (!CheckUniversalXPConnectForTraceMalloc(cx))
return false;

JSString *str = JS_ValueToString(cx, argc ? JS_ARGV(cx, vp)[0] : JSVAL_VOID);
JSString *str = JS::ToString(cx, args.get(0));
if (!str)
return false;
JSAutoByteString pathname(cx, str);
Expand All @@ -1638,7 +1640,7 @@ TraceMallocDumpAllocations(JSContext *cx, unsigned argc, JS::Value *vp)
JS_ReportError(cx, "can't dump to %s: %s", pathname.ptr(), strerror(errno));
return false;
}
JS_SET_RVAL(cx, vp, JSVAL_VOID);
args.rval().setUndefined();
return true;
}

Expand Down Expand Up @@ -1668,7 +1670,8 @@ namespace dmd {
static bool
ReportAndDump(JSContext *cx, unsigned argc, JS::Value *vp)
{
JSString *str = JS_ValueToString(cx, argc ? JS_ARGV(cx, vp)[0] : JSVAL_VOID);
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
JSString *str = JS::ToString(cx, args.get(0));
if (!str)
return false;
JSAutoByteString pathname(cx, str);
Expand All @@ -1690,7 +1693,7 @@ ReportAndDump(JSContext *cx, unsigned argc, JS::Value *vp)

fclose(fp);

JS_SET_RVAL(cx, vp, JSVAL_VOID);
args.rval().setUndefined();
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion dom/base/nsJSTimeoutHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ nsJSScriptTimeoutHandler::Init(nsGlobalWindow *aWindow, bool *aIsInterval,
case JSTYPE_STRING:
case JSTYPE_OBJECT:
{
JSString *str = ::JS_ValueToString(cx, argv[0]);
JS::Rooted<JS::Value> arg(cx, argv[0]);
JSString *str = JS::ToString(cx, arg);
if (!str)
return NS_ERROR_OUT_OF_MEMORY;

Expand Down
3 changes: 2 additions & 1 deletion dom/base/nsJSUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ nsJSUtils::EvaluateString(JSContext* aCx,
}

if (ok && aEvaluateOptions.coerceToString && !aRetValue->isUndefined()) {
JSString* str = JS_ValueToString(aCx, *aRetValue);
JS::Rooted<JS::Value> value(aCx, *aRetValue);
JSString* str = JS::ToString(aCx, value);
ok = !!str;
*aRetValue = ok ? JS::StringValue(str) : JS::UndefinedValue();
}
Expand Down
8 changes: 5 additions & 3 deletions dom/base/nsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,11 @@ nsScreen::GetLockOrientationPermission() const
}

NS_IMETHODIMP
nsScreen::MozLockOrientation(const JS::Value& aOrientation, JSContext* aCx,
nsScreen::MozLockOrientation(const JS::Value& aOrientation_, JSContext* aCx,
bool* aReturn)
{
JS::Rooted<JS::Value> aOrientation(aCx, aOrientation_);

if (aOrientation.isObject()) {
JS::Rooted<JSObject*> seq(aCx, &aOrientation.toObject());
if (IsArrayLike(aCx, seq)) {
Expand All @@ -264,7 +266,7 @@ nsScreen::MozLockOrientation(const JS::Value& aOrientation, JSContext* aCx,
return NS_ERROR_FAILURE;
}

JS::Rooted<JSString*> jsString(aCx, JS_ValueToString(aCx, temp));
JS::Rooted<JSString*> jsString(aCx, JS::ToString(aCx, temp));
if (!jsString) {
return NS_ERROR_FAILURE;
}
Expand All @@ -283,7 +285,7 @@ nsScreen::MozLockOrientation(const JS::Value& aOrientation, JSContext* aCx,
}
}

JS::Rooted<JSString*> jsString(aCx, JS_ValueToString(aCx, aOrientation));
JS::Rooted<JSString*> jsString(aCx, JS::ToString(aCx, aOrientation));
if (!jsString) {
return NS_ERROR_FAILURE;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/bindings/BindingUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2108,7 +2108,7 @@ ConvertJSValueToByteString(JSContext* cx, JS::Handle<JS::Value> v,
return true;
}

s = JS_ValueToString(cx, v);
s = JS::ToString(cx, v);
if (!s) {
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions dom/bindings/BindingUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -900,11 +900,11 @@ EnumValueNotFound<true>(JSContext* cx, const jschar* chars, size_t length,

template<bool InvalidValueFatal>
inline int
FindEnumStringIndex(JSContext* cx, JS::Value v, const EnumEntry* values,
FindEnumStringIndex(JSContext* cx, JS::Handle<JS::Value> v, const EnumEntry* values,
const char* type, const char* sourceDescription, bool* ok)
{
// JS_StringEqualsAscii is slow as molasses, so don't use it here.
JSString* str = JS_ValueToString(cx, v);
JSString* str = JS::ToString(cx, v);
if (!str) {
*ok = false;
return 0;
Expand Down Expand Up @@ -1550,7 +1550,7 @@ ConvertJSValueToString(JSContext* cx, JS::Handle<JS::Value> v,
return true;
}

s = JS_ValueToString(cx, v);
s = JS::ToString(cx, v);
if (!s) {
return false;
}
Expand Down
17 changes: 6 additions & 11 deletions dom/file/LockedFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,12 @@ CreateGenericEvent(mozilla::dom::EventTarget* aEventOwner,
}

inline nsresult
GetInputStreamForJSVal(const JS::Value& aValue, JSContext* aCx,
GetInputStreamForJSVal(JS::Handle<JS::Value> aValue, JSContext* aCx,
nsIInputStream** aInputStream, uint64_t* aInputLength)
{
nsresult rv;

if (!JSVAL_IS_PRIMITIVE(aValue)) {
if (aValue.isObject()) {
JS::Rooted<JSObject*> obj(aCx, &aValue.toObject());
if (JS_IsArrayBufferObject(obj)) {
char* data = reinterpret_cast<char*>(JS_GetArrayBufferData(obj));
Expand Down Expand Up @@ -246,14 +246,8 @@ GetInputStreamForJSVal(const JS::Value& aValue, JSContext* aCx,
}
}

JSString* jsstr;
if (JSVAL_IS_STRING(aValue)) {
jsstr = JSVAL_TO_STRING(aValue);
}
else {
jsstr = JS_ValueToString(aCx, aValue);
NS_ENSURE_TRUE(jsstr, NS_ERROR_XPC_BAD_CONVERT_JS);
}
JSString* jsstr = JS::ToString(aCx, aValue);
NS_ENSURE_TRUE(jsstr, NS_ERROR_XPC_BAD_CONVERT_JS);

nsDependentJSString str;
if (!str.init(aCx, jsstr)) {
Expand Down Expand Up @@ -864,10 +858,11 @@ LockedFile::WriteOrAppend(const JS::Value& aValue,
return NS_OK;
}

JS::Rooted<JS::Value> val(aCx, aValue);
nsCOMPtr<nsIInputStream> inputStream;
uint64_t inputLength;
nsresult rv =
GetInputStreamForJSVal(aValue, aCx, getter_AddRefs(inputStream),
GetInputStreamForJSVal(val, aCx, getter_AddRefs(inputStream),
&inputLength);
NS_ENSURE_SUCCESS(rv, rv);

Expand Down
7 changes: 4 additions & 3 deletions dom/indexedDB/KeyPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,9 @@ KeyPath::Parse(JSContext* aCx, const mozilla::dom::Sequence<nsString>& aStrings,

// static
nsresult
KeyPath::Parse(JSContext* aCx, const JS::Value& aValue, KeyPath* aKeyPath)
KeyPath::Parse(JSContext* aCx, const JS::Value& aValue_, KeyPath* aKeyPath)
{
JS::Rooted<JS::Value> aValue(aCx, aValue_);
KeyPath keyPath(0);

aKeyPath->SetType(NONEXISTENT);
Expand All @@ -283,7 +284,7 @@ KeyPath::Parse(JSContext* aCx, const JS::Value& aValue, KeyPath* aKeyPath)
JSString* jsstr;
nsDependentJSString str;
if (!JS_GetElement(aCx, obj, index, &val) ||
!(jsstr = JS_ValueToString(aCx, val)) ||
!(jsstr = JS::ToString(aCx, val)) ||
!str.init(aCx, jsstr)) {
return NS_ERROR_FAILURE;
}
Expand All @@ -297,7 +298,7 @@ KeyPath::Parse(JSContext* aCx, const JS::Value& aValue, KeyPath* aKeyPath)
else if (!JSVAL_IS_NULL(aValue) && !JSVAL_IS_VOID(aValue)) {
JSString* jsstr;
nsDependentJSString str;
if (!(jsstr = JS_ValueToString(aCx, aValue)) ||
if (!(jsstr = JS::ToString(aCx, aValue)) ||
!str.init(aCx, jsstr)) {
return NS_ERROR_FAILURE;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/media/MediaManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static nsresult CompareDictionaries(JSContext* aCx, JSObject *aA,
bool success = JS_IdToValue(aCx, props[i], nameval.address());
NS_ENSURE_TRUE(success, NS_ERROR_UNEXPECTED);

JS::Rooted<JSString*> namestr(aCx, JS_ValueToString(aCx, nameval));
JS::Rooted<JSString*> namestr(aCx, JS::ToString(aCx, nameval));
NS_ENSURE_TRUE(namestr, NS_ERROR_UNEXPECTED);
aDifference->Assign(JS_GetStringCharsZ(aCx, namestr));
return NS_OK;
Expand Down
Loading

0 comments on commit bc757ef

Please sign in to comment.