2011-11-03 20:39:08 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 11:12:37 +00: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 20:39:08 +00:00
|
|
|
|
|
|
|
#include "nsXBLSerialize.h"
|
2013-03-20 20:09:09 +00:00
|
|
|
#include "nsIXPConnect.h"
|
2011-11-03 20:39:08 +00:00
|
|
|
#include "nsContentUtils.h"
|
2012-12-20 01:12:33 +00:00
|
|
|
#include "jsdbgapi.h"
|
2011-11-03 20:39:08 +00:00
|
|
|
|
2013-02-26 19:04:13 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2011-11-03 20:39:08 +00:00
|
|
|
nsresult
|
|
|
|
XBL_SerializeFunction(nsIScriptContext* aContext,
|
|
|
|
nsIObjectOutputStream* aStream,
|
2013-05-20 12:40:06 +00:00
|
|
|
JS::Handle<JSObject*> aFunction)
|
2011-11-03 20:39:08 +00:00
|
|
|
{
|
2013-02-26 19:04:13 +00:00
|
|
|
AutoPushJSContext cx(aContext->GetNativeContext());
|
2013-05-20 12:40:06 +00:00
|
|
|
return nsContentUtils::XPConnect()->WriteFunction(aStream, cx, aFunction);
|
2011-11-03 20:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
XBL_DeserializeFunction(nsIScriptContext* aContext,
|
|
|
|
nsIObjectInputStream* aStream,
|
2013-04-05 13:21:03 +00:00
|
|
|
JS::MutableHandle<JSObject*> aFunctionObjectp)
|
2011-11-03 20:39:08 +00:00
|
|
|
{
|
2013-02-26 19:04:13 +00:00
|
|
|
AutoPushJSContext cx(aContext->GetNativeContext());
|
2013-04-05 13:21:03 +00:00
|
|
|
nsresult rv = nsContentUtils::XPConnect()->ReadFunction(aStream, cx,
|
|
|
|
aFunctionObjectp.address());
|
2012-12-20 01:12:33 +00:00
|
|
|
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);
|
2013-04-05 13:21:03 +00:00
|
|
|
JSFunction* fun = JS_ValueToFunction(cx, JS::ObjectValue(*aFunctionObjectp));
|
2012-12-20 01:12:33 +00:00
|
|
|
NS_ENSURE_TRUE(fun, NS_ERROR_UNEXPECTED);
|
|
|
|
JS_SetScriptUserBit(JS_GetFunctionScript(cx, fun), true);
|
|
|
|
return NS_OK;
|
2011-11-03 20:39:08 +00:00
|
|
|
}
|