diff options
Diffstat (limited to 'src/node_internals.h')
-rw-r--r-- | src/node_internals.h | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/src/node_internals.h b/src/node_internals.h index d9db29c1b7..082368ee9b 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -25,8 +25,12 @@ #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 { @@ -95,6 +99,20 @@ inline v8::Local<v8::Object> NewInstance( 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); + // 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. @@ -157,7 +175,7 @@ inline static int snprintf(char* buf, unsigned int len, const char* fmt, ...) { #define THROW_ERROR(fun) \ do { \ v8::HandleScope scope(node_isolate); \ - v8::ThrowException(fun(v8::String::New(errmsg))); \ + v8::ThrowException(fun(OneByteString(node_isolate, errmsg))); \ } \ while (0) @@ -333,6 +351,33 @@ inline v8::Local<v8::Object> NewInstance( 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); +} + } // namespace node #endif // SRC_NODE_INTERNALS_H_ |