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 "nsXBLProtoImplProperty.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
2013-02-26 11:04:13 -08:00
|
|
|
#include "nsContentUtils.h"
|
2013-05-22 09:05:26 -07:00
|
|
|
#include "nsCxPusher.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsIScriptContext.h"
|
2013-01-16 18:50:25 -08:00
|
|
|
#include "nsJSUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
2011-11-03 13:39:08 -07:00
|
|
|
#include "nsXBLPrototypeBinding.h"
|
|
|
|
#include "nsXBLSerialize.h"
|
2013-02-08 06:24:22 -08:00
|
|
|
#include "xpcpublic.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-26 11:04:13 -08:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLProtoImplProperty::nsXBLProtoImplProperty(const PRUnichar* aName,
|
|
|
|
const PRUnichar* aGetter,
|
|
|
|
const PRUnichar* aSetter,
|
2012-12-17 12:22:38 -08:00
|
|
|
const PRUnichar* aReadOnly,
|
|
|
|
uint32_t aLineNumber) :
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLProtoImplMember(aName),
|
|
|
|
mJSAttributes(JSPROP_ENUMERATE)
|
|
|
|
#ifdef DEBUG
|
2011-10-17 07:59:28 -07:00
|
|
|
, mIsCompiled(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsXBLProtoImplProperty);
|
|
|
|
|
|
|
|
if (aReadOnly) {
|
|
|
|
nsAutoString readOnly; readOnly.Assign(*aReadOnly);
|
|
|
|
if (readOnly.LowerCaseEqualsLiteral("true"))
|
|
|
|
mJSAttributes |= JSPROP_READONLY;
|
|
|
|
}
|
|
|
|
|
2012-12-17 12:22:38 -08:00
|
|
|
if (aGetter) {
|
2007-03-22 10:30:00 -07:00
|
|
|
AppendGetterText(nsDependentString(aGetter));
|
2012-12-17 12:22:38 -08:00
|
|
|
SetGetterLineNumber(aLineNumber);
|
|
|
|
}
|
|
|
|
if (aSetter) {
|
2007-03-22 10:30:00 -07:00
|
|
|
AppendSetterText(nsDependentString(aSetter));
|
2012-12-17 12:22:38 -08:00
|
|
|
SetSetterLineNumber(aLineNumber);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-11-03 13:39:08 -07:00
|
|
|
nsXBLProtoImplProperty::nsXBLProtoImplProperty(const PRUnichar* aName,
|
|
|
|
const bool aIsReadOnly)
|
|
|
|
: nsXBLProtoImplMember(aName),
|
|
|
|
mJSAttributes(JSPROP_ENUMERATE)
|
|
|
|
#ifdef DEBUG
|
|
|
|
, mIsCompiled(false)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsXBLProtoImplProperty);
|
|
|
|
|
|
|
|
if (aIsReadOnly)
|
|
|
|
mJSAttributes |= JSPROP_READONLY;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLProtoImplProperty::~nsXBLProtoImplProperty()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsXBLProtoImplProperty);
|
|
|
|
|
2013-06-18 03:00:38 -07:00
|
|
|
if (!mGetter.IsCompiled()) {
|
|
|
|
delete mGetter.GetUncompiled();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-06-18 03:00:38 -07:00
|
|
|
if (!mSetter.IsCompiled()) {
|
|
|
|
delete mSetter.GetUncompiled();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsXBLProtoImplProperty::EnsureUncompiledText(PropertyOp& aPropertyOp)
|
|
|
|
{
|
|
|
|
if (!aPropertyOp.GetUncompiled()) {
|
|
|
|
nsXBLTextWithLineNumber* text = new nsXBLTextWithLineNumber();
|
|
|
|
aPropertyOp.SetUncompiled(text);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXBLProtoImplProperty::AppendGetterText(const nsAString& aText)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(!mIsCompiled,
|
|
|
|
"Must not be compiled when accessing getter text");
|
2013-06-18 03:00:38 -07:00
|
|
|
EnsureUncompiledText(mGetter);
|
|
|
|
mGetter.GetUncompiled()->AppendText(aText);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXBLProtoImplProperty::AppendSetterText(const nsAString& aText)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(!mIsCompiled,
|
|
|
|
"Must not be compiled when accessing setter text");
|
2013-06-18 03:00:38 -07:00
|
|
|
EnsureUncompiledText(mSetter);
|
|
|
|
mSetter.GetUncompiled()->AppendText(aText);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXBLProtoImplProperty::SetGetterLineNumber(uint32_t aLineNumber)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(!mIsCompiled,
|
|
|
|
"Must not be compiled when accessing getter text");
|
2013-06-18 03:00:38 -07:00
|
|
|
EnsureUncompiledText(mGetter);
|
|
|
|
mGetter.GetUncompiled()->SetLineNumber(aLineNumber);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXBLProtoImplProperty::SetSetterLineNumber(uint32_t aLineNumber)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(!mIsCompiled,
|
|
|
|
"Must not be compiled when accessing setter text");
|
2013-06-18 03:00:38 -07:00
|
|
|
EnsureUncompiledText(mSetter);
|
|
|
|
mSetter.GetUncompiled()->SetLineNumber(aLineNumber);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* gPropertyArgs[] = { "val" };
|
|
|
|
|
|
|
|
nsresult
|
2013-02-08 06:24:21 -08:00
|
|
|
nsXBLProtoImplProperty::InstallMember(JSContext *aCx,
|
2013-04-05 06:21:02 -07:00
|
|
|
JS::Handle<JSObject*> aTargetClassObject)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(mIsCompiled,
|
|
|
|
"Should not be installing an uncompiled property");
|
2013-06-18 03:00:38 -07:00
|
|
|
MOZ_ASSERT(mGetter.IsCompiled() && mSetter.IsCompiled());
|
2013-02-08 06:24:21 -08:00
|
|
|
MOZ_ASSERT(js::IsObjectInContextCompartment(aTargetClassObject, aCx));
|
2013-04-05 06:21:02 -07:00
|
|
|
JS::Rooted<JSObject*> globalObject(aCx, JS_GetGlobalForObject(aCx, aTargetClassObject));
|
|
|
|
JS::Rooted<JSObject*> scopeObject(aCx, xpc::GetXBLScope(aCx, 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
|
|
|
|
|
|
|
// now we want to reevaluate our property using aContext and the script object for this window...
|
2013-06-18 03:00:38 -07:00
|
|
|
if (mGetter.GetJSFunction() || mSetter.GetJSFunction()) {
|
2013-02-08 06:24:22 -08:00
|
|
|
// First, enter the compartment of the scope object and clone the functions.
|
|
|
|
JSAutoCompartment ac(aCx, scopeObject);
|
2013-04-05 06:21:02 -07:00
|
|
|
|
|
|
|
JS::Rooted<JSObject*> getter(aCx, nullptr);
|
2013-06-18 03:00:38 -07:00
|
|
|
if (mGetter.GetJSFunction()) {
|
|
|
|
if (!(getter = ::JS_CloneFunctionObject(aCx, mGetter.GetJSFunction(), scopeObject)))
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2013-04-05 06:21:02 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-04-05 06:21:02 -07:00
|
|
|
JS::Rooted<JSObject*> setter(aCx, nullptr);
|
2013-06-18 03:00:38 -07:00
|
|
|
if (mSetter.GetJSFunction()) {
|
|
|
|
if (!(setter = ::JS_CloneFunctionObject(aCx, mSetter.GetJSFunction(), scopeObject)))
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2013-04-05 06:21:02 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-08 06:24:22 -08:00
|
|
|
// Now, enter the content compartment, wrap the getter/setter, and define
|
|
|
|
// them on the class object.
|
|
|
|
JSAutoCompartment ac2(aCx, aTargetClassObject);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsDependentString name(mName);
|
2013-04-05 06:21:02 -07:00
|
|
|
if (!JS_WrapObject(aCx, getter.address()) ||
|
|
|
|
!JS_WrapObject(aCx, setter.address()) ||
|
2013-02-08 06:24:22 -08:00
|
|
|
!::JS_DefineUCProperty(aCx, aTargetClassObject,
|
2012-05-05 02:00:06 -07:00
|
|
|
static_cast<const jschar*>(mName),
|
2009-03-10 16:21:40 -07:00
|
|
|
name.Length(), JSVAL_VOID,
|
2013-04-05 06:21:02 -07:00
|
|
|
JS_DATA_TO_FUNC_PTR(JSPropertyOp, getter.get()),
|
|
|
|
JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, setter.get()),
|
2013-02-13 10:16:19 -08:00
|
|
|
mJSAttributes))
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-05 06:21:02 -07:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLProtoImplProperty::CompileMember(nsIScriptContext* aContext, const nsCString& aClassStr,
|
2013-04-05 06:21:02 -07:00
|
|
|
JS::Handle<JSObject*> aClassObject)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(!mIsCompiled,
|
|
|
|
"Trying to compile an already-compiled property");
|
|
|
|
NS_PRECONDITION(aClassObject,
|
|
|
|
"Must have class object to compile");
|
2013-06-18 03:00:38 -07:00
|
|
|
MOZ_ASSERT(!mGetter.IsCompiled() && !mSetter.IsCompiled());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!mName)
|
|
|
|
return NS_ERROR_FAILURE; // Without a valid name, we can't install the member.
|
|
|
|
|
|
|
|
// We have a property.
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString functionUri;
|
2013-06-18 03:00:38 -07:00
|
|
|
if (mGetter.GetUncompiled() || mSetter.GetUncompiled()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool deletedGetter = false;
|
2013-06-18 03:00:38 -07:00
|
|
|
nsXBLTextWithLineNumber *getterText = mGetter.GetUncompiled();
|
|
|
|
if (getterText && getterText->GetText()) {
|
|
|
|
nsDependentString getter(getterText->GetText());
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!getter.IsEmpty()) {
|
2013-02-26 11:04:13 -08:00
|
|
|
AutoPushJSContext cx(aContext->GetNativeContext());
|
2013-01-16 18:50:25 -08:00
|
|
|
JSAutoCompartment ac(cx, aClassObject);
|
|
|
|
JS::CompileOptions options(cx);
|
2013-06-18 03:00:38 -07:00
|
|
|
options.setFileAndLine(functionUri.get(), getterText->GetLineNumber())
|
2013-05-20 21:34:17 -07:00
|
|
|
.setVersion(JSVERSION_LATEST);
|
2013-01-16 18:50:25 -08:00
|
|
|
nsCString name = NS_LITERAL_CSTRING("get_") + NS_ConvertUTF16toUTF8(mName);
|
2013-03-06 08:41:43 -08:00
|
|
|
JS::RootedObject rootedNull(cx, nullptr); // See bug 781070.
|
2013-04-05 06:21:02 -07:00
|
|
|
JS::RootedObject getterObject(cx);
|
2013-01-16 18:50:25 -08:00
|
|
|
rv = nsJSUtils::CompileFunction(cx, rootedNull, options, name, 0, nullptr,
|
2013-04-05 06:21:02 -07:00
|
|
|
getter, getterObject.address());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-06-18 03:00:38 -07:00
|
|
|
delete getterText;
|
2011-10-17 07:59:28 -07:00
|
|
|
deletedGetter = true;
|
2013-06-18 03:00:38 -07:00
|
|
|
|
|
|
|
mGetter.SetJSFunction(getterObject);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-06-18 03:00:38 -07:00
|
|
|
if (mGetter.GetJSFunction() && NS_SUCCEEDED(rv)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mJSAttributes |= JSPROP_GETTER | JSPROP_SHARED;
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) {
|
2013-06-18 03:00:38 -07:00
|
|
|
mGetter.SetJSFunction(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
mJSAttributes &= ~JSPROP_GETTER;
|
|
|
|
/*chaining to return failure*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // if getter is not empty
|
|
|
|
|
|
|
|
if (!deletedGetter) { // Empty getter
|
2013-06-18 03:00:38 -07:00
|
|
|
delete getterText;
|
|
|
|
mGetter.SetJSFunction(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// We failed to compile our getter. So either we've set it to null, or
|
|
|
|
// it's still set to the text object. In either case, it's safe to return
|
|
|
|
// the error here, since then we'll be cleaned up as uncompiled and that
|
|
|
|
// will be ok. Going on and compiling the setter and _then_ returning an
|
|
|
|
// error, on the other hand, will try to clean up a compiled setter as
|
|
|
|
// uncompiled and crash.
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool deletedSetter = false;
|
2013-06-18 03:00:38 -07:00
|
|
|
nsXBLTextWithLineNumber *setterText = mSetter.GetUncompiled();
|
|
|
|
if (setterText && setterText->GetText()) {
|
|
|
|
nsDependentString setter(setterText->GetText());
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!setter.IsEmpty()) {
|
2013-02-26 11:04:13 -08:00
|
|
|
AutoPushJSContext cx(aContext->GetNativeContext());
|
2013-01-16 18:50:25 -08:00
|
|
|
JSAutoCompartment ac(cx, aClassObject);
|
|
|
|
JS::CompileOptions options(cx);
|
2013-06-18 03:00:38 -07:00
|
|
|
options.setFileAndLine(functionUri.get(), setterText->GetLineNumber())
|
2013-05-20 21:34:17 -07:00
|
|
|
.setVersion(JSVERSION_LATEST);
|
2013-01-16 18:50:25 -08:00
|
|
|
nsCString name = NS_LITERAL_CSTRING("set_") + NS_ConvertUTF16toUTF8(mName);
|
2013-03-06 08:41:43 -08:00
|
|
|
JS::RootedObject rootedNull(cx, nullptr); // See bug 781070.
|
2013-04-05 06:21:02 -07:00
|
|
|
JS::RootedObject setterObject(cx);
|
2013-01-16 18:50:25 -08:00
|
|
|
rv = nsJSUtils::CompileFunction(cx, rootedNull, options, name, 1,
|
2013-04-05 06:21:02 -07:00
|
|
|
gPropertyArgs, setter, setterObject.address());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-06-18 03:00:38 -07:00
|
|
|
delete setterText;
|
2011-10-17 07:59:28 -07:00
|
|
|
deletedSetter = true;
|
2013-06-18 03:00:38 -07:00
|
|
|
mSetter.SetJSFunction(setterObject);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-06-18 03:00:38 -07:00
|
|
|
if (mSetter.GetJSFunction() && NS_SUCCEEDED(rv)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mJSAttributes |= JSPROP_SETTER | JSPROP_SHARED;
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) {
|
2013-06-18 03:00:38 -07:00
|
|
|
mSetter.SetJSFunction(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
mJSAttributes &= ~JSPROP_SETTER;
|
|
|
|
/*chaining to return failure*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // if setter wasn't empty....
|
|
|
|
|
|
|
|
if (!deletedSetter) { // Empty setter
|
2013-06-18 03:00:38 -07:00
|
|
|
delete setterText;
|
|
|
|
mSetter.SetJSFunction(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
mIsCompiled = NS_SUCCEEDED(rv);
|
|
|
|
#endif
|
2013-05-27 04:50:49 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
2007-05-24 07:10:02 -07:00
|
|
|
|
|
|
|
void
|
2013-05-27 04:50:49 -07:00
|
|
|
nsXBLProtoImplProperty::Trace(const TraceCallbacks& aCallbacks, void *aClosure)
|
2007-05-24 07:10:02 -07:00
|
|
|
{
|
2008-02-12 08:02:41 -08:00
|
|
|
if (mJSAttributes & JSPROP_GETTER) {
|
2013-06-18 03:00:38 -07:00
|
|
|
aCallbacks.Trace(&mGetter.AsHeapObject(), "mGetter", aClosure);
|
2007-05-24 07:10:02 -07:00
|
|
|
}
|
|
|
|
|
2008-02-12 08:02:41 -08:00
|
|
|
if (mJSAttributes & JSPROP_SETTER) {
|
2013-06-18 03:00:38 -07:00
|
|
|
aCallbacks.Trace(&mSetter.AsHeapObject(), "mSetter", aClosure);
|
2007-05-24 07:10:02 -07:00
|
|
|
}
|
|
|
|
}
|
2011-11-03 13:39:08 -07:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLProtoImplProperty::Read(nsIScriptContext* aContext,
|
|
|
|
nsIObjectInputStream* aStream,
|
|
|
|
XBLBindingSerializeDetails aType)
|
|
|
|
{
|
2013-06-18 03:00:38 -07:00
|
|
|
MOZ_ASSERT(!mIsCompiled);
|
|
|
|
MOZ_ASSERT(!mGetter.GetUncompiled() && !mSetter.GetUncompiled());
|
|
|
|
|
2013-04-05 06:21:02 -07:00
|
|
|
JSContext *cx = aContext->GetNativeContext();
|
|
|
|
|
2013-06-18 03:00:38 -07:00
|
|
|
JS::Rooted<JSObject*> getterObject(cx);
|
2011-11-03 13:39:08 -07:00
|
|
|
if (aType == XBLBinding_Serialize_GetterProperty ||
|
|
|
|
aType == XBLBinding_Serialize_GetterSetterProperty) {
|
2013-04-05 06:21:03 -07:00
|
|
|
nsresult rv = XBL_DeserializeFunction(aContext, aStream, &getterObject);
|
2011-11-03 13:39:08 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mJSAttributes |= JSPROP_GETTER | JSPROP_SHARED;
|
|
|
|
}
|
2013-06-18 03:00:38 -07:00
|
|
|
mGetter.SetJSFunction(getterObject);
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> setterObject(cx);
|
2011-11-03 13:39:08 -07:00
|
|
|
if (aType == XBLBinding_Serialize_SetterProperty ||
|
|
|
|
aType == XBLBinding_Serialize_GetterSetterProperty) {
|
2013-04-05 06:21:03 -07:00
|
|
|
nsresult rv = XBL_DeserializeFunction(aContext, aStream, &setterObject);
|
2011-11-03 13:39:08 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mJSAttributes |= JSPROP_SETTER | JSPROP_SHARED;
|
|
|
|
}
|
2013-06-18 03:00:38 -07:00
|
|
|
mSetter.SetJSFunction(setterObject);
|
2011-11-03 13:39:08 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
mIsCompiled = true;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLProtoImplProperty::Write(nsIScriptContext* aContext,
|
|
|
|
nsIObjectOutputStream* aStream)
|
|
|
|
{
|
|
|
|
XBLBindingSerializeDetails type;
|
|
|
|
|
|
|
|
if (mJSAttributes & JSPROP_GETTER) {
|
|
|
|
type = mJSAttributes & JSPROP_SETTER ?
|
|
|
|
XBLBinding_Serialize_GetterSetterProperty :
|
|
|
|
XBLBinding_Serialize_GetterProperty;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
type = XBLBinding_Serialize_SetterProperty;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mJSAttributes & JSPROP_READONLY) {
|
|
|
|
type |= XBLBinding_Serialize_ReadOnly;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = aStream->Write8(type);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aStream->WriteWStringZ(mName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (mJSAttributes & JSPROP_GETTER) {
|
2013-06-18 03:00:38 -07:00
|
|
|
rv = XBL_SerializeFunction(aContext, aStream, mGetter.AsHeapObject());
|
2011-11-03 13:39:08 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mJSAttributes & JSPROP_SETTER) {
|
2013-06-18 03:00:38 -07:00
|
|
|
rv = XBL_SerializeFunction(aContext, aStream, mSetter.AsHeapObject());
|
2011-11-03 13:39:08 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|