зеркало из https://github.com/mozilla/gecko-dev.git
Bug 580128 - Make IndexedDB work with compartments. r=jst
This commit is contained in:
Родитель
e036314b75
Коммит
1bea2a0e1e
|
@ -465,6 +465,8 @@ IDBCursor::Update(const jsval &aValue,
|
|||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
nsresult rv;
|
||||
|
||||
if (mType != OBJECTSTORE) {
|
||||
NS_NOTYETIMPLEMENTED("Implement me!");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
@ -483,12 +485,7 @@ IDBCursor::Update(const jsval &aValue,
|
|||
|
||||
JSAutoRequest ar(aCx);
|
||||
|
||||
js::AutoValueRooter clone(aCx);
|
||||
nsresult rv = nsContentUtils::CreateStructuredClone(aCx, aValue,
|
||||
clone.jsval_addr());
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
js::AutoValueRooter clone(aCx, aValue);
|
||||
|
||||
if (!mObjectStore->KeyPath().IsEmpty()) {
|
||||
// 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());
|
||||
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()),
|
||||
keyPathChars, keyPathLen, prop.jsval_value(), nsnull,
|
||||
nsnull, JSPROP_ENUMERATE);
|
||||
|
|
|
@ -497,15 +497,9 @@ IDBObjectStore::GetJSONFromArg0(/* jsval arg0, */
|
|||
|
||||
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());
|
||||
|
||||
rv = json->EncodeFromJSVal(clone.jsval_addr(), cx, aJSON);
|
||||
rv = json->EncodeFromJSVal(&argv[0], cx, aJSON);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NS_OK;
|
||||
|
@ -775,14 +769,9 @@ IDBObjectStore::GetAddInfo(JSContext* aCx,
|
|||
Key& aKey,
|
||||
nsTArray<IndexUpdateInfo>& aUpdateInfoArray)
|
||||
{
|
||||
JSAutoRequest ar(aCx);
|
||||
nsresult rv;
|
||||
|
||||
js::AutoValueRooter clone(aCx);
|
||||
nsresult rv = nsContentUtils::CreateStructuredClone(aCx, aValue,
|
||||
clone.jsval_addr());
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
JSAutoRequest ar(aCx);
|
||||
|
||||
if (mKeyPath.IsEmpty()) {
|
||||
rv = GetKeyFromJSVal(aKeyVal, aKey);
|
||||
|
@ -790,11 +779,11 @@ IDBObjectStore::GetAddInfo(JSContext* aCx,
|
|||
}
|
||||
else {
|
||||
// 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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// 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();
|
||||
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);
|
||||
|
||||
nsCOMPtr<nsIJSON> json(new nsJSON());
|
||||
rv = json->EncodeFromJSVal(clone.jsval_addr(), aCx, aJSON);
|
||||
rv = json->EncodeFromJSVal(&aValue, aCx, aJSON);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -1539,14 +1539,11 @@ nsDOMWorker::PostMessageInternal(PRBool aToInner)
|
|||
|
||||
JSAutoRequest ar(cx);
|
||||
|
||||
nsAutoJSValHolder val;
|
||||
if (!val.Hold(cx)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSAutoStructuredCloneBuffer buffer(cx);
|
||||
|
||||
rv = nsContentUtils::CreateStructuredClone(cx, argv[0], val.ToJSValPtr());
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
if (!buffer.write(argv[0])) {
|
||||
NS_WARNING("Failed to serialize!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsRefPtr<nsDOMWorkerMessageEvent> message = new nsDOMWorkerMessageEvent();
|
||||
|
@ -1557,7 +1554,7 @@ nsDOMWorker::PostMessageInternal(PRBool aToInner)
|
|||
nsnull);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = message->SetJSVal(cx, val);
|
||||
rv = message->SetJSData(cx, buffer);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsRefPtr<nsDOMFireEventRunnable> runnable =
|
||||
|
|
|
@ -264,15 +264,17 @@ NS_IMPL_CI_INTERFACE_GETTER2(nsDOMWorkerMessageEvent, nsIDOMEvent,
|
|||
NS_IMPL_THREADSAFE_DOM_CI_GETINTERFACES(nsDOMWorkerMessageEvent)
|
||||
|
||||
nsresult
|
||||
nsDOMWorkerMessageEvent::SetJSVal(JSContext* aCx,
|
||||
jsval aData)
|
||||
nsDOMWorkerMessageEvent::SetJSData(JSContext* aCx,
|
||||
JSAutoStructuredCloneBuffer& aBuffer)
|
||||
{
|
||||
NS_ASSERTION(aCx, "Null context!");
|
||||
|
||||
if (!mDataVal.Hold(aCx)) {
|
||||
NS_WARNING("Failed to hold jsval!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
mDataVal = aData;
|
||||
aBuffer.steal(&mData, &mDataLen);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -287,19 +289,21 @@ nsDOMWorkerMessageEvent::GetData(nsAString& aData)
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(cc, NS_ERROR_UNEXPECTED);
|
||||
|
||||
if (!mDataValWasReparented) {
|
||||
if (JSVAL_IS_OBJECT(mDataVal) && !JSVAL_IS_NULL(mDataVal)) {
|
||||
JSContext* cx;
|
||||
rv = cc->GetJSContext(&cx);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (mData) {
|
||||
JSContext* cx;
|
||||
rv = cc->GetJSContext(&cx);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv =
|
||||
nsContentUtils::ReparentClonedObjectToScope(cx,
|
||||
JSVAL_TO_OBJECT(mDataVal),
|
||||
JS_GetGlobalObject(cx));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
JSAutoRequest ar(cx);
|
||||
JSAutoStructuredCloneBuffer buffer(cx);
|
||||
buffer.adopt(mData, mDataLen);
|
||||
mData = nsnull;
|
||||
mDataLen = 0;
|
||||
|
||||
if (!buffer.read(mDataVal.ToJSValPtr())) {
|
||||
NS_WARNING("Failed to deserialize!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
mDataValWasReparented = PR_TRUE;
|
||||
}
|
||||
|
||||
jsval* retval;
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#include "nsIRunnable.h"
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "jsutil.h"
|
||||
#include "nsAutoJSValHolder.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
@ -210,17 +211,18 @@ public:
|
|||
NS_DECL_NSIWORKERMESSAGEEVENT
|
||||
NS_DECL_NSICLASSINFO_GETINTERFACES
|
||||
|
||||
nsDOMWorkerMessageEvent() : mDataValWasReparented(PR_FALSE) { }
|
||||
nsDOMWorkerMessageEvent() : mData(nsnull) { }
|
||||
|
||||
nsresult SetJSVal(JSContext* aCx,
|
||||
jsval aData);
|
||||
nsresult SetJSData(JSContext* aCx,
|
||||
JSAutoStructuredCloneBuffer& aBuffer);
|
||||
|
||||
protected:
|
||||
nsString mOrigin;
|
||||
nsCOMPtr<nsISupports> mSource;
|
||||
|
||||
nsAutoJSValHolder mDataVal;
|
||||
PRBool mDataValWasReparented;
|
||||
uint64* mData;
|
||||
size_t mDataLen;
|
||||
};
|
||||
|
||||
class nsDOMWorkerProgressEvent : public nsDOMWorkerEvent,
|
||||
|
@ -269,11 +271,6 @@ protected:
|
|||
nsAutoRefCnt mRefCnt;
|
||||
};
|
||||
|
||||
enum SnapshotChoice {
|
||||
WANT_SNAPSHOT,
|
||||
NO_SNAPSHOT
|
||||
};
|
||||
|
||||
class nsDOMWorkerXHREvent : public nsDOMWorkerProgressEvent,
|
||||
public nsIRunnable
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче