Bug 1335862 - Implement mayResolve for arguments objects. r=jandem
authorTom Schuster <evilpies@gmail.com>
Wed, 15 Feb 2017 23:24:44 +0100
changeset 343203 b9ee8724079936ea2adab7d017ff7a3aab61c151
parent 343202 427fd576729151744a2bdd7f433cdf78c0ba3015
child 343204 5a394ec7d209c5edd03760d056fe5fa8dcb9125d
push id31372
push usercbook@mozilla.com
push dateThu, 16 Feb 2017 12:16:10 +0000
treeherdermozilla-central@2737f66ad6ac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1335862
milestone54.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 1335862 - Implement mayResolve for arguments objects. r=jandem
js/src/vm/ArgumentsObject.cpp
js/src/vm/ArgumentsObject.h
--- a/js/src/vm/ArgumentsObject.cpp
+++ b/js/src/vm/ArgumentsObject.cpp
@@ -425,16 +425,31 @@ ArgumentsObject::obj_delProperty(JSConte
     } else if (JSID_IS_ATOM(id, cx->names().callee)) {
         argsobj.as<MappedArgumentsObject>().markCalleeOverridden();
     } else if (JSID_IS_SYMBOL(id) && JSID_TO_SYMBOL(id) == cx->wellKnownSymbols().iterator) {
         argsobj.markIteratorOverridden();
     }
     return result.succeed();
 }
 
+/* static */ bool
+ArgumentsObject::obj_mayResolve(const JSAtomState& names, jsid id, JSObject*)
+{
+    // Arguments might resolve indexes or Symbol.iterator.
+    if (!JSID_IS_ATOM(id))
+        return true;
+
+    JSAtom* atom = JSID_TO_ATOM(id);
+    uint32_t index;
+    if (atom->isIndex(&index))
+        return true;
+
+    return atom == names.length || atom == names.callee;
+}
+
 static bool
 MappedArgGetter(JSContext* cx, HandleObject obj, HandleId id, MutableHandleValue vp)
 {
     MappedArgumentsObject& argsobj = obj->as<MappedArgumentsObject>();
     if (JSID_IS_INT(id)) {
         /*
          * arg can exceed the number of arguments if a script changed the
          * prototype to point to another Arguments object with a bigger argc.
@@ -849,17 +864,17 @@ ArgumentsObject::objectMovedDuringMinorG
  */
 const ClassOps MappedArgumentsObject::classOps_ = {
     nullptr,                 /* addProperty */
     ArgumentsObject::obj_delProperty,
     nullptr,                 /* getProperty */
     nullptr,                 /* setProperty */
     MappedArgumentsObject::obj_enumerate,
     MappedArgumentsObject::obj_resolve,
-    nullptr,                 /* mayResolve  */
+    ArgumentsObject::obj_mayResolve,
     ArgumentsObject::finalize,
     nullptr,                 /* call        */
     nullptr,                 /* hasInstance */
     nullptr,                 /* construct   */
     ArgumentsObject::trace
 };
 
 const ObjectOps MappedArgumentsObject::objectOps_ = {
@@ -886,17 +901,17 @@ const Class MappedArgumentsObject::class
  */
 const ClassOps UnmappedArgumentsObject::classOps_ = {
     nullptr,                 /* addProperty */
     ArgumentsObject::obj_delProperty,
     nullptr,                 /* getProperty */
     nullptr,                 /* setProperty */
     UnmappedArgumentsObject::obj_enumerate,
     UnmappedArgumentsObject::obj_resolve,
-    nullptr,                 /* mayResolve  */
+    ArgumentsObject::obj_mayResolve,
     ArgumentsObject::finalize,
     nullptr,                 /* call        */
     nullptr,                 /* hasInstance */
     nullptr,                 /* construct   */
     ArgumentsObject::trace
 };
 
 const Class UnmappedArgumentsObject::class_ = {
--- a/js/src/vm/ArgumentsObject.h
+++ b/js/src/vm/ArgumentsObject.h
@@ -180,16 +180,18 @@ class ArgumentsObject : public NativeObj
         if (!data()->rareData && !createRareData(cx))
             return nullptr;
         return data()->rareData;
     }
 
     static bool obj_delProperty(JSContext* cx, HandleObject obj, HandleId id,
                                 ObjectOpResult& result);
 
+    static bool obj_mayResolve(const JSAtomState& names, jsid id, JSObject*);
+
   public:
     static const uint32_t RESERVED_SLOTS = 4;
     static const gc::AllocKind FINALIZE_KIND = gc::AllocKind::OBJECT4_BACKGROUND;
 
     /* Create an arguments object for a frame that is expecting them. */
     static ArgumentsObject* createExpected(JSContext* cx, AbstractFramePtr frame);
 
     /*