summaryrefslogtreecommitdiff
path: root/src/node_internals.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/node_internals.h')
-rw-r--r--src/node_internals.h230
1 files changed, 35 insertions, 195 deletions
diff --git a/src/node_internals.h b/src/node_internals.h
index ba110a51c8..141bd92ff0 100644
--- a/src/node_internals.h
+++ b/src/node_internals.h
@@ -22,15 +22,16 @@
#ifndef SRC_NODE_INTERNALS_H_
#define SRC_NODE_INTERNALS_H_
+#include "env.h"
+#include "util.h"
+#include "util-inl.h"
+#include "uv.h"
#include "v8.h"
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
-#define FIXED_ONE_BYTE_STRING(isolate, string) \
- (node::OneByteString((isolate), (string), sizeof(string) - 1))
-
struct sockaddr;
namespace node {
@@ -38,36 +39,6 @@ namespace node {
// Defined in node.cc
extern v8::Isolate* node_isolate;
-// Defined in node.cc at startup.
-extern v8::Persistent<v8::Object> process_p;
-
-template <typename TypeName>
-class CachedBase {
- public:
- CachedBase();
- operator v8::Handle<TypeName>() const;
- void operator=(v8::Handle<TypeName> that); // Can only assign once.
- bool IsEmpty() const;
- private:
- CachedBase(const CachedBase&);
- void operator=(const CachedBase&);
- v8::Persistent<TypeName> handle_;
-};
-
-template <typename TypeName>
-class Cached : public CachedBase<TypeName> {
- public:
- operator v8::Handle<v8::Value>() const;
- void operator=(v8::Handle<TypeName> that);
-};
-
-template <>
-class Cached<v8::Value> : public CachedBase<v8::Value> {
- public:
- operator v8::Handle<v8::Value>() const;
- void operator=(v8::Handle<v8::Value> that);
-};
-
// If persistent.IsWeak() == false, then do not call persistent.Dispose()
// while the returned Local<T> is still in scope, it will destroy the
// reference to the object.
@@ -76,55 +47,41 @@ inline v8::Local<TypeName> PersistentToLocal(
v8::Isolate* isolate,
const v8::Persistent<TypeName>& persistent);
-v8::Handle<v8::Value> MakeCallback(
- const v8::Handle<v8::Object> recv,
- uint32_t index,
- int argc,
- v8::Handle<v8::Value>* argv);
-
-template <typename TypeName>
-v8::Handle<v8::Value> MakeCallback(
- const v8::Persistent<v8::Object>& recv,
- const TypeName method,
- int argc,
- v8::Handle<v8::Value>* argv);
-
-template <typename TypeName>
-v8::Handle<v8::Value> MakeCallback(
- const v8::Persistent<v8::Object>& recv,
- const Cached<TypeName>& method,
- int argc,
- v8::Handle<v8::Value>* argv);
-
-inline bool HasInstance(
- const v8::Persistent<v8::FunctionTemplate>& function_template,
- v8::Handle<v8::Value> value);
-
-inline v8::Local<v8::Object> NewInstance(
- const v8::Persistent<v8::Function>& ctor,
- int argc = 0,
- v8::Handle<v8::Value>* argv = NULL);
-
-// Convenience wrapper around v8::String::NewFromOneByte().
-inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
- const char* data,
- int length = -1);
-
-// For the people that compile with -funsigned-char.
-inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
- const signed char* data,
- int length = -1);
-
-inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
- const unsigned char* data,
- int length = -1);
+// Call with valid HandleScope and while inside Context scope.
+v8::Handle<v8::Value> MakeCallback(Environment* env,
+ const v8::Handle<v8::Object> object,
+ const char* method,
+ int argc = 0,
+ v8::Handle<v8::Value>* argv = NULL);
+
+// Call with valid HandleScope and while inside Context scope.
+v8::Handle<v8::Value> MakeCallback(Environment* env,
+ const v8::Handle<v8::Object> object,
+ uint32_t index,
+ int argc = 0,
+ v8::Handle<v8::Value>* argv = NULL);
+
+// Call with valid HandleScope and while inside Context scope.
+v8::Handle<v8::Value> MakeCallback(Environment* env,
+ const v8::Handle<v8::Object> object,
+ const v8::Handle<v8::String> symbol,
+ int argc = 0,
+ v8::Handle<v8::Value>* argv = NULL);
+
+// Call with valid HandleScope and while inside Context scope.
+v8::Handle<v8::Value> MakeCallback(Environment* env,
+ const v8::Handle<v8::Object> object,
+ const v8::Handle<v8::Function> callback,
+ int argc = 0,
+ v8::Handle<v8::Value>* argv = NULL);
// Convert a struct sockaddr to a { address: '1.2.3.4', port: 1234 } JS object.
// Sets address and port properties on the info object and returns it.
// If |info| is omitted, a new object is returned.
v8::Local<v8::Object> AddressToJS(
+ Environment* env,
const sockaddr* addr,
- v8::Handle<v8::Object> info = v8::Handle<v8::Object>());
+ v8::Local<v8::Object> info = v8::Handle<v8::Object>());
#ifdef _WIN32
// emulate snprintf() on windows, _snprintf() doesn't zero-terminate the buffer
@@ -213,6 +170,8 @@ inline static void ThrowUVException(int errorno,
NO_RETURN void FatalError(const char* location, const char* message);
+v8::Local<v8::Object> BuildStatsObject(Environment* env, const uv_stat_t* s);
+
#define NODE_WRAP(Object, Pointer) \
do { \
assert(!Object.IsEmpty()); \
@@ -286,125 +245,6 @@ inline MUST_USE_RESULT bool ParseArrayIndex(v8::Handle<v8::Value> arg,
return true;
}
-template <class TypeName>
-inline v8::Local<TypeName> PersistentToLocal(
- v8::Isolate* isolate,
- const v8::Persistent<TypeName>& persistent) {
- if (persistent.IsWeak()) {
- return v8::Local<TypeName>::New(isolate, persistent);
- } else {
- return *reinterpret_cast<v8::Local<TypeName>*>(
- const_cast<v8::Persistent<TypeName>*>(&persistent));
- }
-}
-
-template <typename TypeName>
-CachedBase<TypeName>::CachedBase() {
-}
-
-template <typename TypeName>
-CachedBase<TypeName>::operator v8::Handle<TypeName>() const {
- return PersistentToLocal(node_isolate, handle_);
-}
-
-template <typename TypeName>
-void CachedBase<TypeName>::operator=(v8::Handle<TypeName> that) {
- assert(handle_.IsEmpty() == true); // Can only assign once.
- handle_.Reset(node_isolate, that);
-}
-
-template <typename TypeName>
-bool CachedBase<TypeName>::IsEmpty() const {
- return handle_.IsEmpty();
-}
-
-template <typename TypeName>
-Cached<TypeName>::operator v8::Handle<v8::Value>() const {
- return CachedBase<TypeName>::operator v8::Handle<TypeName>();
-}
-
-template <typename TypeName>
-void Cached<TypeName>::operator=(v8::Handle<TypeName> that) {
- CachedBase<TypeName>::operator=(that);
-}
-
-inline Cached<v8::Value>::operator v8::Handle<v8::Value>() const {
- return CachedBase<v8::Value>::operator v8::Handle<v8::Value>();
-}
-
-inline void Cached<v8::Value>::operator=(v8::Handle<v8::Value> that) {
- CachedBase<v8::Value>::operator=(that);
-}
-
-template <typename TypeName>
-v8::Handle<v8::Value> MakeCallback(
- const v8::Persistent<v8::Object>& recv,
- const TypeName method,
- int argc,
- v8::Handle<v8::Value>* argv) {
- v8::Local<v8::Object> recv_obj = PersistentToLocal(node_isolate, recv);
- return MakeCallback(recv_obj, method, argc, argv);
-}
-
-template <typename TypeName>
-v8::Handle<v8::Value> MakeCallback(
- const v8::Persistent<v8::Object>& recv,
- const Cached<TypeName>& method,
- int argc,
- v8::Handle<v8::Value>* argv) {
- const v8::Handle<TypeName> handle = method;
- return MakeCallback(recv, handle, argc, argv);
-}
-
-inline bool HasInstance(
- const v8::Persistent<v8::FunctionTemplate>& function_template,
- v8::Handle<v8::Value> value) {
- if (function_template.IsEmpty()) return false;
- v8::Local<v8::FunctionTemplate> function_template_handle =
- PersistentToLocal(node_isolate, function_template);
- return function_template_handle->HasInstance(value);
-}
-
-inline v8::Local<v8::Object> NewInstance(
- const v8::Persistent<v8::Function>& ctor,
- int argc,
- v8::Handle<v8::Value>* argv) {
- v8::Local<v8::Function> constructor_handle =
- PersistentToLocal(node_isolate, ctor);
- return constructor_handle->NewInstance(argc, argv);
-}
-
-inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
- const char* data,
- int length) {
- return v8::String::NewFromOneByte(isolate,
- reinterpret_cast<const uint8_t*>(data),
- v8::String::kNormalString,
- length);
-}
-
-inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
- const signed char* data,
- int length) {
- return v8::String::NewFromOneByte(isolate,
- reinterpret_cast<const uint8_t*>(data),
- v8::String::kNormalString,
- length);
-}
-
-inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
- const unsigned char* data,
- int length) {
- return v8::String::NewFromOneByte(isolate,
- reinterpret_cast<const uint8_t*>(data),
- v8::String::kNormalString,
- length);
-}
-
-bool InDomain();
-
-v8::Handle<v8::Value> GetDomain();
-
} // namespace node
#endif // SRC_NODE_INTERNALS_H_