mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 23:35:34 +00:00
Bug 1706404 - BaseDOMProxyHandler::getOwnPropertyDescriptor should return Maybe<PropertyDescriptor>. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D113660
This commit is contained in:
parent
45a00f6d24
commit
133196d301
@ -73,7 +73,10 @@ static bool ShouldExposeChildWindow(const nsString& aNameBeingResolved,
|
||||
|
||||
bool WindowNamedPropertiesHandler::getOwnPropDescriptor(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aProxy, JS::Handle<jsid> aId,
|
||||
bool /* unused */, JS::MutableHandle<JS::PropertyDescriptor> aDesc) const {
|
||||
bool /* unused */,
|
||||
JS::MutableHandle<Maybe<JS::PropertyDescriptor>> aDesc) const {
|
||||
aDesc.reset();
|
||||
|
||||
if (!JSID_IS_STRING(aId)) {
|
||||
if (aId.isWellKnownSymbol(JS::SymbolCode::toStringTag)) {
|
||||
JS::Rooted<JSString*> toStringTagStr(
|
||||
@ -83,7 +86,8 @@ bool WindowNamedPropertiesHandler::getOwnPropDescriptor(
|
||||
}
|
||||
|
||||
JS::Rooted<JS::Value> v(aCx, JS::StringValue(toStringTagStr));
|
||||
FillPropertyDescriptor(aDesc, aProxy, JSPROP_READONLY, v);
|
||||
FillPropertyDescriptor(aCx, aDesc, aProxy, v, /* readonly = */ true,
|
||||
/* enumerable = */ false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -120,7 +124,8 @@ bool WindowNamedPropertiesHandler::getOwnPropDescriptor(
|
||||
if (!ToJSValue(aCx, WindowProxyHolder(std::move(child)), &v)) {
|
||||
return false;
|
||||
}
|
||||
FillPropertyDescriptor(aDesc, aProxy, 0, v);
|
||||
FillPropertyDescriptor(aCx, aDesc, aProxy, v, /* readonly = */ false,
|
||||
/* enumerable = */ false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -138,7 +143,8 @@ bool WindowNamedPropertiesHandler::getOwnPropDescriptor(
|
||||
if (!ToJSValue(aCx, element, &v)) {
|
||||
return false;
|
||||
}
|
||||
FillPropertyDescriptor(aDesc, aProxy, 0, v);
|
||||
FillPropertyDescriptor(aCx, aDesc, aProxy, v, /* readonly = */ false,
|
||||
/* enumerable = */ false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -149,7 +155,8 @@ bool WindowNamedPropertiesHandler::getOwnPropDescriptor(
|
||||
}
|
||||
|
||||
if (found) {
|
||||
FillPropertyDescriptor(aDesc, aProxy, 0, v);
|
||||
FillPropertyDescriptor(aCx, aDesc, aProxy, v, /* readonly = */ false,
|
||||
/* enumerable = */ false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ class WindowNamedPropertiesHandler : public BaseDOMProxyHandler {
|
||||
virtual bool getOwnPropDescriptor(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aProxy, JS::Handle<jsid> aId,
|
||||
bool /* unused */,
|
||||
JS::MutableHandle<JS::PropertyDescriptor> aDesc) const override;
|
||||
JS::MutableHandle<Maybe<JS::PropertyDescriptor>> aDesc) const override;
|
||||
virtual bool defineProperty(JSContext* aCx, JS::Handle<JSObject*> aProxy,
|
||||
JS::Handle<jsid> aId,
|
||||
JS::Handle<JS::PropertyDescriptor> aDesc,
|
||||
|
@ -14449,7 +14449,7 @@ class CGDOMJSProxyHandler_getOwnPropDescriptor(ClassMethod):
|
||||
Argument("JS::Handle<JSObject*>", "proxy"),
|
||||
Argument("JS::Handle<jsid>", "id"),
|
||||
Argument("bool", "ignoreNamedProps"),
|
||||
Argument("JS::MutableHandle<JS::PropertyDescriptor>", "desc"),
|
||||
Argument("JS::MutableHandle<Maybe<JS::PropertyDescriptor>>", "desc"),
|
||||
]
|
||||
ClassMethod.__init__(
|
||||
self,
|
||||
@ -14485,11 +14485,12 @@ class CGDOMJSProxyHandler_getOwnPropDescriptor(ClassMethod):
|
||||
if self.descriptor.supportsIndexedProperties():
|
||||
readonly = toStringBool(indexedSetter is None)
|
||||
fillDescriptor = (
|
||||
"FillPropertyDescriptor(desc, proxy, %s);\nreturn true;\n" % readonly
|
||||
"FillPropertyDescriptor(cx, desc, proxy, value, %s);\nreturn true;\n"
|
||||
% readonly
|
||||
)
|
||||
templateValues = {
|
||||
"jsvalRef": "desc.value()",
|
||||
"jsvalHandle": "desc.value()",
|
||||
"jsvalRef": "value",
|
||||
"jsvalHandle": "&value",
|
||||
"obj": "proxy",
|
||||
"successCode": fillDescriptor,
|
||||
}
|
||||
@ -14497,6 +14498,7 @@ class CGDOMJSProxyHandler_getOwnPropDescriptor(ClassMethod):
|
||||
"""
|
||||
uint32_t index = GetArrayIndexFromId(id);
|
||||
if (IsArrayIndex(index)) {
|
||||
JS::Rooted<JS::Value> value(cx);
|
||||
$*{callGetter}
|
||||
}
|
||||
|
||||
@ -14514,13 +14516,13 @@ class CGDOMJSProxyHandler_getOwnPropDescriptor(ClassMethod):
|
||||
operations = self.descriptor.operations
|
||||
readonly = toStringBool(operations["NamedSetter"] is None)
|
||||
fillDescriptor = (
|
||||
"FillPropertyDescriptor(desc, proxy, %s, %s);\n"
|
||||
"FillPropertyDescriptor(cx, desc, proxy, value, %s, %s);\n"
|
||||
"return true;\n"
|
||||
% (readonly, toStringBool(self.descriptor.namedPropertiesEnumerable))
|
||||
)
|
||||
templateValues = {
|
||||
"jsvalRef": "desc.value()",
|
||||
"jsvalHandle": "desc.value()",
|
||||
"jsvalRef": "value",
|
||||
"jsvalHandle": "&value",
|
||||
"obj": "proxy",
|
||||
"successCode": fillDescriptor,
|
||||
}
|
||||
@ -14558,6 +14560,7 @@ class CGDOMJSProxyHandler_getOwnPropDescriptor(ClassMethod):
|
||||
$*{computeCondition}
|
||||
}
|
||||
if (callNamedGetter) {
|
||||
JS::Rooted<JS::Value> value(cx);
|
||||
$*{namedGetCode}
|
||||
}
|
||||
""",
|
||||
@ -14579,15 +14582,13 @@ class CGDOMJSProxyHandler_getOwnPropDescriptor(ClassMethod):
|
||||
if (!JS_GetOwnPropertyDescriptorById(cx, expando, id, desc)) {
|
||||
return false;
|
||||
}
|
||||
if (desc.object()) {
|
||||
// Pretend the property lives on the wrapper.
|
||||
desc.object().set(proxy);
|
||||
if (desc.isSome()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$*{namedGet}
|
||||
desc.object().set(nullptr);
|
||||
desc.reset();
|
||||
return true;
|
||||
""",
|
||||
xrayDecl=xrayDecl,
|
||||
|
@ -197,18 +197,8 @@ bool DOMProxyHandler::isExtensible(JSContext* cx, JS::Handle<JSObject*> proxy,
|
||||
bool BaseDOMProxyHandler::getOwnPropertyDescriptor(
|
||||
JSContext* cx, Handle<JSObject*> proxy, Handle<jsid> id,
|
||||
MutableHandle<Maybe<PropertyDescriptor>> desc) const {
|
||||
Rooted<PropertyDescriptor> ownDesc(cx);
|
||||
if (!getOwnPropDescriptor(cx, proxy, id, /* ignoreNamedProps = */ false,
|
||||
&ownDesc)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ownDesc.object()) {
|
||||
desc.set(Some(ownDesc.get()));
|
||||
} else {
|
||||
desc.reset();
|
||||
}
|
||||
return true;
|
||||
return getOwnPropDescriptor(cx, proxy, id, /* ignoreNamedProps = */ false,
|
||||
desc);
|
||||
}
|
||||
|
||||
bool DOMProxyHandler::defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy,
|
||||
@ -248,17 +238,10 @@ bool DOMProxyHandler::set(JSContext* cx, Handle<JSObject*> proxy,
|
||||
|
||||
// Make sure to ignore our named properties when checking for own
|
||||
// property descriptors for a set.
|
||||
Rooted<PropertyDescriptor> ownDesc_(cx);
|
||||
if (!getOwnPropDescriptor(cx, proxy, id, /* ignoreNamedProps = */ true,
|
||||
&ownDesc_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Rooted<Maybe<PropertyDescriptor>> ownDesc(cx);
|
||||
if (ownDesc_.object()) {
|
||||
ownDesc.set(mozilla::Some(ownDesc_.get()));
|
||||
} else {
|
||||
ownDesc.reset();
|
||||
if (!getOwnPropDescriptor(cx, proxy, id, /* ignoreNamedProps = */ true,
|
||||
&ownDesc)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return js::SetPropertyIgnoringNamedGetter(cx, proxy, id, v, receiver, ownDesc,
|
||||
|
@ -89,7 +89,7 @@ class BaseDOMProxyHandler : public js::BaseProxyHandler {
|
||||
virtual bool getOwnPropDescriptor(
|
||||
JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id,
|
||||
bool ignoreNamedProps,
|
||||
JS::MutableHandle<JS::PropertyDescriptor> desc) const = 0;
|
||||
JS::MutableHandle<Maybe<JS::PropertyDescriptor>> desc) const = 0;
|
||||
};
|
||||
|
||||
class DOMProxyHandler : public BaseDOMProxyHandler {
|
||||
|
Loading…
Reference in New Issue
Block a user