зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1124890 - Replace LookProperty with GetOwnProperty in ObjectToSource. r=Waldo
This commit is contained in:
Родитель
11cb5dd66a
Коммит
7eb1c8173d
|
@ -190,35 +190,27 @@ js::ObjectToSource(JSContext *cx, HandleObject obj)
|
|||
bool comma = false;
|
||||
for (size_t i = 0; i < idv.length(); ++i) {
|
||||
RootedId id(cx, idv[i]);
|
||||
RootedObject obj2(cx);
|
||||
RootedShape shape(cx);
|
||||
if (!LookupProperty(cx, obj, id, &obj2, &shape))
|
||||
Rooted<PropertyDescriptor> desc(cx);
|
||||
if (!GetOwnPropertyDescriptor(cx, obj, id, &desc))
|
||||
return nullptr;
|
||||
|
||||
/* Decide early whether we prefer get/set or old getter/setter syntax. */
|
||||
int valcnt = 0;
|
||||
if (shape) {
|
||||
bool doGet = true;
|
||||
if (obj2->isNative() && !IsImplicitDenseOrTypedArrayElement(shape)) {
|
||||
unsigned attrs = shape->attributes();
|
||||
if (attrs & JSPROP_GETTER) {
|
||||
doGet = false;
|
||||
val[valcnt].set(shape->getterValue());
|
||||
if (desc.object()) {
|
||||
if (desc.hasGetterOrSetterObject()) {
|
||||
if (desc.hasGetterObject() && desc.getterObject()) {
|
||||
val[valcnt].setObject(*desc.getterObject());
|
||||
gsop[valcnt].set(cx->names().get);
|
||||
valcnt++;
|
||||
}
|
||||
if (attrs & JSPROP_SETTER) {
|
||||
doGet = false;
|
||||
val[valcnt].set(shape->setterValue());
|
||||
if (desc.hasSetterObject() && desc.setterObject()) {
|
||||
val[valcnt].setObject(*desc.setterObject());
|
||||
gsop[valcnt].set(cx->names().set);
|
||||
valcnt++;
|
||||
}
|
||||
}
|
||||
if (doGet) {
|
||||
} else {
|
||||
valcnt = 1;
|
||||
val[0].set(desc.value());
|
||||
gsop[0].set(nullptr);
|
||||
if (!GetProperty(cx, obj, obj, id, val[0]))
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -250,13 +242,6 @@ js::ObjectToSource(JSContext *cx, HandleObject obj)
|
|||
}
|
||||
|
||||
for (int j = 0; j < valcnt; j++) {
|
||||
/*
|
||||
* Censor an accessor descriptor getter or setter part if it's
|
||||
* undefined.
|
||||
*/
|
||||
if (gsop[j] && val[j].isUndefined())
|
||||
continue;
|
||||
|
||||
/* Convert val[j] to its canonical source form. */
|
||||
JSString *valsource = ValueToSource(cx, val[j]);
|
||||
if (!valsource)
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/licenses/publicdomain/ */
|
||||
|
||||
var desc = { get: undefined, set: undefined, configurable: true, enumerable: true };
|
||||
var obj = Object.defineProperty({}, "prop", desc);
|
||||
assertEq(obj.toSource(), "({})");
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(0, 0);
|
Загрузка…
Ссылка в новой задаче