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

fix gamelab debugger line numbers by accounting for hidden sharedBlocks and helperLibraries #27360

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/src/gamelab/GameLab.js
Expand Up @@ -945,13 +945,15 @@ GameLab.prototype.initInterpreter = function(attachDebugger = true) {
if (this.level.customHelperLibrary) {
code += this.level.customHelperLibrary + '\n';
}
const userCodeStartOffset = code.length;
code += this.studioApp_.getCode();
this.JSInterpreter.parse({
code,
blocks: dropletConfig.blocks,
blockFilter: this.level.executePaletteApisOnly && this.level.codeFunctions,
enableEvents: true,
initGlobals: injectGamelabGlobals
initGlobals: injectGamelabGlobals,
userCodeStartOffset
});
if (!this.JSInterpreter.initialized()) {
return;
Expand Down
24 changes: 18 additions & 6 deletions apps/src/lib/tools/jsinterpreter/JSInterpreter.js
Expand Up @@ -130,9 +130,13 @@ export default class JSInterpreter {
* @param {Function} [options.initGlobals] when supplied, this function will
* be called during interpreter initialization so that additional globals
* can be added with calls to createGlobalProperty()
* @param {number} [options.userCodeStartOffset] - offset in the code string where
* the user's created code begins. Allows other code to be injected before
* the user's program without disrupting line number calculations for
* debugging (default 0)
*/
parse(options) {
this.calculateCodeInfo(options.code);
this.calculateCodeInfo(options);

if (!this.studioApp.hideSource && this.studioApp.editor) {
const session = this.studioApp.editor.aceEditor.getSession();
Expand Down Expand Up @@ -239,14 +243,22 @@ export default class JSInterpreter {

/**
* Init `this.codeInfo` with cumulative length info (used to locate breakpoints).
* @param code
* @param {!Object} options
* @param {!string} options.code - Code to be executed by the interpreter.
* @param {number} [options.userCodeStartOffset] - offset in the code string where
* the user's created code begins. Allows other code to be injected before
* the user's program without disrupting line number calculations for
* debugging (default 0)
*/
calculateCodeInfo(code) {
calculateCodeInfo(options) {
const {code, userCodeStartOffset = 0} = options;
this.codeInfo = {};
this.codeInfo.code = code;
this.codeInfo.userCodeStartOffset = 0;
this.codeInfo.userCodeLength = code.length;
this.codeInfo.cumulativeLength = codegen.calculateCumulativeLength(code);
this.codeInfo.userCodeStartOffset = userCodeStartOffset;
this.codeInfo.userCodeLength = code.length - userCodeStartOffset;
this.codeInfo.cumulativeLength = codegen.calculateCumulativeLength(
code.slice(userCodeStartOffset)
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion apps/test/unit/lib/tools/jsdebugger/DebugConsoleTest.js
Expand Up @@ -140,7 +140,7 @@ describe('The DebugConsole component', () => {
studioApp: {hideSource: true}
});
const code = '0;\n1;\n2;\n3;\n4;\n5;\n6;\n7;';
interpreter.calculateCodeInfo(code);
interpreter.calculateCodeInfo({code});
interpreter.parse({code});
interpreter.paused = true;
interpreter.nextStep = JSInterpreter.StepType.IN;
Expand Down
2 changes: 1 addition & 1 deletion apps/test/unit/lib/tools/jsdebugger/reduxTest.js
Expand Up @@ -44,7 +44,7 @@ describe('The JSDebugger redux duck', () => {

function runToBreakpoint() {
const code = '0;\n1;\n2;\n3;\n4;\n5;\n6;\n7;';
interpreter.calculateCodeInfo(code);
interpreter.calculateCodeInfo({code});
interpreter.parse({code});
interpreter.paused = true;
interpreter.nextStep = JSInterpreter.StepType.IN;
Expand Down
Expand Up @@ -18,7 +18,7 @@ describe('The JSInterpreter class', function() {
});

// Initialize a test program
jsInterpreter.calculateCodeInfo(code);
jsInterpreter.calculateCodeInfo({code});
jsInterpreter.parse({code: code});

assert(jsInterpreter.initialized());
Expand Down