2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "jsapi.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsXBLProtoImplMethod.h"
|
|
|
|
#include "nsIScriptContext.h"
|
2013-01-16 18:50:25 -08:00
|
|
|
#include "nsJSUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsContentUtils.h"
|
2013-05-22 09:05:26 -07:00
|
|
|
#include "nsCxPusher.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsIXPConnect.h"
|
2013-02-08 06:24:22 -08:00
|
|
|
#include "xpcpublic.h"
|
2011-11-03 13:39:08 -07:00
|
|
|
#include "nsXBLPrototypeBinding.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-26 11:04:13 -08:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
nsXBLProtoImplMethod::nsXBLProtoImplMethod(const char16_t* aName) :
|
2013-06-18 03:00:38 -07:00
|
|
|
nsXBLProtoImplMember(aName),
|
|
|
|
mMethod()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsXBLProtoImplMethod);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLProtoImplMethod::~nsXBLProtoImplMethod()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsXBLProtoImplMethod);
|
|
|
|
|
2008-02-12 08:02:41 -08:00
|
|
|
if (!IsCompiled()) {
|
|
|
|
delete GetUncompiledMethod();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-12 23:38:36 -08:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLProtoImplMethod::AppendBodyText(const nsAString& aText)
|
|
|
|
{
|
2008-02-12 08:02:41 -08:00
|
|
|
NS_PRECONDITION(!IsCompiled(),
|
2007-03-22 10:30:00 -07:00
|
|
|
"Must not be compiled when accessing uncompiled method");
|
2008-02-12 08:02:41 -08:00
|
|
|
|
|
|
|
nsXBLUncompiledMethod* uncompiledMethod = GetUncompiledMethod();
|
|
|
|
if (!uncompiledMethod) {
|
|
|
|
uncompiledMethod = new nsXBLUncompiledMethod();
|
|
|
|
if (!uncompiledMethod)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
2008-02-12 08:02:41 -08:00
|
|
|
SetUncompiledMethod(uncompiledMethod);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-02-12 08:02:41 -08:00
|
|
|
uncompiledMethod->AppendBodyText(aText);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-02-12 23:38:36 -08:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLProtoImplMethod::AddParameter(const nsAString& aText)
|
|
|
|
{
|
2008-02-12 08:02:41 -08:00
|
|
|
NS_PRECONDITION(!IsCompiled(),
|
2007-03-22 10:30:00 -07:00
|
|
|
"Must not be compiled when accessing uncompiled method");
|
2008-02-12 08:02:41 -08:00
|
|
|
|
2012-08-01 23:12:34 -07:00
|
|
|
if (aText.IsEmpty()) {
|
|
|
|
NS_WARNING("Empty name attribute in xbl:parameter!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-12 08:02:41 -08:00
|
|
|
nsXBLUncompiledMethod* uncompiledMethod = GetUncompiledMethod();
|
|
|
|
if (!uncompiledMethod) {
|
|
|
|
uncompiledMethod = new nsXBLUncompiledMethod();
|
|
|
|
if (!uncompiledMethod)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
2008-02-12 08:02:41 -08:00
|
|
|
SetUncompiledMethod(uncompiledMethod);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-02-12 08:02:41 -08:00
|
|
|
uncompiledMethod->AddParameter(aText);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXBLProtoImplMethod::SetLineNumber(uint32_t aLineNumber)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-12 08:02:41 -08:00
|
|
|
NS_PRECONDITION(!IsCompiled(),
|
2007-03-22 10:30:00 -07:00
|
|
|
"Must not be compiled when accessing uncompiled method");
|
2008-02-12 08:02:41 -08:00
|
|
|
|
|
|
|
nsXBLUncompiledMethod* uncompiledMethod = GetUncompiledMethod();
|
|
|
|
if (!uncompiledMethod) {
|
|
|
|
uncompiledMethod = new nsXBLUncompiledMethod();
|
|
|
|
if (!uncompiledMethod)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
2008-02-12 08:02:41 -08:00
|
|
|
SetUncompiledMethod(uncompiledMethod);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-02-12 08:02:41 -08:00
|
|
|
uncompiledMethod->SetLineNumber(aLineNumber);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-02-08 06:24:21 -08:00
|
|
|
nsXBLProtoImplMethod::InstallMember(JSContext* aCx,
|
2013-04-05 06:21:02 -07:00
|
|
|
JS::Handle<JSObject*> aTargetClassObject)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-12 08:02:41 -08:00
|
|
|
NS_PRECONDITION(IsCompiled(),
|
2007-03-22 10:30:00 -07:00
|
|
|
"Should not be installing an uncompiled method");
|
2013-02-08 06:24:21 -08:00
|
|
|
MOZ_ASSERT(js::IsObjectInContextCompartment(aTargetClassObject, aCx));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-04-05 06:21:02 -07:00
|
|
|
JS::Rooted<JSObject*> globalObject(aCx, JS_GetGlobalForObject(aCx, aTargetClassObject));
|
2013-11-01 07:31:57 -07:00
|
|
|
MOZ_ASSERT(xpc::IsInXBLScope(globalObject) ||
|
|
|
|
globalObject == xpc::GetXBLScope(aCx, globalObject));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-06-18 03:00:38 -07:00
|
|
|
JS::Rooted<JSObject*> jsMethodObject(aCx, GetCompiledMethod());
|
|
|
|
if (jsMethodObject) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsDependentString name(mName);
|
2010-09-22 17:34:20 -07:00
|
|
|
|
2013-11-01 07:31:57 -07:00
|
|
|
JS::Rooted<JSObject*> method(aCx, JS_CloneFunctionObject(aCx, jsMethodObject, globalObject));
|
|
|
|
NS_ENSURE_TRUE(method, NS_ERROR_OUT_OF_MEMORY);
|
2013-04-05 06:21:02 -07:00
|
|
|
|
|
|
|
if (!::JS_DefineUCProperty(aCx, aTargetClassObject,
|
2012-05-05 02:00:06 -07:00
|
|
|
static_cast<const jschar*>(mName),
|
2014-04-30 02:10:33 -07:00
|
|
|
name.Length(), method,
|
|
|
|
JSPROP_ENUMERATE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-12 23:38:36 -08:00
|
|
|
nsresult
|
2013-08-09 09:25:13 -07:00
|
|
|
nsXBLProtoImplMethod::CompileMember(const nsCString& aClassStr,
|
2013-04-05 06:21:02 -07:00
|
|
|
JS::Handle<JSObject*> aClassObject)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-08-09 09:25:13 -07:00
|
|
|
AssertInCompilationScope();
|
2008-02-12 08:02:41 -08:00
|
|
|
NS_PRECONDITION(!IsCompiled(),
|
2007-03-22 10:30:00 -07:00
|
|
|
"Trying to compile an already-compiled method");
|
|
|
|
NS_PRECONDITION(aClassObject,
|
|
|
|
"Must have class object to compile");
|
|
|
|
|
2008-02-12 08:02:41 -08:00
|
|
|
nsXBLUncompiledMethod* uncompiledMethod = GetUncompiledMethod();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// No parameters or body was supplied, so don't install method.
|
2008-02-12 08:02:41 -08:00
|
|
|
if (!uncompiledMethod) {
|
|
|
|
// Early return after which we consider ourselves compiled.
|
2013-06-18 03:00:38 -07:00
|
|
|
SetCompiledMethod(nullptr);
|
2008-02-12 08:02:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
2008-02-12 08:02:41 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Don't install method if no name was supplied.
|
|
|
|
if (!mName) {
|
2008-02-12 08:02:41 -08:00
|
|
|
delete uncompiledMethod;
|
|
|
|
|
|
|
|
// Early return after which we consider ourselves compiled.
|
2013-06-18 03:00:38 -07:00
|
|
|
SetCompiledMethod(nullptr);
|
2008-02-12 08:02:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have a method.
|
|
|
|
// Allocate an array for our arguments.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t paramCount = uncompiledMethod->GetParameterCount();
|
2012-07-30 07:20:58 -07:00
|
|
|
char** args = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (paramCount > 0) {
|
|
|
|
args = new char*[paramCount];
|
|
|
|
if (!args)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2009-08-12 02:49:52 -07:00
|
|
|
// Add our parameters to our args array.
|
2014-02-12 23:38:36 -08:00
|
|
|
int32_t argPos = 0;
|
|
|
|
for (nsXBLParameter* curr = uncompiledMethod->mParameters;
|
|
|
|
curr;
|
2009-08-12 02:49:52 -07:00
|
|
|
curr = curr->mNext) {
|
|
|
|
args[argPos] = curr->mName;
|
|
|
|
argPos++;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the body
|
|
|
|
nsDependentString body;
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t *bodyText = uncompiledMethod->mBodyText.GetText();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (bodyText)
|
|
|
|
body.Rebind(bodyText);
|
|
|
|
|
|
|
|
// Now that we have a body and args, compile the function
|
|
|
|
// and then define it.
|
|
|
|
NS_ConvertUTF16toUTF8 cname(mName);
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString functionUri(aClassStr);
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t hash = functionUri.RFindChar('#');
|
2007-03-22 10:30:00 -07:00
|
|
|
if (hash != kNotFound) {
|
|
|
|
functionUri.Truncate(hash);
|
|
|
|
}
|
|
|
|
|
2013-08-09 09:25:13 -07:00
|
|
|
AutoJSContext cx;
|
2013-01-16 18:50:25 -08:00
|
|
|
JSAutoCompartment ac(cx, aClassObject);
|
|
|
|
JS::CompileOptions options(cx);
|
|
|
|
options.setFileAndLine(functionUri.get(),
|
|
|
|
uncompiledMethod->mBodyText.GetLineNumber())
|
2013-05-20 21:34:17 -07:00
|
|
|
.setVersion(JSVERSION_LATEST);
|
2013-11-11 00:04:41 -08:00
|
|
|
JS::Rooted<JSObject*> methodObject(cx);
|
|
|
|
nsresult rv = nsJSUtils::CompileFunction(cx, JS::NullPtr(), options, cname,
|
2013-01-16 18:50:25 -08:00
|
|
|
paramCount,
|
|
|
|
const_cast<const char**>(args),
|
2013-04-05 06:21:02 -07:00
|
|
|
body, methodObject.address());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Destroy our uncompiled method and delete our arg list.
|
2008-02-12 08:02:41 -08:00
|
|
|
delete uncompiledMethod;
|
2007-03-22 10:30:00 -07:00
|
|
|
delete [] args;
|
|
|
|
if (NS_FAILED(rv)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
SetUncompiledMethod(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-06-18 03:00:38 -07:00
|
|
|
SetCompiledMethod(methodObject);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-12 08:02:41 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-05-24 07:10:02 -07:00
|
|
|
void
|
2013-05-27 04:50:49 -07:00
|
|
|
nsXBLProtoImplMethod::Trace(const TraceCallbacks& aCallbacks, void *aClosure)
|
2007-05-24 07:10:02 -07:00
|
|
|
{
|
2013-11-21 13:19:46 -08:00
|
|
|
if (IsCompiled() && GetCompiledMethodPreserveColor()) {
|
2013-06-18 03:00:38 -07:00
|
|
|
aCallbacks.Trace(&mMethod.AsHeapObject(), "mMethod", aClosure);
|
2007-10-29 06:45:07 -07:00
|
|
|
}
|
2007-05-24 07:10:02 -07:00
|
|
|
}
|
|
|
|
|
2011-11-03 13:39:08 -07:00
|
|
|
nsresult
|
2013-08-09 09:25:13 -07:00
|
|
|
nsXBLProtoImplMethod::Read(nsIObjectInputStream* aStream)
|
2011-11-03 13:39:08 -07:00
|
|
|
{
|
2013-08-09 09:25:13 -07:00
|
|
|
AssertInCompilationScope();
|
2013-07-23 02:58:28 -07:00
|
|
|
MOZ_ASSERT(!IsCompiled() && !GetUncompiledMethod());
|
|
|
|
|
2013-08-09 09:25:13 -07:00
|
|
|
AutoJSContext cx;
|
2013-08-09 09:25:13 -07:00
|
|
|
JS::Rooted<JSObject*> methodObject(cx);
|
|
|
|
nsresult rv = XBL_DeserializeFunction(aStream, &methodObject);
|
2011-11-03 13:39:08 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
SetUncompiledMethod(nullptr);
|
2011-11-03 13:39:08 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-06-18 03:00:38 -07:00
|
|
|
SetCompiledMethod(methodObject);
|
2011-11-03 13:39:08 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-08-09 09:25:13 -07:00
|
|
|
nsXBLProtoImplMethod::Write(nsIObjectOutputStream* aStream)
|
2011-11-03 13:39:08 -07:00
|
|
|
{
|
2013-08-09 09:25:13 -07:00
|
|
|
AssertInCompilationScope();
|
2013-06-18 03:00:38 -07:00
|
|
|
MOZ_ASSERT(IsCompiled());
|
2013-11-21 13:19:46 -08:00
|
|
|
if (GetCompiledMethodPreserveColor()) {
|
2012-02-13 11:24:28 -08:00
|
|
|
nsresult rv = aStream->Write8(XBLBinding_Serialize_Method);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-11-03 13:39:08 -07:00
|
|
|
|
2012-02-13 11:24:28 -08:00
|
|
|
rv = aStream->WriteWStringZ(mName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-11-03 13:39:08 -07:00
|
|
|
|
2013-07-23 02:58:28 -07:00
|
|
|
// Calling fromMarkedLocation() is safe because mMethod is traced by the
|
|
|
|
// Trace() method above, and because its value is never changed after it has
|
|
|
|
// been set to a compiled method.
|
2013-07-23 02:58:27 -07:00
|
|
|
JS::Handle<JSObject*> method =
|
|
|
|
JS::Handle<JSObject*>::fromMarkedLocation(mMethod.AsHeapObject().address());
|
2013-08-09 09:25:13 -07:00
|
|
|
return XBL_SerializeFunction(aStream, method);
|
2012-02-13 11:24:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2011-11-03 13:39:08 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsXBLProtoImplAnonymousMethod::Execute(nsIContent* aBoundElement)
|
|
|
|
{
|
2008-02-12 08:02:41 -08:00
|
|
|
NS_PRECONDITION(IsCompiled(), "Can't execute uncompiled method");
|
2013-07-23 02:58:28 -07:00
|
|
|
|
2013-06-18 03:00:38 -07:00
|
|
|
if (!GetCompiledMethod()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Nothing to do here
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the script context the same way
|
|
|
|
// nsXBLProtoImpl::InstallImplementation does.
|
2011-10-18 03:53:36 -07:00
|
|
|
nsIDocument* document = aBoundElement->OwnerDoc();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-06-21 07:25:20 -07:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> global =
|
|
|
|
do_QueryInterface(document->GetWindow());
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!global) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptContext> context = global->GetContext();
|
|
|
|
if (!context) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-03-31 09:30:13 -07:00
|
|
|
|
|
|
|
nsAutoMicroTask mt;
|
|
|
|
|
2013-02-26 11:04:13 -08:00
|
|
|
AutoPushJSContext cx(context->GetNativeContext());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-04-05 06:21:02 -07:00
|
|
|
JS::Rooted<JSObject*> globalObject(cx, global->GetGlobalJSObject());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-04-05 06:21:02 -07:00
|
|
|
JS::Rooted<JS::Value> v(cx);
|
2014-04-09 21:58:41 -07:00
|
|
|
nsresult rv = nsContentUtils::WrapNative(cx, aBoundElement, &v);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-02-08 06:24:22 -08:00
|
|
|
// Use nsCxPusher to make sure we call ScriptEvaluated when we're done.
|
|
|
|
//
|
|
|
|
// Make sure to do this before entering the compartment, since pushing Push()
|
|
|
|
// may call JS_SaveFrameChain(), which puts us back in an unentered state.
|
|
|
|
nsCxPusher pusher;
|
2012-10-08 12:52:24 -07:00
|
|
|
if (!pusher.Push(aBoundElement))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2013-02-08 06:24:22 -08:00
|
|
|
MOZ_ASSERT(cx == nsContentUtils::GetCurrentJSContext());
|
|
|
|
|
2013-04-05 06:21:02 -07:00
|
|
|
JS::Rooted<JSObject*> thisObject(cx, &v.toObject());
|
2014-03-19 09:35:45 -07:00
|
|
|
JS::Rooted<JSObject*> scopeObject(cx, xpc::GetXBLScopeOrGlobal(cx, globalObject));
|
2013-04-05 12:04:09 -07:00
|
|
|
NS_ENSURE_TRUE(scopeObject, NS_ERROR_OUT_OF_MEMORY);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-08 06:24:22 -08:00
|
|
|
JSAutoCompartment ac(cx, scopeObject);
|
2013-10-15 17:02:23 -07:00
|
|
|
if (!JS_WrapObject(cx, &thisObject))
|
2013-02-08 06:24:22 -08:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Clone the function object, using thisObject as the parent so "this" is in
|
|
|
|
// the scope chain of the resulting function (for backwards compat to the
|
|
|
|
// days when this was an event handler).
|
2014-01-17 10:09:38 -08:00
|
|
|
JS::Rooted<JSObject*> jsMethodObject(cx, GetCompiledMethod());
|
|
|
|
JS::Rooted<JSObject*> method(cx, ::JS_CloneFunctionObject(cx, jsMethodObject, thisObject));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!method)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
// Now call the method
|
|
|
|
|
2013-11-12 16:43:32 -08:00
|
|
|
// Check whether script is enabled.
|
|
|
|
bool scriptAllowed = nsContentUtils::GetSecurityManager()->
|
|
|
|
ScriptAllowed(js::GetGlobalForObjectCrossCompartment(method));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
bool ok = true;
|
2013-11-12 16:43:32 -08:00
|
|
|
if (scriptAllowed) {
|
2013-04-05 06:21:02 -07:00
|
|
|
JS::Rooted<JS::Value> retval(cx);
|
2014-02-13 07:33:04 -08:00
|
|
|
JS::Rooted<JS::Value> methodVal(cx, JS::ObjectValue(*method));
|
2014-02-12 23:38:36 -08:00
|
|
|
ok = ::JS::Call(cx, thisObject, methodVal, JS::HandleValueArray::empty(), &retval);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok) {
|
2009-05-19 19:11:01 -07:00
|
|
|
// If a constructor or destructor threw an exception, it doesn't stop
|
|
|
|
// anything else. We just report it. Note that we need to set aside the
|
|
|
|
// frame chain here, since the constructor invocation is not related to
|
|
|
|
// whatever is on the stack right now, really.
|
2013-07-17 11:53:52 -07:00
|
|
|
nsJSUtils::ReportPendingException(cx);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-11-03 13:39:08 -07:00
|
|
|
|
|
|
|
nsresult
|
2013-08-09 09:25:13 -07:00
|
|
|
nsXBLProtoImplAnonymousMethod::Write(nsIObjectOutputStream* aStream,
|
2011-11-03 13:39:08 -07:00
|
|
|
XBLBindingSerializeDetails aType)
|
|
|
|
{
|
2013-08-09 09:25:13 -07:00
|
|
|
AssertInCompilationScope();
|
2013-06-18 03:00:38 -07:00
|
|
|
MOZ_ASSERT(IsCompiled());
|
2013-11-21 13:19:46 -08:00
|
|
|
if (GetCompiledMethodPreserveColor()) {
|
2011-11-03 13:39:08 -07:00
|
|
|
nsresult rv = aStream->Write8(aType);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-08-21 16:45:52 -07:00
|
|
|
rv = aStream->WriteWStringZ(mName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-07-23 02:58:28 -07:00
|
|
|
// Calling fromMarkedLocation() is safe because mMethod is traced by the
|
|
|
|
// Trace() method above, and because its value is never changed after it has
|
|
|
|
// been set to a compiled method.
|
2013-07-23 02:58:27 -07:00
|
|
|
JS::Handle<JSObject*> method =
|
|
|
|
JS::Handle<JSObject*>::fromMarkedLocation(mMethod.AsHeapObject().address());
|
2013-08-09 09:25:13 -07:00
|
|
|
rv = XBL_SerializeFunction(aStream, method);
|
2011-11-03 13:39:08 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|