Skip to content

Fix crash when modifying array length#89

Merged
sindresorhus merged 1 commit intosindresorhus:mainfrom
Jimbly:patch-1
Jan 22, 2022
Merged

Fix crash when modifying array length#89
sindresorhus merged 1 commit intosindresorhus:mainfrom
Jimbly:patch-1

Conversation

@Jimbly
Copy link
Contributor

@Jimbly Jimbly commented Jan 1, 2022

Also avoids unnecessary allocation and set.

Fixes cases like the following:

let obj = { a: [1,2] };
dotProp.delete(obj, 'a.1');
dotProp.set(obj, 'a.length', 1);

Previously would throw Uncaught RangeError: Invalid array length when it tries to set obj.a.length = {}

@sindresorhus
Copy link
Owner

Can you add a test?

Also avoids unnecessary allocation and set.

Fixes cases like the following:
```javascript
let obj = { a: [1,2] };
dotProp.delete(obj, 'a.1');
dotProp.set(obj, 'a.length', 1);
```
Previously would throw `Uncaught RangeError: Invalid array length` when it tries to set `obj.a.length = {}`
@Jimbly
Copy link
Contributor Author

Jimbly commented Jan 22, 2022

Merge conflicts resolved and test added (also verified the test still fails on main).

@sindresorhus sindresorhus changed the title Fix crashing modifying array length Fix crash when modifying array length Jan 22, 2022
@sindresorhus sindresorhus merged commit d363922 into sindresorhus:main Jan 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants