Bug 1265594 - Expose FromPropertyDescriptor() as a public JS API; r=jorendorff
☠☠ backed out by 8dbe34ec0786 ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 18 Apr 2016 21:18:13 -0400
changeset 331802 d5920404005033ac00cd2eabdbb1826b30215269
parent 331801 4f139d664ccc461f43174119bfe356841482e6ca
child 331803 dc6cc76f3c7e096d15b84bd7736c59723984dfec
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1265594
milestone48.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 1265594 - Expose FromPropertyDescriptor() as a public JS API; r=jorendorff
js/src/builtin/Object.cpp
js/src/jsapi-tests/testGetPropertyDescriptor.cpp
js/src/jsapi.h
js/src/jsobj.cpp
js/src/jsobj.h
js/src/vm/Debugger.cpp
--- a/js/src/builtin/Object.cpp
+++ b/js/src/builtin/Object.cpp
@@ -672,17 +672,17 @@ js::obj_getOwnPropertyDescriptor(JSConte
     // Steps 3-4.
     RootedId id(cx);
     if (!ToPropertyKey(cx, args.get(1), &id))
         return false;
 
     // Steps 5-7.
     Rooted<PropertyDescriptor> desc(cx);
     return GetOwnPropertyDescriptor(cx, obj, id, &desc) &&
-           FromPropertyDescriptor(cx, desc, args.rval());
+           JS::FromPropertyDescriptor(cx, desc, args.rval());
 }
 
 enum EnumerableOwnPropertiesKind {
     Keys,
     Values,
     KeysAndValues
 };
 
--- a/js/src/jsapi-tests/testGetPropertyDescriptor.cpp
+++ b/js/src/jsapi-tests/testGetPropertyDescriptor.cpp
@@ -12,16 +12,34 @@ BEGIN_TEST(test_GetPropertyDescriptor)
 
   JS::RootedObject obj(cx, &v.toObject());
   JS::Rooted<JS::PropertyDescriptor> desc(cx);
 
   CHECK(JS_GetPropertyDescriptor(cx, obj, "somename", &desc));
   CHECK_EQUAL(desc.object(), obj);
   CHECK_SAME(desc.value(), JS::Int32Value(123));
 
