Skip to content

Commit

Permalink
fix(Build): Make Array prototypes writeable to prevent conflicts with…
Browse files Browse the repository at this point in the history
… other libraries (#980, #1288, PR #1289)

fix by @momolarson - thanks!

* writable to prototypes

* Update CollectionUtil.ts

* space fix

* formatting fix

* Update CollectionUtil.ts
  • Loading branch information
momolarson committed Dec 22, 2022
1 parent 946065b commit be3dc1d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Util/CollectionUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ if (!Array.prototype.last) {
// using Object.defineProperty instead of assigning Array.prototype.x directly prevents prototype pollution, see #980
Object.defineProperty(Array.prototype, "last", {
enumerable: false,
writable: true,
value: function<T>(): T {
return this[this.length - 1];
}
Expand All @@ -24,6 +25,7 @@ if (!Array.prototype.last) {
if (!Array.prototype.clear) {
Object.defineProperty(Array.prototype, "clear", {
enumerable: false,
writable: true,
value: function<T>(): void {
this.length = 0;
}
Expand All @@ -33,6 +35,7 @@ if (!Array.prototype.clear) {
if (!Array.prototype.contains) {
Object.defineProperty(Array.prototype, "contains", {
enumerable: false,
writable: true,
value: function<T>(elem: T): boolean {
return this.indexOf(elem) !== -1;
}
Expand Down

0 comments on commit be3dc1d

Please sign in to comment.