English subtitles

← 06-32 Mistakes Solution

Get Embed Code
3 Languages

Showing Revision 1 created 06/10/2012 by Amara Bot.

  1. Well, let's take a look.
  2. The first one is actually true.
  3. With only one function in our program, we'll have our top level global environment
  4. and then the environment for our new function, and
  5. we're making its declaration, or its parent pointer,
  6. go back here to the global environment.
  7. That's where it should go, but that's also where the bug is putting it,
  8. so we won't be able to tell the difference.
  9. Now if this weren't an anonymous function
  10. but were instead a recursive function like factorial,
  11. we might be able to see the bug with only one.
  12. But with just one anonymous function, we can't quite see the bug.
  13. We need at least three variables in the global environment to see the bug.
  14. This isn't really true.
  15. One variable in the global environment--one local variable--
  16. maybe even no variables in the
  17. global environment--should be totally fine.
  18. The only time the parent pointer matters is when
  19. we're looking up a variable in
  20. a child environment and we don't find it locally.
  21. So we should be able to construct a test case
  22. that has just one such variable, like the "a" in
  23. the Balder example we did earlier.
  24. We won't need three.
  25. We can show the bug with only two functions,
  26. each separately declared at the top level.
  27. If I have another function, function two, declared at the top level,
  28. its parent pointer should point back to global
  29. and because of the bug, it will point back to global anyway.
  30. So this won't let us see the bug.
  31. We can show the bug with one function nested inside another.
  32. This is the plan.
  33. Let's say we have function one with function two nested inside of it.
  34. The parent pointer for function one,
  35. or this pointer, should go back to global.
  36. The bug will make it go back to global.
  37. Function two should point back to function one
  38. but the bug will make it point to global.
  39. So all I have to do is put some variable "a" in here,
  40. and have function two refer to it.
  41. Then in my test case we won't find it and we'll get an error,
  42. but in the real world we should find it and that will
  43. allow me to pin down the defect.