Skip to content

Commit

Permalink
add ability to create proxies that provide insight into being used on…
Browse files Browse the repository at this point in the history
…ly in experimental mode
  • Loading branch information
lastmjs committed Aug 28, 2024
1 parent a6b1d97 commit af700d0
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/lib/stable/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,42 @@ if (globalThis._azleInsideCanister === true) {
warn: log,
info: log
};

(globalThis as any).Buffer = createExperimentalWarningProxy('Buffer');
}

function createExperimentalWarningProxy(name: string): object {
return new Proxy(
{},
{
get(): any {
throw new Error(experimentalWarningMessage(name));
},
apply(): any {
throw new Error(experimentalWarningMessage(name));
},
construct(): any {
throw new Error(experimentalWarningMessage(name));
},
set(): any {
throw new Error(experimentalWarningMessage(name));
}
}
);
}

function experimentalWarningMessage(name: string): string {
return `Azle: experimental mode must be enabled to use global ${name}. You can enable experimental mode in your dfx.json file like this:
{
"canisters": {
"canisterName": {
"type": "azle",
"main": "index.ts",
"custom": {
"experimental": true
}
}
}
}
`;
}

0 comments on commit af700d0

Please sign in to comment.