Minor cleanups in ArrayPop

This commit is contained in:
Scott Kyle 2015-09-28 16:00:24 -07:00
parent 75dc7bd05e
commit 38a4e993ae
1 changed files with 5 additions and 3 deletions

View File

@ -106,11 +106,13 @@ JSValueRef ArrayPop(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObje
try { try {
ObjectArray *array = RJSVerifiedArray(thisObject); ObjectArray *array = RJSVerifiedArray(thisObject);
RJSValidateArgumentCount(argumentCount, 0); RJSValidateArgumentCount(argumentCount, 0);
if (array->link_view->size() == 0) {
size_t size = array->size();
if (size == 0) {
return JSValueMakeUndefined(ctx); return JSValueMakeUndefined(ctx);
} }
size_t index = array->link_view->size()-1; size_t index = size - 1;
JSValueRef obj = RJSObjectCreate(ctx, Object(array->realm, array->object_schema, array->get(array->link_view->size()-1))); JSValueRef obj = RJSObjectCreate(ctx, Object(array->realm, array->object_schema, array->get(index)));
array->link_view->remove(index); array->link_view->remove(index);
return obj; return obj;
} }