Bug 532062 - localStorage/sessionStorage should return undefined (not null) for undefined keys through property access; r=mayhemer

This commit is contained in:
Ms2ger 2012-04-03 09:25:39 +02:00
Родитель 662e9e4a31
Коммит aed7d318eb
5 изменённых файлов: 56 добавлений и 56 удалений

Просмотреть файл

@ -10516,15 +10516,15 @@ nsStorage2SH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSAutoRequest ar(cx);
if (DOMStringIsNull(val)) {
*vp = JSVAL_NULL;
}
else {
JSString *str =
::JS_NewUCStringCopyN(cx, reinterpret_cast<const jschar *>(val.get()),
val.Length());
NS_ENSURE_TRUE(str, NS_ERROR_OUT_OF_MEMORY);
// No such key.
*vp = JSVAL_VOID;
} else {
JSString* str =
JS_NewUCStringCopyN(cx, static_cast<const jschar *>(val.get()),
val.Length());
NS_ENSURE_TRUE(str, NS_ERROR_OUT_OF_MEMORY);
*vp = STRING_TO_JSVAL(str);
*vp = STRING_TO_JSVAL(str);
}
return NS_SUCCESS_I_DID_SOMETHING;

Просмотреть файл

@ -17,16 +17,16 @@ function startTest()
is(localStorage.key(-1), null, "key() should return null for out-of-bounds access");
is(localStorage.key(1), null, "key() should return null for out-of-bounds access");
is(localStorage.getItem("nonexisting"), null, "Nonexisting item is null (getItem())");
is(localStorage["nonexisting"], null, "Nonexisting item is null (array access)");
is(localStorage.nonexisting, null, "Nonexisting item is null (property access)");
is(localStorage["nonexisting"], undefined, "Nonexisting item is undefined (array access)");
is(localStorage.nonexisting, undefined, "Nonexisting item is undefined (property access)");
localStorage.removeItem("nonexisting"); // Just check there is no exception
is(typeof localStorage.getItem("nonexisting"), "object", "getItem('nonexisting') is object");
is(typeof localStorage["nonexisting"], "object", "['nonexisting'] is object");
is(typeof localStorage.nonexisting, "object", "nonexisting is object");
is(typeof localStorage["nonexisting"], "undefined", "['nonexisting'] is undefined");
is(typeof localStorage.nonexisting, "undefined", "nonexisting is undefined");
is(typeof localStorage.getItem("nonexisting2"), "object", "getItem('nonexisting2') is object");
is(typeof localStorage["nonexisting2"], "object", "['nonexisting2'] is object");
is(typeof localStorage.nonexisting2, "object", "nonexisting2 is object");
is(typeof localStorage["nonexisting2"], "undefined", "['nonexisting2'] is undefined");
is(typeof localStorage.nonexisting2, "undefined", "nonexisting2 is undefined");
var mozStorageChangedReceived = 0;
var localStorageCopy = localStorage;
@ -50,11 +50,11 @@ function startTest()
localStorage.removeItem("empty");
is(localStorage.length, 0, "The storage has no keys");
is(localStorage.getItem("empty"), null, "empty item is null (getItem())");
is(localStorage["empty"], null, "empty item is null (array access)");
is(localStorage.empty, null, "empty item is null (property access)");
is(localStorage["empty"], undefined, "empty item is undefined (array access)");
is(localStorage.empty, undefined, "empty item is undefined (property access)");
is(typeof localStorage.getItem("empty"), "object", "getItem('empty') is object");
is(typeof localStorage["empty"], "object", "['empty'] is object");
is(typeof localStorage.empty, "object", "empty is object");
is(typeof localStorage["empty"], "undefined", "['empty'] is undefined");
is(typeof localStorage.empty, "undefined", "empty is undefined");
// add one key, check it is there
localStorage.setItem("key1", "value1");
@ -80,8 +80,8 @@ function startTest()
is(localStorage.getItem("key1"), null, "\'key1\' removed");
is(typeof localStorage.getItem("key1"), "object", "getItem('key1') is object");
is(typeof localStorage["key1"], "object", "['key1'] is object");
is(typeof localStorage.key1, "object", "key1 is object");
is(typeof localStorage["key1"], "undefined", "['key1'] is object");
is(typeof localStorage.key1, "undefined", "key1 is object");
// add one key, check it is there
localStorage.setItem("key1", "value1");

Просмотреть файл

