EngineInterfaceObject.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. #if defined(ENABLE_INTL_OBJECT) || defined(ENABLE_PROJECTION)
  7. namespace Js
  8. {
  9. class WindowsGlobalizationAdapter;
  10. enum EngineInterfaceExtensionKind
  11. {
  12. EngineInterfaceExtensionKind_Intl = 0,
  13. EngineInterfaceExtensionKind_WinRTPromise = 1,
  14. MaxEngineInterfaceExtensionKind = EngineInterfaceExtensionKind_WinRTPromise
  15. };
  16. class EngineExtensionObjectBase
  17. {
  18. public:
  19. EngineExtensionObjectBase(EngineInterfaceExtensionKind kind, Js::ScriptContext * context) :
  20. extensionKind(kind),
  21. scriptContext(context)
  22. {
  23. }
  24. EngineInterfaceExtensionKind GetExtensionKind() const { return extensionKind; }
  25. ScriptContext* GetScriptContext() const { return scriptContext; }
  26. virtual void Initialize() = 0;
  27. #if DBG
  28. virtual void DumpByteCode() = 0;
  29. #endif
  30. protected:
  31. EngineInterfaceExtensionKind extensionKind;
  32. ScriptContext* scriptContext;
  33. };
  34. #define EngineInterfaceObject_CommonFunctionProlog(function, callInfo) \
  35. PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault); \
  36. RUNTIME_ARGUMENTS(args, callInfo); \
  37. Assert(!(callInfo.Flags & CallFlags_New)); \
  38. unsigned argCount = args.Info.Count; \
  39. ScriptContext* scriptContext = function->GetScriptContext(); \
  40. AssertMsg(argCount > 0, "Should always have implicit 'this'"); \
  41. class EngineInterfaceObject : public DynamicObject
  42. {
  43. private:
  44. DEFINE_VTABLE_CTOR(EngineInterfaceObject, DynamicObject);
  45. DEFINE_MARSHAL_OBJECT_TO_SCRIPT_CONTEXT(EngineInterfaceObject);
  46. DynamicObject* commonNativeInterfaces;
  47. EngineExtensionObjectBase* engineExtensions[MaxEngineInterfaceExtensionKind + 1];
  48. public:
  49. EngineInterfaceObject(DynamicType * type) : DynamicObject(type) {}
  50. DynamicObject* GetCommonNativeInterfaces() const { return commonNativeInterfaces; }
  51. EngineExtensionObjectBase* GetEngineExtension(EngineInterfaceExtensionKind extensionKind) const;
  52. void SetEngineExtension(EngineInterfaceExtensionKind extensionKind, EngineExtensionObjectBase* extensionObject);
  53. static EngineInterfaceObject* New(Recycler * recycler, DynamicType * type);
  54. static bool Is(Var aValue);
  55. static EngineInterfaceObject* FromVar(Var aValue);
  56. void Initialize();
  57. static void __cdecl InitializeCommonNativeInterfaces(DynamicObject* engineInterface, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode);
  58. class EntryInfo
  59. {
  60. public:
  61. static NoProfileFunctionInfo GetErrorMessage;
  62. static NoProfileFunctionInfo LogDebugMessage;
  63. static NoProfileFunctionInfo TagPublicLibraryCode;
  64. #ifndef GlobalBuiltIn
  65. #define GlobalBuiltIn(global, method) \
  66. static NoProfileFunctionInfo Intl_BuiltIn_##global##_##method##; \
  67. #define GlobalBuiltInConstructor(global)
  68. #define BuiltInRaiseException(exceptionType, exceptionID) \
  69. static NoProfileFunctionInfo Intl_BuiltIn_raise##exceptionID;
  70. #define BuiltInRaiseException1(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID)
  71. #define BuiltInRaiseException2(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID)
  72. #define BuiltInRaiseException3(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID##_3)
  73. #include "EngineInterfaceObjectBuiltIns.h"
  74. #undef BuiltInRaiseException
  75. #undef BuiltInRaiseException1
  76. #undef BuiltInRaiseException2
  77. #undef BuiltInRaiseException3
  78. #undef GlobalBuiltInConstructor
  79. #undef GlobalBuiltIn
  80. #endif
  81. };
  82. static Var Entry_GetErrorMessage(RecyclableObject *function, CallInfo callInfo, ...);
  83. static Var Entry_LogDebugMessage(RecyclableObject *function, CallInfo callInfo, ...);
  84. static Var Entry_TagPublicLibraryCode(RecyclableObject *function, CallInfo callInfo, ...);
  85. #ifdef ENABLE_PROJECTION
  86. static Var EntryPromise_EnqueueTask(RecyclableObject *function, CallInfo callInfo, ...);
  87. #endif
  88. #ifndef GlobalBuiltIn
  89. #define GlobalBuiltIn(global, method)
  90. #define GlobalBuiltInConstructor(global)
  91. #define BuiltInRaiseException(exceptionType, exceptionID) \
  92. static Var EntryIntl_BuiltIn_raise##exceptionID(RecyclableObject *function, CallInfo callInfo, ...);
  93. #define BuiltInRaiseException1(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID)
  94. #define BuiltInRaiseException2(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID)
  95. #define BuiltInRaiseException3(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID##_3)
  96. #include "EngineInterfaceObjectBuiltIns.h"
  97. #undef BuiltInRaiseException
  98. #undef BuiltInRaiseException1
  99. #undef BuiltInRaiseException2
  100. #undef BuiltInRaiseException3
  101. #undef GlobalBuiltInConstructor
  102. #undef GlobalBuiltIn
  103. #endif
  104. };
  105. }
  106. #endif // ENABLE_INTL_OBJECT || ENABLE_PROJECTION