Bug 1112778, part 4 - Rename a static function HasProperty -> GetPropertyIfPresent, to get it out of the way for js::HasProperty, which is coming in a subsequent patch. Remove the js::GetOwnPropertyDescriptor signature that makes an object: it was only used in one place. r=Waldo.
authorJason Orendorff <jorendorff@mozilla.com>
Thu, 18 Dec 2014 06:17:10 -0600
changeset 251148 d172d554c7326d971e275f51e31208cb871d0195
parent 251147 42e833ab7dea24b06adf2a374b4dadacec777387
child 251149 2575c07d5b5b722235c7706133714e5fae258c6a
push id4610
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:32:55 +0000
treeherdermozilla-beta@4df54044d9ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs1112778
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 1112778, part 4 - Rename a static function HasProperty -> GetPropertyIfPresent, to get it out of the way for js::HasProperty, which is coming in a subsequent patch. Remove the js::GetOwnPropertyDescriptor signature that makes an object: it was only used in one place. r=Waldo.
js/src/builtin/Object.cpp
js/src/jsobj.cpp
js/src/jsobj.h
--- a/js/src/builtin/Object.cpp
+++ b/js/src/builtin/Object.cpp
@@ -699,17 +699,19 @@ js::obj_getOwnPropertyDescriptor(JSConte
         return false;
 
     // Steps 3-4.
     RootedId id(cx);
     if (!ValueToId<CanGC>(cx, args.get(1), &id))
         return false;
 
     // Steps 5-7.
-    return GetOwnPropertyDescriptor(cx, obj, id, args.rval());
+    Rooted<PropertyDescriptor> desc(cx);
+    return GetOwnPropertyDescriptor(cx, obj, id, &desc) &&
+           NewPropertyDescriptorObject(cx, desc, args.rval());
 }
 
 // ES6 draft rev27 (2014/08/24) 19.1.2.14 Object.keys(O)
 static bool
 obj_keys(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     return GetOwnPropertyKeys(cx, args, JSITER_OWNONLY);
--- a/js/src/jsobj.cpp
+++ b/js/src/jsobj.cpp
@@ -277,24 +277,16 @@ js::GetOwnPropertyDescriptor(JSContext *
         return false;
 
     desc.value().set(value);
     desc.object().set(obj);
     return true;
 }
 
 bool
-js::GetOwnPropertyDescriptor(JSContext *cx, HandleObject obj, HandleId id, MutableHandleValue vp)
-{
-    Rooted<PropertyDescriptor> desc(cx);
-    return GetOwnPropertyDescriptor(cx, obj, id, &desc) &&
-           NewPropertyDescriptorObject(cx, desc, vp);
-}
-
-bool
 js::GetFirstArgumentAsObject(JSContext *cx, const CallArgs &args, const char *method,
                              MutableHandleObject objp)
 {
     if (args.length() == 0) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_MORE_ARGS_NEEDED,
                              method, "0", "s");
         return false;
     }
@@ -310,32 +302,27 @@ js::GetFirstArgumentAsObject(JSContext *
         return false;
     }
 
     objp.set(&v.toObject());
     return true;
 }
 
 static bool
