зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1452981 - Use ToJSValue instead of WrapObject if we know we have a nsWrapperCache. r=bz.
--HG-- extra : rebase_source : 17bf9dabcf0a9c841612e808ca08755f6841e8c9
This commit is contained in:
Родитель
b293adf1cf
Коммит
ea57f65484
|
@ -113,7 +113,7 @@ WindowNamedPropertiesHandler::getOwnPropDescriptor(JSContext* aCx,
|
|||
// global scope is still allowed, since |var| only looks up |own|
|
||||
// properties. But unqualified shadowing will fail, per-spec.
|
||||
JS::Rooted<JS::Value> v(aCx);
|
||||
if (!WrapObject(aCx, childWin, &v)) {
|
||||
if (!ToJSValue(aCx, nsGlobalWindowOuter::Cast(childWin), &v)) {
|
||||
return false;
|
||||
}
|
||||
FillPropertyDescriptor(aDesc, aProxy, 0, v);
|
||||
|
@ -128,27 +128,25 @@ WindowNamedPropertiesHandler::getOwnPropDescriptor(JSContext* aCx,
|
|||
}
|
||||
nsHTMLDocument* document = static_cast<nsHTMLDocument*>(htmlDoc.get());
|
||||
|
||||
JS::Rooted<JS::Value> v(aCx);
|
||||
Element* element = document->GetElementById(str);
|
||||
if (element) {
|
||||
JS::Rooted<JS::Value> v(aCx);
|
||||
if (!WrapObject(aCx, element, &v)) {
|
||||
if (!ToJSValue(aCx, element, &v)) {
|
||||
return false;
|
||||
}
|
||||
FillPropertyDescriptor(aDesc, aProxy, 0, v);
|
||||
return true;
|
||||
}
|
||||
|
||||
nsWrapperCache* cache;
|
||||
nsISupports* result = document->ResolveName(str, &cache);
|
||||
if (!result) {
|
||||
return true;
|
||||
}
|
||||
|
||||
JS::Rooted<JS::Value> v(aCx);
|
||||
if (!WrapObject(aCx, result, cache, nullptr, &v)) {
|
||||
ErrorResult rv;
|
||||
bool found = document->ResolveName(aCx, str, &v, rv);
|
||||
if (rv.MaybeSetPendingException(aCx)) {
|
||||
return false;
|
||||
}
|
||||
FillPropertyDescriptor(aDesc, aProxy, 0, v);
|
||||
|
||||
if (found) {
|
||||
FillPropertyDescriptor(aDesc, aProxy, 0, v);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1889,64 +1889,49 @@ nsHTMLDocument::ReleaseEvents()
|
|||
WarnOnceAbout(nsIDocument::eUseOfReleaseEvents);
|
||||
}
|
||||
|
||||
nsISupports*
|
||||
nsHTMLDocument::ResolveName(const nsAString& aName, nsWrapperCache **aCache)
|
||||
bool
|
||||
nsHTMLDocument::ResolveName(JSContext* aCx, const nsAString& aName,
|
||||
JS::MutableHandle<JS::Value> aRetval, ErrorResult& aError)
|
||||
{
|
||||
nsIdentifierMapEntry *entry = mIdentifierMap.GetEntry(aName);
|
||||
if (!entry) {
|
||||
*aCache = nullptr;
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
nsBaseContentList *list = entry->GetNameContentList();
|
||||
uint32_t length = list ? list->Length() : 0;
|
||||
|
||||
nsIContent *node;
|
||||
if (length > 0) {
|
||||
if (length == 1) {
|
||||
// Only one element in the list, return the element instead of returning
|
||||
// the list.
|
||||
nsIContent *node = list->Item(0);
|
||||
*aCache = node;
|
||||
return node;
|
||||
if (length > 1) {
|
||||
// The list contains more than one element, return the whole list.
|
||||
if (!ToJSValue(aCx, list, aRetval)) {
|
||||
aError.NoteJSContextException(aCx);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// The list contains more than one element, return the whole list.
|
||||
*aCache = list;
|
||||
return list;
|
||||
// Only one element in the list, return the element instead of returning
|
||||
// the list.
|
||||
node = list->Item(0);
|
||||
} else {
|
||||
// No named items were found, see if there's one registerd by id for aName.
|
||||
Element *e = entry->GetIdElement();
|
||||
|
||||
if (!e || !nsGenericHTMLElement::ShouldExposeIdAsHTMLDocumentProperty(e)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
node = e;
|
||||
}
|
||||
|
||||
// No named items were found, see if there's one registerd by id for aName.
|
||||
Element *e = entry->GetIdElement();
|
||||
|
||||
if (e && nsGenericHTMLElement::ShouldExposeIdAsHTMLDocumentProperty(e)) {
|
||||
*aCache = e;
|
||||
return e;
|
||||
if (!ToJSValue(aCx, node, aRetval)) {
|
||||
aError.NoteJSContextException(aCx);
|
||||
return false;
|
||||
}
|
||||
|
||||
*aCache = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLDocument::NamedGetter(JSContext* cx, const nsAString& aName, bool& aFound,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& rv)
|
||||
{
|
||||
nsWrapperCache* cache;
|
||||
nsISupports* supp = ResolveName(aName, &cache);
|
||||
if (!supp) {
|
||||
aFound = false;
|
||||
aRetval.set(nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
JS::Rooted<JS::Value> val(cx);
|
||||
if (!dom::WrapObject(cx, supp, cache, nullptr, &val)) {
|
||||
rv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
||||
return;
|
||||
}
|
||||
aFound = true;
|
||||
aRetval.set(&val.toObject());
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -79,7 +79,9 @@ public:
|
|||
|
||||
mozilla::dom::HTMLAllCollection* All();
|
||||
|
||||
nsISupports* ResolveName(const nsAString& aName, nsWrapperCache **aCache);
|
||||
// Returns whether an object was found for aName.
|
||||
bool ResolveName(JSContext* aCx, const nsAString& aName,
|
||||
JS::MutableHandle<JS::Value> aRetval, mozilla::ErrorResult& aError);
|
||||
|
||||
virtual void AddedForm() override;
|
||||
virtual void RemovedForm() override;
|
||||
|
@ -151,7 +153,13 @@ public:
|
|||
void SetCookie(const nsAString& aCookie, mozilla::ErrorResult& rv);
|
||||
void NamedGetter(JSContext* cx, const nsAString& aName, bool& aFound,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
mozilla::ErrorResult& rv);
|
||||
mozilla::ErrorResult& rv)
|
||||
{
|
||||
JS::Rooted<JS::Value> v(cx);
|
||||
if ((aFound = ResolveName(cx, aName, &v, rv))) {
|
||||
aRetval.set(v.toObjectOrNull());
|
||||
}
|
||||
}
|
||||
void GetSupportedNames(nsTArray<nsString>& aNames);
|
||||
already_AddRefed<nsIDocument> Open(JSContext* cx,
|
||||
const mozilla::dom::Optional<nsAString>& /* unused */,
|
||||
|
|
Загрузка…
Ссылка в новой задаче