Skip to content

Commit

Permalink
Bug 1034689 part 3 - Fix remaining places in Gecko to handle Latin1 s…
Browse files Browse the repository at this point in the history
…trings. r=bz
  • Loading branch information
jandem committed Jul 12, 2014
1 parent 2a7ce8f commit 8772025
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 35 deletions.
11 changes: 5 additions & 6 deletions dom/plugins/base/nsJSNPRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "nsIScriptGlobalObject.h"
#include "nsIScriptContext.h"
#include "nsDOMJSUtils.h"
#include "nsJSUtils.h"
#include "nsCxPusher.h"
#include "nsIDocument.h"
#include "nsIJSRuntimeService.h"
Expand Down Expand Up @@ -405,13 +406,11 @@ JSValToNPVariant(NPP npp, JSContext *cx, JS::Value val, NPVariant *variant)
}
} else if (val.isString()) {
JSString *jsstr = val.toString();
size_t length;
const jschar *chars = ::JS_GetStringCharsZAndLength(cx, jsstr, &length);
if (!chars) {
return false;
}

nsDependentString str(chars, length);
nsAutoJSString str;
if (!str.init(cx, jsstr)) {
return false;
}

uint32_t len;
char *p = ToNewUTF8String(str, &len);
Expand Down
7 changes: 1 addition & 6 deletions js/ipc/JavaScriptShared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,7 @@ JavaScriptShared::convertIdToGeckoString(JSContext *cx, JS::HandleId id, nsStrin
if (!str)
return false;

const jschar *chars = JS_GetStringCharsZ(cx, str);
if (!chars)
return false;

*to = chars;
return true;
return AssignJSString(cx, *to, str);
}

bool
Expand Down
10 changes: 7 additions & 3 deletions storage/src/mozStorageAsyncStatementParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "nsMemory.h"
#include "nsString.h"
#include "nsCOMPtr.h"
#include "nsJSUtils.h"

#include "jsapi.h"

Expand Down Expand Up @@ -65,9 +66,12 @@ AsyncStatementParams::SetProperty(
}
else if (JSID_IS_STRING(aId)) {
JSString *str = JSID_TO_STRING(aId);
size_t length;
const jschar *chars = JS_GetInternedStringCharsAndLength(str, &length);
NS_ConvertUTF16toUTF8 name(chars, length);
nsAutoJSString autoStr;
if (!autoStr.init(aCtx, str)) {
return NS_ERROR_FAILURE;
}

NS_ConvertUTF16toUTF8 name(autoStr);

nsCOMPtr<nsIVariant> variant(convertJSValToVariant(aCtx, *_vp));
NS_ENSURE_TRUE(variant, NS_ERROR_UNEXPECTED);
Expand Down
20 changes: 12 additions & 8 deletions storage/src/mozStorageStatementParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsJSUtils.h"
#include "nsMemory.h"
#include "nsString.h"

Expand Down Expand Up @@ -63,10 +64,12 @@ StatementParams::SetProperty(nsIXPConnectWrappedNative *aWrapper,
}
else if (JSID_IS_STRING(aId)) {
JSString *str = JSID_TO_STRING(aId);
size_t length;
const jschar *chars = JS_GetStringCharsAndLength(aCtx, str, &length);
NS_ENSURE_TRUE(chars, NS_ERROR_UNEXPECTED);
NS_ConvertUTF16toUTF8 name(chars, length);
nsAutoJSString autoStr;
if (!autoStr.init(aCtx, str)) {
return NS_ERROR_FAILURE;
}

NS_ConvertUTF16toUTF8 name(autoStr);

// check to see if there's a parameter with this name
nsCOMPtr<nsIVariant> variant(convertJSValToVariant(aCtx, *_vp));
Expand Down Expand Up @@ -182,13 +185,14 @@ StatementParams::NewResolve(nsIXPConnectWrappedNative *aWrapper,
}
else if (JSID_IS_STRING(id)) {
JSString *str = JSID_TO_STRING(id);
size_t nameLength;
const jschar *nameChars = JS_GetStringCharsAndLength(aCtx, str, &nameLength);
NS_ENSURE_TRUE(nameChars, NS_ERROR_UNEXPECTED);
nsAutoJSString autoStr;
if (!autoStr.init(aCtx, str)) {
return NS_ERROR_FAILURE;
}

// Check to see if there's a parameter with this name, and if not, let
// the rest of the prototype chain be checked.
NS_ConvertUTF16toUTF8 name(nameChars, nameLength);
NS_ConvertUTF16toUTF8 name(autoStr);
uint32_t idx;
nsresult rv = mStatement->GetParameterIndex(name, &idx);
if (NS_SUCCEEDED(rv)) {
Expand Down
9 changes: 3 additions & 6 deletions toolkit/components/places/History.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "nsIXPConnect.h"
#include "mozilla/unused.h"
#include "nsContentUtils.h" // for nsAutoScriptBlocker
#include "nsJSUtils.h"
#include "mozilla/ipc/URIUtils.h"
#include "nsPrintfCString.h"
#include "nsTHashtable.h"
Expand Down Expand Up @@ -326,14 +327,10 @@ GetJSValueAsString(JSContext* aCtx,
_string.Truncate();
return;
}
size_t length;
const jschar* chars =
JS_GetStringCharsZAndLength(aCtx, aValue.toString(), &length);
if (!chars) {

if (!AssignJSString(aCtx, _string, aValue.toString())) {
_string.SetIsVoid(true);
return;
}
_string.Assign(static_cast<const char16_t*>(chars), length);
}

/**
Expand Down
10 changes: 4 additions & 6 deletions widget/android/NativeJSContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "AndroidBridge.h"
#include "mozilla/Vector.h"
#include "prthread.h"
#include "nsJSUtils.h"

using namespace mozilla;
using namespace mozilla::widget;
Expand Down Expand Up @@ -502,14 +503,11 @@ struct StringProperty

static Type FromValue(JNIEnv* env, jobject instance,
JSContext* cx, const JS::HandleString str) {
size_t strLen = 0;
const jschar* const strChars =
JS_GetStringCharsAndLength(cx, str, &strLen);
if (!CheckJSCall(env, !!strChars)) {
nsAutoJSString autoStr;
if (!CheckJSCall(env, autoStr.init(cx, str))) {
return nullptr;
}
jstring ret = env->NewString(
reinterpret_cast<const jchar*>(strChars), strLen);
jstring ret = env->NewString(autoStr.BeginReading(), autoStr.Length());
MOZ_ASSERT(ret);
return ret;
}
Expand Down

0 comments on commit 8772025

Please sign in to comment.