Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some JSInterpreter code cleanup #15744

Merged
merged 7 commits into from
Jun 13, 2017
Merged

Conversation

pcardune
Copy link
Contributor

@pcardune pcardune commented Jun 9, 2017

  • Moved JSInterpreter to lib/tools/jsinterpreter/JSInterpreter.js where it belongs
  • Switch everything to es6 class syntax
  • Removed use of unnecessary bind calls in favor of arrow functions
  • Remove direct access to interpreter stack, putting everything behind accessor functions instead
  • Replace var with const and let throughout

@pcardune pcardune requested a review from islemaster June 9, 2017 18:47
Copy link
Contributor

@islemaster islemaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, much cleaner! I caught a couple of lint issues and one possible refactoring error.

@@ -92,8 +93,11 @@ export function evalWithEvents(apis, events, evalCode = '') {
// to call, and any arguments.
const eventLoop = ';while(true){var event=wait();setReturnValue(this[event.name].apply(null,event.args));}';

interpreter = new Interpreter(
// TODO (pcardune): remove circular dependency
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will this TODO be addressed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to move codegen to lib/tools/jsinterpreter. At that point, I will probably move a number of these functions onto CustomMarshalingInterpreter and kill off the circular deps.

this.level[prop] === undefined ||
this.level[prop] === group.defaultValues[prop]))) {
this.level[prop] === undefined ||
this.level[prop] === group.defaultValues[prop]))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whitespace change looks like a mistake.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep. I blame my editor which does auto-indenting.

* @return {boolean} true if program is complete (or an error has occurred).
*/
isProgramDone() {
const topStackFrame = this.interpreter.peekStackFrame();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible null reference: Should probably pull the this.interpreter null check in the expression below up into this assignment.

this.yield();
}
return retVal;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.

"slider to its maximum value)");
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting. eslint doesn't seem to catch this.


if (this.paused) {
// Store the first call expression stack depth seen while in this step operation:
if (inUserCode && this.interpreter.peekStackFrame().node.type === "CallExpression") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think extracting inUserCallExpression (here and eight lines above) makes sense.

@pcardune pcardune force-pushed the pcardune-cleanup-jsinterpreter branch from bd16816 to 60acb47 Compare June 12, 2017 21:00
@pcardune
Copy link
Contributor Author

Ok, pushed a new version without the unintentional indentation changes.

}
const topStackFrame = this.interpreter.peekStackFrame();
return this.executionError ||
!this.interpreter ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This guard is now redundant.

@pcardune pcardune merged commit 3d54021 into staging Jun 13, 2017
@pcardune pcardune deleted the pcardune-cleanup-jsinterpreter branch June 13, 2017 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants