From 6271970a916128d21b1ead1c8a9387611fb83dd3 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 11 Dec 2014 13:07:44 -0500 Subject: [PATCH] Bug 990484 part 2. Remove a bunch of now-unnecessary JSContext bits in indexedDB code. r=baku --- dom/bindings/Bindings.conf | 1 - dom/datastore/DataStoreDB.cpp | 2 +- dom/indexedDB/IDBObjectStore.cpp | 15 ++++++--------- dom/indexedDB/IDBObjectStore.h | 9 +++------ dom/indexedDB/KeyPath.cpp | 32 +++++++++++--------------------- dom/indexedDB/KeyPath.h | 7 +++---- 6 files changed, 24 insertions(+), 42 deletions(-) diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 861a21a3398..139413821b7 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -586,7 +586,6 @@ DOMInterfaces = { 'IDBObjectStore': { 'nativeType': 'mozilla::dom::indexedDB::IDBObjectStore', - 'implicitJSContext': [ 'createIndex' ], 'binaryNames': { 'mozGetAll': 'getAll' } diff --git a/dom/datastore/DataStoreDB.cpp b/dom/datastore/DataStoreDB.cpp index ee7c7b23334..6bc506c13d6 100644 --- a/dom/datastore/DataStoreDB.cpp +++ b/dom/datastore/DataStoreDB.cpp @@ -275,7 +275,7 @@ DataStoreDB::UpgradeSchema(nsIDOMEvent* aEvent) RootedDictionary params(cx); params.Init(NS_LITERAL_STRING("{ \"unique\": true }")); nsRefPtr index = - store->CreateIndex(cx, NS_LITERAL_STRING(DATASTOREDB_REVISION_INDEX), + store->CreateIndex(NS_LITERAL_STRING(DATASTOREDB_REVISION_INDEX), NS_LITERAL_STRING("revisionId"), params, error); if (NS_WARN_IF(error.Failed())) { return error.ErrorCode(); diff --git a/dom/indexedDB/IDBObjectStore.cpp b/dom/indexedDB/IDBObjectStore.cpp index a45b3aa4b14..5d5410f9cfc 100644 --- a/dom/indexedDB/IDBObjectStore.cpp +++ b/dom/indexedDB/IDBObjectStore.cpp @@ -1646,8 +1646,7 @@ IDBObjectStore::Delete(JSContext* aCx, } already_AddRefed -IDBObjectStore::CreateIndex(JSContext* aCx, - const nsAString& aName, +IDBObjectStore::CreateIndex(const nsAString& aName, const nsAString& aKeyPath, const IDBIndexParameters& aOptionalParameters, ErrorResult& aRv) @@ -1655,18 +1654,17 @@ IDBObjectStore::CreateIndex(JSContext* aCx, AssertIsOnOwningThread(); KeyPath keyPath(0); - if (NS_FAILED(KeyPath::Parse(aCx, aKeyPath, &keyPath)) || + if (NS_FAILED(KeyPath::Parse(aKeyPath, &keyPath)) || !keyPath.IsValid()) { aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR); return nullptr; } - return CreateIndexInternal(aCx, aName, keyPath, aOptionalParameters, aRv); + return CreateIndexInternal(aName, keyPath, aOptionalParameters, aRv); } already_AddRefed -IDBObjectStore::CreateIndex(JSContext* aCx, - const nsAString& aName, +IDBObjectStore::CreateIndex(const nsAString& aName, const Sequence& aKeyPath, const IDBIndexParameters& aOptionalParameters, ErrorResult& aRv) @@ -1675,18 +1673,17 @@ IDBObjectStore::CreateIndex(JSContext* aCx, KeyPath keyPath(0); if (aKeyPath.IsEmpty() || - NS_FAILED(KeyPath::Parse(aCx, aKeyPath, &keyPath)) || + NS_FAILED(KeyPath::Parse(aKeyPath, &keyPath)) || !keyPath.IsValid()) { aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR); return nullptr; } - return CreateIndexInternal(aCx, aName, keyPath, aOptionalParameters, aRv); + return CreateIndexInternal(aName, keyPath, aOptionalParameters, aRv); } already_AddRefed IDBObjectStore::CreateIndexInternal( - JSContext* aCx, const nsAString& aName, const KeyPath& aKeyPath, const IDBIndexParameters& aOptionalParameters, diff --git a/dom/indexedDB/IDBObjectStore.h b/dom/indexedDB/IDBObjectStore.h index 1ce9c869bac..ccb12baf035 100644 --- a/dom/indexedDB/IDBObjectStore.h +++ b/dom/indexedDB/IDBObjectStore.h @@ -184,15 +184,13 @@ public: Clear(ErrorResult& aRv); already_AddRefed - CreateIndex(JSContext* aCx, - const nsAString& aName, + CreateIndex(const nsAString& aName, const nsAString& aKeyPath, const IDBIndexParameters& aOptionalParameters, ErrorResult& aRv); already_AddRefed - CreateIndex(JSContext* aCx, - const nsAString& aName, + CreateIndex(const nsAString& aName, const Sequence& aKeyPath, const IDBIndexParameters& aOptionalParameters, ErrorResult& aRv); @@ -298,8 +296,7 @@ private: ErrorResult& aRv); already_AddRefed - CreateIndexInternal(JSContext* aCx, - const nsAString& aName, + CreateIndexInternal(const nsAString& aName, const KeyPath& aKeyPath, const IDBIndexParameters& aOptionalParameters, ErrorResult& aRv); diff --git a/dom/indexedDB/KeyPath.cpp b/dom/indexedDB/KeyPath.cpp index 9f440746372..e577c6ea9bb 100644 --- a/dom/indexedDB/KeyPath.cpp +++ b/dom/indexedDB/KeyPath.cpp @@ -31,7 +31,7 @@ IgnoreWhitespace(char16_t c) typedef nsCharSeparatedTokenizerTemplate KeyPathTokenizer; bool -IsValidKeyPathString(JSContext* aCx, const nsAString& aKeyPath) +IsValidKeyPathString(const nsAString& aKeyPath) { NS_ASSERTION(!aKeyPath.IsVoid(), "What?"); @@ -44,16 +44,7 @@ IsValidKeyPathString(JSContext* aCx, const nsAString& aKeyPath) return false; } - JS::Rooted stringVal(aCx); - if (!xpc::StringToJsval(aCx, token, &stringVal)) { - return false; - } - - NS_ASSERTION(stringVal.toString(), "This should never happen"); - JS::Rooted str(aCx, stringVal.toString()); - - bool isIdentifier = false; - if (!JS_IsIdentifier(aCx, str, &isIdentifier) || !isIdentifier) { + if (!JS_IsIdentifier(token.get(), token.Length())) { return false; } } @@ -83,7 +74,7 @@ GetJSValFromKeyPathString(JSContext* aCx, void* aClosure) { NS_ASSERTION(aCx, "Null pointer!"); - NS_ASSERTION(IsValidKeyPathString(aCx, aKeyPathString), + NS_ASSERTION(IsValidKeyPathString(aKeyPathString), "This will explode!"); NS_ASSERTION(!(aCallback || aClosure) || aOptions == CreateProperties, "This is not allowed!"); @@ -229,12 +220,12 @@ GetJSValFromKeyPathString(JSContext* aCx, // static nsresult -KeyPath::Parse(JSContext* aCx, const nsAString& aString, KeyPath* aKeyPath) +KeyPath::Parse(const nsAString& aString, KeyPath* aKeyPath) { KeyPath keyPath(0); keyPath.SetType(STRING); - if (!keyPath.AppendStringWithValidation(aCx, aString)) { + if (!keyPath.AppendStringWithValidation(aString)) { return NS_ERROR_FAILURE; } @@ -244,14 +235,13 @@ KeyPath::Parse(JSContext* aCx, const nsAString& aString, KeyPath* aKeyPath) //static nsresult -KeyPath::Parse(JSContext* aCx, const mozilla::dom::Sequence& aStrings, - KeyPath* aKeyPath) +KeyPath::Parse(const Sequence& aStrings, KeyPath* aKeyPath) { KeyPath keyPath(0); keyPath.SetType(ARRAY); for (uint32_t i = 0; i < aStrings.Length(); ++i) { - if (!keyPath.AppendStringWithValidation(aCx, aStrings[i])) { + if (!keyPath.AppendStringWithValidation(aStrings[i])) { return NS_ERROR_FAILURE; } } @@ -295,7 +285,7 @@ KeyPath::Parse(JSContext* aCx, const JS::Value& aValue_, KeyPath* aKeyPath) return NS_ERROR_FAILURE; } - if (!keyPath.AppendStringWithValidation(aCx, str)) { + if (!keyPath.AppendStringWithValidation(str)) { return NS_ERROR_FAILURE; } } @@ -311,7 +301,7 @@ KeyPath::Parse(JSContext* aCx, const JS::Value& aValue_, KeyPath* aKeyPath) keyPath.SetType(STRING); - if (!keyPath.AppendStringWithValidation(aCx, str)) { + if (!keyPath.AppendStringWithValidation(str)) { return NS_ERROR_FAILURE; } } @@ -328,9 +318,9 @@ KeyPath::SetType(KeyPathType aType) } bool -KeyPath::AppendStringWithValidation(JSContext* aCx, const nsAString& aString) +KeyPath::AppendStringWithValidation(const nsAString& aString) { - if (!IsValidKeyPathString(aCx, aString)) { + if (!IsValidKeyPathString(aString)) { return false; } diff --git a/dom/indexedDB/KeyPath.h b/dom/indexedDB/KeyPath.h index abcd22c0022..2e9c80988af 100644 --- a/dom/indexedDB/KeyPath.h +++ b/dom/indexedDB/KeyPath.h @@ -39,8 +39,7 @@ public: void SetType(KeyPathType aType); - // This does not set exceptions. - bool AppendStringWithValidation(JSContext* aCx, const nsAString& aString); + bool AppendStringWithValidation(const nsAString& aString); explicit KeyPath(int aDummy) : mType(NONEXISTENT) @@ -60,10 +59,10 @@ public: } static nsresult - Parse(JSContext* aCx, const nsAString& aString, KeyPath* aKeyPath); + Parse(const nsAString& aString, KeyPath* aKeyPath); static nsresult - Parse(JSContext* aCx, const Sequence& aStrings, KeyPath* aKeyPath); + Parse(const Sequence& aStrings, KeyPath* aKeyPath); static nsresult Parse(JSContext* aCx, const JS::Value& aValue, KeyPath* aKeyPath);