WScriptJsrt.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. class WScriptJsrt
  7. {
  8. public:
  9. static bool Initialize();
  10. class CallbackMessage : public MessageBase
  11. {
  12. JsValueRef m_function;
  13. CallbackMessage(CallbackMessage const&);
  14. public:
  15. CallbackMessage(unsigned int time, JsValueRef function);
  16. ~CallbackMessage();
  17. HRESULT Call(LPCWSTR fileName);
  18. };
  19. static void AddMessageQueue(MessageQueue *messageQueue);
  20. static LPCWSTR ConvertErrorCodeToMessage(JsErrorCode errorCode)
  21. {
  22. switch (errorCode)
  23. {
  24. case (JsErrorCode::JsErrorInvalidArgument) :
  25. return _u("TypeError: InvalidArgument");
  26. case (JsErrorCode::JsErrorNullArgument) :
  27. return _u("TypeError: NullArgument");
  28. case (JsErrorCode::JsErrorArgumentNotObject) :
  29. return _u("TypeError: ArgumentNotAnObject");
  30. case (JsErrorCode::JsErrorOutOfMemory) :
  31. return _u("OutOfMemory");
  32. case (JsErrorCode::JsErrorScriptException) :
  33. return _u("ScriptError");
  34. case (JsErrorCode::JsErrorScriptCompile) :
  35. return _u("SyntaxError");
  36. case (JsErrorCode::JsErrorFatal) :
  37. return _u("FatalError");
  38. default:
  39. AssertMsg(false, "Unexpected JsErrorCode");
  40. return nullptr;
  41. }
  42. }
  43. static bool PrintException(LPCWSTR fileName, JsErrorCode jsErrorCode);
  44. static JsValueRef LoadScript(JsValueRef callee, LPCWSTR fileName, size_t fileNameLength, LPCWSTR fileContent, LPCWSTR scriptInjectType, bool isSourceModule);
  45. static DWORD_PTR GetNextSourceContext();
  46. static JsValueRef LoadScriptFileHelper(JsValueRef callee, JsValueRef *arguments, unsigned short argumentCount, bool isSourceModule);
  47. static JsValueRef LoadScriptHelper(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState, bool isSourceModule);
  48. private:
  49. static bool CreateArgumentsObject(JsValueRef *argsObject);
  50. static bool CreateNamedFunction(const char16*, JsNativeFunction callback, JsValueRef* functionVar);
  51. static JsValueRef __stdcall EchoCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
  52. static JsValueRef __stdcall QuitCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
  53. static JsValueRef __stdcall LoadModuleFileCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
  54. static JsValueRef __stdcall LoadScriptFileCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
  55. static JsValueRef __stdcall LoadScriptCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
  56. static JsValueRef __stdcall LoadModuleCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
  57. static JsValueRef __stdcall SetTimeoutCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
  58. static JsValueRef __stdcall ClearTimeoutCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
  59. static MessageQueue *messageQueue;
  60. static DWORD_PTR sourceContext;
  61. };