JSSpiderMonkeyVM.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #ifdef USE_SPIDERMONKEY
  5. #pragma once
  6. #include "Object.h"
  7. using namespace Atomic;
  8. struct JSRuntime;
  9. struct JSContext;
  10. class JSAutoRequest;
  11. class JSAutoCompartment;
  12. namespace AtomicEditor
  13. {
  14. // Notes: SpiderMonkey Reflect API is giving some bad loc's, which seems to be an issue with the
  15. // C++ generator not passing in tokens for some nodes (MemberExpression.property for example)
  16. // probably should use http://esprima.org/
  17. class JSSpiderMonkeyVM : public Object
  18. {
  19. OBJECT(JSSpiderMonkeyVM);
  20. public:
  21. /// Construct.
  22. JSSpiderMonkeyVM(Context* context);
  23. /// Destruct.
  24. ~JSSpiderMonkeyVM();
  25. bool ExecuteFile(const String& path);
  26. bool ParseJavascriptToJSON(const char* source, String& json);
  27. bool ParseJavascriptToJSONWithSpiderMonkeyReflectAPI(const char* source, String& json);
  28. private:
  29. bool ReadZeroTerminatedSourceFile(const String& path, String& source);
  30. // for access within duktape callbacks
  31. static WeakPtr<JSSpiderMonkeyVM> instance_;
  32. JSRuntime* runtime_;
  33. JSContext* jscontext_;
  34. JSAutoRequest* autorequest_;
  35. JSAutoCompartment* autocompartment_;
  36. };
  37. }
  38. #endif