Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[embedlite] Fix async/sync message handling. Fixes JB#49818
  • Loading branch information
rainemak committed May 11, 2020
1 parent 4651ac5 commit efd8bc4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
3 changes: 1 addition & 2 deletions embedding/embedlite/modules/EmbedLiteJSON.cpp
Expand Up @@ -53,8 +53,7 @@ bool
EmbedLiteJSON::JSONCreator(const char16_t* aBuf, uint32_t aLen, void* aData)
{
nsAString* result = static_cast<nsAString*>(aData);
result->Append(static_cast<const char16_t*>(aBuf),
static_cast<uint32_t>(aLen));
result->Append(aBuf, aLen);
return true;
}

Expand Down
30 changes: 16 additions & 14 deletions embedding/embedlite/utils/TabChildHelper.cpp
Expand Up @@ -328,12 +328,14 @@ TabChildHelper::DoSendBlockingMessage(JSContext* aCx,
JSAutoRequest ar(aCx);

// FIXME: Need callback interface for simple JSON to avoid useless conversion here
bool hasData = (aData.DataLength() > 0);
JS::Rooted<JS::Value> rval(aCx, JS::NullValue());
JSAutoStructuredCloneBuffer cloneBuffer(JS::StructuredCloneScope::Unassigned, nullptr, nullptr);
cloneBuffer.steal(&aData.Data());

if (hasData && !cloneBuffer.read(aCx, &rval)) {
JS::RootedValue rval(aCx);
JS::StructuredCloneScope scope = JS::StructuredCloneScope::SameProcessSameThread;

if (aData.DataLength() > 0 && !JS_ReadStructuredClone(aCx, aData.Data(),
JS_STRUCTURED_CLONE_VERSION,
scope,
&rval,
nullptr, nullptr)) {
JS_ClearPendingException(aCx);
return false;
}
Expand Down Expand Up @@ -400,14 +402,14 @@ nsresult TabChildHelper::DoSendAsyncMessage(JSContext* aCx,
}

JSAutoRequest ar(aCx);

// FIXME: Need callback interface for simple JSON to avoid useless conversion here
bool hasData = (aData.DataLength() > 0);
JS::Rooted<JS::Value> rval(aCx, JS::NullValue());
JSAutoStructuredCloneBuffer cloneBuffer(JS::StructuredCloneScope::Unassigned, nullptr, nullptr);
cloneBuffer.steal(&aData.Data());

if (hasData && !cloneBuffer.read(aCx, &rval)) {
JS::RootedValue rval(aCx);
JS::StructuredCloneScope scope = JS::StructuredCloneScope::SameProcessSameThread;

if (aData.DataLength() > 0 && !JS_ReadStructuredClone(aCx, aData.Data(),
JS_STRUCTURED_CLONE_VERSION,
scope,
&rval,
nullptr, nullptr)) {
JS_ClearPendingException(aCx);
return NS_ERROR_UNEXPECTED;
}
Expand Down

0 comments on commit efd8bc4

Please sign in to comment.