Bug 572577 - Generate only a proxy's enumerable properties by filtering a vector of all its properties in-place, without copying properties to a second vector. r=gal

This commit is contained in:
Jeff Walden 2010-06-17 14:37:33 -07:00
parent 157c408713
commit 06de83b720

View File

@ -170,19 +170,24 @@ JSProxyHandler::enumerateOwn(JSContext *cx, JSObject *proxy, AutoValueVector &pr
JS_ASSERT(OperationInProgress(cx, proxy)); JS_ASSERT(OperationInProgress(cx, proxy));
JS_ASSERT(props.length() == 0); JS_ASSERT(props.length() == 0);
AutoValueVector proxyProps(cx); if (!getOwnPropertyNames(cx, proxy, props))
if (!getOwnPropertyNames(cx, proxy, proxyProps))
return false; return false;
/* Select only the enumerable properties through in-place iteration. */
AutoDescriptor desc(cx); AutoDescriptor desc(cx);
for (size_t n = 0, len = proxyProps.length(); n < len; n++) { size_t i = 0;
jsid id = proxyProps[n]; for (size_t j = 0, len = props.length(); j < len; j++) {
JS_ASSERT(i <= j);
jsid id = props[j];
if (!getOwnPropertyDescriptor(cx, proxy, id, &desc)) if (!getOwnPropertyDescriptor(cx, proxy, id, &desc))
return false; return false;
if (desc.obj && (desc.attrs & JSPROP_ENUMERATE) && !props.append(id)) if (desc.obj && (desc.attrs & JSPROP_ENUMERATE))
return false; props[i++] = id;
} }
JS_ASSERT(i <= props.length());
props.resize(i);
return true; return true;
} }