-HasProperty(JSContext *cx, HandleObject obj, HandleId id, MutableHandleValue vp, bool *foundp)
+GetPropertyIfPresent(JSContext *cx, HandleObject obj, HandleId id, MutableHandleValue vp,
+                     bool *foundp)
 {
     if (!JSObject::hasProperty(cx, obj, id, foundp))
         return false;
     if (!*foundp) {
         vp.setUndefined();
         return true;
     }
 
-    /*
-     * We must go through the method read barrier in case id is 'get' or 'set'.
-     * There is no obvious way to defer cloning a joined function object whose
-     * identity will be used by DefinePropertyOnObject, e.g., or reflected via
-     * js::GetOwnPropertyDescriptor, as the getter or setter callable object.
-     */
-    return !!JSObject::getGeneric(cx, obj, obj, id, vp);
+    return JSObject::getGeneric(cx, obj, obj, id, vp);
 }
 
 bool
 PropDesc::initialize(JSContext *cx, const Value &origval, bool checkAccessors)
 {
     MOZ_ASSERT(isUndefined());
 
     RootedValue v(cx, origval);
@@ -355,69 +342,69 @@ PropDesc::initialize(JSContext *cx, cons
      */
     attrs = JSPROP_PERMANENT | JSPROP_READONLY;
 
     bool found = false;
     RootedId id(cx);
 
     /* 8.10.5 step 3 */
     id = NameToId(cx->names().enumerable);
-    if (!HasProperty(cx, desc, id, &v, &found))
+    if (!GetPropertyIfPresent(cx, desc, id, &v, &found))
         return false;
     if (found) {
         hasEnumerable_ = true;
         if (ToBoolean(v))
             attrs |= JSPROP_ENUMERATE;
     }
 
     /* 8.10.5 step 4 */
     id = NameToId(cx->names().configurable);
-    if (!HasProperty(cx, desc, id, &v, &found))
+    if (!GetPropertyIfPresent(cx, desc, id, &v, &found))
         return false;
     if (found) {
         hasConfigurable_ = true;
         if (ToBoolean(v))
             attrs &= ~JSPROP_PERMANENT;
     }
 
     /* 8.10.5 step 5 */
     id = NameToId(cx->names().value);
-    if (!HasProperty(cx, desc, id, &v, &found))
+    if (!GetPropertyIfPresent(cx, desc, id, &v, &found))
         return false;
     if (found) {
         hasValue_ = true;
         value_ = v;
     }
 
     /* 8.10.6 step 6 */
     id = NameToId(cx->names().writable);
-    if (!HasProperty(cx, desc, id, &v, &found))
+    if (!GetPropertyIfPresent(cx, desc, id, &v, &found))
         return false;
     if (found) {
         hasWritable_ = true;
         if (ToBoolean(v))
             attrs &= ~JSPROP_READONLY;
     }
 
     /* 8.10.7 step 7 */
     id = NameToId(cx->names().get);
-    if (!HasProperty(cx, desc, id, &v, &found))
+    if (!GetPropertyIfPresent(cx, desc, id, &v, &found))
         return false;
     if (found) {
         hasGet_ = true;
         get_ = v;
         attrs |= JSPROP_GETTER | JSPROP_SHARED;
         attrs &= ~JSPROP_READONLY;
         if (checkAccessors && !checkGetter(cx))
             return false;
     }
 
     /* 8.10.7 step 8 */
     id = NameToId(cx->names().set);
-    if (!HasProperty(cx, desc, id, &v, &found))
+    if (!GetPropertyIfPresent(cx, desc, id, &v, &found))
         return false;
     if (found) {
         hasSet_ = true;
         set_ = v;
         attrs |= JSPROP_SETTER | JSPROP_SHARED;
         attrs &= ~JSPROP_READONLY;
         if (checkAccessors && !checkSetter(cx))
             return false;
--- a/js/src/jsobj.h
+++ b/js/src/jsobj.h
@@ -922,16 +922,27 @@ IsExtensible(ExclusiveContext *cx, Handl
 /*
  * ES6 [[PreventExtensions]]. Attempt to change the [[Extensible]] bit on |obj|
  * to false.  Indicate success or failure through the |*succeeded| outparam, or
  * actual error through the return value.
  */
 extern bool
 PreventExtensions(JSContext *cx, HandleObject obj, bool *succeeded);
 
+/*
+ * ES6 [[GetOwnPropertyDescriptor]]. Get a description of one of obj's own
+ * properties.
+ *
+ * If no such property exists on obj, return true with desc.object() set to
+ * null.
+ */
+extern bool
+GetOwnPropertyDescriptor(JSContext *cx, HandleObject obj, HandleId id,
+                         MutableHandle<PropertyDescriptor> desc);
+
 
 /*** SpiderMonkey nonstandard internal methods ***************************************************/
 
 /*
  * Attempt to make |obj|'s [[Prototype]] immutable, such that subsequently
  * trying to change it will not work.  If an internal error occurred,
  * returns false.  Otherwise, |*succeeded| is set to true iff |obj|'s
  * [[Prototype]] is now immutable.
@@ -1135,16 +1146,25 @@ js_FindVariableScope(JSContext *cx, JSFu
 
 namespace js {
 
 bool
 LookupPropertyPure(ExclusiveContext *cx, JSObject *obj, jsid id, NativeObject **objp,
                    Shape **propp);
 
 bool
+GetPropertyPure(ExclusiveContext *cx, JSObject *obj, jsid id, Value *vp);
+
+inline bool
+GetPropertyPure(ExclusiveContext *cx, JSObject *obj, PropertyName *name, Value *vp)
+{
+    return GetPropertyPure(cx, obj, NameToId(name), vp);
+}
+
+bool
 GetOwnPropertyDescriptor(JSContext *cx, HandleObject obj, HandleId id,
                          MutableHandle<PropertyDescriptor> desc);
 
 bool
 GetOwnPropertyDescriptor(JSContext *cx, HandleObject obj, HandleId id, MutableHandleValue vp);
 
 bool
 NewPropertyDescriptorObject(JSContext *cx, Handle<PropertyDescriptor> desc, MutableHandleValue vp);