From 756b6222956b5d25b2e7db81f4e79033a3a4d20e Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sun, 11 Aug 2013 00:26:11 +0200 Subject: src: add multi-context support This commit makes it possible to use multiple V8 execution contexts within a single event loop. Put another way, handle and request wrap objects now "remember" the context they belong to and switch back to that context when the time comes to call into JS land. This could have been done in a quick and hacky way by calling v8::Object::GetCreationContext() on the wrap object right before making a callback but that leaves a fairly wide margin for bugs. Instead, we make the context explicit through a new Environment class that encapsulates everything (or almost everything) that belongs to the context. Variables that used to be a static or a global are now members of the aforementioned class. An additional benefit is that this approach should make it relatively straightforward to add full isolate support in due course. There is no JavaScript API yet but that will be added in the near future. This work was graciously sponsored by GitHub, Inc. --- src/node_buffer.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/node_buffer.h') diff --git a/src/node_buffer.h b/src/node_buffer.h index ca9a135e9df..78e6e42f6cb 100644 --- a/src/node_buffer.h +++ b/src/node_buffer.h @@ -26,6 +26,10 @@ #include "smalloc.h" #include "v8.h" +#if defined(NODE_WANT_INTERNALS) +#include "env.h" +#endif // defined(NODE_WANT_INTERNALS) + namespace node { namespace Buffer { @@ -56,6 +60,20 @@ NODE_EXTERN v8::Local New(char* data, // TODO(trevnorris): should be New() for consistency NODE_EXTERN v8::Local Use(char* data, uint32_t len); +// Internal. Not for public consumption. We can't define these in +// src/node_internals.h due to a circular dependency issue with +// the smalloc.h and node_internals.h headers. +#if defined(NODE_WANT_INTERNALS) +v8::Local New(Environment* env, size_t size); +v8::Local New(Environment* env, const char* data, size_t len); +v8::Local New(Environment* env, + char* data, + size_t length, + smalloc::FreeCallback callback, + void* hint); +v8::Local Use(Environment* env, char* data, uint32_t length); +#endif // defined(NODE_WANT_INTERNALS) + } // namespace Buffer } // namespace node -- cgit v1.2.3