-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: marked all manifests that are loaded as frozen
- Loading branch information
Showing
4 changed files
with
83 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Recursively freezes an object and all of its properties. This prevents the | ||
* object from being modified at runtime. When the JS runtime is running in | ||
* strict mode, any attempts to modify a frozen object will throw an error. | ||
* | ||
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze | ||
* @param obj The object to freeze. | ||
*/ | ||
export function freeze(obj: object): void { | ||
// `null` is an object, if we get this, we should just return it. | ||
if (obj === null) return | ||
|
||
// An array is an object, but we also want to freeze each element in the array | ||
// as well. | ||
if (Array.isArray(obj)) { | ||
for (const item of obj) { | ||
if (!item || typeof item !== 'object') continue | ||
freeze(item) | ||
} | ||
|
||
Object.freeze(obj) | ||
return | ||
} | ||
|
||
for (const name of Object.keys(obj)) { | ||
const value = obj[name as keyof typeof obj] | ||
|
||
if (!value || typeof value !== 'object') continue | ||
freeze(value) | ||
} | ||
|
||
Object.freeze(obj) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters