mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Sandbox: Patch array vector prototype methods inside the sandbox (#75835)
This commit is contained in:
@@ -13,42 +13,46 @@ declare global {
|
||||
|
||||
// JS original sin
|
||||
// this if condition is because Jest will re-exec this block multiple times (in a browser this only runs once)
|
||||
if (!Object.getOwnPropertyDescriptor(Array.prototype, 'toArray')) {
|
||||
Object.defineProperties(Array.prototype, {
|
||||
get: {
|
||||
value: function (idx: number) {
|
||||
return this[idx];
|
||||
export function patchArrayVectorProrotypeMethods() {
|
||||
if (!Object.getOwnPropertyDescriptor(Array.prototype, 'toArray')) {
|
||||
Object.defineProperties(Array.prototype, {
|
||||
get: {
|
||||
value: function (idx: number) {
|
||||
return this[idx];
|
||||
},
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
},
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
},
|
||||
set: {
|
||||
value: function (idx: number, value: unknown) {
|
||||
this[idx] = value;
|
||||
set: {
|
||||
value: function (idx: number, value: unknown) {
|
||||
this[idx] = value;
|
||||
},
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
},
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
},
|
||||
add: {
|
||||
value: function (value: unknown) {
|
||||
this.push(value);
|
||||
add: {
|
||||
value: function (value: unknown) {
|
||||
this.push(value);
|
||||
},
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
},
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
},
|
||||
toArray: {
|
||||
value: function () {
|
||||
return this;
|
||||
toArray: {
|
||||
value: function () {
|
||||
return this;
|
||||
},
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
},
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
//this function call is intentional
|
||||
patchArrayVectorProrotypeMethods();
|
||||
|
||||
/** @deprecated use a simple Array<T> */
|
||||
export interface Vector<T = any> extends Array<T> {
|
||||
|
||||
Reference in New Issue
Block a user