SM 91 compatibility with MSVC

A small list of problems that I’ve encountered when embedding with MSVC:

  • mozilla/Result.h: error C2039: 'result_of_t': is not a member of 'std'
    Cause: std::result_of was deprecared in C++17 and removed in C++20.
    Solution: replace with conditional macro for std::invoke_result?

  • mozilla\LinkedList.h(440,1): '__PRETTY_FUNCTION__': identifier not found
    Cause: __PRETTY_FUNCTION__ is not a C++ standard macro.
    Solution: replace with conditional macro for __FUNCSIG__?

  • js\TracingAPI.h(264,63): warning C4275: non dll-interface class 'js::GenericTracer' used as base for dll-interface class 'JS::CallbackTracer'
    Solution: add JS_PUBLIC_API to GenericTracer?

  • error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall js::ForwardingProxyHandler::ForwardingProxyHandler(void const *,bool,bool)"
    Reason: a binary generation bug in Clang - https://bugs.llvm.org/show_bug.cgi?id=43954
    Solution: use explicit constructors:

--- a/js/public/Wrapper.h
+++ b/js/public/Wrapper.h
@@ -42,11 +42,14 @@
// Base class for proxy handlers that want to forward all operations to an
// object stored in the proxy's private slot.
class JS_PUBLIC_API ForwardingProxyHandler : public BaseProxyHandler {
 public:
-  using BaseProxyHandler::BaseProxyHandler;
+  explicit constexpr ForwardingProxyHandler(const void* aFamily,
+                                            bool aHasPrototype = false,
+                                            bool aHasSecurityPolicy = false)
+      : BaseProxyHandler(aFamily, aHasPrototype, aHasSecurityPolicy) {}

  /* Standard internal methods. */
  virtual bool getOwnPropertyDescriptor(
      JSContext* cx, JS::HandleObject proxy, JS::HandleId id,
      JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc)
      const override;

1 Like

Oh and I’m not sure if this needs needs to be fixed, but there are a lot of C4251 warnings ('object_1' needs to have dll-interface to be used by clients of class 'object_2')

A full list of C4251 warnings
js\Utility.h(313,7): warning C4251: 'js::AutoEnterOOMUnsafeRegion::annotateOOMSizeCallback': class 'mozilla::Atomic<js::AutoEnterOOMUnsafeRegion::AnnotateOOMAllocationSizeCallback,mozilla::Relaxed,void>' needs to have dll-interface to be used by clients of struct 'js::AutoEnterOOMUnsafeRegion'
js\Utility.h(312): message : see declaration of 'mozilla::Atomic<js::AutoEnterOOMUnsafeRegion::AnnotateOOMAllocationSizeCallback,mozilla::Relaxed,void>'
js\Utility.h(337,53): warning C4251: 'js::AutoEnterOOMUnsafeRegion::owner_': class 'mozilla::Atomic<js::AutoEnterOOMUnsafeRegion *,mozilla::SequentiallyConsistent,void>' needs to have dll-interface to be used by clients of struct 'js::AutoEnterOOMUnsafeRegion'
js\Utility.h(337): message : see declaration of 'mozilla::Atomic<js::AutoEnterOOMUnsafeRegion *,mozilla::SequentiallyConsistent,void>'
js\TracingAPI.h(221,26): warning C4251: 'JSTracer::options_': struct 'JS::TraceOptions' needs to have dll-interface to be used by clients of class 'JSTracer'
js\TracingAPI.h(93): message : see declaration of 'JS::TraceOptions'
js\TracingAPI.h(222,22): warning C4251: 'JSTracer::context_': class 'JS::TracingContext' needs to have dll-interface to be used by clients of class 'JSTracer'
js\TracingAPI.h(118): message : see declaration of 'JS::TracingContext'
js\ProfilingStack.h(497,7): warning C4251: 'ProfilingStack::frames': class 'mozilla::Atomic<js::ProfilingStackFrame *,mozilla::SequentiallyConsistent,void>' needs to have dll-interface to be used by clients of class 'ProfilingStack'
js\ProfilingStack.h(496): message : see declaration of 'mozilla::Atomic<js::ProfilingStackFrame *,mozilla::SequentiallyConsistent,void>'
js\ProfilingStack.h(510,54): warning C4251: 'ProfilingStack::stackPointer': class 'mozilla::Atomic<uint32_t,mozilla::ReleaseAcquire,void>' needs to have dll-interface to be used by clients of class 'ProfilingStack'
js\ProfilingStack.h(149): message : see declaration of 'mozilla::Atomic<uint32_t,mozilla::ReleaseAcquire,void>'
js\Class.h(361,20): warning C4251: 'js::ElementAdder::resObj_': class 'JS::Rooted<JSObject *>' needs to have dll-interface to be used by clients of class 'js::ElementAdder'
js\TypeDecls.h(97): message : see declaration of 'JS::Rooted<JSObject *>'
js\ErrorReport.h(341,17): warning C4251: 'JS::ErrorReportBuilder::ownedReport': class 'JSErrorReport' needs to have dll-interface to be used by clients of struct 'JS::ErrorReportBuilder'
js\ErrorReport.h(219): message : see declaration of 'JSErrorReport'
js\ErrorReport.h(344,20): warning C4251: 'JS::ErrorReportBuilder::exnObject': class 'JS::Rooted<JSObject *>' needs to have dll-interface to be used by clients of struct 'JS::ErrorReportBuilder'
js\TypeDecls.h(97): message : see declaration of 'JS::Rooted<JSObject *>'
js\ErrorReport.h(347,19): warning C4251: 'JS::ErrorReportBuilder::filename': class 'mozilla::UniquePtr<char [],JS::FreePolicy>' needs to have dll-interface to be used by clients of struct 'JS::ErrorReportBuilder'
js\Utility.h(632): message : see declaration of 'mozilla::UniquePtr<char [],JS::FreePolicy>'
js\ErrorReport.h(353,19): warning C4251: 'JS::ErrorReportBuilder::toStringResultBytesStorage': class 'mozilla::UniquePtr<char [],JS::FreePolicy>' needs to have dll-interface to be used by clients of struct 'JS::ErrorReportBuilder'
js\Utility.h(632): message : see declaration of 'mozilla::UniquePtr<char [],JS::FreePolicy>'
js\Exception.h(106,15): warning C4251: 'JS::AutoSaveExceptionState::exceptionValue': class 'JS::Rooted<JS::Value>' needs to have dll-interface to be used by clients of class 'JS::AutoSaveExceptionState'
js\TypeDecls.h(104): message : see declaration of 'JS::Rooted<JS::Value>'
js\Exception.h(107,16): warning C4251: 'JS::AutoSaveExceptionState::exceptionStack': class 'JS::Rooted<JSObject *>' needs to have dll-interface to be used by clients of class 'JS::AutoSaveExceptionState'
js\TypeDecls.h(97): message : see declaration of 'JS::Rooted<JSObject *>'
jsapi.h(1635,16): warning C4251: 'JS::AutoSetAsyncStackForNewCalls::oldAsyncStack': class 'JS::Rooted<JSObject *>' needs to have dll-interface to be used by clients of class 'JS::AutoSetAsyncStackForNewCalls'
js\TypeDecls.h(97): message : see declaration of 'JS::Rooted<JSObject *>'
jsapi.h(1802,46): warning C4251: 'JS::AutoFilename::filename_': class 'mozilla::Variant<const char *,JS::UniqueChars>' needs to have dll-interface to be used by clients of class 'JS::AutoFilename'
jsapi.h(1802): message : see declaration of 'mozilla::Variant<const char *,JS::UniqueChars>'