| 1261 | } |
| 1262 | |
| 1263 | ResultType Map::Capacity(ResultToken &aResultToken, int aID, int aFlags, ExprTokenType *aParam[], int aParamCount) |
| 1264 | { |
| 1265 | if (IS_INVOKE_GET) |
| 1266 | { |
| 1267 | _o_return(mCapacity); |
| 1268 | } |
| 1269 | |
| 1270 | if (!ParamIndexIsNumeric(0)) |
| 1271 | _o_throw_type(_T("Number"), *aParam[0]); |
| 1272 | |
| 1273 | index_t desired_count = (index_t)ParamIndexToInt64(0); |
| 1274 | if (desired_count < mCount) |
| 1275 | { |
| 1276 | // It doesn't seem intuitive to allow SetCapacity to truncate the item array, so just reallocate |
| 1277 | // as necessary to remove any unused space. Allow negative values since SetCapacity(-1) seems more |
| 1278 | // intuitive than SetCapacity(0) when the contents aren't being discarded. |
| 1279 | desired_count = mCount; |
| 1280 | } |
| 1281 | if (!desired_count) |
| 1282 | { |
| 1283 | if (mItem) |
| 1284 | { |
| 1285 | free(mItem); |
| 1286 | mItem = nullptr; |
| 1287 | mCapacity = 0; |
| 1288 | } |
| 1289 | //else mCapacity should already be 0. |
| 1290 | // Since mCapacity and desired_size are both 0, below will return 0 and won't call SetInternalCapacity. |
| 1291 | } |
| 1292 | if (desired_count == mCapacity || SetInternalCapacity(desired_count)) |
| 1293 | { |
| 1294 | _o_return(mCapacity); |
| 1295 | } |
| 1296 | // At this point, failure isn't critical since nothing is being stored yet. However, it might be easier to |
| 1297 | // debug if an error is thrown here rather than possibly later, when the array attempts to resize itself to |
| 1298 | // fit new items. This also avoids the need for scripts to check if the return value is less than expected: |
| 1299 | _o_throw_oom; |
| 1300 | } |
| 1301 | |
| 1302 | ResultType Object::OwnProps(ResultToken &aResultToken, int aID, int aFlags, ExprTokenType *aParam[], int aParamCount) |
| 1303 | { |
no outgoing calls
no test coverage detected