Advertisement
Guest User

Untitled

a guest
Oct 20th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. > Seems like a much simpler approach that would minimize code duplication, though.
  2. What you're describing is the existing solution in master. There are a number of problems with it, but you've inspired me to revisit the idea of making minor modifications to patch what's in master to work for everybody.
  3.  
  4. Basic problems with the existing solution in master:
  5. * It's possible to fool the parser with shenanigans. There is currently a hack in place to block any ')' character in the parameter string, but this incorrectly rejects some valid invocations.
  6. * A dynamic function's toString must show that the function has a name of "anonymous". However, there should be no symbol that binds the name "anonymous" to the function. This becomes an issue when you try to solve v8:4958.
  7.  
  8. Here's a test case that tests for all of that:
  9.  
  10. ```
  11. assertThrows(function() {
  12. Function(") { function a(", "}");
  13. });
  14. Function("a=(1)", "");
  15.  
  16. var anonymous = "global";
  17. var f = Function("return anonymous;");
  18. assertEqual(f(), anonymous);
  19. var g = eval("(" + f.toString() + ")");
  20. assertEqual(g(), g);
  21. ```
  22.  
  23. I'd like to investigate solutions to each of those problems independently.
  24.  
  25. * After parsing, check token positions of either the last parameter or the first token in the body to make sure there are no shenanigans going on.
  26. * Give special instructions to the parser or someone else to not create a binding for the function name.
  27.  
  28. I still need to do some research to figure out how exactly to go about doing those two things, but I think the strategy deserves some attention when compared to all the scary code duplication currently in this CL.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement