Skip to content

src: fix linking when built as shared library

Rodrigo Muino Tomonari requested to merge github/fork/zcbenz/fix-linking into master

This is another solution to fix the problem in #3046 as suggested by @bnoordhuis.

Currently linking Node as shared library in third party embedders will result in undefined symbols problem because the constructor of Environment is inlined and is calling constructor of debugger::Agent, which is not exported. This fix moves the constructor and destructor of Environment to src/env.cc to avoid leaking implementation details to solve this problem.

Following changes are also made for the fix:

  1. The types of Environment's properties are changed from v8::Persistent to v8::Global, so we don't have to manually reset all of them, this is because the ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES macro is removed in env-inl.h and calling Reset() in env.cc would be very hard.
  2. A new IsolateData::Scope class is introduced to manage IsolateData automatically instead of manually calling Put(), so we can rely the destructor to do clean up job.
  3. The *_buffer_ members are managed by std::vector so we don't have to manually delete them in destructor.
  4. PersistentToLocal are extended to handle v8::Global.
  5. The Environment::New and Environment::Dispose are now exported functions so embedders can still use them as APIs without knowing the definition of Environment's constructor.

Merge request reports

Loading