Bug 1124890 - Replace LookProperty with GetOwnProperty in ObjectToSource. r=Waldo
authorTom Schuster <evilpies@gmail.com>
Sat, 24 Jan 2015 01:18:25 +0100
changeset 225515 42d4b2cb18b6567890c2113784761eb8f17337a1
parent 225514 2cff252b37e2332d79e5a40d9bce36c5613ba3aa
child 225516 e4cea48ed2f5a3c23272d2693be6197c9480d750
push id28163
push userphilringnalda@gmail.com
push dateSat, 24 Jan 2015 16:27:39 +0000
treeherdermozilla-central@1cf171c1a177 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs1124890
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1124890 - Replace LookProperty with GetOwnProperty in ObjectToSource. r=Waldo
js/src/builtin/Object.cpp
js/src/tests/js1_8_5/extensions/object-toSource-undefined-getter.js
--- a/js/src/builtin/Object.cpp
+++ b/js/src/builtin/Object.cpp
@@ -185,45 +185,37 @@ js::ObjectToSource(JSContext *cx, Handle
 
     AutoIdVector idv(cx);
     if (!GetPropertyKeys(cx, obj, JSITER_OWNONLY | JSITER_SYMBOLS, &idv))
         return nullptr;
 
     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;
             }
         }
 
         /* Convert id to a string. */
         RootedString idstr(cx);
         if (JSID_IS_SYMBOL(id)) {
             RootedValue v(cx, SymbolValue(JSID_TO_SYMBOL(id)));
             idstr = ValueToSource(cx, v);
@@ -245,23 +237,16 @@ js::ObjectToSource(JSContext *cx, Handle
             {
                 idstr = js_QuoteString(cx, idstr, char16_t('\''));
                 if (!idstr)
                     return nullptr;
             }
         }
 
         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)
                 return nullptr;
 
             RootedLinearString valstr(cx, valsource->ensureLinear(cx));
             if (!valstr)
                 return nullptr;
new file mode 100644
--- /dev/null
+++ b/js/src/tests/js1_8_5/extensions/object-toSource-undefined-getter.js
@@ -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);