mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-01 06:35:42 +00:00
fc46faa46f
--HG-- rename : content/xbl/src/XBLChildrenElement.cpp => dom/xbl/XBLChildrenElement.cpp rename : content/xbl/src/XBLChildrenElement.h => dom/xbl/XBLChildrenElement.h rename : content/xbl/builtin/android/jar.mn => dom/xbl/builtin/android/jar.mn rename : content/xbl/builtin/android/moz.build => dom/xbl/builtin/android/moz.build rename : content/xbl/builtin/android/platformHTMLBindings.xml => dom/xbl/builtin/android/platformHTMLBindings.xml rename : content/xbl/builtin/browser-base.inc => dom/xbl/builtin/browser-base.inc rename : content/xbl/builtin/editor-base.inc => dom/xbl/builtin/editor-base.inc rename : content/xbl/builtin/emacs/jar.mn => dom/xbl/builtin/emacs/jar.mn rename : content/xbl/builtin/emacs/moz.build => dom/xbl/builtin/emacs/moz.build rename : content/xbl/builtin/emacs/platformHTMLBindings.xml => dom/xbl/builtin/emacs/platformHTMLBindings.xml rename : content/xbl/builtin/input-fields-base.inc => dom/xbl/builtin/input-fields-base.inc rename : content/xbl/builtin/mac/jar.mn => dom/xbl/builtin/mac/jar.mn rename : content/xbl/builtin/mac/moz.build => dom/xbl/builtin/mac/moz.build rename : content/xbl/builtin/mac/platformHTMLBindings.xml => dom/xbl/builtin/mac/platformHTMLBindings.xml rename : content/xbl/builtin/moz.build => dom/xbl/builtin/moz.build rename : content/xbl/builtin/textareas-base.inc => dom/xbl/builtin/textareas-base.inc rename : content/xbl/builtin/unix/jar.mn => dom/xbl/builtin/unix/jar.mn rename : content/xbl/builtin/unix/moz.build => dom/xbl/builtin/unix/moz.build rename : content/xbl/builtin/unix/platformHTMLBindings.xml => dom/xbl/builtin/unix/platformHTMLBindings.xml rename : content/xbl/builtin/win/jar.mn => dom/xbl/builtin/win/jar.mn rename : content/xbl/builtin/win/moz.build => dom/xbl/builtin/win/moz.build rename : content/xbl/builtin/win/platformHTMLBindings.xml => dom/xbl/builtin/win/platformHTMLBindings.xml rename : content/xbl/crashtests/205735-1.xhtml => dom/xbl/crashtests/205735-1.xhtml rename : content/xbl/crashtests/223799-1.xul => dom/xbl/crashtests/223799-1.xul rename : content/xbl/crashtests/226744-1.xhtml => dom/xbl/crashtests/226744-1.xhtml rename : content/xbl/crashtests/232095-1.xul => dom/xbl/crashtests/232095-1.xul rename : content/xbl/crashtests/277523-1.xhtml => dom/xbl/crashtests/277523-1.xhtml rename : content/xbl/crashtests/277950-1.xhtml => dom/xbl/crashtests/277950-1.xhtml rename : content/xbl/crashtests/336744-1-inner.html => dom/xbl/crashtests/336744-1-inner.html rename : content/xbl/crashtests/336744-1.html => dom/xbl/crashtests/336744-1.html rename : content/xbl/crashtests/336960-1-inner.xhtml => dom/xbl/crashtests/336960-1-inner.xhtml rename : content/xbl/crashtests/336960-1.html => dom/xbl/crashtests/336960-1.html rename : content/xbl/crashtests/342954-1.xhtml => dom/xbl/crashtests/342954-1.xhtml rename : content/xbl/crashtests/342954-2-xbl.xml => dom/xbl/crashtests/342954-2-xbl.xml rename : content/xbl/crashtests/342954-2.xhtml => dom/xbl/crashtests/342954-2.xhtml rename : content/xbl/crashtests/368276-1.xhtml => dom/xbl/crashtests/368276-1.xhtml rename : content/xbl/crashtests/368641-1.xhtml => dom/xbl/crashtests/368641-1.xhtml rename : content/xbl/crashtests/378521-1.xhtml => dom/xbl/crashtests/378521-1.xhtml rename : content/xbl/crashtests/382376-1.xhtml => dom/xbl/crashtests/382376-1.xhtml rename : content/xbl/crashtests/382376-2.xhtml => dom/xbl/crashtests/382376-2.xhtml rename : content/xbl/crashtests/397596-1.xhtml => dom/xbl/crashtests/397596-1.xhtml rename : content/xbl/crashtests/404125-1.xhtml => dom/xbl/crashtests/404125-1.xhtml rename : content/xbl/crashtests/406900-1.xul => dom/xbl/crashtests/406900-1.xul rename : content/xbl/crashtests/406904-1.xhtml => dom/xbl/crashtests/406904-1.xhtml rename : content/xbl/crashtests/406904-2.xhtml => dom/xbl/crashtests/406904-2.xhtml rename : content/xbl/crashtests/415192-1.xul => dom/xbl/crashtests/415192-1.xul rename : content/xbl/crashtests/415301-1.xul => dom/xbl/crashtests/415301-1.xul rename : content/xbl/crashtests/418133-1.xhtml => dom/xbl/crashtests/418133-1.xhtml rename : content/xbl/crashtests/420233-1.xhtml => dom/xbl/crashtests/420233-1.xhtml rename : content/xbl/crashtests/421997-1.xhtml => dom/xbl/crashtests/421997-1.xhtml rename : content/xbl/crashtests/432813-1-xbl.xml => dom/xbl/crashtests/432813-1-xbl.xml rename : content/xbl/crashtests/432813-1.xhtml => dom/xbl/crashtests/432813-1.xhtml rename : content/xbl/crashtests/454820-1.html => dom/xbl/crashtests/454820-1.html rename : content/xbl/crashtests/460665-1.xhtml => dom/xbl/crashtests/460665-1.xhtml rename : content/xbl/crashtests/463511-1.xhtml => dom/xbl/crashtests/463511-1.xhtml rename : content/xbl/crashtests/464863-1.xhtml => dom/xbl/crashtests/464863-1.xhtml rename : content/xbl/crashtests/472260-1.xhtml => dom/xbl/crashtests/472260-1.xhtml rename : content/xbl/crashtests/477878-1.html => dom/xbl/crashtests/477878-1.html rename : content/xbl/crashtests/492978-1.xul => dom/xbl/crashtests/492978-1.xul rename : content/xbl/crashtests/493123-1.xhtml => dom/xbl/crashtests/493123-1.xhtml rename : content/xbl/crashtests/495354-1.xhtml => dom/xbl/crashtests/495354-1.xhtml rename : content/xbl/crashtests/507628-1.xhtml => dom/xbl/crashtests/507628-1.xhtml rename : content/xbl/crashtests/507991-1.xhtml => dom/xbl/crashtests/507991-1.xhtml rename : content/xbl/crashtests/830614-1.xul => dom/xbl/crashtests/830614-1.xul rename : content/xbl/crashtests/895805-1.xhtml => dom/xbl/crashtests/895805-1.xhtml rename : content/xbl/crashtests/crashtests.list => dom/xbl/crashtests/crashtests.list rename : content/xbl/crashtests/set-field-bad-this.xhtml => dom/xbl/crashtests/set-field-bad-this.xhtml rename : content/xbl/src/moz.build => dom/xbl/moz.build rename : content/xbl/src/nsBindingManager.cpp => dom/xbl/nsBindingManager.cpp rename : content/xbl/src/nsBindingManager.h => dom/xbl/nsBindingManager.h rename : content/xbl/src/nsXBLBinding.cpp => dom/xbl/nsXBLBinding.cpp rename : content/xbl/src/nsXBLBinding.h => dom/xbl/nsXBLBinding.h rename : content/xbl/src/nsXBLContentSink.cpp => dom/xbl/nsXBLContentSink.cpp rename : content/xbl/src/nsXBLContentSink.h => dom/xbl/nsXBLContentSink.h rename : content/xbl/src/nsXBLDocumentInfo.cpp => dom/xbl/nsXBLDocumentInfo.cpp rename : content/xbl/src/nsXBLDocumentInfo.h => dom/xbl/nsXBLDocumentInfo.h rename : content/xbl/src/nsXBLEventHandler.cpp => dom/xbl/nsXBLEventHandler.cpp rename : content/xbl/src/nsXBLEventHandler.h => dom/xbl/nsXBLEventHandler.h rename : content/xbl/src/nsXBLMaybeCompiled.h => dom/xbl/nsXBLMaybeCompiled.h rename : content/xbl/src/nsXBLProtoImpl.cpp => dom/xbl/nsXBLProtoImpl.cpp rename : content/xbl/src/nsXBLProtoImpl.h => dom/xbl/nsXBLProtoImpl.h rename : content/xbl/src/nsXBLProtoImplField.cpp => dom/xbl/nsXBLProtoImplField.cpp rename : content/xbl/src/nsXBLProtoImplField.h => dom/xbl/nsXBLProtoImplField.h rename : content/xbl/src/nsXBLProtoImplMember.h => dom/xbl/nsXBLProtoImplMember.h rename : content/xbl/src/nsXBLProtoImplMethod.cpp => dom/xbl/nsXBLProtoImplMethod.cpp rename : content/xbl/src/nsXBLProtoImplMethod.h => dom/xbl/nsXBLProtoImplMethod.h rename : content/xbl/src/nsXBLProtoImplProperty.cpp => dom/xbl/nsXBLProtoImplProperty.cpp rename : content/xbl/src/nsXBLProtoImplProperty.h => dom/xbl/nsXBLProtoImplProperty.h rename : content/xbl/src/nsXBLPrototypeBinding.cpp => dom/xbl/nsXBLPrototypeBinding.cpp rename : content/xbl/src/nsXBLPrototypeBinding.h => dom/xbl/nsXBLPrototypeBinding.h rename : content/xbl/src/nsXBLPrototypeHandler.cpp => dom/xbl/nsXBLPrototypeHandler.cpp rename : content/xbl/src/nsXBLPrototypeHandler.h => dom/xbl/nsXBLPrototypeHandler.h rename : content/xbl/src/nsXBLPrototypeResources.cpp => dom/xbl/nsXBLPrototypeResources.cpp rename : content/xbl/src/nsXBLPrototypeResources.h => dom/xbl/nsXBLPrototypeResources.h rename : content/xbl/src/nsXBLResourceLoader.cpp => dom/xbl/nsXBLResourceLoader.cpp rename : content/xbl/src/nsXBLResourceLoader.h => dom/xbl/nsXBLResourceLoader.h rename : content/xbl/src/nsXBLSerialize.cpp => dom/xbl/nsXBLSerialize.cpp rename : content/xbl/src/nsXBLSerialize.h => dom/xbl/nsXBLSerialize.h rename : content/xbl/src/nsXBLService.cpp => dom/xbl/nsXBLService.cpp rename : content/xbl/src/nsXBLService.h => dom/xbl/nsXBLService.h rename : content/xbl/src/nsXBLWindowKeyHandler.cpp => dom/xbl/nsXBLWindowKeyHandler.cpp rename : content/xbl/src/nsXBLWindowKeyHandler.h => dom/xbl/nsXBLWindowKeyHandler.h rename : content/xbl/test/bug310107-resource.xhtml => dom/xbl/test/bug310107-resource.xhtml rename : content/xbl/test/chrome.ini => dom/xbl/test/chrome.ini rename : content/xbl/test/file_bug372769.xhtml => dom/xbl/test/file_bug372769.xhtml rename : content/xbl/test/file_bug379959_cross.html => dom/xbl/test/file_bug379959_cross.html rename : content/xbl/test/file_bug379959_data.html => dom/xbl/test/file_bug379959_data.html rename : content/xbl/test/file_bug379959_xbl.xml => dom/xbl/test/file_bug379959_xbl.xml rename : content/xbl/test/file_bug397934.xhtml => dom/xbl/test/file_bug397934.xhtml rename : content/xbl/test/file_bug481558.xbl => dom/xbl/test/file_bug481558.xbl rename : content/xbl/test/file_bug481558css.sjs => dom/xbl/test/file_bug481558css.sjs rename : content/xbl/test/file_bug591198_inner.html => dom/xbl/test/file_bug591198_inner.html rename : content/xbl/test/file_bug591198_xbl.xml => dom/xbl/test/file_bug591198_xbl.xml rename : content/xbl/test/file_bug821850.xhtml => dom/xbl/test/file_bug821850.xhtml rename : content/xbl/test/file_bug844783.xhtml => dom/xbl/test/file_bug844783.xhtml rename : content/xbl/test/file_bug944407.html => dom/xbl/test/file_bug944407.html rename : content/xbl/test/file_bug944407.xml => dom/xbl/test/file_bug944407.xml rename : content/xbl/test/file_bug950909.html => dom/xbl/test/file_bug950909.html rename : content/xbl/test/file_bug950909.xml => dom/xbl/test/file_bug950909.xml rename : content/xbl/test/mochitest.ini => dom/xbl/test/mochitest.ini rename : content/xbl/test/moz.build => dom/xbl/test/moz.build rename : content/xbl/test/test_bug310107.html => dom/xbl/test/test_bug310107.html rename : content/xbl/test/test_bug366770.html => dom/xbl/test/test_bug366770.html rename : content/xbl/test/test_bug371724.xhtml => dom/xbl/test/test_bug371724.xhtml rename : content/xbl/test/test_bug372769.html => dom/xbl/test/test_bug372769.html rename : content/xbl/test/test_bug378518.xul => dom/xbl/test/test_bug378518.xul rename : content/xbl/test/test_bug378866.xhtml => dom/xbl/test/test_bug378866.xhtml rename : content/xbl/test/test_bug379959.html => dom/xbl/test/test_bug379959.html rename : content/xbl/test/test_bug389322.xhtml => dom/xbl/test/test_bug389322.xhtml rename : content/xbl/test/test_bug397934.html => dom/xbl/test/test_bug397934.html rename : content/xbl/test/test_bug398135.xul => dom/xbl/test/test_bug398135.xul rename : content/xbl/test/test_bug398492.xul => dom/xbl/test/test_bug398492.xul rename : content/xbl/test/test_bug400705.xhtml => dom/xbl/test/test_bug400705.xhtml rename : content/xbl/test/test_bug401907.xhtml => dom/xbl/test/test_bug401907.xhtml rename : content/xbl/test/test_bug403162.xhtml => dom/xbl/test/test_bug403162.xhtml rename : content/xbl/test/test_bug468210.xhtml => dom/xbl/test/test_bug468210.xhtml rename : content/xbl/test/test_bug481558.html => dom/xbl/test/test_bug481558.html rename : content/xbl/test/test_bug526178.xhtml => dom/xbl/test/test_bug526178.xhtml rename : content/xbl/test/test_bug542406.xhtml => dom/xbl/test/test_bug542406.xhtml rename : content/xbl/test/test_bug591198.html => dom/xbl/test/test_bug591198.html rename : content/xbl/test/test_bug639338.xhtml => dom/xbl/test/test_bug639338.xhtml rename : content/xbl/test/test_bug721452.xul => dom/xbl/test/test_bug721452.xul rename : content/xbl/test/test_bug723676.xul => dom/xbl/test/test_bug723676.xul rename : content/xbl/test/test_bug772966.xul => dom/xbl/test/test_bug772966.xul rename : content/xbl/test/test_bug790265.xhtml => dom/xbl/test/test_bug790265.xhtml rename : content/xbl/test/test_bug821850.html => dom/xbl/test/test_bug821850.html rename : content/xbl/test/test_bug844783.html => dom/xbl/test/test_bug844783.html rename : content/xbl/test/test_bug944407.xul => dom/xbl/test/test_bug944407.xul rename : content/xbl/test/test_bug950909.xul => dom/xbl/test/test_bug950909.xul extra : rebase_source : 44ab05088f70826c70dee3af30221e628ec1e4e8
368 lines
11 KiB
C++
368 lines
11 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* 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/. */
|
|
|
|
#include "nsIAtom.h"
|
|
#include "nsString.h"
|
|
#include "jsapi.h"
|
|
#include "nsIContent.h"
|
|
#include "nsXBLProtoImplProperty.h"
|
|
#include "nsUnicharUtils.h"
|
|
#include "nsCxPusher.h"
|
|
#include "nsReadableUtils.h"
|
|
#include "nsJSUtils.h"
|
|
#include "nsXBLPrototypeBinding.h"
|
|
#include "nsXBLSerialize.h"
|
|
#include "xpcpublic.h"
|
|
|
|
using namespace mozilla;
|
|
|
|
nsXBLProtoImplProperty::nsXBLProtoImplProperty(const char16_t* aName,
|
|
const char16_t* aGetter,
|
|
const char16_t* aSetter,
|
|
const char16_t* aReadOnly,
|
|
uint32_t aLineNumber) :
|
|
nsXBLProtoImplMember(aName),
|
|
mJSAttributes(JSPROP_ENUMERATE)
|
|
#ifdef DEBUG
|
|
, mIsCompiled(false)
|
|
#endif
|
|
{
|
|
MOZ_COUNT_CTOR(nsXBLProtoImplProperty);
|
|
|
|
if (aReadOnly) {
|
|
nsAutoString readOnly; readOnly.Assign(*aReadOnly);
|
|
if (readOnly.LowerCaseEqualsLiteral("true"))
|
|
mJSAttributes |= JSPROP_READONLY;
|
|
}
|
|
|
|
if (aGetter) {
|
|
AppendGetterText(nsDependentString(aGetter));
|
|
SetGetterLineNumber(aLineNumber);
|
|
}
|
|
if (aSetter) {
|
|
AppendSetterText(nsDependentString(aSetter));
|
|
SetSetterLineNumber(aLineNumber);
|
|
}
|
|
}
|
|
|
|
nsXBLProtoImplProperty::nsXBLProtoImplProperty(const char16_t* aName,
|
|
const bool aIsReadOnly)
|
|
: nsXBLProtoImplMember(aName),
|
|
mJSAttributes(JSPROP_ENUMERATE)
|
|
#ifdef DEBUG
|
|
, mIsCompiled(false)
|
|
#endif
|
|
{
|
|
MOZ_COUNT_CTOR(nsXBLProtoImplProperty);
|
|
|
|
if (aIsReadOnly)
|
|
mJSAttributes |= JSPROP_READONLY;
|
|
}
|
|
|
|
nsXBLProtoImplProperty::~nsXBLProtoImplProperty()
|
|
{
|
|
MOZ_COUNT_DTOR(nsXBLProtoImplProperty);
|
|
|
|
if (!mGetter.IsCompiled()) {
|
|
delete mGetter.GetUncompiled();
|
|
}
|
|
|
|
if (!mSetter.IsCompiled()) {
|
|
delete mSetter.GetUncompiled();
|
|
}
|
|
}
|
|
|
|
void nsXBLProtoImplProperty::EnsureUncompiledText(PropertyOp& aPropertyOp)
|
|
{
|
|
if (!aPropertyOp.GetUncompiled()) {
|
|
nsXBLTextWithLineNumber* text = new nsXBLTextWithLineNumber();
|
|
aPropertyOp.SetUncompiled(text);
|
|
}
|
|
}
|
|
|
|
void
|
|
nsXBLProtoImplProperty::AppendGetterText(const nsAString& aText)
|
|
{
|
|
NS_PRECONDITION(!mIsCompiled,
|
|
"Must not be compiled when accessing getter text");
|
|
EnsureUncompiledText(mGetter);
|
|
mGetter.GetUncompiled()->AppendText(aText);
|
|
}
|
|
|
|
void
|
|
nsXBLProtoImplProperty::AppendSetterText(const nsAString& aText)
|
|
{
|
|
NS_PRECONDITION(!mIsCompiled,
|
|
"Must not be compiled when accessing setter text");
|
|
EnsureUncompiledText(mSetter);
|
|
mSetter.GetUncompiled()->AppendText(aText);
|
|
}
|
|
|
|
void
|
|
nsXBLProtoImplProperty::SetGetterLineNumber(uint32_t aLineNumber)
|
|
{
|
|
NS_PRECONDITION(!mIsCompiled,
|
|
"Must not be compiled when accessing getter text");
|
|
EnsureUncompiledText(mGetter);
|
|
mGetter.GetUncompiled()->SetLineNumber(aLineNumber);
|
|
}
|
|
|
|
void
|
|
nsXBLProtoImplProperty::SetSetterLineNumber(uint32_t aLineNumber)
|
|
{
|
|
NS_PRECONDITION(!mIsCompiled,
|
|
"Must not be compiled when accessing setter text");
|
|
EnsureUncompiledText(mSetter);
|
|
mSetter.GetUncompiled()->SetLineNumber(aLineNumber);
|
|
}
|
|
|
|
const char* gPropertyArgs[] = { "val" };
|
|
|
|
nsresult
|
|
nsXBLProtoImplProperty::InstallMember(JSContext *aCx,
|
|
JS::Handle<JSObject*> aTargetClassObject)
|
|
{
|
|
NS_PRECONDITION(mIsCompiled,
|
|
"Should not be installing an uncompiled property");
|
|
MOZ_ASSERT(mGetter.IsCompiled() && mSetter.IsCompiled());
|
|
MOZ_ASSERT(js::IsObjectInContextCompartment(aTargetClassObject, aCx));
|
|
JS::Rooted<JSObject*> globalObject(aCx, JS_GetGlobalForObject(aCx, aTargetClassObject));
|
|
MOZ_ASSERT(xpc::IsInXBLScope(globalObject) ||
|
|
globalObject == xpc::GetXBLScope(aCx, globalObject));
|
|
|
|
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)))
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
}
|
|
|
|
if (setter) {
|
|
if (!(setter = ::JS_CloneFunctionObject(aCx, setter, globalObject)))
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
}
|
|
|
|
nsDependentString name(mName);
|
|
if (!::JS_DefineUCProperty(aCx, aTargetClassObject,
|
|
static_cast<const jschar*>(mName),
|
|
name.Length(), JSVAL_VOID,
|
|
JS_DATA_TO_FUNC_PTR(JSPropertyOp, getter.get()),
|
|
JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, setter.get()),
|
|
mJSAttributes))
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
nsXBLProtoImplProperty::CompileMember(const nsCString& aClassStr,
|
|
JS::Handle<JSObject*> aClassObject)
|
|
{
|
|
AssertInCompilationScope();
|
|
NS_PRECONDITION(!mIsCompiled,
|
|
"Trying to compile an already-compiled property");
|
|
NS_PRECONDITION(aClassObject,
|
|
"Must have class object to compile");
|
|
MOZ_ASSERT(!mGetter.IsCompiled() && !mSetter.IsCompiled());
|
|
|
|
if (!mName)
|
|
return NS_ERROR_FAILURE; // Without a valid name, we can't install the member.
|
|
|
|
// We have a property.
|
|
nsresult rv = NS_OK;
|
|
|
|
nsAutoCString functionUri;
|
|
if (mGetter.GetUncompiled() || mSetter.GetUncompiled()) {
|
|
functionUri = aClassStr;
|
|
int32_t hash = functionUri.RFindChar('#');
|
|
if (hash != kNotFound) {
|
|
functionUri.Truncate(hash);
|
|
}
|
|
}
|
|
|
|
bool deletedGetter = false;
|
|
nsXBLTextWithLineNumber *getterText = mGetter.GetUncompiled();
|
|
if (getterText && getterText->GetText()) {
|
|
nsDependentString getter(getterText->GetText());
|
|
if (!getter.IsEmpty()) {
|
|
AutoJSContext cx;
|
|
JSAutoCompartment ac(cx, aClassObject);
|
|
JS::CompileOptions options(cx);
|
|
options.setFileAndLine(functionUri.get(), getterText->GetLineNumber())
|
|
.setVersion(JSVERSION_LATEST);
|
|
nsCString name = NS_LITERAL_CSTRING("get_") + NS_ConvertUTF16toUTF8(mName);
|
|
JS::Rooted<JSObject*> getterObject(cx);
|
|
rv = nsJSUtils::CompileFunction(cx, JS::NullPtr(), options, name, 0,
|
|
nullptr, getter, getterObject.address());
|
|
|
|
delete getterText;
|
|
deletedGetter = true;
|
|
|
|
mGetter.SetJSFunction(getterObject);
|
|
|
|
if (mGetter.GetJSFunction() && NS_SUCCEEDED(rv)) {
|
|
mJSAttributes |= JSPROP_GETTER | JSPROP_SHARED;
|
|
}
|
|
if (NS_FAILED(rv)) {
|
|
mGetter.SetJSFunction(nullptr);
|
|
mJSAttributes &= ~JSPROP_GETTER;
|
|
/*chaining to return failure*/
|
|
}
|
|
}
|
|
} // if getter is not empty
|
|
|
|
if (!deletedGetter) { // Empty getter
|
|
delete getterText;
|
|
mGetter.SetJSFunction(nullptr);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
bool deletedSetter = false;
|
|
nsXBLTextWithLineNumber *setterText = mSetter.GetUncompiled();
|
|
if (setterText && setterText->GetText()) {
|
|
nsDependentString setter(setterText->GetText());
|
|
if (!setter.IsEmpty()) {
|
|
AutoJSContext cx;
|
|
JSAutoCompartment ac(cx, aClassObject);
|
|
JS::CompileOptions options(cx);
|
|
options.setFileAndLine(functionUri.get(), setterText->GetLineNumber())
|
|
.setVersion(JSVERSION_LATEST);
|
|
nsCString name = NS_LITERAL_CSTRING("set_") + NS_ConvertUTF16toUTF8(mName);
|
|
JS::Rooted<JSObject*> setterObject(cx);
|
|
rv = nsJSUtils::CompileFunction(cx, JS::NullPtr(), options, name, 1,
|
|
gPropertyArgs, setter,
|
|
setterObject.address());
|
|
|
|
delete setterText;
|
|
deletedSetter = true;
|
|
mSetter.SetJSFunction(setterObject);
|
|
|
|
if (mSetter.GetJSFunction() && NS_SUCCEEDED(rv)) {
|
|
mJSAttributes |= JSPROP_SETTER | JSPROP_SHARED;
|
|
}
|
|
if (NS_FAILED(rv)) {
|
|
mSetter.SetJSFunction(nullptr);
|
|
mJSAttributes &= ~JSPROP_SETTER;
|
|
/*chaining to return failure*/
|
|
}
|
|
}
|
|
} // if setter wasn't empty....
|
|
|
|
if (!deletedSetter) { // Empty setter
|
|
delete setterText;
|
|
mSetter.SetJSFunction(nullptr);
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
mIsCompiled = NS_SUCCEEDED(rv);
|
|
#endif
|
|
|
|
return rv;
|
|
}
|
|
|
|
void
|
|
nsXBLProtoImplProperty::Trace(const TraceCallbacks& aCallbacks, void *aClosure)
|
|
{
|
|
if (mJSAttributes & JSPROP_GETTER) {
|
|
aCallbacks.Trace(&mGetter.AsHeapObject(), "mGetter", aClosure);
|
|
}
|
|
|
|
if (mJSAttributes & JSPROP_SETTER) {
|
|
aCallbacks.Trace(&mSetter.AsHeapObject(), "mSetter", aClosure);
|
|
}
|
|
}
|
|
|
|
nsresult
|
|
nsXBLProtoImplProperty::Read(nsIObjectInputStream* aStream,
|
|
XBLBindingSerializeDetails aType)
|
|
{
|
|
AssertInCompilationScope();
|
|
MOZ_ASSERT(!mIsCompiled);
|
|
MOZ_ASSERT(!mGetter.GetUncompiled() && !mSetter.GetUncompiled());
|
|
|
|
AutoJSContext cx;
|
|
JS::Rooted<JSObject*> getterObject(cx);
|
|
if (aType == XBLBinding_Serialize_GetterProperty ||
|
|
aType == XBLBinding_Serialize_GetterSetterProperty) {
|
|
nsresult rv = XBL_DeserializeFunction(aStream, &getterObject);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
mJSAttributes |= JSPROP_GETTER | JSPROP_SHARED;
|
|
}
|
|
mGetter.SetJSFunction(getterObject);
|
|
|
|
JS::Rooted<JSObject*> setterObject(cx);
|
|
if (aType == XBLBinding_Serialize_SetterProperty ||
|
|
aType == XBLBinding_Serialize_GetterSetterProperty) {
|
|
nsresult rv = XBL_DeserializeFunction(aStream, &setterObject);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
mJSAttributes |= JSPROP_SETTER | JSPROP_SHARED;
|
|
}
|
|
mSetter.SetJSFunction(setterObject);
|
|
|
|
#ifdef DEBUG
|
|
mIsCompiled = true;
|
|
#endif
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
nsXBLProtoImplProperty::Write(nsIObjectOutputStream* aStream)
|
|
{
|
|
AssertInCompilationScope();
|
|
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);
|
|
|
|
// 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);
|
|
|
|
if (mJSAttributes & JSPROP_GETTER) {
|
|
JS::Handle<JSObject*> function =
|
|
JS::Handle<JSObject*>::fromMarkedLocation(mGetter.AsHeapObject().address());
|
|
rv = XBL_SerializeFunction(aStream, function);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
}
|
|
|
|
if (mJSAttributes & JSPROP_SETTER) {
|
|
JS::Handle<JSObject*> function =
|
|
JS::Handle<JSObject*>::fromMarkedLocation(mSetter.AsHeapObject().address());
|
|
rv = XBL_SerializeFunction(aStream, function);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|