Bug 860473 part 1. Root WebIDL dictionary ParseJSON. r=evilpie, smaug

This commit is contained in:
Boris Zbarsky 2013-04-11 14:31:05 -04:00
parent 2dca5a07b2
commit 3987fa669a
3 changed files with 12 additions and 11 deletions

View File

@ -34,9 +34,9 @@ struct MainThreadDictionaryBase
{
protected:
JSContext* ParseJSON(const nsAString& aJSON,
mozilla::Maybe<JSAutoRequest>& aAr,
mozilla::Maybe<JSAutoCompartment>& aAc,
JS::Value& aVal);
Maybe<JSAutoRequest>& aAr,
Maybe<JSAutoCompartment>& aAc,
Maybe< JS::Rooted<JS::Value> >& aVal);
};
struct EnumEntry {

View File

@ -1307,21 +1307,22 @@ SetXrayExpandoChain(JSObject* obj, JSObject* chain)
JSContext*
MainThreadDictionaryBase::ParseJSON(const nsAString& aJSON,
mozilla::Maybe<JSAutoRequest>& aAr,
mozilla::Maybe<JSAutoCompartment>& aAc,
JS::Value& aVal)
Maybe<JSAutoRequest>& aAr,
Maybe<JSAutoCompartment>& aAc,
Maybe< JS::Rooted<JS::Value> >& aVal)
{
JSContext* cx = nsContentUtils::ThreadJSContextStack()->GetSafeJSContext();
NS_ENSURE_TRUE(cx, nullptr);
JSObject* global = JS_GetGlobalObject(cx);
aAr.construct(cx);
aAc.construct(cx, global);
aVal.construct(cx, JS::UndefinedValue());
if (aJSON.IsEmpty()) {
return cx;
}
if (!JS_ParseJSON(cx,
static_cast<const jschar*>(PromiseFlatString(aJSON).get()),
aJSON.Length(), &aVal)) {
aJSON.Length(), aVal.ref().address())) {
return nullptr;
}
return cx;

View File

@ -6817,12 +6817,12 @@ class CGDictionary(CGThing):
"\n" +
(" bool Init(const nsAString& aJSON)\n"
" {\n"
" mozilla::Maybe<JSAutoRequest> ar;\n"
" mozilla::Maybe<JSAutoCompartment> ac;\n"
" jsval json = JSVAL_VOID;\n"
" Maybe<JSAutoRequest> ar;\n"
" Maybe<JSAutoCompartment> ac;\n"
" Maybe< JS::Rooted<JS::Value> > json;\n"
" JSContext* cx = ParseJSON(aJSON, ar, ac, json);\n"
" NS_ENSURE_TRUE(cx, false);\n"
" return Init(cx, nullptr, json);\n"
" return Init(cx, nullptr, json.ref());\n"
" }\n" if not self.workers else "") +
"\n" +
"\n".join(memberDecls) + "\n"