Merge pull request #1354 from hgiesel/preventoverwrite

Disallow setting, deleting or defining properties on packages
This commit is contained in:
Damien Elmes 2021-09-06 20:57:37 +10:00 committed by GitHub
commit 6b3c309725
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,6 +3,8 @@
import { runtimeLibraries } from "./runtime-require"; import { runtimeLibraries } from "./runtime-require";
const prohibit = () => false;
export function registerPackage( export function registerPackage(
name: string, name: string,
entries: Record<string, unknown>, entries: Record<string, unknown>,
@ -10,6 +12,9 @@ export function registerPackage(
): void { ): void {
const pack = deprecation const pack = deprecation
? new Proxy(entries, { ? new Proxy(entries, {
set: prohibit,
defineProperty: prohibit,
deleteProperty: prohibit,
get: (target, name: string) => { get: (target, name: string) => {
if (name in deprecation) { if (name in deprecation) {
console.log(`anki: ${name} is deprecated: ${deprecation[name]}`); console.log(`anki: ${name} is deprecated: ${deprecation[name]}`);