Bug 686582 - Add element-valued inline methods to JSObject, which forward to the corresponding id-valued methods for the moment. r=dvander
authorJeff Walden <jwalden@mit.edu>
Wed, 10 Aug 2011 14:54:51 -0700
changeset 77018 c010d17e5d4c1d81b1d267491f8ae9fa958e0cac
parent 77017 e8859f6047e5deaace3ccb7d42da690a92d03bdd
child 77019 26ba8b0c1bdd24c86b1f946a48249c467c5eec5f
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersdvander
bugs686582
milestone9.0a1
Bug 686582 - Add element-valued inline methods to JSObject, which forward to the corresponding id-valued methods for the moment. r=dvander
js/src/jsobj.h
js/src/jsobjinlines.h
--- a/js/src/jsobj.h
+++ b/js/src/jsobj.h
@@ -1371,43 +1371,64 @@ struct JSObject : js::gc::Cell {
     /* Clear the scope, making it empty. */
     void clear(JSContext *cx);
 
     JSBool lookupProperty(JSContext *cx, jsid id, JSObject **objp, JSProperty **propp) {
         js::LookupPropOp op = getOps()->lookupProperty;
         return (op ? op : js_LookupProperty)(cx, this, id, objp, propp);
     }
 
+    inline JSBool lookupElement(JSContext *cx, uint32 index, JSObject **objp, JSProperty **propp);
+
     JSBool defineProperty(JSContext *cx, jsid id, const js::Value &value,
                           js::PropertyOp getter = js::PropertyStub,
                           js::StrictPropertyOp setter = js::StrictPropertyStub,
                           uintN attrs = JSPROP_ENUMERATE) {
         js::DefinePropOp op = getOps()->defineProperty;
         return (op ? op : js_DefineProperty)(cx, this, id, &value, getter, setter, attrs);
     }
 
+    inline JSBool defineElement(JSContext *cx, uint32 index, const js::Value &value,
+                                js::PropertyOp getter = js::PropertyStub,
+                                js::StrictPropertyOp setter = js::StrictPropertyStub,
+                                uintN attrs = JSPROP_ENUMERATE);
+
     inline JSBool getProperty(JSContext *cx, JSObject *receiver, jsid id, js::Value *vp);
+
+    inline JSBool getElement(JSContext *cx, JSObject *receiver, uint32 index, js::Value *vp);
+
     inline JSBool getProperty(JSContext *cx, jsid id, js::Value *vp);
 
+    inline JSBool getElement(JSContext *cx, uint32 index, js::Value *vp);
+
     JSBool setProperty(JSContext *cx, jsid id, js::Value *vp, JSBool strict) {
         if (getOps()->setProperty)
             return nonNativeSetProperty(cx, id, vp, strict);
         return js_SetPropertyHelper(cx, this, id, 0, vp, strict);
     }
 
+    inline JSBool setElement(JSContext *cx, uint32 index, js::Value *vp, JSBool strict);
+
     JSBool nonNativeSetProperty(JSContext *cx, jsid id, js::Value *vp, JSBool strict);
 
     JSBool getAttributes(JSContext *cx, jsid id, uintN *attrsp) {
         js::AttributesOp op = getOps()->getAttributes;
         return (op ? op : js_GetAttributes)(cx, this, id, attrsp);
     }
 
+    inline JSBool getElementAttributes(JSContext *cx, uint32 index, uintN *attrsp);
+
     inline JSBool setAttributes(JSContext *cx, jsid id, uintN *attrsp);
+
+    inline JSBool setElementAttributes(JSContext *cx, uint32 index, uintN *attrsp);
+
     inline JSBool deleteProperty(JSContext *cx, jsid id, js::Value *rval, JSBool strict);
 
+    inline JSBool deleteElement(JSContext *cx, uint32 index, js::Value *rval, JSBool strict);
+
     JSBool enumerate(JSContext *cx, JSIterateOp iterop, js::Value *statep, jsid *idp) {
         js::NewEnumerateOp op = getOps()->enumerate;
         return (op ? op : js_Enumerate)(cx, this, iterop, statep, idp);
     }
 
     bool defaultValue(JSContext *cx, JSType hint, js::Value *vp) {
         js::ConvertOp op = getClass()->convert;
         bool ok = (op == js::ConvertStub ? js::DefaultValue : op)(cx, this, hint, vp);
--- a/js/src/jsobjinlines.h
+++ b/js/src/jsobjinlines.h
@@ -62,16 +62,17 @@
 #include "jsnum.h"
 #include "jsinferinlines.h"
 #include "jsscopeinlines.h"
 #include "jsscriptinlines.h"
 #include "jsstr.h"
 
 #include "vm/GlobalObject.h"
 
+#include "jsatominlines.h"
 #include "jsfuninlines.h"
 #include "jsgcinlines.h"
 #include "jsprobes.h"
 #include "jsscopeinlines.h"
 
 inline bool
 JSObject::preventExtensions(JSContext *cx, js::AutoIdVector *props)
 {
@@ -1087,16 +1088,89 @@ JSObject::removeLastProperty()
 }
 
 inline void
 JSObject::setSharedNonNativeMap()
 {
     setMap(&js::Shape::sharedNonNative);
 }
 
+inline JSBool
+JSObject::lookupElement(JSContext *cx, uint32 index, JSObject **objp, JSProperty **propp)
+{
+    jsid id;
+    if (!js::IndexToId(cx, index, &id))
+        return false;
+    return lookupProperty(cx, id, objp, propp);
+}
+
+inline JSBool
+JSObject::defineElement(JSContext *cx, uint32 index, const js::Value &value,
+                        js::PropertyOp getter, js::StrictPropertyOp setter, uintN attrs)
+{
+    jsid id;
+    if (!js::IndexToId(cx, index, &id))
+        return false;
+    return defineProperty(cx, id, value, getter, setter, attrs);
+}
+
+inline JSBool
+JSObject::getElement(JSContext *cx, JSObject *receiver, uint32 index, js::Value *vp)
+{
+    jsid id;
+    if (!js::IndexToId(cx, index, &id))
+        return false;
+    return getProperty(cx, receiver, id, vp);
+}
+
+inline JSBool
+JSObject::getElement(JSContext *cx, uint32 index, js::Value *vp)
+{
+    jsid id;
+    if (!js::IndexToId(cx, index, &id))
+        return false;
+    return getProperty(cx, id, vp);
+}
+
+inline JSBool
+JSObject::setElement(JSContext *cx, uint32 index, js::Value *vp, JSBool strict)
+{
+    jsid id;
+    if (!js::IndexToId(cx, index, &id))
+        return false;
+    return setProperty(cx, id, vp, strict);
+}
+
+inline JSBool
+JSObject::getElementAttributes(JSContext *cx, uint32 index, uintN *attrsp)
+{
+    jsid id;
+    if (!js::IndexToId(cx, index, &id))
+        return false;
+    return getAttributes(cx, id, attrsp);
+}
+
+inline JSBool
+JSObject::setElementAttributes(JSContext *cx, uint32 index, uintN *attrsp)
+{
+    jsid id;
+    if (!js::IndexToId(cx, index, &id))
+        return false;
+    return setAttributes(cx, id, attrsp);
+}
+
+inline JSBool
+JSObject::deleteElement(JSContext *cx, uint32 index, js::Value *rval, JSBool strict)
+{
+    jsid id;
+    if (!js::IndexToId(cx, index, &id))
+        return false;
+    return deleteProperty(cx, id, rval, strict);
+}
+
 static inline bool
 js_IsCallable(const js::Value &v)
 {
     return v.isObject() && v.toObject().isCallable();
 }
 
 inline JSObject *
 js_UnwrapWithObject(JSContext *cx, JSObject *withobj)