WScriptJsrt.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 L"TypeError: InvalidArgument";
  26. case (JsErrorCode::JsErrorNullArgument) :
  27. return L"TypeError: NullArgument";
  28. case (JsErrorCode::JsErrorArgumentNotObject) :
  29. return L"TypeError: ArgumentNotAnObject";
  30. case (JsErrorCode::JsErrorOutOfMemory) :
  31. return L"OutOfMemory";
  32. case (JsErrorCode::JsErrorScriptException) :
  33. return L"ScriptError";
  34. case (JsErrorCode::JsErrorScriptCompile) :
  35. return L"SyntaxError";
  36. case (JsErrorCode::JsErrorFatal) :
  37. return L"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);
  45. static DWORD_PTR GetNextSourceContext();
  46. private:
  47. static bool CreateArgumentsObject(JsValueRef *argsObject);
  48. static bool CreateNamedFunction(const wchar_t*, JsNativeFunction callback, JsValueRef* functionVar);
  49. static JsValueRef __stdcall EchoCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
  50. static JsValueRef __stdcall QuitCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
  51. static JsValueRef __stdcall LoadScriptFileCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
  52. static JsValueRef __stdcall LoadScriptCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
  53. static JsValueRef __stdcall SetTimeoutCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
  54. static JsValueRef __stdcall ClearTimeoutCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
  55. static MessageQueue *messageQueue;
  56. static DWORD_PTR sourceContext;
  57. };