Bug 823279 - Mark deserialized XBL script as XBL. r=bz
authorBobby Holley <bobbyholley@gmail.com>
Wed, 19 Dec 2012 17:12:33 -0800
changeset 116579 9c5effe633f0de18246b787fb43aedddfc302714
parent 116578 5f697a87ec466d96daffc0b515147e5adf91ccfa
child 116580 20cb0fa34108f6f7a25679041f5487daa6a0bec1
push idunknown
push userunknown
push dateunknown
reviewersbz
bugs823279
milestone20.0a1
Bug 823279 - Mark deserialized XBL script as XBL. r=bz
content/xbl/src/nsXBLSerialize.cpp
--- a/content/xbl/src/nsXBLSerialize.cpp
+++ b/content/xbl/src/nsXBLSerialize.cpp
@@ -1,26 +1,39 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsXBLSerialize.h"
 #include "nsDOMScriptObjectHolder.h"
 #include "nsContentUtils.h"
+#include "jsdbgapi.h"
 
 nsresult
 XBL_SerializeFunction(nsIScriptContext* aContext,
                       nsIObjectOutputStream* aStream,
                       JSObject* aFunctionObject)
 {
   JSContext* cx = aContext->GetNativeContext();
   return nsContentUtils::XPConnect()->WriteFunction(aStream, cx, aFunctionObject);
 }
 
 nsresult
 XBL_DeserializeFunction(nsIScriptContext* aContext,
                         nsIObjectInputStream* aStream,
                         JSObject** aFunctionObjectp)
 {
   JSContext* cx = aContext->GetNativeContext();
-  return nsContentUtils::XPConnect()->ReadFunction(aStream, cx, aFunctionObjectp);
+  nsresult rv = nsContentUtils::XPConnect()->ReadFunction(aStream, cx, aFunctionObjectp);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  // Mark the script as XBL.
+  //
+  // This might be more elegantly handled as a flag via the XPConnect serialization
+  // code, but that would involve profile compat issues between different builds.
+  // Given that we know this code is XBL, just flag it as such.
+  JSAutoRequest ar(cx);
+  JSFunction* fun = JS_ValueToFunction(cx, JS::ObjectValue(**aFunctionObjectp));
+  NS_ENSURE_TRUE(fun, NS_ERROR_UNEXPECTED);
+  JS_SetScriptUserBit(JS_GetFunctionScript(cx, fun), true);
+  return NS_OK;
 }