Fix for bug 820657 (Implement the NamedGetter functionality on HTMLDocument) - refactor code to support document.all. r=bz.

--HG--
extra : rebase_source : b69d963e8931a4f62dce64d7f90b78a05c488347
This commit is contained in:
Peter Van der Beken 2013-03-27 18:15:37 +01:00
parent 4bdb531d59
commit ca9babdeb5

View File

@ -7120,44 +7120,9 @@ nsHTMLDocumentSH::DocumentAllTagsNewResolve(JSContext *cx, JSHandleObject obj,
}
NS_IMETHODIMP
nsHTMLDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, uint32_t flags,
JSObject **objp, bool *_retval)
static nsresult
ResolveAll(JSContext* cx, nsIDocument* doc, JSObject* obj)
{
// nsDocumentSH::NewResolve() does a security check that we'd kinda
// want to do here too before doing anything else. But given that we
// only define dynamic properties here before the call to
// nsDocumentSH::NewResolve() we're ok, since once those properties
// are accessed, we'll do the necessary security check.
if (!(flags & JSRESOLVE_ASSIGNING)) {
// For native wrappers, do not resolve random names on document
JSAutoRequest ar(cx);
if (!ObjectIsNativeWrapper(cx, obj) ||
xpc::WrapperFactory::XrayWrapperNotShadowing(obj, id)) {
nsCOMPtr<nsISupports> result;
nsWrapperCache *cache;
nsresult rv = ResolveImpl(cx, wrapper, id, getter_AddRefs(result),
&cache);
NS_ENSURE_SUCCESS(rv, rv);
if (result) {
JSBool ok = *_retval =
::JS_DefinePropertyById(cx, obj, id, JSVAL_VOID, nullptr, nullptr, 0);
*objp = obj;
return ok ? NS_OK : NS_ERROR_FAILURE;
}
}
if (id == sAll_id && !sDisableDocumentAllSupport &&
!ObjectIsNativeWrapper(cx, obj)) {
nsIDocument *doc = static_cast<nsIDocument*>(wrapper->Native());
if (doc->GetCompatibilityMode() == eCompatibility_NavQuirks) {
JSObject *proto;
if (!::JS_GetPrototype(cx, obj, &proto)) {
return NS_ERROR_FAILURE;
@ -7221,6 +7186,49 @@ nsHTMLDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
return NS_ERROR_UNEXPECTED;
}
}
return NS_OK;
}
NS_IMETHODIMP
nsHTMLDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, uint32_t flags,
JSObject **objp, bool *_retval)
{
// nsDocumentSH::NewResolve() does a security check that we'd kinda
// want to do here too before doing anything else. But given that we
// only define dynamic properties here before the call to
// nsDocumentSH::NewResolve() we're ok, since once those properties
// are accessed, we'll do the necessary security check.
if (!(flags & JSRESOLVE_ASSIGNING)) {
// For native wrappers, do not resolve random names on document
JSAutoRequest ar(cx);
if (!ObjectIsNativeWrapper(cx, obj) ||
xpc::WrapperFactory::XrayWrapperNotShadowing(obj, id)) {
nsCOMPtr<nsISupports> result;
nsWrapperCache *cache;
nsresult rv = ResolveImpl(cx, wrapper, id, getter_AddRefs(result),
&cache);
NS_ENSURE_SUCCESS(rv, rv);
if (result) {
JSBool ok = *_retval =
::JS_DefinePropertyById(cx, obj, id, JSVAL_VOID, nullptr, nullptr, 0);
*objp = obj;
return ok ? NS_OK : NS_ERROR_FAILURE;
}
}
if (id == sAll_id && !sDisableDocumentAllSupport &&
!ObjectIsNativeWrapper(cx, obj)) {
nsIDocument *doc = static_cast<nsIDocument*>(wrapper->Native());
if (doc->GetCompatibilityMode() == eCompatibility_NavQuirks) {
return ResolveAll(cx, doc, obj);
}
return NS_OK;