Files
quickjs/tests/null_or_undefined.js
Ben Noordhuis 5f91729b92 Improve computed property lookup error messages (#1179)
QuickJS reported "cannot read property of null" for computed property
lookups (`a[k]` where `a === null`), which is markedly less helpful
than "cannot read property 'foo' of null".
2025-10-06 21:04:51 +02:00

39 lines
656 B
JavaScript

import {assert} from "./assert.js"
let ex
try {
null.x
} catch (e) {
ex = e
}
assert(ex instanceof TypeError)
assert(ex.message, "cannot read property 'x' of null")
ex = undefined
try {
null["x"]
} catch (e) {
ex = e
}
assert(ex instanceof TypeError)
assert(ex.message, "cannot read property 'x' of null")
ex = undefined
try {
undefined.x
} catch (e) {
ex = e
}
assert(ex instanceof TypeError)
assert(ex.message, "cannot read property 'x' of undefined")
ex = undefined
try {
undefined["x"]
} catch (e) {
ex = e
}
assert(ex instanceof TypeError)
assert(ex.message, "cannot read property 'x' of undefined")
ex = undefined