зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1706404 - Change internal GetPropertyDescriptor to use Maybe and return holder object seperately. r=jandem
Depends on D112790 Differential Revision: https://phabricator.services.mozilla.com/D112917
This commit is contained in:
Родитель
2a9dcca214
Коммит
26e2ecda9f
|
@ -2037,7 +2037,19 @@ JS_PUBLIC_API bool JS_GetPropertyDescriptorById(
|
|||
JSContext* cx, HandleObject obj, HandleId id,
|
||||
MutableHandle<PropertyDescriptor> desc) {
|
||||
cx->check(obj, id);
|
||||
return GetPropertyDescriptor(cx, obj, id, desc);
|
||||
|
||||
Rooted<Maybe<PropertyDescriptor>> desc_(cx);
|
||||
RootedObject holder(cx);
|
||||
if (!GetPropertyDescriptor(cx, obj, id, &desc_, &holder)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (desc_.isNothing()) {
|
||||
desc.object().set(nullptr);
|
||||
} else {
|
||||
desc.set(*desc_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API bool JS_GetPropertyDescriptor(
|
||||
|
|
|
@ -1410,12 +1410,13 @@ static bool SuppressDeletedProperty(JSContext* cx, NativeIterator* ni,
|
|||
return false;
|
||||
}
|
||||
|
||||
Rooted<PropertyDescriptor> desc(cx);
|
||||
if (!GetPropertyDescriptor(cx, proto, id, &desc)) {
|
||||
Rooted<mozilla::Maybe<PropertyDescriptor>> desc(cx);
|
||||
RootedObject holder(cx);
|
||||
if (!GetPropertyDescriptor(cx, proto, id, &desc, &holder)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (desc.object() && desc.enumerable()) {
|
||||
if (desc.isSome() && desc->enumerable()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2505,18 +2505,18 @@ bool js::SetImmutablePrototype(JSContext* cx, HandleObject obj,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool js::GetPropertyDescriptor(JSContext* cx, HandleObject obj, HandleId id,
|
||||
MutableHandle<PropertyDescriptor> desc) {
|
||||
bool js::GetPropertyDescriptor(
|
||||
JSContext* cx, HandleObject obj, HandleId id,
|
||||
MutableHandle<mozilla::Maybe<PropertyDescriptor>> desc,
|
||||
MutableHandleObject holder) {
|
||||
RootedObject pobj(cx);
|
||||
|
||||
Rooted<Maybe<PropertyDescriptor>> desc_(cx);
|
||||
for (pobj = obj; pobj;) {
|
||||
if (!GetOwnPropertyDescriptor(cx, pobj, id, &desc_)) {
|
||||
if (!GetOwnPropertyDescriptor(cx, pobj, id, desc)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (desc_.isSome()) {
|
||||
desc.set(*desc_);
|
||||
if (desc.isSome()) {
|
||||
holder.set(desc->objectDoNotUse());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2525,7 +2525,8 @@ bool js::GetPropertyDescriptor(JSContext* cx, HandleObject obj, HandleId id,
|
|||
}
|
||||
}
|
||||
|
||||
MOZ_ASSERT(!desc.object());
|
||||
MOZ_ASSERT(desc.isNothing());
|
||||
MOZ_ASSERT(!holder);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -265,9 +265,15 @@ extern bool GetPrototypeIfOrdinary(JSContext* cx, JS::Handle<JSObject*> obj,
|
|||
extern bool SetImmutablePrototype(JSContext* cx, JS::Handle<JSObject*> obj,
|
||||
bool* succeeded);
|
||||
|
||||
extern bool GetPropertyDescriptor(JSContext* cx, JS::Handle<JSObject*> obj,
|
||||
JS::Handle<jsid> id,
|
||||
MutableHandle<JS::PropertyDescriptor> desc);
|
||||
/*
|
||||
* Deprecated. Finds a PropertyDescriptor somewhere along the prototype chain,
|
||||
* similar to GetOwnPropertyDescriptor. |holder| indicates on which object the
|
||||
* property was found.
|
||||
*/
|
||||
extern bool GetPropertyDescriptor(
|
||||
JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id,
|
||||
MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc,
|
||||
JS::MutableHandle<JSObject*> holder);
|
||||
|
||||
/*
|
||||
* Deprecated. A version of HasProperty that also returns the object on which
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Compression.h"
|
||||
#include "mozilla/MathAlgorithms.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/ScopeExit.h"
|
||||
#include "mozilla/Sprintf.h" // SprintfLiteral
|
||||
#include "mozilla/Unused.h"
|
||||
|
@ -6436,21 +6437,22 @@ static bool GetDataProperty(JSContext* cx, HandleValue objVal, HandleAtom field,
|
|||
return LinkFail(cx, "accessing property of a Proxy");
|
||||
}
|
||||
|
||||
Rooted<PropertyDescriptor> desc(cx);
|
||||
RootedId id(cx, AtomToId(field));
|
||||
if (!GetPropertyDescriptor(cx, obj, id, &desc)) {
|
||||
Rooted<mozilla::Maybe<PropertyDescriptor>> desc(cx);
|
||||
RootedObject holder(cx);
|
||||
if (!GetPropertyDescriptor(cx, obj, id, &desc, &holder)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!desc.object()) {
|
||||
if (!desc.isSome()) {
|
||||
return LinkFail(cx, "property not present on object");
|
||||
}
|
||||
|
||||
if (!desc.isDataDescriptor()) {
|
||||
if (!desc->isDataDescriptor()) {
|
||||
return LinkFail(cx, "property is not a data property");
|
||||
}
|
||||
|
||||
v.set(desc.value());
|
||||
v.set(desc->value());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче