src: fix linking when built as shared library
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:
- The types of
Environment
's properties are changed fromv8::Persistent
tov8::Global
, so we don't have to manually reset all of them, this is because theENVIRONMENT_STRONG_PERSISTENT_PROPERTIES
macro is removed inenv-inl.h
and callingReset()
inenv.cc
would be very hard. - A new
IsolateData::Scope
class is introduced to manageIsolateData
automatically instead of manually callingPut()
, so we can rely the destructor to do clean up job. - The
*_buffer_
members are managed bystd::vector
so we don't have to manually delete them in destructor. -
PersistentToLocal
are extended to handlev8::Global
. - The
Environment::New
andEnvironment::Dispose
are now exported functions so embedders can still use them as APIs without knowing the definition ofEnvironment
's constructor.