@ -34,16 +34,16 @@ function doTest()
is(localStorage.key(-1), null, "key() should return null for out-of-bounds access");
is(localStorage.key(1), null, "key() should return null for out-of-bounds access");
is(localStorage.getItem("nonexisting"), null, "Nonexisting item is null (getItem())");
is(localStorage["nonexisting"], null, "Nonexisting item is null (array access)");
is(localStorage.nonexisting, null, "Nonexisting item is null (property access)");
is(localStorage["nonexisting"], undefined, "Nonexisting item is null (array access)");
is(localStorage.nonexisting, undefined, "Nonexisting item is null (property access)");
localStorage.removeItem("nonexisting"); // Just check there is no exception
is(typeof localStorage.getItem("nonexisting"), "object", "getItem('nonexisting') is object");
is(typeof localStorage["nonexisting"], "object", "['nonexisting'] is object");
is(typeof localStorage.nonexisting, "object", "nonexisting is object");
is(typeof localStorage["nonexisting"], "undefined", "['nonexisting'] is undefined");
is(typeof localStorage.nonexisting, "undefined", "nonexisting is undefined");
is(typeof localStorage.getItem("nonexisting2"), "object", "getItem('nonexisting2') is object");
is(typeof localStorage["nonexisting2"], "object", "['nonexisting2'] is object");
is(typeof localStorage.nonexisting2, "object", "nonexisting2 is object");
is(typeof localStorage["nonexisting2"], "undefined", "['nonexisting2'] is undefined");
is(typeof localStorage.nonexisting2, "undefined", "nonexisting2 is undefined");
// add an empty-value key
localStorage.setItem("empty", "");
@ -56,11 +56,11 @@ function doTest()
localStorage.removeItem("empty");
is(localStorage.length, 0, "The storage has no keys");
is(localStorage.getItem("empty"), null, "empty item is null (getItem())");
is(localStorage["empty"], null, "empty item is null (array access)");
is(localStorage.empty, null, "empty item is null (property access)");
is(localStorage["empty"], null, "empty item is undefined (array access)");
is(localStorage.empty, null, "empty item is undefined (property access)");
is(typeof localStorage.getItem("empty"), "object", "getItem('empty') is object");
is(typeof localStorage["empty"], "object", "['empty'] is object");
is(typeof localStorage.empty, "object", "empty is object");
is(typeof localStorage["empty"], "undefined", "['empty'] is undefined");
is(typeof localStorage.empty, "undefined", "empty is undefined");
// add one key, check it is there
localStorage.setItem("key1", "value1");
@ -86,8 +86,8 @@ function doTest()
is(localStorage.getItem("key1"), null, "\'key1\' removed");
is(typeof localStorage.getItem("key1"), "object", "getItem('key1') is object");
is(typeof localStorage["key1"], "object", "['key1'] is object");
is(typeof localStorage.key1, "object", "key1 is object");
is(typeof localStorage["key1"], "undefined", "['key1'] is undefined");
is(typeof localStorage.key1, "undefined", "key1 is undefined");
// add one key, check it is there
localStorage.setItem("key1", "value1");

Просмотреть файл

@ -25,16 +25,16 @@ function startTest()
is(localStorage.key(-1), null, "key() should return null for out-of-bounds access");
is(localStorage.key(1), null, "key() should return null for out-of-bounds access");
is(localStorage.getItem("nonexisting"), null, "Nonexisting item is null (getItem())");
is(localStorage["nonexisting"], null, "Nonexisting item is null (array access)");
is(localStorage.nonexisting, null, "Nonexisting item is null (property access)");
is(localStorage["nonexisting"], undefined, "Nonexisting item is undefined (array access)");
is(localStorage.nonexisting, undefined, "Nonexisting item is undefined (property access)");
localStorage.removeItem("nonexisting"); // Just check there is no exception
is(typeof localStorage.getItem("nonexisting"), "object", "getItem('nonexisting') is object");
is(typeof localStorage["nonexisting"], "object", "['nonexisting'] is object");
is(typeof localStorage.nonexisting, "object", "nonexisting is object");
is(typeof localStorage["nonexisting"], "undefined", "['nonexisting'] is undefined");
is(typeof localStorage.nonexisting, "undefined", "nonexisting is undefined");
is(typeof localStorage.getItem("nonexisting2"), "object", "getItem('nonexisting2') is object");
is(typeof localStorage["nonexisting2"], "object", "['nonexisting2'] is object");
is(typeof localStorage.nonexisting2, "object", "nonexisting2 is object");
is(typeof localStorage["nonexisting2"], "undefined", "['nonexisting2'] is undefined");
is(typeof localStorage.nonexisting2, "undefined", "nonexisting2 is undefined");
// add an empty-value key
localStorage.setItem("empty", "");
@ -47,11 +47,11 @@ function startTest()
localStorage.removeItem("empty");
is(localStorage.length, 0, "The storage has no keys");
is(localStorage.getItem("empty"), null, "empty item is null (getItem())");
is(localStorage["empty"], null, "empty item is null (array access)");
is(localStorage.empty, null, "empty item is null (property access)");
is(localStorage["empty"], undefined, "empty item is undefined (array access)");
is(localStorage.empty, undefined, "empty item is undefined (property access)");
is(typeof localStorage.getItem("empty"), "object", "getItem('empty') is object");
is(typeof localStorage["empty"], "object", "['empty'] is object");
is(typeof localStorage.empty, "object", "empty is object");
is(typeof localStorage["empty"], "undefined", "['empty'] is undefined");
is(typeof localStorage.empty, "undefined", "empty is undefined");
// add one key, check it is there
localStorage.setItem("key1", "value1");
@ -77,8 +77,8 @@ function startTest()
is(localStorage.getItem("key1"), null, "\'key1\' removed");
is(typeof localStorage.getItem("key1"), "object", "getItem('key1') is object");
is(typeof localStorage["key1"], "object", "['key1'] is object");
is(typeof localStorage.key1, "object", "key1 is object");
is(typeof localStorage["key1"], "undefined", "['key1'] is undefined");
is(typeof localStorage.key1, "undefined", "key1 is undefined");
// add one key, check it is there
localStorage.setItem("key1", "value1");

