Bug 1130031 - Better serialization for non-transferable objects from workers to main-thread in the console API, r=sfink

This commit is contained in:
Andrea Marchesini 2015-02-05 18:50:43 +00:00
Родитель c83256046f
Коммит f53ff9249c
3 изменённых файлов: 12 добавлений и 27 удалений

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

@ -45,8 +45,7 @@
// This tags are used in the Structured Clone Algorithm to move js values from
// worker thread to main thread
#define CONSOLE_TAG_STRING JS_SCTAG_USER_MIN
#define CONSOLE_TAG_BLOB JS_SCTAG_USER_MIN + 1
#define CONSOLE_TAG_BLOB JS_SCTAG_USER_MIN
using namespace mozilla::dom::exceptions;
using namespace mozilla::dom::workers;
@ -58,7 +57,6 @@ struct
ConsoleStructuredCloneData
{
nsCOMPtr<nsISupports> mParent;
nsTArray<nsString> mStrings;
nsTArray<nsRefPtr<FileImpl>> mFiles;
};
@ -82,22 +80,6 @@ ConsoleStructuredCloneCallbacksRead(JSContext* aCx,
static_cast<ConsoleStructuredCloneData*>(aClosure);
MOZ_ASSERT(data);
if (aTag == CONSOLE_TAG_STRING) {
MOZ_ASSERT(data->mStrings.Length() > aIndex);
JS::Rooted<JS::Value> value(aCx);
if (!xpc::StringToJsval(aCx, data->mStrings.ElementAt(aIndex), &value)) {
return nullptr;
}
JS::Rooted<JSObject*> obj(aCx);
if (!JS_ValueToObject(aCx, value, &obj)) {
return nullptr;
}
return obj;
}
if (aTag == CONSOLE_TAG_BLOB) {
MOZ_ASSERT(data->mFiles.Length() > aIndex);
@ -146,17 +128,10 @@ ConsoleStructuredCloneCallbacksWrite(JSContext* aCx,
return false;
}
nsAutoJSString string;
if (!string.init(aCx, jsString)) {
if (!JS_WriteString(aWriter, jsString)) {
return false;
}
if (!JS_WriteUint32Pair(aWriter, CONSOLE_TAG_STRING,
data->mStrings.Length())) {
return false;
}
data->mStrings.AppendElement(string);
return true;
}

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

@ -239,6 +239,9 @@ JS_WriteUint32Pair(JSStructuredCloneWriter *w, uint32_t tag, uint32_t data);
JS_PUBLIC_API(bool)
JS_WriteBytes(JSStructuredCloneWriter *w, const void *p, size_t len);
JS_PUBLIC_API(bool)
JS_WriteString(JSStructuredCloneWriter *w, JS::HandleString str);
JS_PUBLIC_API(bool)
JS_WriteTypedArray(JSStructuredCloneWriter *w, JS::HandleValue v);

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

@ -335,6 +335,7 @@ struct JSStructuredCloneWriter {
RootedValue transferable;
AutoObjectVector transferableObjects;
friend bool JS_WriteString(JSStructuredCloneWriter *w, HandleString str);
friend bool JS_WriteTypedArray(JSStructuredCloneWriter *w, HandleValue v);
};
@ -2130,6 +2131,12 @@ JS_WriteBytes(JSStructuredCloneWriter *w, const void *p, size_t len)
return w->output().writeBytes(p, len);
}
JS_PUBLIC_API(bool)
JS_WriteString(JSStructuredCloneWriter *w, HandleString str)
{
return w->writeString(SCTAG_STRING, str);
}
JS_PUBLIC_API(bool)
JS_WriteTypedArray(JSStructuredCloneWriter *w, HandleValue v)
{