Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

BrowserJS.cpp 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "BrowserJS.h"
  2. std::vector<std::string> getConstructs() {
  3. std::vector<std::string> constructs;
  4. constructs.push_back("document.getElementsByTagName");
  5. constructs.push_back("document.addEventListener");
  6. constructs.push_back("document.querySelector");
  7. constructs.push_back("console.log");
  8. return constructs;
  9. }
  10. bool isConstruct(std::string construct) {
  11. std::vector<std::string> constructs = getConstructs();
  12. std::vector<std::string>::iterator it = std::find(constructs.begin(), constructs.end(), construct);
  13. std::cout << "isConstruct [" << construct << "](" << ((it != constructs.end())?"true":"false") << ")\n";
  14. return it != constructs.end();
  15. }
  16. js_internal_storage *executeConstruct(std::string functionName, std::string params, js_function &scope) {
  17. std::vector<std::string> constructs = getConstructs();
  18. std::vector<std::string>::iterator it = std::find(constructs.begin(), constructs.end(), functionName);
  19. if (it == constructs.end()) {
  20. return nullptr;
  21. }
  22. std::cout << "executeConstruct [" << functionName << "](" << params << ")\n";
  23. if (functionName == "document.querySelector") {
  24. return jsConstruct_querySelector(params, scope);
  25. }
  26. if (functionName == "document.addEventListener") {
  27. return jsConstruct_addEventListener(params, scope);
  28. }
  29. std::cout << "executeConstruct hanlder needs to be written\n";
  30. return nullptr;
  31. }
  32. js_internal_storage *jsConstruct_querySelector(std::string params, js_function &scope) {
  33. js_bool *jb = new js_bool;
  34. jb->value = false;
  35. return jb;
  36. }
  37. js_internal_storage *jsConstruct_addEventListener(std::string params, js_function &scope) {
  38. std::cout << "WARNING implement jsConstruct_addEventListener\n";
  39. js_bool *jb = new js_bool;
  40. jb->value = false;
  41. return jb;
  42. }