Просмотреть файл

@ -22,16 +22,16 @@ function startTest()
is(sessionStorage.key(-1), null, "key() should return null for out-of-bounds access");
is(sessionStorage.key(1), null, "key() should return null for out-of-bounds access");
is(sessionStorage.getItem("nonexisting"), null, "Nonexisting item is null (getItem())");
is(sessionStorage["nonexisting"], null, "Nonexisting item is null (array access)");
is(sessionStorage.nonexisting, null, "Nonexisting item is null (property access)");
is(sessionStorage["nonexisting"], undefined, "Nonexisting item is undefined (array access)");
is(sessionStorage.nonexisting, undefined, "Nonexisting item is undefined (property access)");
sessionStorage.removeItem("nonexisting"); // Just check there is no exception
is(typeof sessionStorage.getItem("nonexisting"), "object", "getItem('nonexisting') is object");
is(typeof sessionStorage["nonexisting"], "object", "['nonexisting'] is object");
is(typeof sessionStorage.nonexisting, "object", "nonexisting is object");
is(typeof sessionStorage["nonexisting"], "undefined", "['nonexisting'] is undefined");
is(typeof sessionStorage.nonexisting, "undefined", "nonexisting is undefined");
is(typeof sessionStorage.getItem("nonexisting2"), "object", "getItem('nonexisting2') is object");
is(typeof sessionStorage["nonexisting2"], "object", "['nonexisting2'] is object");
is(typeof sessionStorage.nonexisting2, "object", "nonexisting2 is object");
is(typeof sessionStorage["nonexisting2"], "undefined", "['nonexisting2'] is undefined");
is(typeof sessionStorage.nonexisting2, "undefined", "nonexisting2 is undefined");
var mozStorageChangedReceived = 0;
var sessionStorageCopy = sessionStorage;
@ -55,11 +55,11 @@ function startTest()
sessionStorage.removeItem("empty");
is(sessionStorage.length, 0, "The storage has no keys");
is(sessionStorage.getItem("empty"), null, "empty item is null (getItem())");
is(sessionStorage["empty"], null, "empty item is null (array access)");
is(sessionStorage.empty, null, "empty item is null (property access)");
is(sessionStorage["empty"], undefined, "empty item is undefined (array access)");
is(sessionStorage.empty, undefined, "empty item is undefined (property access)");
is(typeof sessionStorage.getItem("empty"), "object", "getItem('empty') is object");
is(typeof sessionStorage["empty"], "object", "['empty'] is object");
is(typeof sessionStorage.empty, "object", "empty is object");
is(typeof sessionStorage["empty"], "undefined", "['empty'] is undefined");
is(typeof sessionStorage.empty, "undefined", "empty is undefined");
// add one key, check it is there
sessionStorage.setItem("key1", "value1");
@ -85,8 +85,8 @@ function startTest()
is(sessionStorage.getItem("key1"), null, "\'key1\' removed");
is(typeof sessionStorage.getItem("key1"), "object", "getItem('key1') is object");
is(typeof sessionStorage["key1"], "object", "['key1'] is object");
is(typeof sessionStorage.key1, "object", "key1 is object");
is(typeof sessionStorage["key1"], "undefined", "['key1'] is undefined");
is(typeof sessionStorage.key1, "undefined", "key1 is undefined");
// add one key, check it is there
sessionStorage.setItem("key1", "value1");