Skip to content

Commit

Permalink
Merge pull request #1203 from samchon/feature/console.info
Browse files Browse the repository at this point in the history
Playground console movie to handle async function.
  • Loading branch information
samchon authored Aug 7, 2024
2 parents 19a414c + b5cfcce commit bf16c43
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions website/src/pages/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,38 +104,43 @@ const Playground = () => {

const execute = async () => {
const service = await createCompilerService.get();
const res: ICompilerService.IOutput = await service.bundle(source ?? "");
if (res.success === false)
const compiled: ICompilerService.IOutput = await service.bundle(
source ?? "",
);
if (compiled.success === false)
return setConsoleBox({
messages: [
{
type: "error",
value: res.error,
value: compiled.error,
},
],
});

const func: Function = new Function("console", res.content);
const func: Function = new Function("console", compiled.content);
const messages: ConsoleViewer.IMessage[] = [];
func({
error: (...args: any[]) => {
console.error(...args);
args.forEach((value) => messages.push({ type: "error", value }));
setConsoleBox({ messages });
},
info: (...args: any[]) => {
console.info(...args);
args.forEach((value) => messages.push({ type: "info", value }));
setConsoleBox({ messages });
},
log: (...args: any[]) => {
console.log(...args);
args.forEach((value) => messages.push({ type: "log", value }));
setConsoleBox({ messages });
},
warn: (...args: any[]) => {
console.warn(...args);
args.forEach((value) => messages.push({ type: "warn", value }));
setConsoleBox({ messages });
},
});
setConsoleBox({ messages });
};

return (
Expand Down

0 comments on commit bf16c43

Please sign in to comment.