2011-11-03 13:39:08 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2011-11-03 13:39:08 -07:00
|
|
|
|
|
|
|
#include "nsXBLSerialize.h"
|
|
|
|
#include "nsDOMScriptObjectHolder.h"
|
|
|
|
#include "nsContentUtils.h"
|
2012-12-19 17:12:33 -08:00
|
|
|
#include "jsdbgapi.h"
|
2011-11-03 13:39:08 -07:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
XBL_SerializeFunction(nsIScriptContext* aContext,
|
|
|
|
nsIObjectOutputStream* aStream,
|
2011-11-03 13:39:08 -07:00
|
|
|
JSObject* aFunctionObject)
|
2011-11-03 13:39:08 -07:00
|
|
|
{
|
2011-11-15 23:50:18 -08:00
|
|
|
JSContext* cx = aContext->GetNativeContext();
|
2012-02-13 05:10:04 -08:00
|
|
|
return nsContentUtils::XPConnect()->WriteFunction(aStream, cx, aFunctionObject);
|
2011-11-03 13:39:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
XBL_DeserializeFunction(nsIScriptContext* aContext,
|
|
|
|
nsIObjectInputStream* aStream,
|
2012-02-13 05:10:04 -08:00
|
|
|
JSObject** aFunctionObjectp)
|
2011-11-03 13:39:08 -07:00
|
|
|
{
|
2011-11-15 23:50:18 -08:00
|
|
|
JSContext* cx = aContext->GetNativeContext();
|
2012-12-19 17:12:33 -08:00
|
|
|
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;
|
2011-11-03 13:39:08 -07:00
|
|
|
}
|