IndexedDB add() should fail if key is NaN

https://bugs.webkit.org/show_bug.cgi?id=62286

Patch by Joshua Bell <jsbell@chromium.org> on 2011-10-04
Reviewed by Tony Chang.

Source/WebCore:

Test: storage/indexeddb/invalid-keys.html

Implement special case - numbers are valid keys, except for NaN.

* bindings/v8/IDBBindingUtilities.cpp:
(WebCore::createIDBKeyFromValue):

LayoutTests:

Tests for NaN and other invalid IndexedDB keys.

* storage/indexeddb/invalid-keys-expected.txt: Added.
* storage/indexeddb/invalid-keys.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96631 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent dd90ed20
2011-10-04 Joshua Bell <jsbell@chromium.org>
IndexedDB add() should fail if key is NaN
https://bugs.webkit.org/show_bug.cgi?id=62286
Reviewed by Tony Chang.
Tests for NaN and other invalid IndexedDB keys.
* storage/indexeddb/invalid-keys-expected.txt: Added.
* storage/indexeddb/invalid-keys.html: Added.
2011-10-04 Young Han Lee <joybro201@gmail.com>
HTML canvas strokes with dash and dashOffset
Test IndexedDB invalid keys
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;
PASS indexedDB == null is false
IDBDatabaseException = window.IDBDatabaseException || window.webkitIDBDatabaseException;
PASS IDBDatabaseException == null is false
indexedDB.open(name, description)
db = event.target.result
request = db.setVersion('1')
Deleted all object stores.
db.createObjectStore('foo');
Expecting exception from request = objectStore.put('value', void 0)
PASS Exception was thrown.
FAIL code should be 5. Was 17.
Expecting exception from request = objectStore.put('value', null)
PASS Exception was thrown.
PASS code is IDBDatabaseException.DATA_ERR
Expecting exception from request = objectStore.put('value', (function() { return arguments; }()))
PASS Exception was thrown.
FAIL code should be 5. Was 17.
Expecting exception from request = objectStore.put('value', true)
PASS Exception was thrown.
FAIL code should be 5. Was 17.
Expecting exception from request = objectStore.put('value', false)
PASS Exception was thrown.
FAIL code should be 5. Was 17.
Expecting exception from request = objectStore.put('value', new Error)
PASS Exception was thrown.
FAIL code should be 5. Was 17.
Expecting exception from request = objectStore.put('value', function () {})
PASS Exception was thrown.
FAIL code should be 5. Was 17.
Expecting exception from request = objectStore.put('value', JSON)
PASS Exception was thrown.
FAIL code should be 5. Was 17.
Expecting exception from request = objectStore.put('value', Math)
PASS Exception was thrown.
FAIL code should be 5. Was 17.
Expecting exception from request = objectStore.put('value', NaN)
PASS Exception was thrown.
FAIL code should be 5. Was 17.
Expecting exception from request = objectStore.put('value', {})
PASS Exception was thrown.
FAIL code should be 5. Was 17.
Expecting exception from request = objectStore.put('value', /regex/)
PASS Exception was thrown.
FAIL code should be 5. Was 17.
Expecting exception from request = objectStore.put('value', window)
PASS Exception was thrown.
FAIL code should be 5. Was 17.
Expecting exception from request = objectStore.put('value', window.document)
PASS Exception was thrown.
FAIL code should be 5. Was 17.
Expecting exception from request = objectStore.put('value', window.document.body)
PASS Exception was thrown.
FAIL code should be 5. Was 17.
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
<script src="../../fast/js/resources/js-test-pre.js"></script>
<script src="../../fast/js/resources/js-test-post-function.js"></script>
<script src="resources/shared.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Test IndexedDB invalid keys");
if (window.layoutTestController)
layoutTestController.waitUntilDone();
function test()
{
indexedDB = evalAndLog("indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;");
shouldBeFalse("indexedDB == null");
IDBDatabaseException = evalAndLog("IDBDatabaseException = window.IDBDatabaseException || window.webkitIDBDatabaseException;");
shouldBeFalse("IDBDatabaseException == null");
name = window.location.pathname;
description = "My Test Database";
request = evalAndLog("indexedDB.open(name, description)");
request.onsuccess = openSuccess;
request.onerror = unexpectedErrorCallback;
}
function openSuccess()
{
db = evalAndLog("db = event.target.result");
request = evalAndLog("request = db.setVersion('1')");
request.onsuccess = testGroup1;
request.onerror = unexpectedErrorCallback;
}
function testGroup1()
{
deleteAllObjectStores(db);
objectStore = evalAndLog("db.createObjectStore('foo');");
testInvalidKeys();
}
function testInvalidKeys()
{
var invalidKeys = [
"void 0", // Undefined
"null", // Null
"(function() { return arguments; }())", // Arguments
"true", // Boolean
"false", // Boolean
"new Error", // Error
"function () {}", // Function
"JSON", // JSON
"Math", // Math
"NaN", // Number (special case)
"{}", // Object
"/regex/", // RegExp
"window", // global
"window.document", // HTMLDocument
"window.document.body" // HTMLBodyElement
];
invalidKeys.forEach(function(key) {
evalAndExpectException("request = objectStore.put('value', " + key + ")", "IDBDatabaseException.DATA_ERR");
});
done();
}
var successfullyParsed = true;
test();
</script>
</body>
</html>
2011-10-04 Joshua Bell <jsbell@chromium.org>
IndexedDB add() should fail if key is NaN
https://bugs.webkit.org/show_bug.cgi?id=62286
Reviewed by Tony Chang.
Test: storage/indexeddb/invalid-keys.html
Implement special case - numbers are valid keys, except for NaN.
* bindings/v8/IDBBindingUtilities.cpp:
(WebCore::createIDBKeyFromValue):
2011-10-04 Mark Hahnenberg <mhahnenberg@apple.com>
Add static ClassInfo structs to classes that override JSCell::getCallData
......@@ -42,7 +42,7 @@ PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Handle<v8::Value> value)
{
if (value->IsNull())
return IDBKey::createNull();
if (value->IsNumber())
if (value->IsNumber() && !isnan(value->NumberValue()))
return IDBKey::createNumber(value->NumberValue());
if (value->IsString())
return IDBKey::createString(v8ValueToWebCoreString(value));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment