Out of bounds list item getters return undefined

Resolves #50
This commit is contained in:
Scott Kyle 2015-10-12 15:25:23 -07:00
parent a5bd3264c1
commit 6788cd6f3d
2 changed files with 15 additions and 7 deletions

View File

@ -87,6 +87,10 @@ JSValueRef ArrayGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef pr
return RJSObjectCreate(ctx, Object(array->realm, array->object_schema, array->get(RJSVerifiedPositiveIndex(indexStr))));
}
catch (std::out_of_range &exp) {
// getters for nonexistent properties in JS should always return undefined
return JSValueMakeUndefined(ctx);
}
catch (std::invalid_argument &exp) {
// for stol failure this could be another property that is handled externally, so ignore
return NULL;

View File

@ -30,6 +30,10 @@ var ArrayTests = {
obj.arrayCol = [[1], [2]];
TestCase.assertEqual(obj.arrayCol.length, 2);
TestCase.assertThrows(function() {
obj.arrayCol.length = 0;
}, 'cannot set length property on lists');
});
},
@ -44,8 +48,8 @@ var ArrayTests = {
TestCase.assertEqual(array[0].doubleCol, 3);
TestCase.assertEqual(array[1].doubleCol, 4);
TestCase.assertThrows(function() { array[2]; }, 'Invalid index');
TestCase.assertThrows(function() { array[-1]; }, 'Invalid index');
TestCase.assertEqual(array[2], undefined);
TestCase.assertEqual(array[-1], undefined);
},
testArraySubscriptSetters: function() {
@ -62,13 +66,13 @@ var ArrayTests = {
TestCase.assertEqual(array[0].doubleCol, 5);
TestCase.assertEqual(array[1].doubleCol, 6);
TestCase.assertThrows(function() {
array.length = 0;
}, 'cannot set length property on lists');
TestCase.assertThrows(function() {
array[2] = [1];
}, 'cannot set list item beyond its bounds');
TestCase.assertThrows(function() {
array[-1] = [1];
}, 'cannot set list item with negative index');
});
TestCase.assertThrows(function() {
@ -133,7 +137,7 @@ var ArrayTests = {
TestCase.assertThrows(function() {
array.push();
});
});
});
TestCase.assertEqual(array.length, 4);
TestCase.assertThrows(function() {