Search code examples
c++v8

What's difference between namespace v8 and namespace v8::internal?


While I was reading the v8's source code, I've got a part that I don't know very well.

  v8::Isolate::CreateParams create_params;
  create_params.array_buffer_allocator =
      v8::ArrayBuffer::Allocator::NewDefaultAllocator();
  v8::Isolate* isolate = v8::Isolate::New(create_params);

I tracked that the implementation of v8::Isolate::New, then I found following code:

// static
Isolate* Isolate::Allocate() {
  return reinterpret_cast<Isolate*>(i::Isolate::New());
}

Because I read the code a little more, I know that 'i' means 'internal', but I'm not sure about the rest. Are v8::Isolate and v8::internal::Isolate compatible?


Solution

  • Typically, C++ libraries use an internal (also commonly called detail) namespace whenever they need to declare/define stuff that is used by the library, but shouldn't be used by the users.

    It is a way to have something resembling "library linkage". Hopefully if/when modules arrive to C++, we will have a better way to handle this.