+  JS::RootedValue descValue(cx);
+  CHECK(JS::FromPropertyDescriptor(cx, desc, &descValue));
+  CHECK(descValue.isObject());
+  JS::RootedObject descObj(cx, &descValue.toObject());
+  JS::RootedValue value(cx);
+  CHECK(JS_GetProperty(cx, descObj, "value", &value));
+  CHECK_EQUAL(value.toInt32(), 123);
+  CHECK(JS_GetProperty(cx, descObj, "get", &value));
+  CHECK(value.isUndefined());
+  CHECK(JS_GetProperty(cx, descObj, "set", &value));
+  CHECK(value.isUndefined());
+  CHECK(JS_GetProperty(cx, descObj, "writable", &value));
+  CHECK(value.isTrue());
+  CHECK(JS_GetProperty(cx, descObj, "configurable", &value));
+  CHECK(value.isTrue());
+  CHECK(JS_GetProperty(cx, descObj, "enumerable", &value));
+  CHECK(value.isTrue());
+
   CHECK(JS_GetPropertyDescriptor(cx, obj, "not-here", &desc));
   CHECK_EQUAL(desc.object(), nullptr);
 
   CHECK(JS_GetPropertyDescriptor(cx, obj, "toString", &desc));
   JS::RootedObject objectProto(cx, JS_GetObjectPrototype(cx, obj));
   CHECK(objectProto);
   CHECK_EQUAL(desc.object(), objectProto);
   CHECK(desc.value().isObject());
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -2841,16 +2841,26 @@ class MutableHandleBase<JS::PropertyDesc
 namespace JS {
 
 extern JS_PUBLIC_API(bool)
 ObjectToCompletePropertyDescriptor(JSContext* cx,
                                    JS::HandleObject obj,
                                    JS::HandleValue descriptor,
                                    JS::MutableHandle<PropertyDescriptor> desc);
 
+/*
+ * ES6 draft rev 32 (2015 Feb 2) 6.2.4.4 FromPropertyDescriptor(Desc).
+ *
+ * If desc.object() is null, then vp is set to undefined.
+ */
+extern JS_PUBLIC_API(bool)
+FromPropertyDescriptor(JSContext* cx,
+                       JS::Handle<JS::PropertyDescriptor> desc,
+                       JS::MutableHandleValue vp);
+
 } // namespace JS
 
 
 /*** Standard internal methods ********************************************************************
  *
  * The functions below are the fundamental operations on objects.
  *
  * ES6 specifies 14 internal methods that define how objects behave.  The
--- a/js/src/jsobj.cpp
+++ b/js/src/jsobj.cpp
@@ -103,19 +103,23 @@ js::InformalValueTypeName(const Value& v
     if (v.isNull())
         return "null";
     if (v.isUndefined())
         return "undefined";
     return "value";
 }
 
 // ES6 draft rev37 6.2.4.4 FromPropertyDescriptor
-bool
-js::FromPropertyDescriptor(JSContext* cx, Handle<PropertyDescriptor> desc, MutableHandleValue vp)
+JS_PUBLIC_API(bool)
+JS::FromPropertyDescriptor(JSContext* cx, Handle<PropertyDescriptor> desc, MutableHandleValue vp)
 {
+    AssertHeapIsIdle(cx);
+    CHECK_REQUEST(cx);
+    assertSameCompartment(cx, desc);
+
     // Step 1.
     if (!desc.object()) {
         vp.setUndefined();
         return true;
     }
 
     return FromPropertyDescriptorToObject(cx, desc, vp);
 }
--- a/js/src/jsobj.h
+++ b/js/src/jsobj.h
@@ -1236,28 +1236,20 @@ HasOwnDataPropertyPure(JSContext* cx, JS
 bool
 GetOwnPropertyDescriptor(JSContext* cx, HandleObject obj, HandleId id,
                          MutableHandle<PropertyDescriptor> desc);
 
 bool
 GetOwnPropertyDescriptor(JSContext* cx, HandleObject obj, HandleId id, MutableHandleValue vp);
 
 /*
- * ES6 draft rev 32 (2015 Feb 2) 6.2.4.4 FromPropertyDescriptor(Desc).
- *
- * If desc.object() is null, then vp is set to undefined.
- */
-extern bool
-FromPropertyDescriptor(JSContext* cx, Handle<PropertyDescriptor> desc, MutableHandleValue vp);
-
-/*
- * Like FromPropertyDescriptor, but ignore desc.object() and always set vp
+ * Like JS::FromPropertyDescriptor, but ignore desc.object() and always set vp
  * to an object on success.
  *
- * Use FromPropertyDescriptor for getOwnPropertyDescriptor, since desc.object()
+ * Use JS::FromPropertyDescriptor for getOwnPropertyDescriptor, since desc.object()
  * is used to indicate whether a result was found or not.  Use this instead for
  * defineProperty: it would be senseless to define a "missing" property.
  */
 extern bool
 FromPropertyDescriptorToObject(JSContext* cx, Handle<PropertyDescriptor> desc,
                                MutableHandleValue vp);
 
 extern bool
--- a/js/src/vm/Debugger.cpp
+++ b/js/src/vm/Debugger.cpp
@@ -8183,17 +8183,17 @@ DebuggerObject_getOwnPropertyDescriptor(
         if (desc.hasSetterObject()) {
             RootedValue set(cx, ObjectOrNullValue(desc.setterObject()));
             if (!dbg->wrapDebuggeeValue(cx, &set))
                 return false;
             desc.setSetterObject(set.toObjectOrNull());
         }
     }
 
-    return FromPropertyDescriptor(cx, desc, args.rval());
+    return JS::FromPropertyDescriptor(cx, desc, args.rval());
 }
 
 
 static bool
 getOwnPropertyKeys(JSContext* cx, unsigned argc, unsigned flags, Value* vp)
 {
     THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, "getOwnPropertyKeys", args, obj);
     AutoIdVector keys(cx);