Bug 580128 - Make IndexedDB work with compartments. r=jst

This commit is contained in:
Ben Turner 2010-10-10 15:35:42 -07:00
Родитель e036314b75
Коммит 1bea2a0e1e
5 изменённых файлов: 42 добавлений и 55 удалений

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

@ -465,6 +465,8 @@ IDBCursor::Update(const jsval &aValue,
{ {
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
nsresult rv;
if (mType != OBJECTSTORE) { if (mType != OBJECTSTORE) {
NS_NOTYETIMPLEMENTED("Implement me!"); NS_NOTYETIMPLEMENTED("Implement me!");
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
@ -483,12 +485,7 @@ IDBCursor::Update(const jsval &aValue,
JSAutoRequest ar(aCx); JSAutoRequest ar(aCx);
js::AutoValueRooter clone(aCx); js::AutoValueRooter clone(aCx, aValue);
nsresult rv = nsContentUtils::CreateStructuredClone(aCx, aValue,
clone.jsval_addr());
if (NS_FAILED(rv)) {
return rv;
}
if (!mObjectStore->KeyPath().IsEmpty()) { if (!mObjectStore->KeyPath().IsEmpty()) {
// Make sure the object given has the correct keyPath value set on it or // Make sure the object given has the correct keyPath value set on it or
@ -506,6 +503,9 @@ IDBCursor::Update(const jsval &aValue,
rv = IDBObjectStore::GetJSValFromKey(key, aCx, prop.jsval_addr()); rv = IDBObjectStore::GetJSValFromKey(key, aCx, prop.jsval_addr());
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
ok = JS_StructuredClone(aCx, clone.jsval_value(), clone.jsval_addr());
NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
ok = JS_DefineUCProperty(aCx, JSVAL_TO_OBJECT(clone.jsval_value()), ok = JS_DefineUCProperty(aCx, JSVAL_TO_OBJECT(clone.jsval_value()),
keyPathChars, keyPathLen, prop.jsval_value(), nsnull, keyPathChars, keyPathLen, prop.jsval_value(), nsnull,
nsnull, JSPROP_ENUMERATE); nsnull, JSPROP_ENUMERATE);

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

@ -497,15 +497,9 @@ IDBObjectStore::GetJSONFromArg0(/* jsval arg0, */
JSAutoRequest ar(cx); JSAutoRequest ar(cx);
js::AutoValueRooter clone(cx);
rv = nsContentUtils::CreateStructuredClone(cx, argv[0], clone.jsval_addr());
if (NS_FAILED(rv)) {
return rv;
}
nsCOMPtr<nsIJSON> json(new nsJSON()); nsCOMPtr<nsIJSON> json(new nsJSON());
rv = json->EncodeFromJSVal(clone.jsval_addr(), cx, aJSON); rv = json->EncodeFromJSVal(&argv[0], cx, aJSON);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
return NS_OK; return NS_OK;
@ -775,14 +769,9 @@ IDBObjectStore::GetAddInfo(JSContext* aCx,
Key& aKey, Key& aKey,
nsTArray<IndexUpdateInfo>& aUpdateInfoArray) nsTArray<IndexUpdateInfo>& aUpdateInfoArray)
{ {
JSAutoRequest ar(aCx); nsresult rv;
js::AutoValueRooter clone(aCx); JSAutoRequest ar(aCx);
nsresult rv = nsContentUtils::CreateStructuredClone(aCx, aValue,
clone.jsval_addr());
if (NS_FAILED(rv)) {
return rv;
}
if (mKeyPath.IsEmpty()) { if (mKeyPath.IsEmpty()) {
rv = GetKeyFromJSVal(aKeyVal, aKey); rv = GetKeyFromJSVal(aKeyVal, aKey);
@ -790,11 +779,11 @@ IDBObjectStore::GetAddInfo(JSContext* aCx,
} }
else { else {
// Inline keys live on the object. Make sure it is an object. // Inline keys live on the object. Make sure it is an object.
if (JSVAL_IS_PRIMITIVE(clone.jsval_value())) { if (JSVAL_IS_PRIMITIVE(aValue)) {
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
} }
rv = GetKeyFromObject(aCx, JSVAL_TO_OBJECT(clone.jsval_value()), mKeyPath, aKey); rv = GetKeyFromObject(aCx, JSVAL_TO_OBJECT(aValue), mKeyPath, aKey);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// Except if null was passed, in which case we're supposed to generate the // Except if null was passed, in which case we're supposed to generate the
@ -812,11 +801,11 @@ IDBObjectStore::GetAddInfo(JSContext* aCx,
ObjectStoreInfo* objectStoreInfo = GetObjectStoreInfo(); ObjectStoreInfo* objectStoreInfo = GetObjectStoreInfo();
NS_ENSURE_TRUE(objectStoreInfo, NS_ERROR_FAILURE); NS_ENSURE_TRUE(objectStoreInfo, NS_ERROR_FAILURE);
rv = GetIndexUpdateInfo(objectStoreInfo, aCx, clone.jsval_value(), aUpdateInfoArray); rv = GetIndexUpdateInfo(objectStoreInfo, aCx, aValue, aUpdateInfoArray);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIJSON> json(new nsJSON()); nsCOMPtr<nsIJSON> json(new nsJSON());
rv = json->EncodeFromJSVal(clone.jsval_addr(), aCx, aJSON); rv = json->EncodeFromJSVal(&aValue, aCx, aJSON);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
return NS_OK; return NS_OK;

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

@ -1539,14 +1539,11 @@ nsDOMWorker::PostMessageInternal(PRBool aToInner)
JSAutoRequest ar(cx); JSAutoRequest ar(cx);
nsAutoJSValHolder val; JSAutoStructuredCloneBuffer buffer(cx);
if (!val.Hold(cx)) {
return NS_ERROR_FAILURE;
}
rv = nsContentUtils::CreateStructuredClone(cx, argv[0], val.ToJSValPtr()); if (!buffer.write(argv[0])) {
if (NS_FAILED(rv)) { NS_WARNING("Failed to serialize!");
return rv; return NS_ERROR_FAILURE;
} }
nsRefPtr<nsDOMWorkerMessageEvent> message = new nsDOMWorkerMessageEvent(); nsRefPtr<nsDOMWorkerMessageEvent> message = new nsDOMWorkerMessageEvent();
@ -1557,7 +1554,7 @@ nsDOMWorker::PostMessageInternal(PRBool aToInner)
nsnull); nsnull);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = message->SetJSVal(cx, val); rv = message->SetJSData(cx, buffer);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsRefPtr<nsDOMFireEventRunnable> runnable = nsRefPtr<nsDOMFireEventRunnable> runnable =

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

@ -264,15 +264,17 @@ NS_IMPL_CI_INTERFACE_GETTER2(nsDOMWorkerMessageEvent, nsIDOMEvent,
NS_IMPL_THREADSAFE_DOM_CI_GETINTERFACES(nsDOMWorkerMessageEvent) NS_IMPL_THREADSAFE_DOM_CI_GETINTERFACES(nsDOMWorkerMessageEvent)
nsresult nsresult
nsDOMWorkerMessageEvent::SetJSVal(JSContext* aCx, nsDOMWorkerMessageEvent::SetJSData(JSContext* aCx,
jsval aData) JSAutoStructuredCloneBuffer& aBuffer)
{ {
NS_ASSERTION(aCx, "Null context!");
if (!mDataVal.Hold(aCx)) { if (!mDataVal.Hold(aCx)) {
NS_WARNING("Failed to hold jsval!"); NS_WARNING("Failed to hold jsval!");
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
mDataVal = aData; aBuffer.steal(&mData, &mDataLen);
return NS_OK; return NS_OK;
} }
@ -287,19 +289,21 @@ nsDOMWorkerMessageEvent::GetData(nsAString& aData)
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(cc, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(cc, NS_ERROR_UNEXPECTED);
if (!mDataValWasReparented) { if (mData) {
if (JSVAL_IS_OBJECT(mDataVal) && !JSVAL_IS_NULL(mDataVal)) { JSContext* cx;
JSContext* cx; rv = cc->GetJSContext(&cx);
rv = cc->GetJSContext(&cx); NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = JSAutoRequest ar(cx);
nsContentUtils::ReparentClonedObjectToScope(cx, JSAutoStructuredCloneBuffer buffer(cx);
JSVAL_TO_OBJECT(mDataVal), buffer.adopt(mData, mDataLen);
JS_GetGlobalObject(cx)); mData = nsnull;
NS_ENSURE_SUCCESS(rv, rv); mDataLen = 0;
if (!buffer.read(mDataVal.ToJSValPtr())) {
NS_WARNING("Failed to deserialize!");
return NS_ERROR_FAILURE;
} }
mDataValWasReparented = PR_TRUE;
} }
jsval* retval; jsval* retval;

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

@ -47,6 +47,7 @@
#include "nsIRunnable.h" #include "nsIRunnable.h"
#include "jsapi.h" #include "jsapi.h"
#include "jsutil.h"
#include "nsAutoJSValHolder.h" #include "nsAutoJSValHolder.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
@ -210,17 +211,18 @@ public:
NS_DECL_NSIWORKERMESSAGEEVENT NS_DECL_NSIWORKERMESSAGEEVENT
NS_DECL_NSICLASSINFO_GETINTERFACES NS_DECL_NSICLASSINFO_GETINTERFACES
nsDOMWorkerMessageEvent() : mDataValWasReparented(PR_FALSE) { } nsDOMWorkerMessageEvent() : mData(nsnull) { }
nsresult SetJSVal(JSContext* aCx, nsresult SetJSData(JSContext* aCx,
jsval aData); JSAutoStructuredCloneBuffer& aBuffer);
protected: protected:
nsString mOrigin; nsString mOrigin;
nsCOMPtr<nsISupports> mSource; nsCOMPtr<nsISupports> mSource;
nsAutoJSValHolder mDataVal; nsAutoJSValHolder mDataVal;
PRBool mDataValWasReparented; uint64* mData;
size_t mDataLen;
}; };
class nsDOMWorkerProgressEvent : public nsDOMWorkerEvent, class nsDOMWorkerProgressEvent : public nsDOMWorkerEvent,
@ -269,11 +271,6 @@ protected:
nsAutoRefCnt mRefCnt; nsAutoRefCnt mRefCnt;
}; };
enum SnapshotChoice {
WANT_SNAPSHOT,
NO_SNAPSHOT
};
class nsDOMWorkerXHREvent : public nsDOMWorkerProgressEvent, class nsDOMWorkerXHREvent : public nsDOMWorkerProgressEvent,
public nsIRunnable public nsIRunnable
{ {