return null in bad retrieval, throw on bad insert
This commit is contained in:
@@ -1831,4 +1831,69 @@ return {
|
||||
if (!caught) throw "object should not be able to use null as key"
|
||||
},
|
||||
|
||||
// ============================================================================
|
||||
// RETRIEVAL WITH INVALID KEY RETURNS NULL (not throw)
|
||||
// ============================================================================
|
||||
|
||||
test_array_get_string_key_returns_null: function() {
|
||||
var a = [1, 2, 3]
|
||||
var result = a["x"]
|
||||
if (result != null) throw "array get with string key should return null"
|
||||
},
|
||||
|
||||
test_array_get_negative_index_returns_null: function() {
|
||||
var a = [1, 2, 3]
|
||||
var result = a[-1]
|
||||
if (result != null) throw "array get with negative index should return null"
|
||||
},
|
||||
|
||||
test_array_get_object_key_returns_null: function() {
|
||||
var a = [1, 2, 3]
|
||||
var k = {}
|
||||
var result = a[k]
|
||||
if (result != null) throw "array get with object key should return null"
|
||||
},
|
||||
|
||||
test_array_get_array_key_returns_null: function() {
|
||||
var a = [1, 2, 3]
|
||||
var result = a[[1, 2]]
|
||||
if (result != null) throw "array get with array key should return null"
|
||||
},
|
||||
|
||||
test_array_get_boolean_key_returns_null: function() {
|
||||
var a = [1, 2, 3]
|
||||
var result = a[true]
|
||||
if (result != null) throw "array get with boolean key should return null"
|
||||
},
|
||||
|
||||
test_array_get_null_key_returns_null: function() {
|
||||
var a = [1, 2, 3]
|
||||
var result = a[null]
|
||||
if (result != null) throw "array get with null key should return null"
|
||||
},
|
||||
|
||||
test_obj_get_number_key_returns_null: function() {
|
||||
var o = {a: 1}
|
||||
var result = o[5]
|
||||
if (result != null) throw "object get with number key should return null"
|
||||
},
|
||||
|
||||
test_obj_get_array_key_returns_null: function() {
|
||||
var o = {a: 1}
|
||||
var result = o[[1, 2]]
|
||||
if (result != null) throw "object get with array key should return null"
|
||||
},
|
||||
|
||||
test_obj_get_boolean_key_returns_null: function() {
|
||||
var o = {a: 1}
|
||||
var result = o[true]
|
||||
if (result != null) throw "object get with boolean key should return null"
|
||||
},
|
||||
|
||||
test_obj_get_null_key_returns_null: function() {
|
||||
var o = {a: 1}
|
||||
var result = o[null]
|
||||
if (result != null) throw "object get with null key should return null"
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user