chakra-core / chakra-core/ChakraCore
Bug:Strict mode write to indexed getter only prop should throw TypeError
- Dominant language
- JavaScript
- Stars
- 9.3k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
There appears to be an error in strict mode detecting that a getter only property is read-only when that property is numerically indexed instead of having a name.
I would expect both of the below tests (1 and 2) to throw errors in strict mode, but with current CC master (and latests release) only the 2nd one does.
```js
"use strict";
const obj = { get "0" () { return 0; }, get bar () { return 0; }}
try { //test 1
obj[0] = 1;
print("expected error not thrown - attempted write to getter only obj[0]");
}
catch(e) {
print(e);
}
try { //test 2
obj.bar = 1;
print("expected error not thrown - attempted write to getter only obj.bar");
}
catch(e) {
print(e);
}
```
eshost output:
```
#### Chakra
expected error not thrown - attempted write to getter only obj[0]
TypeError: Assignment to read-only properties is not allowed in strict mode
#### V8 --harmony
TypeError: Cannot set property 0 of # which has only a getter
TypeError: Cannot set property bar of # which has only a getter
#### JavaScriptCore
TypeError: Attempted to assign to readonly property.
TypeError: Attempted to assign to readonly property.
#### SpiderMonkey
TypeError: setting getter-only property 0
TypeError: setting getter-only property "bar"
```
Contributor guide
Research direction
Reproduce the two strict-mode assignments from the issue, comparing the numeric key obj[0] with the named getter obj.bar. Trace the strict-mode assignment handling for indexed properties and add a regression test; done means both writes throw TypeError as shown by the other engines.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100