Bug 797806 - Helper method to handle stringified JSON in C++, part2, r=khuey
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Tue, 16 Oct 2012 18:37:44 +0300
changeset 110514 5a707ebc03294847732922f6b4d2b8a0560d56e8
parent 110513 b3d5c1bcf8470f13703aca76c7890ac7abd8df4e
child 110515 be64e9425b0b7b1c7da1051853037f85c3654b34
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewerskhuey
bugs797806
milestone19.0a1
Bug 797806 - Helper method to handle stringified JSON in C++, part2, r=khuey
dom/bindings/BindingUtils.cpp
dom/bindings/Codegen.py
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -746,16 +746,19 @@ MainThreadDictionaryBase::ParseJSON(cons
                                     mozilla::Maybe<JSAutoCompartment>& aAc,
                                     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);
+  if (aJSON.IsEmpty()) {
+    return cx;
+  }
   if (!JS_ParseJSON(cx,
                     static_cast<const jschar*>(PromiseFlatString(aJSON).get()),
                     aJSON.Length(), &aVal)) {
     return nullptr;
   }
   return cx;
 }
 
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -5400,19 +5400,16 @@ class CGDictionary(CGThing):
 
         return (string.Template(
                 "struct ${selfName} ${inheritance}{\n"
                 "  ${selfName}() {}\n"
                 "  bool Init(JSContext* cx, const JS::Value& val);\n"
                 "  \n" +
                 ("  bool Init(const nsAString& aJSON)\n"
                  "  {\n"
-                 "    if (aJSON.IsEmpty()) {\n"
-                 "      return true;\n"
-                 "    }\n"
                  "    mozilla::Maybe<JSAutoRequest> ar;\n"
                  "    mozilla::Maybe<JSAutoCompartment> ac;\n"
                  "    jsval json = JSVAL_VOID;\n"
                  "    JSContext* cx = ParseJSON(aJSON, ar, ac, json);\n"
                  "    NS_ENSURE_TRUE(cx, false);\n"
                  "    return Init(cx, json);\n"
                  "  }\n" if not self.workers else "") +
                 "\n" +