Skip to content

Commit

Permalink
fix: rAF callback and console (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
vault-developer authored Dec 29, 2024
1 parent 989381f commit 88ac9e3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/utils/ast/ast.traverse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@ export const astTraverse = ({
logger({ time, type: 'push', queue: 'callstack', ast: callExpression });
if (isConsoleExpression(callExpression)) {
// console.log, console.error, console.warn, console.info
logger({ time, type: 'push', queue: 'console', ast: callExpression });
if (callExpression.arguments.length > 1)
throw new Error('Unsupported console argument');
logger({
time,
type: 'push',
queue: 'console',
ast: callExpression.arguments[0],
});
} else if (isPromiseCallbackExpression(callExpression)) {
// promise.resolve.then()
addToQueue({ type: 'microtask', ast: callExpression.arguments[0] });
Expand Down
5 changes: 3 additions & 2 deletions src/utils/calculator/calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ export class Calculator {
render: (time) => {
this.lastRender = time;
this.log({ time, type: 'render' });
while (this.rafCallbacks.length > 0) {
// TODO: exclude infinite loop, when rAF is invoked inside rAF
const count = this.rafCallbacks.length;
// exclude inner callbacks execution in the same step
for (let i = 0; i < count; i++) {
const task = this.rafCallbacks.shift();
if (!task) throw new Error('No raf callback found');
this.log({ time, type: 'shift', queue: 'rafCallback', ast: task });
Expand Down

0 comments on commit 88ac9e3

Please sign in to comment.