debug_innerhtml_eventlistener.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. from evaluator import *
  2. DESCRIPTION = "Test if a model knows that editing the innerHTML clears event listeners."
  3. TAGS = ['explain']
  4. question = """
  5. Why doesn't the slider onchange event fire when I run this code?
  6. ```
  7. <body>
  8. <script>
  9. var candidate_paper_list;
  10. class Dropdown {
  11. constructor(parent_html, parent_node) {
  12. var r = Math.random()
  13. parent_html.innerHTML += `<div class="autocomplete-container" style="border: 1px solid #000; padding: 1em">
  14. <label for="search-input">Search Paper Titles:</label>
  15. <input type="text" id="search-input-${r}" autocomplete="off">
  16. <div id="autocomplete-results"></div>
  17. </div>`;
  18. }
  19. }
  20. class Mul {
  21. constructor(parent_html, parent_node) {
  22. var div = document.createElement("div");
  23. div.style = "border: 1px solid #000; padding: 1em"
  24. parent_html.appendChild(div);
  25. var slider = document.createElement("input");
  26. slider.type = "range"
  27. slider.id = "foo"
  28. slider.min = "0"
  29. slider.max = "100"
  30. slider.step = ".1"
  31. this.slider = slider
  32. div.appendChild(slider);
  33. this.node = div;
  34. div.appendChild(document.createElement("br"));
  35. parent_node.child = this;
  36. slider.addEventListener("input", (event) => {
  37. console.log(event.target.value);
  38. });
  39. }
  40. serialize() {
  41. console.log("VALUE", this.slider.value);
  42. console.log("VALUE", this.slider);
  43. let positive_papers = ['const_mul', this.child.serialize(), +this.slider.value];
  44. return positive_papers;
  45. }
  46. }
  47. document.body.onload = function() {
  48. var mul = new Mul(document.body, {})
  49. root_node = mul;
  50. var dropdown = new Dropdown(mul.node, mul);
  51. }
  52. </script>
  53. </body>
  54. ```
  55. Tell me how to fix it.
  56. """
  57. evaluation = """
  58. Below is a student's answer to a question about what a particular instruction does: <A>
  59. Does the student's say something similar to "editing the innerHTML clears event listeners"?
  60. If the answer is correct say "The student passes" otherwise "The student fails".
  61. """
  62. TestInnerHTMLEventListener = question >> LLMRun() >> LLMRun(evaluation, llm=EVAL_LLM) >> SubstringEvaluator("student passes")
  63. if __name__ == "__main__":
  64. print(run_test(TestInnerHTMLEventListener))