mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1034191 - Make nsDependentJSString users work with Latin1 strings and nursery-allocated strings. r=bz
This commit is contained in:
parent
66ce2813a7
commit
3c7459b21a
@ -366,7 +366,7 @@ DOMMultipartFileImpl::InitChromeFile(JSContext* aCx,
|
||||
JSString* str = JS::ToString(aCx, JS::Handle<JS::Value>::fromMarkedLocation(&aArgv[0]));
|
||||
NS_ENSURE_TRUE(str, NS_ERROR_XPC_BAD_CONVERT_JS);
|
||||
|
||||
nsDependentJSString xpcomStr;
|
||||
nsAutoJSString xpcomStr;
|
||||
if (!xpcomStr.init(aCx, str)) {
|
||||
return NS_ERROR_XPC_BAD_CONVERT_JS;
|
||||
}
|
||||
@ -434,7 +434,7 @@ DOMMultipartFileImpl::InitFile(JSContext* aCx,
|
||||
JSString* str = JS::ToString(aCx, JS::Handle<JS::Value>::fromMarkedLocation(&aArgv[1]));
|
||||
NS_ENSURE_TRUE(str, NS_ERROR_XPC_BAD_CONVERT_JS);
|
||||
|
||||
nsDependentJSString xpcomStr;
|
||||
nsAutoJSString xpcomStr;
|
||||
if (!xpcomStr.init(aCx, str)) {
|
||||
return NS_ERROR_XPC_BAD_CONVERT_JS;
|
||||
}
|
||||
@ -472,7 +472,7 @@ BlobSet::AppendVoidPtr(const void* aData, uint32_t aLength)
|
||||
nsresult
|
||||
BlobSet::AppendString(JSString* aString, bool nativeEOL, JSContext* aCx)
|
||||
{
|
||||
nsDependentJSString xpcomStr;
|
||||
nsAutoJSString xpcomStr;
|
||||
if (!xpcomStr.init(aCx, aString)) {
|
||||
return NS_ERROR_XPC_BAD_CONVERT_JS;
|
||||
}
|
||||
|
@ -5409,7 +5409,7 @@ nsDocument::CustomElementConstructor(JSContext* aCx, unsigned aArgc, JS::Value*
|
||||
// Function name is the type of the custom element.
|
||||
JSString* jsFunName =
|
||||
JS_GetFunctionId(JS_ValueToFunction(aCx, args.calleev()));
|
||||
nsDependentJSString elemName;
|
||||
nsAutoJSString elemName;
|
||||
if (!elemName.init(aCx, jsFunName)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -440,7 +440,7 @@ HTMLCanvasElement::ParseParams(JSContext* aCx,
|
||||
*usingCustomParseOptions = false;
|
||||
if (aParams.Length() == 0 && aEncoderOptions.isString()) {
|
||||
NS_NAMED_LITERAL_STRING(mozParseOptions, "-moz-parse-options:");
|
||||
nsDependentJSString paramString;
|
||||
nsAutoJSString paramString;
|
||||
if (!paramString.init(aCx, aEncoderOptions.toString())) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -763,7 +763,7 @@ AudioChannelService::Observe(nsISupports* aSubject, const char* aTopic, const ch
|
||||
if (!jsKey) {
|
||||
return NS_OK;
|
||||
}
|
||||
nsDependentJSString keyStr;
|
||||
nsAutoJSString keyStr;
|
||||
if (!keyStr.init(cx, jsKey) || keyStr.Find("audio.volume.", 0, false)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ ConsoleStructuredCloneCallbacksWrite(JSContext* aCx,
|
||||
return false;
|
||||
}
|
||||
|
||||
nsDependentJSString string;
|
||||
nsAutoJSString string;
|
||||
if (!string.init(aCx, jsString)) {
|
||||
return false;
|
||||
}
|
||||
@ -1227,7 +1227,7 @@ Console::ProcessArguments(JSContext* aCx,
|
||||
return;
|
||||
}
|
||||
|
||||
nsDependentJSString string;
|
||||
nsAutoJSString string;
|
||||
if (!string.init(aCx, jsString)) {
|
||||
return;
|
||||
}
|
||||
@ -1378,7 +1378,7 @@ Console::ProcessArguments(JSContext* aCx,
|
||||
return;
|
||||
}
|
||||
|
||||
nsDependentJSString v;
|
||||
nsAutoJSString v;
|
||||
if (!v.init(aCx, jsString)) {
|
||||
return;
|
||||
}
|
||||
@ -1473,7 +1473,7 @@ Console::ComposeGroupName(JSContext* aCx,
|
||||
return;
|
||||
}
|
||||
|
||||
nsDependentJSString string;
|
||||
nsAutoJSString string;
|
||||
if (!string.init(aCx, jsString)) {
|
||||
return;
|
||||
}
|
||||
@ -1505,7 +1505,7 @@ Console::StartTimer(JSContext* aCx, const JS::Value& aName,
|
||||
return JS::UndefinedValue();
|
||||
}
|
||||
|
||||
nsDependentJSString key;
|
||||
nsAutoJSString key;
|
||||
if (!key.init(aCx, jsString)) {
|
||||
return JS::UndefinedValue();
|
||||
}
|
||||
@ -1539,7 +1539,7 @@ Console::StopTimer(JSContext* aCx, const JS::Value& aName,
|
||||
return JS::UndefinedValue();
|
||||
}
|
||||
|
||||
nsDependentJSString key;
|
||||
nsAutoJSString key;
|
||||
if (!key.init(aCx, jsString)) {
|
||||
return JS::UndefinedValue();
|
||||
}
|
||||
@ -1585,7 +1585,7 @@ Console::IncreaseCounter(JSContext* aCx, const ConsoleStackEntry& aFrame,
|
||||
JS::Rooted<JS::Value> labelValue(aCx, aArguments[0]);
|
||||
JS::Rooted<JSString*> jsString(aCx, JS::ToString(aCx, labelValue));
|
||||
|
||||
nsDependentJSString string;
|
||||
nsAutoJSString string;
|
||||
if (jsString && string.init(aCx, jsString)) {
|
||||
label = string;
|
||||
key = string;
|
||||
|
@ -1953,7 +1953,6 @@ Navigator::DoNewResolve(JSContext* aCx, JS::Handle<JSObject*> aObject,
|
||||
JS::Handle<jsid> aId,
|
||||
JS::MutableHandle<JSPropertyDescriptor> aDesc)
|
||||
{
|
||||
// Note: The infallibleInit call below depends on this check.
|
||||
if (!JSID_IS_STRING(aId)) {
|
||||
return true;
|
||||
}
|
||||
@ -1963,8 +1962,10 @@ Navigator::DoNewResolve(JSContext* aCx, JS::Handle<JSObject*> aObject,
|
||||
return Throw(aCx, NS_ERROR_NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
nsDependentJSString name;
|
||||
name.infallibleInit(aId);
|
||||
nsAutoJSString name;
|
||||
if (!name.init(aCx, JSID_TO_STRING(aId))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const nsGlobalNameStruct* name_struct =
|
||||
nameSpaceManager->LookupNavigatorName(name);
|
||||
|
@ -89,7 +89,6 @@ WindowNamedPropertiesHandler::getOwnPropertyDescriptor(JSContext* aCx,
|
||||
JS::MutableHandle<JSPropertyDescriptor> aDesc)
|
||||
const
|
||||
{
|
||||
// Note: The infallibleInit call below depends on this check.
|
||||
if (!JSID_IS_STRING(aId)) {
|
||||
// Nothing to do if we're resolving a non-string property.
|
||||
return true;
|
||||
@ -100,8 +99,10 @@ WindowNamedPropertiesHandler::getOwnPropertyDescriptor(JSContext* aCx,
|
||||
return true;
|
||||
}
|
||||
|
||||
nsDependentJSString str;
|
||||
str.infallibleInit(aId);
|
||||
nsAutoJSString str;
|
||||
if (!str.init(aCx, JSID_TO_STRING(aId))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Grab the DOM window.
|
||||
nsGlobalWindow* win = GetWindowFromGlobal(global);
|
||||
|
@ -342,7 +342,7 @@ nsContentPermissionRequestProxy::Allow(JS::HandleValue aChoices)
|
||||
!val.isString()) {
|
||||
// no setting for the permission type, skip it
|
||||
} else {
|
||||
nsDependentJSString choice;
|
||||
nsAutoJSString choice;
|
||||
if (!choice.init(cx, val)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -2652,8 +2652,10 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
|
||||
|
||||
// Note - Our only caller is nsGlobalWindow::DoNewResolve, which checks that
|
||||
// JSID_IS_STRING(id) is true.
|
||||
nsDependentJSString name;
|
||||
name.infallibleInit(id);
|
||||
nsAutoJSString name;
|
||||
if (!name.init(cx, JSID_TO_STRING(id))) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
const char16_t *class_name = nullptr;
|
||||
const nsGlobalNameStruct *name_struct =
|
||||
@ -2982,10 +2984,10 @@ LocationSetterGuts(JSContext *cx, JSObject *obj, JS::MutableHandle<JS::Value> vp
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsDependentJSString depStr;
|
||||
NS_ENSURE_TRUE(depStr.init(cx, val), NS_ERROR_UNEXPECTED);
|
||||
nsAutoJSString str;
|
||||
NS_ENSURE_TRUE(str.init(cx, val), NS_ERROR_UNEXPECTED);
|
||||
|
||||
return location->SetHref(depStr);
|
||||
return location->SetHref(str);
|
||||
}
|
||||
|
||||
template<class Interface>
|
||||
@ -3436,13 +3438,13 @@ nsStorage2SH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||
|
||||
nsCOMPtr<nsIDOMStorage> storage(do_QueryWrappedNative(wrapper));
|
||||
|
||||
nsDependentJSString depStr;
|
||||
NS_ENSURE_TRUE(depStr.init(cx, jsstr), NS_ERROR_UNEXPECTED);
|
||||
nsAutoJSString autoStr;
|
||||
NS_ENSURE_TRUE(autoStr.init(cx, jsstr), NS_ERROR_UNEXPECTED);
|
||||
|
||||
// GetItem() will return null if the caller can't access the session
|
||||
// storage item.
|
||||
nsAutoString data;
|
||||
nsresult rv = storage->GetItem(depStr, data);
|
||||
nsresult rv = storage->GetItem(autoStr, data);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!DOMStringIsNull(data)) {
|
||||
@ -3469,7 +3471,7 @@ nsStorage2SH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||
JSString* key = IdToString(cx, id);
|
||||
NS_ENSURE_TRUE(key, NS_ERROR_UNEXPECTED);
|
||||
|
||||
nsDependentJSString keyStr;
|
||||
nsAutoJSString keyStr;
|
||||
NS_ENSURE_TRUE(keyStr.init(cx, key), NS_ERROR_UNEXPECTED);
|
||||
|
||||
// For native wrappers, do not get random names on storage objects.
|
||||
@ -3508,14 +3510,14 @@ nsStorage2SH::SetProperty(nsIXPConnectWrappedNative *wrapper,
|
||||
JSString *key = IdToString(cx, id);
|
||||
NS_ENSURE_TRUE(key, NS_ERROR_UNEXPECTED);
|
||||
|
||||
nsDependentJSString keyStr;
|
||||
nsAutoJSString keyStr;
|
||||
NS_ENSURE_TRUE(keyStr.init(cx, key), NS_ERROR_UNEXPECTED);
|
||||
|
||||
JS::Rooted<JS::Value> val(cx, *vp);
|
||||
JSString *value = JS::ToString(cx, val);
|
||||
NS_ENSURE_TRUE(value, NS_ERROR_UNEXPECTED);
|
||||
|
||||
nsDependentJSString valueStr;
|
||||
nsAutoJSString valueStr;
|
||||
NS_ENSURE_TRUE(valueStr.init(cx, value), NS_ERROR_UNEXPECTED);
|
||||
|
||||
nsresult rv = storage->SetItem(keyStr, valueStr);
|
||||
@ -3538,7 +3540,7 @@ nsStorage2SH::DelProperty(nsIXPConnectWrappedNative *wrapper,
|
||||
JSString *key = IdToString(cx, id);
|
||||
NS_ENSURE_TRUE(key, NS_ERROR_UNEXPECTED);
|
||||
|
||||
nsDependentJSString keyStr;
|
||||
nsAutoJSString keyStr;
|
||||
NS_ENSURE_TRUE(keyStr.init(cx, key), NS_ERROR_UNEXPECTED);
|
||||
|
||||
nsresult rv = storage->RemoveItem(keyStr);
|
||||
|
@ -3069,11 +3069,9 @@ nsDOMWindowUtils::GetPCCountScriptSummary(int32_t script, JSContext* cx, nsAStri
|
||||
if (!text)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsDependentJSString str;
|
||||
if (!str.init(cx, text))
|
||||
if (!AssignJSString(cx, result, text))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
result = str;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -3086,11 +3084,9 @@ nsDOMWindowUtils::GetPCCountScriptContents(int32_t script, JSContext* cx, nsAStr
|
||||
if (!text)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsDependentJSString str;
|
||||
if (!str.init(cx, text))
|
||||
if (!AssignJSString(cx, result, text))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
result = str;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "mozilla/Assertions.h"
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "jsfriendapi.h"
|
||||
#include "nsString.h"
|
||||
|
||||
class nsIScriptContext;
|
||||
@ -137,28 +138,38 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline bool
|
||||
AssignJSString(JSContext *cx, T &dest, JSString *s)
|
||||
{
|
||||
size_t len = js::GetStringLength(s);
|
||||
static_assert(js::MaxStringLength < (1 << 28),
|
||||
"Shouldn't overflow here or in SetCapacity");
|
||||
if (MOZ_UNLIKELY(!dest.SetCapacity(len + 1, mozilla::fallible_t()))) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return false;
|
||||
}
|
||||
if (MOZ_UNLIKELY(!js::CopyStringChars(cx, dest.BeginWriting(), s, len))) {
|
||||
return false;
|
||||
}
|
||||
dest.BeginWriting()[len] = '\0';
|
||||
dest.SetLength(len);
|
||||
return true;
|
||||
}
|
||||
|
||||
class nsDependentJSString : public nsDependentString
|
||||
class nsAutoJSString : public nsAutoString
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* nsDependentJSString should be default constructed, which leaves it empty
|
||||
* (this->IsEmpty()), and initialized with one of the init() or infallibleInit()
|
||||
* methods below.
|
||||
* nsAutoJSString should be default constructed, which leaves it empty
|
||||
* (this->IsEmpty()), and initialized with one of the init() methods below.
|
||||
*/
|
||||
nsDependentJSString() {}
|
||||
nsAutoJSString() {}
|
||||
|
||||
bool init(JSContext* aContext, JSString* str)
|
||||
{
|
||||
size_t length;
|
||||
const jschar* chars = JS_GetStringCharsZAndLength(aContext, str, &length);
|
||||
if (!chars) {
|
||||
return false;
|
||||
}
|
||||
|
||||
infallibleInit(chars, length);
|
||||
return true;
|
||||
return AssignJSString(aContext, *this, str);
|
||||
}
|
||||
|
||||
bool init(JSContext* aContext, const JS::Value &v)
|
||||
@ -185,27 +196,7 @@ public:
|
||||
return JS_IdToValue(aContext, id, &v) && init(aContext, v);
|
||||
}
|
||||
|
||||
void infallibleInit(const char16_t* aChars, size_t aLength)
|
||||
{
|
||||
MOZ_ASSERT(IsEmpty(), "init() on initialized string");
|
||||
nsDependentString* base = this;
|
||||
new (base) nsDependentString(aChars, aLength);
|
||||
}
|
||||
|
||||
// For use when JSID_IS_STRING(id) is known to be true.
|
||||
void infallibleInit(jsid id)
|
||||
{
|
||||
MOZ_ASSERT(JSID_IS_STRING(id));
|
||||
infallibleInit(JS_GetInternedStringChars(JSID_TO_STRING(id)),
|
||||
JS_GetStringLength(JSID_TO_STRING(id)));
|
||||
}
|
||||
|
||||
void infallibleInit(JSFlatString* fstr)
|
||||
{
|
||||
infallibleInit(JS_GetFlatStringChars(fstr), JS_GetStringLength(JS_FORGET_STRING_FLATNESS(fstr)));
|
||||
}
|
||||
|
||||
~nsDependentJSString() {}
|
||||
~nsAutoJSString() {}
|
||||
};
|
||||
|
||||
#endif /* nsJSUtils_h__ */
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "nsCycleCollector.h"
|
||||
#include "nsIXPConnect.h"
|
||||
#include "nsJSUtils.h"
|
||||
#include "MainThreadUtils.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "qsObjectHelper.h"
|
||||
@ -1857,25 +1858,6 @@ private:
|
||||
};
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline bool
|
||||
AssignJSString(JSContext *cx, T &dest, JSString *s)
|
||||
{
|
||||
size_t len = js::GetStringLength(s);
|
||||
static_assert(js::MaxStringLength < (1 << 28),
|
||||
"Shouldn't overflow here or in FakeString::SetCapacity");
|
||||
if (MOZ_UNLIKELY(!dest.SetCapacity(len + 1, mozilla::fallible_t()))) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return false;
|
||||
}
|
||||
if (MOZ_UNLIKELY(!js::CopyStringChars(cx, dest.BeginWriting(), s, len))) {
|
||||
return false;
|
||||
}
|
||||
dest.BeginWriting()[len] = '\0';
|
||||
dest.SetLength(len);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace binding_detail
|
||||
|
||||
enum StringificationBehavior {
|
||||
@ -1919,7 +1901,7 @@ ConvertJSValueToString(JSContext* cx, JS::Handle<JS::Value> v,
|
||||
}
|
||||
}
|
||||
|
||||
return binding_detail::AssignJSString(cx, result, s);
|
||||
return AssignJSString(cx, result, s);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -119,9 +119,9 @@ EventListenerInfo::ToSource(nsAString& aResult)
|
||||
if (GetJSVal(cx, ac, &v)) {
|
||||
JSString* str = JS_ValueToSource(cx, v);
|
||||
if (str) {
|
||||
nsDependentJSString depStr;
|
||||
if (depStr.init(cx, str)) {
|
||||
aResult.Assign(depStr);
|
||||
nsAutoJSString autoStr;
|
||||
if (autoStr.init(cx, str)) {
|
||||
aResult.Assign(autoStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -681,7 +681,7 @@ FMRadioService::Observe(nsISupports * aSubject,
|
||||
}
|
||||
|
||||
JS::Rooted<JSString*> jsKey(cx, key.toString());
|
||||
nsDependentJSString keyStr;
|
||||
nsAutoJSString keyStr;
|
||||
if (!keyStr.init(cx, jsKey)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ Key::EncodeJSValInternal(JSContext* aCx, JS::Handle<JS::Value> aVal,
|
||||
"Unable to encode jsvals.");
|
||||
|
||||
if (aVal.isString()) {
|
||||
nsDependentJSString str;
|
||||
nsAutoJSString str;
|
||||
if (!str.init(aCx, aVal)) {
|
||||
IDB_REPORT_INTERNAL_ERR();
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
|
@ -285,7 +285,7 @@ KeyPath::Parse(JSContext* aCx, const JS::Value& aValue_, KeyPath* aKeyPath)
|
||||
for (uint32_t index = 0; index < length; index++) {
|
||||
JS::Rooted<JS::Value> val(aCx);
|
||||
JSString* jsstr;
|
||||
nsDependentJSString str;
|
||||
nsAutoJSString str;
|
||||
if (!JS_GetElement(aCx, obj, index, &val) ||
|
||||
!(jsstr = JS::ToString(aCx, val)) ||
|
||||
!str.init(aCx, jsstr)) {
|
||||
@ -300,7 +300,7 @@ KeyPath::Parse(JSContext* aCx, const JS::Value& aValue_, KeyPath* aKeyPath)
|
||||
// Otherwise convert it to a string.
|
||||
else if (!aValue.isNull() && !aValue.isUndefined()) {
|
||||
JSString* jsstr;
|
||||
nsDependentJSString str;
|
||||
nsAutoJSString str;
|
||||
if (!(jsstr = JS::ToString(aCx, aValue)) ||
|
||||
!str.init(aCx, jsstr)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -287,7 +287,7 @@ MediaPermissionRequest::Allow(JS::HandleValue aChoices)
|
||||
if (!JS_GetProperty(cx, obj, AUDIO_PERMISSION_NAME, &v) || !v.isString()) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
nsDependentJSString deviceName;
|
||||
nsAutoJSString deviceName;
|
||||
if (!deviceName.init(cx, v)) {
|
||||
MOZ_ASSERT(false, "Couldn't initialize string from aChoices");
|
||||
return NS_ERROR_FAILURE;
|
||||
@ -301,7 +301,7 @@ MediaPermissionRequest::Allow(JS::HandleValue aChoices)
|
||||
if (!JS_GetProperty(cx, obj, VIDEO_PERMISSION_NAME, &v) || !v.isString()) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
nsDependentJSString deviceName;
|
||||
nsAutoJSString deviceName;
|
||||
if (!deviceName.init(cx, v)) {
|
||||
MOZ_ASSERT(false, "Couldn't initialize string from aChoices");
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -250,8 +250,11 @@ MmsMessage::Create(int32_t aId,
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nsDependentJSString receiverStr;
|
||||
receiverStr.init(aCx, receiverJsVal.toString());
|
||||
nsAutoJSString receiverStr;
|
||||
if (!receiverStr.init(aCx, receiverJsVal.toString())) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
receivers.AppendElement(receiverStr);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include "nsIDOMClassInfo.h"
|
||||
#include "jsapi.h" // For OBJECT_TO_JSVAL and JS_NewDateObjectMsec
|
||||
#include "jsfriendapi.h" // For js_DateGetMsecSinceEpoch
|
||||
#include "nsJSUtils.h" // For nsDependentJSString
|
||||
#include "nsJSUtils.h" // For nsAutoJSString
|
||||
#include "nsTArrayHelpers.h" // For nsTArrayToJSArray
|
||||
#include "mozilla/dom/mobilemessage/Constants.h" // For MessageType
|
||||
|
||||
@ -70,8 +70,11 @@ MobileMessageThread::Create(uint64_t aId,
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nsDependentJSString str;
|
||||
str.init(aCx, val.toString());
|
||||
nsAutoJSString str;
|
||||
if (!str.init(aCx, val.toString())) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
data.participants().AppendElement(str);
|
||||
}
|
||||
}
|
||||
|
@ -170,8 +170,10 @@ SmsFilter::SetNumbers(JSContext* aCx, JS::Handle<JS::Value> aNumbers)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nsDependentJSString number;
|
||||
number.init(aCx, jsNumber.toString());
|
||||
nsAutoJSString number;
|
||||
if (!number.init(aCx, jsNumber.toString())) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
numbers.AppendElement(number);
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ TCPSocketChild::SendSend(JS::Handle<JS::Value> aData,
|
||||
{
|
||||
if (aData.isString()) {
|
||||
JSString* jsstr = aData.toString();
|
||||
nsDependentJSString str;
|
||||
nsAutoJSString str;
|
||||
bool ok = str.init(aCx, jsstr);
|
||||
NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
|
||||
SendData(str, aTrackingNumber);
|
||||
|
@ -206,7 +206,7 @@ TCPSocketParent::SendEvent(const nsAString& aType, JS::Handle<JS::Value> aDataVa
|
||||
CallbackData data;
|
||||
if (aDataVal.isString()) {
|
||||
JSString* jsstr = aDataVal.toString();
|
||||
nsDependentJSString str;
|
||||
nsAutoJSString str;
|
||||
if (!str.init(aCx, jsstr)) {
|
||||
FireInteralError(this, __LINE__);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
@ -235,7 +235,7 @@ TCPSocketParent::SendEvent(const nsAString& aType, JS::Handle<JS::Value> aDataVa
|
||||
data = SendableData(arr);
|
||||
|
||||
} else {
|
||||
nsDependentJSString name;
|
||||
nsAutoJSString name;
|
||||
|
||||
JS::Rooted<JS::Value> val(aCx);
|
||||
if (!JS_GetProperty(aCx, obj, "name", &val)) {
|
||||
|
@ -282,7 +282,7 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel,
|
||||
} else if (v.isUndefined()) {
|
||||
return NS_ERROR_DOM_RETVAL_UNDEFINED;
|
||||
} else {
|
||||
nsDependentJSString result;
|
||||
nsAutoJSString result;
|
||||
if (!result.init(cx, v)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -355,7 +355,7 @@ AudioManager::Observe(nsISupports* aSubject,
|
||||
if (!jsKey) {
|
||||
return NS_OK;
|
||||
}
|
||||
nsDependentJSString keyStr;
|
||||
nsAutoJSString keyStr;
|
||||
if (!keyStr.init(cx, jsKey) || !keyStr.EqualsLiteral("audio.volume.bt_sco")) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -250,7 +250,7 @@ AutoMounterSetting::Observe(nsISupports* aSubject,
|
||||
}
|
||||
|
||||
JSString *jsKey = JS::ToString(cx, key);
|
||||
nsDependentJSString keyStr;
|
||||
nsAutoJSString keyStr;
|
||||
if (!keyStr.init(cx, jsKey)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -850,8 +850,10 @@ GonkGPSGeolocationProvider::Handle(const nsAString& aName,
|
||||
NS_ENSURE_TRUE(cx, NS_OK);
|
||||
|
||||
// NB: No need to enter a compartment to read the contents of a string.
|
||||
nsDependentJSString apn;
|
||||
apn.init(cx, aResult.toString());
|
||||
nsAutoJSString apn;
|
||||
if (!apn.init(cx, aResult.toString())) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
if (!apn.IsEmpty()) {
|
||||
SetAGpsDataConn(apn);
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ nsresult TimeZoneSettingObserver::SetTimeZone(const JS::Value &aValue, JSContext
|
||||
{
|
||||
// Convert the JS value to a nsCString type.
|
||||
// The value should be a JS string like "America/Chicago" or "UTC-05:00".
|
||||
nsDependentJSString valueStr;
|
||||
nsAutoJSString valueStr;
|
||||
if (!valueStr.init(aContext, aValue.toString())) {
|
||||
ERR("Failed to convert JS value to nsCString");
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -190,7 +190,7 @@ private:
|
||||
return false;
|
||||
}
|
||||
|
||||
nsDependentJSString contentType;
|
||||
nsAutoJSString contentType;
|
||||
if (!contentType.init(aCx, jsContentType)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -5192,9 +5192,9 @@ WorkerPrivate::ReportError(JSContext* aCx, const char* aMessage,
|
||||
JS::Rooted<JSString*> messageStr(aCx,
|
||||
js::ErrorReportToString(aCx, aReport));
|
||||
if (messageStr) {
|
||||
nsDependentJSString depStr;
|
||||
if (depStr.init(aCx, messageStr)) {
|
||||
message = depStr;
|
||||
nsAutoJSString autoStr;
|
||||
if (autoStr.init(aCx, messageStr)) {
|
||||
message = autoStr;
|
||||
}
|
||||
}
|
||||
filename = NS_ConvertUTF8toUTF16(aReport->filename);
|
||||
|
@ -1100,13 +1100,13 @@ nsXBLBinding::LookupMember(JSContext* aCx, JS::Handle<jsid> aId,
|
||||
|
||||
// Get the string as an nsString before doing anything, so we can make
|
||||
// convenient comparisons during our search.
|
||||
//
|
||||
// Note: the infallibleInit call below depends on this check.
|
||||
if (!JSID_IS_STRING(aId)) {
|
||||
return true;
|
||||
}
|
||||
nsDependentJSString name;
|
||||
name.infallibleInit(aId);
|
||||
nsAutoJSString name;
|
||||
if (!name.init(aCx, JSID_TO_STRING(aId))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We have a weak reference to our bound element, so make sure it's alive.
|
||||
if (!mBoundElement || !mBoundElement->GetWrapper()) {
|
||||
|
@ -181,7 +181,7 @@ InstallXBLField(JSContext* cx,
|
||||
// Field[GS]etter where we attempt a cross-compartment call), we must enter
|
||||
// the callee's compartment to access its reserved slots.
|
||||
nsXBLPrototypeBinding* protoBinding;
|
||||
nsDependentJSString fieldName;
|
||||
nsAutoJSString fieldName;
|
||||
{
|
||||
JSAutoCompartment ac(cx, callee);
|
||||
|
||||
@ -189,8 +189,9 @@ InstallXBLField(JSContext* cx,
|
||||
xblProto = &js::GetFunctionNativeReserved(callee, XBLPROTO_SLOT).toObject();
|
||||
|
||||
JS::Rooted<JS::Value> name(cx, js::GetFunctionNativeReserved(callee, FIELD_SLOT));
|
||||
JSFlatString* fieldStr = JS_ASSERT_STRING_IS_FLAT(name.toString());
|
||||
fieldName.infallibleInit(fieldStr);
|
||||
if (!fieldName.init(cx, name.toString())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MOZ_ALWAYS_TRUE(JS_ValueToId(cx, name, idp));
|
||||
|
||||
|
@ -44,7 +44,7 @@ EXTRA_COMPONENTS += [
|
||||
|
||||
FAIL_ON_WARNINGS = True
|
||||
|
||||
# For nsDependentJSString
|
||||
# For nsAutoJSString
|
||||
LOCAL_INCLUDES += ["/dom/base"]
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
|
@ -1437,7 +1437,7 @@ txVariable::Convert(nsIVariant *aValue, txAExprResult** aResult)
|
||||
JS::Rooted<JSString*> str(cx, JS::ToString(cx, v));
|
||||
NS_ENSURE_TRUE(str, NS_ERROR_FAILURE);
|
||||
|
||||
nsDependentJSString value;
|
||||
nsAutoJSString value;
|
||||
NS_ENSURE_TRUE(value.init(cx, str), NS_ERROR_FAILURE);
|
||||
|
||||
*aResult = new StringResult(value, nullptr);
|
||||
|
@ -596,13 +596,13 @@ XPCShellEnvironment::EvaluateString(const nsString& aString,
|
||||
if (ok && result != JSVAL_VOID) {
|
||||
JSErrorReporter old = JS_SetErrorReporter(cx, nullptr);
|
||||
JSString* str = JS::ToString(cx, result);
|
||||
nsDependentJSString depStr;
|
||||
nsAutoJSString autoStr;
|
||||
if (str)
|
||||
depStr.init(cx, str);
|
||||
autoStr.init(cx, str);
|
||||
JS_SetErrorReporter(cx, old);
|
||||
|
||||
if (!depStr.IsEmpty() && aResult) {
|
||||
aResult->Assign(depStr);
|
||||
if (!autoStr.IsEmpty() && aResult) {
|
||||
aResult->Assign(autoStr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ include('/ipc/chromium/chromium-config.mozbuild')
|
||||
|
||||
FINAL_LIBRARY = 'xul'
|
||||
|
||||
# For xpcshell error messages and nsDependentJSString
|
||||
# For xpcshell error messages and nsAutoJSString
|
||||
LOCAL_INCLUDES += [
|
||||
'/dom/base',
|
||||
'/js/xpconnect/src',
|
||||
|
@ -254,10 +254,10 @@ JavaScriptShared::toVariant(JSContext *cx, JS::HandleValue from, JSVariant *to)
|
||||
|
||||
case JSTYPE_STRING:
|
||||
{
|
||||
nsDependentJSString dep;
|
||||
if (!dep.init(cx, from))
|
||||
nsAutoJSString autoStr;
|
||||
if (!autoStr.init(cx, from))
|
||||
return false;
|
||||
*to = dep;
|
||||
*to = autoStr;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -344,7 +344,7 @@ WrapperOwner::toString(JSContext *cx, HandleObject cpow, JS::CallArgs &args)
|
||||
return true;
|
||||
|
||||
RootedString cpowResult(cx, args.rval().toString());
|
||||
nsDependentJSString toStringResult;
|
||||
nsAutoJSString toStringResult;
|
||||
if (!toStringResult.init(cx, cpowResult))
|
||||
return false;
|
||||
|
||||
|
@ -283,13 +283,13 @@ SandboxEvalInWindow(JSContext *cx, unsigned argc, jsval *vp)
|
||||
RootedString srcString(cx, args[0].toString());
|
||||
RootedObject targetScope(cx, &args[1].toObject());
|
||||
|
||||
nsDependentJSString srcDepString;
|
||||
if (!srcDepString.init(cx, srcString)) {
|
||||
nsAutoJSString srcAutoString;
|
||||
if (!srcAutoString.init(cx, srcString)) {
|
||||
JS_ReportError(cx, "Source string is invalid");
|
||||
return false;
|
||||
}
|
||||
|
||||
return EvalInWindow(cx, srcDepString, targetScope, args.rval());
|
||||
return EvalInWindow(cx, srcAutoString, targetScope, args.rval());
|
||||
}
|
||||
|
||||
static bool
|
||||
@ -1037,7 +1037,7 @@ ParsePrincipal(JSContext *cx, HandleString codebase, nsIPrincipal **principal)
|
||||
MOZ_ASSERT(principal);
|
||||
MOZ_ASSERT(codebase);
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsDependentJSString codebaseStr;
|
||||
nsAutoJSString codebaseStr;
|
||||
NS_ENSURE_TRUE(codebaseStr.init(cx, codebase), false);
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(uri), codebaseStr);
|
||||
if (NS_FAILED(rv)) {
|
||||
@ -1283,8 +1283,10 @@ OptionsBase::ParseString(const char *name, nsString &prop)
|
||||
return false;
|
||||
}
|
||||
|
||||
nsDependentJSString strVal;
|
||||
strVal.init(mCx, value.toString());
|
||||
nsAutoJSString strVal;
|
||||
if (!strVal.init(mCx, value.toString()))
|
||||
return false;
|
||||
|
||||
prop = strVal;
|
||||
return true;
|
||||
}
|
||||
|
@ -102,13 +102,13 @@ private:
|
||||
ChangeCase(JSContext* cx, HandleString src, MutableHandleValue rval,
|
||||
void(*changeCaseFnc)(const nsAString&, nsAString&))
|
||||
{
|
||||
nsDependentJSString depStr;
|
||||
if (!depStr.init(cx, src)) {
|
||||
nsAutoJSString autoStr;
|
||||
if (!autoStr.init(cx, src)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsAutoString result;
|
||||
changeCaseFnc(depStr, result);
|
||||
changeCaseFnc(autoStr, result);
|
||||
|
||||
JSString *ucstr =
|
||||
JS_NewUCStringCopyN(cx, result.get(), result.Length());
|
||||
@ -149,14 +149,14 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
nsDependentJSString depStr1, depStr2;
|
||||
if (!depStr1.init(cx, src1) || !depStr2.init(cx, src2)) {
|
||||
nsAutoJSString autoStr1, autoStr2;
|
||||
if (!autoStr1.init(cx, src1) || !autoStr2.init(cx, src2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t result;
|
||||
rv = mCollation->CompareString(nsICollation::kCollationStrengthDefault,
|
||||
depStr1, depStr2, &result);
|
||||
autoStr1, autoStr2, &result);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
xpc::Throw(cx, rv);
|
||||
|
@ -148,8 +148,10 @@ IsFrameId(JSContext *cx, JSObject *objArg, jsid idArg)
|
||||
if (JSID_IS_INT(id)) {
|
||||
col->Item(JSID_TO_INT(id), getter_AddRefs(domwin));
|
||||
} else if (JSID_IS_STRING(id)) {
|
||||
nsDependentJSString idAsString;
|
||||
idAsString.infallibleInit(id);
|
||||
nsAutoJSString idAsString;
|
||||
if (!idAsString.init(cx, JSID_TO_STRING(id))) {
|
||||
return false;
|
||||
}
|
||||
col->NamedItem(idAsString, getter_AddRefs(domwin));
|
||||
}
|
||||
|
||||
|
@ -458,7 +458,7 @@ inline bool
|
||||
SilentFailure(JSContext *cx, HandleId id, const char *reason)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
nsDependentJSString name;
|
||||
nsAutoJSString name;
|
||||
if (!name.init(cx, id))
|
||||
return false;
|
||||
AutoFilename filename;
|
||||
@ -2252,9 +2252,9 @@ XrayWrapper<Base, Traits>::getPropertyDescriptor(JSContext *cx, HandleObject wra
|
||||
JSID_IS_STRING(id) &&
|
||||
(win = AsWindow(cx, wrapper)))
|
||||
{
|
||||
// Note - The infallibleInit() depends on the JSID_IS_STRING check above.
|
||||
nsDependentJSString name;
|
||||
name.infallibleInit(id);
|
||||
nsAutoJSString name;
|
||||
if (!name.init(cx, JSID_TO_STRING(id)))
|
||||
return false;
|
||||
nsCOMPtr<nsIDOMWindow> childDOMWin = win->GetChildWindow(name);
|
||||
if (childDOMWin) {
|
||||
nsGlobalWindow *cwin = static_cast<nsGlobalWindow*>(childDOMWin.get());
|
||||
|
@ -409,7 +409,7 @@ bool PACDnsResolve(JSContext *cx, unsigned int argc, JS::Value *vp)
|
||||
if (!JS_ConvertArguments(cx, args, "S", arg1.address()))
|
||||
return false;
|
||||
|
||||
nsDependentJSString hostName;
|
||||
nsAutoJSString hostName;
|
||||
nsAutoCString dottedDecimal;
|
||||
|
||||
if (!hostName.init(cx, arg1))
|
||||
@ -458,11 +458,11 @@ bool PACProxyAlert(JSContext *cx, unsigned int argc, JS::Value *vp)
|
||||
if (!JS_ConvertArguments(cx, args, "S", arg1.address()))
|
||||
return false;
|
||||
|
||||
nsDependentJSString message;
|
||||
nsAutoJSString message;
|
||||
if (!message.init(cx, arg1))
|
||||
return false;
|
||||
|
||||
nsString alertMessage;
|
||||
nsAutoString alertMessage;
|
||||
alertMessage.SetCapacity(32 + message.Length());
|
||||
alertMessage += NS_LITERAL_STRING("PAC-alert: ");
|
||||
alertMessage += message;
|
||||
@ -706,7 +706,7 @@ ProxyAutoConfig::GetProxyForURI(const nsCString &aTestURI,
|
||||
bool ok = JS_CallFunctionName(cx, global, "FindProxyForURL", args, &rval);
|
||||
|
||||
if (ok && rval.isString()) {
|
||||
nsDependentJSString pacString;
|
||||
nsAutoJSString pacString;
|
||||
if (pacString.init(cx, rval.toString())) {
|
||||
CopyUTF16toUTF8(pacString, result);
|
||||
rv = NS_OK;
|
||||
|
@ -972,13 +972,13 @@ cryptojs_ReadArgsAndGenerateKey(JSContext *cx,
|
||||
jsString = JS::ToString(cx, v);
|
||||
NS_ENSURE_TRUE(jsString, NS_ERROR_OUT_OF_MEMORY);
|
||||
argv[2] = STRING_TO_JSVAL(jsString);
|
||||
nsDependentJSString dependentKeyGenAlg;
|
||||
NS_ENSURE_TRUE(dependentKeyGenAlg.init(cx, jsString), NS_ERROR_UNEXPECTED);
|
||||
nsAutoString keyGenAlg(dependentKeyGenAlg);
|
||||
nsAutoJSString autoJSKeyGenAlg;
|
||||
NS_ENSURE_TRUE(autoJSKeyGenAlg.init(cx, jsString), NS_ERROR_UNEXPECTED);
|
||||
nsAutoString keyGenAlg(autoJSKeyGenAlg);
|
||||
keyGenAlg.Trim("\r\n\t ");
|
||||
keyGenType->keyGenType = cryptojs_interpret_key_gen_type(keyGenAlg);
|
||||
if (keyGenType->keyGenType == invalidKeyGen) {
|
||||
NS_LossyConvertUTF16toASCII keyGenAlgNarrow(dependentKeyGenAlg);
|
||||
NS_LossyConvertUTF16toASCII keyGenAlgNarrow(autoJSKeyGenAlg);
|
||||
JS_ReportError(cx, "%s%s%s", JS_ERROR,
|
||||
"invalid key generation argument:",
|
||||
keyGenAlgNarrow.get());
|
||||
@ -994,7 +994,7 @@ cryptojs_ReadArgsAndGenerateKey(JSContext *cx,
|
||||
*slot,willEscrow);
|
||||
|
||||
if (rv != NS_OK) {
|
||||
NS_LossyConvertUTF16toASCII keyGenAlgNarrow(dependentKeyGenAlg);
|
||||
NS_LossyConvertUTF16toASCII keyGenAlgNarrow(autoJSKeyGenAlg);
|
||||
JS_ReportError(cx,"%s%s%s", JS_ERROR,
|
||||
"could not generate the key for algorithm ",
|
||||
keyGenAlgNarrow.get());
|
||||
|
@ -126,8 +126,8 @@ convertJSValToVariant(
|
||||
return new FloatVariant(aValue.toDouble());
|
||||
|
||||
if (aValue.isString()) {
|
||||
nsDependentJSString value;
|
||||
if (!value.init(aCtx, aValue))
|
||||
nsAutoJSString value;
|
||||
if (!value.init(aCtx, aValue.toString()))
|
||||
return nullptr;
|
||||
return new TextVariant(value);
|
||||
}
|
||||
|
@ -754,7 +754,7 @@ XRE_SendTestShellCommand(JSContext* aCx,
|
||||
TestShellParent* tsp = GetOrCreateTestShellParent();
|
||||
NS_ENSURE_TRUE(tsp, false);
|
||||
|
||||
nsDependentJSString command;
|
||||
nsAutoJSString command;
|
||||
NS_ENSURE_TRUE(command.init(aCx, cmd), false);
|
||||
|
||||
if (!aCallback) {
|
||||
|
Loading…
Reference in New Issue
Block a user