From 552afaeaecd987c03fd091f1fd93f8d09d7b0844 Mon Sep 17 00:00:00 2001 From: Matthias Wahl Date: Mon, 7 Oct 2024 08:52:52 +0200 Subject: [PATCH] Do not use bind for callbacks that need to call session.getValue() upon callback time --- static/web.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/static/web.js b/static/web.js index 11a9151..b3c947c 100644 --- a/static/web.js +++ b/static/web.js @@ -760,11 +760,16 @@ delete transposeletters.bindKey; editor.commands.addCommand(transposeletters); - asmButton.onclick = compile.bind(window, "asm", result, session.getValue(), asmButton); - - irButton.onclick = compile.bind(window, "llvm-ir", result, session.getValue(), irButton); - - gistButton.onclick = shareGist.bind(window, result, session.getValue(), gistButton); + // do not use .bind() here, as the call to `session.getValue()` needs to be delayed until the actual click + asmButton.onclick = function() { + compile("asm", result, session.getValue(), asmButton); + }; + irButton.onclick = function() { + compile("llvm-ir", result, session.getValue(), irButton); + }; + gistButton.onclick = function() { + shareGist(result, session.getValue(), gistButton); + }; configureEditorButton.onclick = function () { const dropdown = configureEditorButton.nextElementSibling; @@ -773,11 +778,15 @@ clearResultButton.onclick = clear_result.bind(window, result); - themes.onkeyup = themes.onchange = set_theme.bind(window, editor, themelist, themes.options[themes.selectedIndex].text); + // not sure, if .bind() could be used here, just for good measure + themes.onkeyup = themes.onchange = function() { + set_theme(editor, themelist, themes.options[themes.selectedIndex].text); + }; }, false); }()); + // called via javascript:fn events from formatCompilerOutput var old_range;