Skip to content

Commit

Permalink
Merge pull request #2021 from demergent-labs/experimental_globals
Browse files Browse the repository at this point in the history
Experimental globals
  • Loading branch information
lastmjs authored Aug 29, 2024
2 parents aa3ca4c + 1d1f23d commit 9090280
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 9090280

Please sign in to comment.