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 110382 5a707ebc03294847732922f6b4d2b8a0560d56e8
parent 110381 b3d5c1bcf8470f13703aca76c7890ac7abd8df4e
child 110383 be64e9425b0b7b1c7da1051853037f85c3654b34
push id23682
push useropettay@mozilla.com
push dateTue, 16 Oct 2012 16:11:00 +0000
treeherdermozilla-central@5a707ebc0329 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs797806
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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" +