2001-11-13 07:09:56 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
2001-11-13 07:09:56 +03:00
|
|
|
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "jsapi.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsXBLProtoImplProperty.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "nsReadableUtils.h"
|
2013-01-17 06:50:25 +04:00
|
|
|
#include "nsJSUtils.h"
|
2011-11-04 00:39:08 +04:00
|
|
|
#include "nsXBLPrototypeBinding.h"
|
|
|
|
#include "nsXBLSerialize.h"
|
2013-02-08 18:24:22 +04:00
|
|
|
#include "xpcpublic.h"
|
2001-11-13 07:09:56 +03:00
|
|
|
|
2013-02-26 23:04:13 +04:00
|
|
|
using namespace mozilla;
|
2014-09-29 17:34:21 +04:00
|
|
|
using namespace mozilla::dom;
|
2013-02-26 23:04:13 +04:00
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXBLProtoImplProperty::nsXBLProtoImplProperty(const char16_t* aName,
|
|
|
|
const char16_t* aGetter,
|
|
|
|
const char16_t* aSetter,
|
|
|
|
const char16_t* aReadOnly,
|
2012-12-18 00:22:38 +04:00
|
|
|
uint32_t aLineNumber) :
|
2003-06-24 05:20:40 +04:00
|
|
|
nsXBLProtoImplMember(aName),
|
|
|
|
mJSAttributes(JSPROP_ENUMERATE)
|
2005-02-06 23:34:15 +03:00
|
|
|
#ifdef DEBUG
|
2011-10-17 18:59:28 +04:00
|
|
|
, mIsCompiled(false)
|
2005-02-06 23:34:15 +03:00
|
|
|
#endif
|
2001-11-13 07:09:56 +03:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsXBLProtoImplProperty);
|
|
|
|
|
|
|
|
if (aReadOnly) {
|
|
|
|
nsAutoString readOnly; readOnly.Assign(*aReadOnly);
|
2004-06-17 04:13:25 +04:00
|
|
|
if (readOnly.LowerCaseEqualsLiteral("true"))
|
2001-11-13 07:09:56 +03:00
|
|
|
mJSAttributes |= JSPROP_READONLY;
|
|
|
|
}
|
|
|
|
|
2012-12-18 00:22:38 +04:00
|
|
|
if (aGetter) {
|
2002-01-10 00:50:08 +03:00
|
|
|
AppendGetterText(nsDependentString(aGetter));
|
2012-12-18 00:22:38 +04:00
|
|
|
SetGetterLineNumber(aLineNumber);
|
|
|
|
}
|
|
|
|
if (aSetter) {
|
2002-01-10 00:50:08 +03:00
|
|
|
AppendSetterText(nsDependentString(aSetter));
|
2012-12-18 00:22:38 +04:00
|
|
|
SetSetterLineNumber(aLineNumber);
|
|
|
|
}
|
2001-11-13 07:09:56 +03:00
|
|
|
}
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXBLProtoImplProperty::nsXBLProtoImplProperty(const char16_t* aName,
|
2011-11-04 00:39:08 +04:00
|
|
|
const bool aIsReadOnly)
|
|
|
|
: nsXBLProtoImplMember(aName),
|
|
|
|
mJSAttributes(JSPROP_ENUMERATE)
|
|
|
|
#ifdef DEBUG
|
|
|
|
, mIsCompiled(false)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsXBLProtoImplProperty);
|
|
|
|
|
|
|
|
if (aIsReadOnly)
|
|
|
|
mJSAttributes |= JSPROP_READONLY;
|
|
|
|
}
|
|
|
|
|
2001-11-13 07:09:56 +03:00
|
|
|
nsXBLProtoImplProperty::~nsXBLProtoImplProperty()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsXBLProtoImplProperty);
|
|
|
|
|
2013-06-18 14:00:38 +04:00
|
|
|
if (!mGetter.IsCompiled()) {
|
|
|
|
delete mGetter.GetUncompiled();
|
2005-02-07 22:38:10 +03:00
|
|
|
}
|
|
|
|
|
2013-06-18 14:00:38 +04:00
|
|
|
if (!mSetter.IsCompiled()) {
|
|
|
|
delete mSetter.GetUncompiled();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsXBLProtoImplProperty::EnsureUncompiledText(PropertyOp& aPropertyOp)
|
|
|
|
{
|
|
|
|
if (!aPropertyOp.GetUncompiled()) {
|
|
|
|
nsXBLTextWithLineNumber* text = new nsXBLTextWithLineNumber();
|
|
|
|
aPropertyOp.SetUncompiled(text);
|
2001-11-13 07:09:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-03-24 01:46:13 +03:00
|
|
|
nsXBLProtoImplProperty::AppendGetterText(const nsAString& aText)
|
2001-11-13 07:09:56 +03:00
|
|
|
{
|
2005-02-06 23:34:15 +03:00
|
|
|
NS_PRECONDITION(!mIsCompiled,
|
|
|
|
"Must not be compiled when accessing getter text");
|
2013-06-18 14:00:38 +04:00
|
|
|
EnsureUncompiledText(mGetter);
|
|
|
|
mGetter.GetUncompiled()->AppendText(aText);
|
2001-11-13 07:09:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-03-24 01:46:13 +03:00
|
|
|
nsXBLProtoImplProperty::AppendSetterText(const nsAString& aText)
|
2001-11-13 07:09:56 +03:00
|
|
|
{
|
2005-02-06 23:34:15 +03:00
|
|
|
NS_PRECONDITION(!mIsCompiled,
|
|
|
|
"Must not be compiled when accessing setter text");
|
2013-06-18 14:00:38 +04:00
|
|
|
EnsureUncompiledText(mSetter);
|
|
|
|
mSetter.GetUncompiled()->AppendText(aText);
|
2003-06-24 05:20:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsXBLProtoImplProperty::SetGetterLineNumber(uint32_t aLineNumber)
|
2005-02-06 23:34:15 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(!mIsCompiled,
|
|
|
|
"Must not be compiled when accessing getter text");
|
2013-06-18 14:00:38 +04:00
|
|
|
EnsureUncompiledText(mGetter);
|
|
|
|
mGetter.GetUncompiled()->SetLineNumber(aLineNumber);
|
2003-06-24 05:20:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsXBLProtoImplProperty::SetSetterLineNumber(uint32_t aLineNumber)
|
2005-02-06 23:34:15 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(!mIsCompiled,
|
|
|
|
"Must not be compiled when accessing setter text");
|
2013-06-18 14:00:38 +04:00
|
|
|
EnsureUncompiledText(mSetter);
|
|
|
|
mSetter.GetUncompiled()->SetLineNumber(aLineNumber);
|
2001-11-13 07:09:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* gPropertyArgs[] = { "val" };
|
|
|
|
|
|
|
|
nsresult
|
2013-02-08 18:24:21 +04:00
|
|
|
nsXBLProtoImplProperty::InstallMember(JSContext *aCx,
|
2013-04-05 17:21:02 +04:00
|
|
|
JS::Handle<JSObject*> aTargetClassObject)
|
2001-11-13 07:09:56 +03:00
|
|
|
{
|
2005-02-06 23:34:15 +03:00
|
|
|
NS_PRECONDITION(mIsCompiled,
|
|
|
|
"Should not be installing an uncompiled property");
|
2013-06-18 14:00:38 +04:00
|
|
|
MOZ_ASSERT(mGetter.IsCompiled() && mSetter.IsCompiled());
|
2013-02-08 18:24:21 +04:00
|
|
|
MOZ_ASSERT(js::IsObjectInContextCompartment(aTargetClassObject, aCx));
|
2013-04-05 17:21:02 +04:00
|
|
|
JS::Rooted<JSObject*> globalObject(aCx, JS_GetGlobalForObject(aCx, aTargetClassObject));
|
2014-06-03 05:04:21 +04:00
|
|
|
MOZ_ASSERT(xpc::IsInContentXBLScope(globalObject) ||
|
2014-06-24 03:33:37 +04:00
|
|
|
xpc::IsInAddonScope(globalObject) ||
|
2013-11-01 18:31:57 +04:00
|
|
|
globalObject == xpc::GetXBLScope(aCx, globalObject));
|
2001-11-13 07:09:56 +03:00
|
|
|
|
2013-11-22 01:19:46 +04:00
|
|
|
JS::Rooted<JSObject*> getter(aCx, mGetter.GetJSFunction());
|
|
|
|
JS::Rooted<JSObject*> setter(aCx, mSetter.GetJSFunction());
|
|
|
|
if (getter || setter) {
|
|
|
|
if (getter) {
|
|
|
|
if (!(getter = ::JS_CloneFunctionObject(aCx, getter, globalObject)))
|
2003-09-11 08:10:20 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2013-04-05 17:21:02 +04:00
|
|
|
}
|
2005-09-16 19:44:59 +04:00
|
|
|
|
2013-11-22 01:19:46 +04:00
|
|
|
if (setter) {
|
|
|
|
if (!(setter = ::JS_CloneFunctionObject(aCx, setter, globalObject)))
|
2003-09-11 08:10:20 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2013-04-05 17:21:02 +04:00
|
|
|
}
|
2001-11-13 07:09:56 +03:00
|
|
|
|
|
|
|
nsDependentString name(mName);
|
2013-11-01 18:31:57 +04:00
|
|
|
if (!::JS_DefineUCProperty(aCx, aTargetClassObject,
|
2014-07-22 08:43:21 +04:00
|
|
|
static_cast<const char16_t*>(mName),
|
2014-04-30 13:10:33 +04:00
|
|
|
name.Length(), JS::UndefinedHandleValue, mJSAttributes,
|
2014-10-29 22:06:31 +03:00
|
|
|
JS_DATA_TO_FUNC_PTR(JSNative, getter.get()),
|
|
|
|
JS_DATA_TO_FUNC_PTR(JSNative, setter.get())))
|
2003-09-11 08:10:20 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2001-11-13 07:09:56 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-05 17:21:02 +04:00
|
|
|
nsresult
|
2014-09-29 17:34:21 +04:00
|
|
|
nsXBLProtoImplProperty::CompileMember(AutoJSAPI& jsapi, const nsCString& aClassStr,
|
2013-04-05 17:21:02 +04:00
|
|
|
JS::Handle<JSObject*> aClassObject)
|
2001-11-13 07:09:56 +03:00
|
|
|
{
|
2013-08-09 20:25:13 +04:00
|
|
|
AssertInCompilationScope();
|
2005-02-06 23:34:15 +03:00
|
|
|
NS_PRECONDITION(!mIsCompiled,
|
|
|
|
"Trying to compile an already-compiled property");
|
|
|
|
NS_PRECONDITION(aClassObject,
|
|
|
|
"Must have class object to compile");
|
2013-06-18 14:00:38 +04:00
|
|
|
MOZ_ASSERT(!mGetter.IsCompiled() && !mSetter.IsCompiled());
|
2014-09-29 17:34:21 +04:00
|
|
|
JSContext *cx = jsapi.cx();
|
2001-11-13 07:09:56 +03: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-02 06:35:17 +04:00
|
|
|
nsAutoCString functionUri;
|
2013-06-18 14:00:38 +04:00
|
|
|
if (mGetter.GetUncompiled() || mSetter.GetUncompiled()) {
|
2003-06-24 05:20:40 +04:00
|
|
|
functionUri = aClassStr;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t hash = functionUri.RFindChar('#');
|
2003-06-24 05:20:40 +04:00
|
|
|
if (hash != kNotFound) {
|
|
|
|
functionUri.Truncate(hash);
|
|
|
|
}
|
2004-02-20 01:24:41 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool deletedGetter = false;
|
2013-06-18 14:00:38 +04:00
|
|
|
nsXBLTextWithLineNumber *getterText = mGetter.GetUncompiled();
|
|
|
|
if (getterText && getterText->GetText()) {
|
|
|
|
nsDependentString getter(getterText->GetText());
|
2004-02-20 01:24:41 +03:00
|
|
|
if (!getter.IsEmpty()) {
|
2013-01-17 06:50:25 +04:00
|
|
|
JSAutoCompartment ac(cx, aClassObject);
|
|
|
|
JS::CompileOptions options(cx);
|
2013-06-18 14:00:38 +04:00
|
|
|
options.setFileAndLine(functionUri.get(), getterText->GetLineNumber())
|
2014-10-25 10:09:12 +04:00
|
|
|
.setVersion(JSVERSION_LATEST)
|
|
|
|
.setDefineOnScope(false);
|
2013-01-17 06:50:25 +04:00
|
|
|
nsCString name = NS_LITERAL_CSTRING("get_") + NS_ConvertUTF16toUTF8(mName);
|
2013-11-11 12:04:41 +04:00
|
|
|
JS::Rooted<JSObject*> getterObject(cx);
|
2014-10-25 08:50:29 +04:00
|
|
|
JS::AutoObjectVector emptyVector(cx);
|
|
|
|
rv = nsJSUtils::CompileFunction(jsapi, emptyVector, options, name, 0,
|
2013-11-11 12:04:41 +04:00
|
|
|
nullptr, getter, getterObject.address());
|
2004-02-20 01:24:41 +03:00
|
|
|
|
2013-06-18 14:00:38 +04:00
|
|
|
delete getterText;
|
2011-10-17 18:59:28 +04:00
|
|
|
deletedGetter = true;
|
2013-06-18 14:00:38 +04:00
|
|
|
|
|
|
|
mGetter.SetJSFunction(getterObject);
|
2004-02-20 01:24:41 +03:00
|
|
|
|
2013-06-18 14:00:38 +04:00
|
|
|
if (mGetter.GetJSFunction() && NS_SUCCEEDED(rv)) {
|
2004-02-20 01:24:41 +03:00
|
|
|
mJSAttributes |= JSPROP_GETTER | JSPROP_SHARED;
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) {
|
2013-06-18 14:00:38 +04:00
|
|
|
mGetter.SetJSFunction(nullptr);
|
2004-02-20 01:24:41 +03:00
|
|
|
mJSAttributes &= ~JSPROP_GETTER;
|
|
|
|
/*chaining to return failure*/
|
|
|
|
}
|
2001-11-13 07:09:56 +03:00
|
|
|
}
|
|
|
|
} // if getter is not empty
|
|
|
|
|
2004-02-20 01:24:41 +03:00
|
|
|
if (!deletedGetter) { // Empty getter
|
2013-06-18 14:00:38 +04:00
|
|
|
delete getterText;
|
|
|
|
mGetter.SetJSFunction(nullptr);
|
2004-02-20 01:24:41 +03:00
|
|
|
}
|
|
|
|
|
2005-02-06 23:34:15 +03: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;
|
|
|
|
}
|
2003-06-21 07:08:56 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool deletedSetter = false;
|
2013-06-18 14:00:38 +04:00
|
|
|
nsXBLTextWithLineNumber *setterText = mSetter.GetUncompiled();
|
|
|
|
if (setterText && setterText->GetText()) {
|
|
|
|
nsDependentString setter(setterText->GetText());
|
2004-02-20 01:24:41 +03:00
|
|
|
if (!setter.IsEmpty()) {
|
2013-01-17 06:50:25 +04:00
|
|
|
JSAutoCompartment ac(cx, aClassObject);
|
|
|
|
JS::CompileOptions options(cx);
|
2013-06-18 14:00:38 +04:00
|
|
|
options.setFileAndLine(functionUri.get(), setterText->GetLineNumber())
|
2014-10-25 10:09:12 +04:00
|
|
|
.setVersion(JSVERSION_LATEST)
|
|
|
|
.setDefineOnScope(false);
|
2013-01-17 06:50:25 +04:00
|
|
|
nsCString name = NS_LITERAL_CSTRING("set_") + NS_ConvertUTF16toUTF8(mName);
|
2013-11-11 12:04:41 +04:00
|
|
|
JS::Rooted<JSObject*> setterObject(cx);
|
2014-10-25 08:50:29 +04:00
|
|
|
JS::AutoObjectVector emptyVector(cx);
|
|
|
|
rv = nsJSUtils::CompileFunction(jsapi, emptyVector, options, name, 1,
|
2013-11-11 12:04:41 +04:00
|
|
|
gPropertyArgs, setter,
|
|
|
|
setterObject.address());
|
2004-02-20 01:24:41 +03:00
|
|
|
|
2013-06-18 14:00:38 +04:00
|
|
|
delete setterText;
|
2011-10-17 18:59:28 +04:00
|
|
|
deletedSetter = true;
|
2013-06-18 14:00:38 +04:00
|
|
|
mSetter.SetJSFunction(setterObject);
|
2004-02-20 01:24:41 +03:00
|
|
|
|
2013-06-18 14:00:38 +04:00
|
|
|
if (mSetter.GetJSFunction() && NS_SUCCEEDED(rv)) {
|
2004-02-20 01:24:41 +03:00
|
|
|
mJSAttributes |= JSPROP_SETTER | JSPROP_SHARED;
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) {
|
2013-06-18 14:00:38 +04:00
|
|
|
mSetter.SetJSFunction(nullptr);
|
2004-02-20 01:24:41 +03:00
|
|
|
mJSAttributes &= ~JSPROP_SETTER;
|
|
|
|
/*chaining to return failure*/
|
|
|
|
}
|
2001-11-13 07:09:56 +03:00
|
|
|
}
|
|
|
|
} // if setter wasn't empty....
|
|
|
|
|
2004-02-20 01:24:41 +03:00
|
|
|
if (!deletedSetter) { // Empty setter
|
2013-06-18 14:00:38 +04:00
|
|
|
delete setterText;
|
|
|
|
mSetter.SetJSFunction(nullptr);
|
2004-02-20 01:24:41 +03:00
|
|
|
}
|
2005-02-06 23:34:15 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
mIsCompiled = NS_SUCCEEDED(rv);
|
|
|
|
#endif
|
2013-05-27 15:50:49 +04:00
|
|
|
|
2005-02-06 23:34:15 +03:00
|
|
|
return rv;
|
2001-11-13 07:09:56 +03:00
|
|
|
}
|
2007-05-24 18:10:02 +04:00
|
|
|
|
|
|
|
void
|
2013-05-27 15:50:49 +04:00
|
|
|
nsXBLProtoImplProperty::Trace(const TraceCallbacks& aCallbacks, void *aClosure)
|
2007-05-24 18:10:02 +04:00
|
|
|
{
|
2008-02-12 19:02:41 +03:00
|
|
|
if (mJSAttributes & JSPROP_GETTER) {
|
2013-06-18 14:00:38 +04:00
|
|
|
aCallbacks.Trace(&mGetter.AsHeapObject(), "mGetter", aClosure);
|
2007-05-24 18:10:02 +04:00
|
|
|
}
|
|
|
|
|
2008-02-12 19:02:41 +03:00
|
|
|
if (mJSAttributes & JSPROP_SETTER) {
|
2013-06-18 14:00:38 +04:00
|
|
|
aCallbacks.Trace(&mSetter.AsHeapObject(), "mSetter", aClosure);
|
2007-05-24 18:10:02 +04:00
|
|
|
}
|
|
|
|
}
|
2011-11-04 00:39:08 +04:00
|
|
|
|
|
|
|
nsresult
|
2013-08-09 20:25:13 +04:00
|
|
|
nsXBLProtoImplProperty::Read(nsIObjectInputStream* aStream,
|
2011-11-04 00:39:08 +04:00
|
|
|
XBLBindingSerializeDetails aType)
|
|
|
|
{
|
2013-08-09 20:25:13 +04:00
|
|
|
AssertInCompilationScope();
|
2013-06-18 14:00:38 +04:00
|
|
|
MOZ_ASSERT(!mIsCompiled);
|
|
|
|
MOZ_ASSERT(!mGetter.GetUncompiled() && !mSetter.GetUncompiled());
|
|
|
|
|
2013-08-09 20:25:13 +04:00
|
|
|
AutoJSContext cx;
|
2013-06-18 14:00:38 +04:00
|
|
|
JS::Rooted<JSObject*> getterObject(cx);
|
2011-11-04 00:39:08 +04:00
|
|
|
if (aType == XBLBinding_Serialize_GetterProperty ||
|
|
|
|
aType == XBLBinding_Serialize_GetterSetterProperty) {
|
2013-08-09 20:25:13 +04:00
|
|
|
nsresult rv = XBL_DeserializeFunction(aStream, &getterObject);
|
2011-11-04 00:39:08 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mJSAttributes |= JSPROP_GETTER | JSPROP_SHARED;
|
|
|
|
}
|
2013-06-18 14:00:38 +04:00
|
|
|
mGetter.SetJSFunction(getterObject);
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> setterObject(cx);
|
2011-11-04 00:39:08 +04:00
|
|
|
if (aType == XBLBinding_Serialize_SetterProperty ||
|
|
|
|
aType == XBLBinding_Serialize_GetterSetterProperty) {
|
2013-08-09 20:25:13 +04:00
|
|
|
nsresult rv = XBL_DeserializeFunction(aStream, &setterObject);
|
2011-11-04 00:39:08 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mJSAttributes |= JSPROP_SETTER | JSPROP_SHARED;
|
|
|
|
}
|
2013-06-18 14:00:38 +04:00
|
|
|
mSetter.SetJSFunction(setterObject);
|
2011-11-04 00:39:08 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
mIsCompiled = true;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-08-09 20:25:13 +04:00
|
|
|
nsXBLProtoImplProperty::Write(nsIObjectOutputStream* aStream)
|
2011-11-04 00:39:08 +04:00
|
|
|
{
|
2013-08-09 20:25:13 +04:00
|
|
|
AssertInCompilationScope();
|
2011-11-04 00:39:08 +04:00
|
|
|
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);
|
|
|
|
|
2013-07-23 13:58:28 +04:00
|
|
|
// The calls to fromMarkedLocation() below are safe because mSetter and
|
|
|
|
// mGetter are traced by the Trace() method above, and because their values
|
|
|
|
// are never changed after they have been set to a compiled function.
|
|
|
|
MOZ_ASSERT_IF(mJSAttributes & (JSPROP_GETTER | JSPROP_SETTER), mIsCompiled);
|
|
|
|
|
2011-11-04 00:39:08 +04:00
|
|
|
if (mJSAttributes & JSPROP_GETTER) {
|
2013-07-23 13:58:27 +04:00
|
|
|
JS::Handle<JSObject*> function =
|
|
|
|
JS::Handle<JSObject*>::fromMarkedLocation(mGetter.AsHeapObject().address());
|
2013-08-09 20:25:13 +04:00
|
|
|
rv = XBL_SerializeFunction(aStream, function);
|
2011-11-04 00:39:08 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mJSAttributes & JSPROP_SETTER) {
|
2013-07-23 13:58:27 +04:00
|
|
|
JS::Handle<JSObject*> function =
|
|
|
|
JS::Handle<JSObject*>::fromMarkedLocation(mSetter.AsHeapObject().address());
|
2013-08-09 20:25:13 +04:00
|
|
|
rv = XBL_SerializeFunction(aStream, function);
|
2011-11-04 00:39:08 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|