JSSpiderMonkeyVM.h 1.4 KB

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