mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
src: replace usage of String::Utf8Value
v8::String::Utf8Value previously could allow invalid surrogates when interpreting values.
This commit is contained in:
1 parent
066e97867a
commit
15f0e0a596
11 files changed
+166
-69
No files matched your search
+4
-3
@@ -47,6 +47,7 @@
|
||||
# define uv_inet_ntop inet_ntop
|
||||
#endif
|
||||
|
||||
#include "util.h"
|
||||
|
||||
namespace node {
|
||||
|
||||
@@ -555,7 +556,7 @@ static Handle<Value> Query(const Arguments& args) {
|
||||
// object reference, causing wrap->GetObject() to return undefined.
|
||||
Local<Object> object = Local<Object>::New(wrap->GetObject());
|
||||
|
||||
String::Utf8Value name(args[0]);
|
||||
node::Utf8Value name(args[0]);
|
||||
|
||||
int r = wrap->Send(*name);
|
||||
if (r) {
|
||||
@@ -584,7 +585,7 @@ static Handle<Value> QueryWithFamily(const Arguments& args) {
|
||||
// object reference, causing wrap->GetObject() to return undefined.
|
||||
Local<Object> object = Local<Object>::New(wrap->GetObject());
|
||||
|
||||
String::Utf8Value name(args[0]);
|
||||
node::Utf8Value name(args[0]);
|
||||
int family = args[1]->Int32Value();
|
||||
|
||||
int r = wrap->Send(*name, family);
|
||||
@@ -706,7 +707,7 @@ static Handle<Value> IsIP(const Arguments& args) {
|
||||
static Handle<Value> GetAddrInfo(const Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
String::Utf8Value hostname(args[0]);
|
||||
node::Utf8Value hostname(args[0]);
|
||||
|
||||
int fam = AF_UNSPEC;
|
||||
if (args[1]->IsInt32()) {
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "node.h"
|
||||
#include "handle_wrap.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -97,7 +98,7 @@ Handle<Value> FSEventWrap::Start(const Arguments& args) {
|
||||
return ThrowException(Exception::TypeError(String::New("Bad arguments")));
|
||||
}
|
||||
|
||||
String::Utf8Value path(args[0]);
|
||||
node::Utf8Value path(args[0]);
|
||||
|
||||
int r = uv_fs_event_init(uv_default_loop(), &wrap->handle_, *path, OnEvent, 0);
|
||||
if (r == 0) {
|
||||
|
||||
+22
-20
@@ -80,6 +80,8 @@ typedef int mode_t;
|
||||
#include "node_script.h"
|
||||
#include "v8_typed_array.h"
|
||||
|
||||
#include "util.h"
|
||||
|
||||
using namespace v8;
|
||||
|
||||
# ifdef __APPLE__
|
||||
@@ -989,7 +991,7 @@ MakeCallback(const Handle<Object> object,
|
||||
|
||||
Local<Value> callback_v = object->Get(symbol);
|
||||
if (!callback_v->IsFunction()) {
|
||||
String::Utf8Value method(symbol);
|
||||
node::Utf8Value method(symbol);
|
||||
// XXX: If the object has a domain attached, handle it there?
|
||||
// At least, would be good to get *some* sort of indication
|
||||
// of how we got here, even if it's not catchable.
|
||||
@@ -1082,7 +1084,7 @@ enum encoding ParseEncoding(Handle<Value> encoding_v, enum encoding _default) {
|
||||
|
||||
if (!encoding_v->IsString()) return _default;
|
||||
|
||||
String::Utf8Value encoding(encoding_v);
|
||||
node::Utf8Value encoding(encoding_v);
|
||||
|
||||
if (strcasecmp(*encoding, "utf8") == 0) {
|
||||
return UTF8;
|
||||
@@ -1258,12 +1260,12 @@ void DisplayExceptionLine (TryCatch &try_catch) {
|
||||
|
||||
if (!message.IsEmpty()) {
|
||||
// Print (filename):(line number): (message).
|
||||
String::Utf8Value filename(message->GetScriptResourceName());
|
||||
node::Utf8Value filename(message->GetScriptResourceName());
|
||||
const char* filename_string = *filename;
|
||||
int linenum = message->GetLineNumber();
|
||||
fprintf(stderr, "%s:%i\n", filename_string, linenum);
|
||||
// Print line of source code.
|
||||
String::Utf8Value sourceline(message->GetSourceLine());
|
||||
node::Utf8Value sourceline(message->GetSourceLine());
|
||||
const char* sourceline_string = *sourceline;
|
||||
|
||||
// Because of how node modules work, all scripts are wrapped with a
|
||||
@@ -1310,7 +1312,7 @@ static void ReportException(TryCatch &try_catch, bool show_line) {
|
||||
|
||||
if (show_line) DisplayExceptionLine(try_catch);
|
||||
|
||||
String::Utf8Value trace(try_catch.StackTrace());
|
||||
node::Utf8Value trace(try_catch.StackTrace());
|
||||
|
||||
// range errors have a trace member set to undefined
|
||||
if (trace.length() > 0 && !try_catch.StackTrace()->IsUndefined()) {
|
||||
@@ -1325,11 +1327,11 @@ static void ReportException(TryCatch &try_catch, bool show_line) {
|
||||
!(er->ToObject()->Get(String::New("name"))->IsUndefined());
|
||||
|
||||
if (isErrorObject) {
|
||||
String::Utf8Value name(er->ToObject()->Get(String::New("name")));
|
||||
node::Utf8Value name(er->ToObject()->Get(String::New("name")));
|
||||
fprintf(stderr, "%s: ", *name);
|
||||
}
|
||||
|
||||
String::Utf8Value msg(!isErrorObject ? er
|
||||
node::Utf8Value msg(!isErrorObject ? er
|
||||
: er->ToObject()->Get(String::New("message")));
|
||||
fprintf(stderr, "%s\n", *msg);
|
||||
}
|
||||
@@ -1411,7 +1413,7 @@ static Handle<Value> Chdir(const Arguments& args) {
|
||||
return ThrowException(Exception::Error(String::New("Bad argument.")));
|
||||
}
|
||||
|
||||
String::Utf8Value path(args[0]);
|
||||
node::Utf8Value path(args[0]);
|
||||
|
||||
uv_err_t r = uv_chdir(*path);
|
||||
|
||||
@@ -1462,7 +1464,7 @@ static Handle<Value> Umask(const Arguments& args) {
|
||||
oct = args[0]->Uint32Value();
|
||||
} else {
|
||||
oct = 0;
|
||||
String::Utf8Value str(args[0]);
|
||||
node::Utf8Value str(args[0]);
|
||||
|
||||
// Parse the octal string.
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
@@ -1511,7 +1513,7 @@ static Handle<Value> SetGid(const Arguments& args) {
|
||||
if (args[0]->IsNumber()) {
|
||||
gid = args[0]->Int32Value();
|
||||
} else if (args[0]->IsString()) {
|
||||
String::Utf8Value grpnam(args[0]);
|
||||
node::Utf8Value grpnam(args[0]);
|
||||
struct group grp, *grpp = NULL;
|
||||
int err;
|
||||
|
||||
@@ -1552,7 +1554,7 @@ static Handle<Value> SetUid(const Arguments& args) {
|
||||
if (args[0]->IsNumber()) {
|
||||
uid = args[0]->Int32Value();
|
||||
} else if (args[0]->IsString()) {
|
||||
String::Utf8Value pwnam(args[0]);
|
||||
node::Utf8Value pwnam(args[0]);
|
||||
struct passwd pwd, *pwdp = NULL;
|
||||
int err;
|
||||
|
||||
@@ -1760,7 +1762,7 @@ Handle<Value> DLOpen(const v8::Arguments& args) {
|
||||
return ThrowException(exception);
|
||||
}
|
||||
|
||||
String::Utf8Value filename(args[0]); // Cast
|
||||
node::Utf8Value filename(args[0]); // Cast
|
||||
Local<Object> target = args[1]->ToObject(); // Cast
|
||||
|
||||
if (uv_dlopen(*filename, &lib)) {
|
||||
@@ -1772,7 +1774,7 @@ Handle<Value> DLOpen(const v8::Arguments& args) {
|
||||
return ThrowException(Exception::Error(errmsg));
|
||||
}
|
||||
|
||||
String::Utf8Value path(args[0]);
|
||||
node::Utf8Value path(args[0]);
|
||||
base = *path;
|
||||
|
||||
/* Find the shared library filename within the full path. */
|
||||
@@ -1905,7 +1907,7 @@ static Handle<Value> Binding(const Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
Local<String> module = args[0]->ToString();
|
||||
String::Utf8Value module_v(module);
|
||||
node::Utf8Value module_v(module);
|
||||
node_module_struct* modp;
|
||||
|
||||
if (binding_cache.IsEmpty()) {
|
||||
@@ -1969,7 +1971,7 @@ static void ProcessTitleSetter(Local<String> property,
|
||||
Local<Value> value,
|
||||
const AccessorInfo& info) {
|
||||
HandleScope scope;
|
||||
String::Utf8Value title(value);
|
||||
node::Utf8Value title(value);
|
||||
// TODO: protect with a lock
|
||||
uv_set_process_title(*title);
|
||||
}
|
||||
@@ -1979,7 +1981,7 @@ static Handle<Value> EnvGetter(Local<String> property,
|
||||
const AccessorInfo& info) {
|
||||
HandleScope scope;
|
||||
#ifdef __POSIX__
|
||||
String::Utf8Value key(property);
|
||||
node::Utf8Value key(property);
|
||||
const char* val = getenv(*key);
|
||||
if (val) {
|
||||
return scope.Close(String::New(val));
|
||||
@@ -2008,8 +2010,8 @@ static Handle<Value> EnvSetter(Local<String> property,
|
||||
const AccessorInfo& info) {
|
||||
HandleScope scope;
|
||||
#ifdef __POSIX__
|
||||
String::Utf8Value key(property);
|
||||
String::Utf8Value val(value);
|
||||
node::Utf8Value key(property);
|
||||
node::Utf8Value val(value);
|
||||
setenv(*key, *val, 1);
|
||||
#else // _WIN32
|
||||
String::Value key(property);
|
||||
@@ -2029,7 +2031,7 @@ static Handle<Integer> EnvQuery(Local<String> property,
|
||||
const AccessorInfo& info) {
|
||||
HandleScope scope;
|
||||
#ifdef __POSIX__
|
||||
String::Utf8Value key(property);
|
||||
node::Utf8Value key(property);
|
||||
if (getenv(*key)) {
|
||||
return scope.Close(Integer::New(None));
|
||||
}
|
||||
@@ -2057,7 +2059,7 @@ static Handle<Boolean> EnvDeleter(Local<String> property,
|
||||
const AccessorInfo& info) {
|
||||
HandleScope scope;
|
||||
#ifdef __POSIX__
|
||||
String::Utf8Value key(property);
|
||||
node::Utf8Value key(property);
|
||||
if (!getenv(*key)) return False();
|
||||
unsetenv(*key); // can't check return value, it's void on some platforms
|
||||
return True();
|
||||
|
||||
+3
-1
@@ -34,6 +34,8 @@
|
||||
# include <arpa/inet.h> // htons, htonl
|
||||
#endif
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
#define BUFFER_CLASS_ID (0xBABE)
|
||||
@@ -100,7 +102,7 @@ static size_t ByteLength (Handle<String> string, enum encoding enc) {
|
||||
if (enc == UTF8) {
|
||||
return string->Utf8Length();
|
||||
} else if (enc == BASE64) {
|
||||
String::Utf8Value v(string);
|
||||
node::Utf8Value v(string);
|
||||
return base64_decoded_size(*v, v.length());
|
||||
} else if (enc == UCS2) {
|
||||
return string->Length() * 2;
|
||||
|
||||
+16
-15
@@ -26,6 +26,7 @@
|
||||
#include "node.h"
|
||||
#include "node_buffer.h"
|
||||
#include "node_root_certs.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <string.h>
|
||||
#ifdef _MSC_VER
|
||||
@@ -181,7 +182,7 @@ Handle<Value> SecureContext::Init(const Arguments& args) {
|
||||
OPENSSL_CONST SSL_METHOD *method = SSLv23_method();
|
||||
|
||||
if (args.Length() == 1 && args[0]->IsString()) {
|
||||
String::Utf8Value sslmethod(args[0]);
|
||||
node::Utf8Value sslmethod(args[0]);
|
||||
|
||||
if (strcmp(*sslmethod, "SSLv2_method") == 0) {
|
||||
#ifndef OPENSSL_NO_SSL2
|
||||
@@ -245,7 +246,7 @@ static BIO* LoadBIO (Handle<Value> v) {
|
||||
int r = -1;
|
||||
|
||||
if (v->IsString()) {
|
||||
String::Utf8Value s(v);
|
||||
node::Utf8Value s(v);
|
||||
r = BIO_write(bio, *s, s.length());
|
||||
} else if (Buffer::HasInstance(v)) {
|
||||
Local<Object> buffer_obj = v->ToObject();
|
||||
@@ -298,7 +299,7 @@ Handle<Value> SecureContext::SetKey(const Arguments& args) {
|
||||
BIO *bio = LoadBIO(args[0]);
|
||||
if (!bio) return False();
|
||||
|
||||
String::Utf8Value passphrase(args[1]);
|
||||
node::Utf8Value passphrase(args[1]);
|
||||
|
||||
EVP_PKEY* key = PEM_read_bio_PrivateKey(bio, NULL, NULL,
|
||||
len == 1 ? NULL : *passphrase);
|
||||
@@ -532,7 +533,7 @@ Handle<Value> SecureContext::SetCiphers(const Arguments& args) {
|
||||
return ThrowException(Exception::TypeError(String::New("Bad parameter")));
|
||||
}
|
||||
|
||||
String::Utf8Value ciphers(args[0]);
|
||||
node::Utf8Value ciphers(args[0]);
|
||||
SSL_CTX_set_cipher_list(sc->ctx_, *ciphers);
|
||||
|
||||
return True();
|
||||
@@ -563,7 +564,7 @@ Handle<Value> SecureContext::SetSessionIdContext(const Arguments& args) {
|
||||
return ThrowException(Exception::TypeError(String::New("Bad parameter")));
|
||||
}
|
||||
|
||||
String::Utf8Value sessionIdContext(args[0]);
|
||||
node::Utf8Value sessionIdContext(args[0]);
|
||||
const unsigned char* sid_ctx = (const unsigned char*) *sessionIdContext;
|
||||
unsigned int sid_ctx_len = sessionIdContext.length();
|
||||
|
||||
@@ -1023,7 +1024,7 @@ Handle<Value> Connection::New(const Arguments& args) {
|
||||
if (is_server) {
|
||||
SSL_CTX_set_tlsext_servername_callback(sc->ctx_, SelectSNIContextCallback_);
|
||||
} else {
|
||||
String::Utf8Value servername(args[2]);
|
||||
node::Utf8Value servername(args[2]);
|
||||
SSL_set_tlsext_host_name(p->ssl_, *servername);
|
||||
}
|
||||
#endif
|
||||
@@ -2132,7 +2133,7 @@ class Cipher : public ObjectWrap {
|
||||
ssize_t key_written = DecodeWrite(key_buf, key_buf_len, args[1], BINARY);
|
||||
assert(key_written == key_buf_len);
|
||||
|
||||
String::Utf8Value cipherType(args[0]);
|
||||
node::Utf8Value cipherType(args[0]);
|
||||
|
||||
bool r = cipher->CipherInit(*cipherType, key_buf, key_buf_len);
|
||||
|
||||
@@ -2186,7 +2187,7 @@ class Cipher : public ObjectWrap {
|
||||
ssize_t iv_written = DecodeWrite(iv_buf, iv_len, args[2], BINARY);
|
||||
assert(iv_written == iv_len);
|
||||
|
||||
String::Utf8Value cipherType(args[0]);
|
||||
node::Utf8Value cipherType(args[0]);
|
||||
|
||||
bool r = cipher->CipherInitIv(*cipherType, key_buf,key_len,iv_buf,iv_len);
|
||||
|
||||
@@ -2548,7 +2549,7 @@ class Decipher : public ObjectWrap {
|
||||
ssize_t key_written = DecodeWrite(key_buf, key_len, args[1], BINARY);
|
||||
assert(key_written == key_len);
|
||||
|
||||
String::Utf8Value cipherType(args[0]);
|
||||
node::Utf8Value cipherType(args[0]);
|
||||
|
||||
bool r = cipher->DecipherInit(*cipherType, key_buf,key_len);
|
||||
|
||||
@@ -2602,7 +2603,7 @@ class Decipher : public ObjectWrap {
|
||||
ssize_t iv_written = DecodeWrite(iv_buf, iv_len, args[2], BINARY);
|
||||
assert(iv_written == iv_len);
|
||||
|
||||
String::Utf8Value cipherType(args[0]);
|
||||
node::Utf8Value cipherType(args[0]);
|
||||
|
||||
bool r = cipher->DecipherInitIv(*cipherType, key_buf,key_len,iv_buf,iv_len);
|
||||
|
||||
@@ -2900,7 +2901,7 @@ class Hmac : public ObjectWrap {
|
||||
return ThrowException(exception);
|
||||
}
|
||||
|
||||
String::Utf8Value hashType(args[0]);
|
||||
node::Utf8Value hashType(args[0]);
|
||||
|
||||
bool r;
|
||||
|
||||
@@ -3060,7 +3061,7 @@ class Hash : public ObjectWrap {
|
||||
"Must give hashtype string as argument")));
|
||||
}
|
||||
|
||||
String::Utf8Value hashType(args[0]);
|
||||
node::Utf8Value hashType(args[0]);
|
||||
|
||||
Hash *hash = new Hash();
|
||||
if (!hash->HashInit(*hashType)) {
|
||||
@@ -3253,7 +3254,7 @@ class Sign : public ObjectWrap {
|
||||
"Must give signtype string as argument")));
|
||||
}
|
||||
|
||||
String::Utf8Value signType(args[0]);
|
||||
node::Utf8Value signType(args[0]);
|
||||
|
||||
bool r = sign->SignInit(*signType);
|
||||
|
||||
@@ -3506,7 +3507,7 @@ class Verify : public ObjectWrap {
|
||||
"Must give verifytype string as argument")));
|
||||
}
|
||||
|
||||
String::Utf8Value verifyType(args[0]);
|
||||
node::Utf8Value verifyType(args[0]);
|
||||
|
||||
bool r = verify->VerifyInit(*verifyType);
|
||||
|
||||
@@ -3705,7 +3706,7 @@ class DiffieHellman : public ObjectWrap {
|
||||
String::New("No group name given")));
|
||||
}
|
||||
|
||||
String::Utf8Value group_name(args[0]);
|
||||
node::Utf8Value group_name(args[0]);
|
||||
|
||||
modp_group* it = modp_groups;
|
||||
|
||||
|
||||
+4
-2
@@ -48,6 +48,8 @@
|
||||
#define NODE_GC_DONE(arg0, arg1)
|
||||
#endif
|
||||
|
||||
#include "util.h"
|
||||
|
||||
namespace node {
|
||||
|
||||
using namespace v8;
|
||||
@@ -57,7 +59,7 @@ using namespace v8;
|
||||
return (ThrowException(Exception::Error(String::New("expected " \
|
||||
"object for " #obj " to contain string member " #member)))); \
|
||||
} \
|
||||
String::Utf8Value _##member(obj->Get(String::New(#member))); \
|
||||
node::Utf8Value _##member(obj->Get(String::New(#member))); \
|
||||
if ((*(const char **)valp = *_##member) == NULL) \
|
||||
*(const char **)valp = "<unknown>";
|
||||
|
||||
@@ -206,7 +208,7 @@ Handle<Value> DTRACE_HTTP_SERVER_REQUEST(const Arguments& args) {
|
||||
"object for request to contain string member headers"))));
|
||||
|
||||
Local<Value> strfwdfor = headers->Get(String::New("x-forwarded-for"));
|
||||
String::Utf8Value fwdfor(strfwdfor);
|
||||
node::Utf8Value fwdfor(strfwdfor);
|
||||
|
||||
if (!strfwdfor->IsString() || (req.forwardedFor = *fwdfor) == NULL)
|
||||
req.forwardedFor = const_cast<char*>("");
|
||||
|
||||
+19
-18
@@ -24,6 +24,7 @@
|
||||
#include "node_buffer.h"
|
||||
#include "node_stat_watcher.h"
|
||||
#include "req_wrap.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
@@ -364,7 +365,7 @@ static Handle<Value> Stat(const Arguments& args) {
|
||||
if (args.Length() < 1) return TYPE_ERROR("path required");
|
||||
if (!args[0]->IsString()) return TYPE_ERROR("path must be a string");
|
||||
|
||||
String::Utf8Value path(args[0]);
|
||||
node::Utf8Value path(args[0]);
|
||||
|
||||
if (args[1]->IsFunction()) {
|
||||
ASYNC_CALL(stat, args[1], *path)
|
||||
@@ -381,7 +382,7 @@ static Handle<Value> LStat(const Arguments& args) {
|
||||
if (args.Length() < 1) return TYPE_ERROR("path required");
|
||||
if (!args[0]->IsString()) return TYPE_ERROR("path must be a string");
|
||||
|
||||
String::Utf8Value path(args[0]);
|
||||
node::Utf8Value path(args[0]);
|
||||
|
||||
if (args[1]->IsFunction()) {
|
||||
ASYNC_CALL(lstat, args[1], *path)
|
||||
@@ -419,12 +420,12 @@ static Handle<Value> Symlink(const Arguments& args) {
|
||||
if (!args[0]->IsString()) return TYPE_ERROR("dest path must be a string");
|
||||
if (!args[1]->IsString()) return TYPE_ERROR("src path must be a string");
|
||||
|
||||
String::Utf8Value dest(args[0]);
|
||||
String::Utf8Value path(args[1]);
|
||||
node::Utf8Value dest(args[0]);
|
||||
node::Utf8Value path(args[1]);
|
||||
int flags = 0;
|
||||
|
||||
if (args[2]->IsString()) {
|
||||
String::Utf8Value mode(args[2]);
|
||||
node::Utf8Value mode(args[2]);
|
||||
if (strcmp(*mode, "dir") == 0) {
|
||||
flags |= UV_FS_SYMLINK_DIR;
|
||||
} else if (strcmp(*mode, "junction") == 0) {
|
||||
@@ -452,8 +453,8 @@ static Handle<Value> Link(const Arguments& args) {
|
||||
if (!args[0]->IsString()) return TYPE_ERROR("dest path must be a string");
|
||||
if (!args[1]->IsString()) return TYPE_ERROR("src path must be a string");
|
||||
|
||||
String::Utf8Value orig_path(args[0]);
|
||||
String::Utf8Value new_path(args[1]);
|
||||
node::Utf8Value orig_path(args[0]);
|
||||
node::Utf8Value new_path(args[1]);
|
||||
|
||||
if (args[2]->IsFunction()) {
|
||||
ASYNC_CALL(link, args[2], *orig_path, *new_path)
|
||||
@@ -469,7 +470,7 @@ static Handle<Value> ReadLink(const Arguments& args) {
|
||||
if (args.Length() < 1) return TYPE_ERROR("path required");
|
||||
if (!args[0]->IsString()) return TYPE_ERROR("path must be a string");
|
||||
|
||||
String::Utf8Value path(args[0]);
|
||||
node::Utf8Value path(args[0]);
|
||||
|
||||
if (args[1]->IsFunction()) {
|
||||
ASYNC_CALL(readlink, args[1], *path)
|
||||
@@ -488,8 +489,8 @@ static Handle<Value> Rename(const Arguments& args) {
|
||||
if (!args[0]->IsString()) return TYPE_ERROR("old path must be a string");
|
||||
if (!args[1]->IsString()) return TYPE_ERROR("new path must be a string");
|
||||
|
||||
String::Utf8Value old_path(args[0]);
|
||||
String::Utf8Value new_path(args[1]);
|
||||
node::Utf8Value old_path(args[0]);
|
||||
node::Utf8Value new_path(args[1]);
|
||||
|
||||
if (args[2]->IsFunction()) {
|
||||
ASYNC_CALL(rename, args[2], *old_path, *new_path)
|
||||
@@ -559,7 +560,7 @@ static Handle<Value> Unlink(const Arguments& args) {
|
||||
if (args.Length() < 1) return TYPE_ERROR("path required");
|
||||
if (!args[0]->IsString()) return TYPE_ERROR("path must be a string");
|
||||
|
||||
String::Utf8Value path(args[0]);
|
||||
node::Utf8Value path(args[0]);
|
||||
|
||||
if (args[1]->IsFunction()) {
|
||||
ASYNC_CALL(unlink, args[1], *path)
|
||||
@@ -575,7 +576,7 @@ static Handle<Value> RMDir(const Arguments& args) {
|
||||
if (args.Length() < 1) return TYPE_ERROR("path required");
|
||||
if (!args[0]->IsString()) return TYPE_ERROR("path must be a string");
|
||||
|
||||
String::Utf8Value path(args[0]);
|
||||
node::Utf8Value path(args[0]);
|
||||
|
||||
if (args[1]->IsFunction()) {
|
||||
ASYNC_CALL(rmdir, args[1], *path)
|
||||
@@ -592,7 +593,7 @@ static Handle<Value> MKDir(const Arguments& args) {
|
||||
return THROW_BAD_ARGS;
|
||||
}
|
||||
|
||||
String::Utf8Value path(args[0]);
|
||||
node::Utf8Value path(args[0]);
|
||||
int mode = static_cast<int>(args[1]->Int32Value());
|
||||
|
||||
if (args[2]->IsFunction()) {
|
||||
@@ -633,7 +634,7 @@ static Handle<Value> ReadDir(const Arguments& args) {
|
||||
if (args.Length() < 1) return TYPE_ERROR("path required");
|
||||
if (!args[0]->IsString()) return TYPE_ERROR("path must be a string");
|
||||
|
||||
String::Utf8Value path(args[0]);
|
||||
node::Utf8Value path(args[0]);
|
||||
|
||||
if (args[1]->IsFunction()) {
|
||||
ASYNC_CALL(readdir, args[1], *path, 0 /*flags*/)
|
||||
@@ -671,7 +672,7 @@ static Handle<Value> Open(const Arguments& args) {
|
||||
if (!args[1]->IsInt32()) return TYPE_ERROR("flags must be an int");
|
||||
if (!args[2]->IsInt32()) return TYPE_ERROR("mode must be an int");
|
||||
|
||||
String::Utf8Value path(args[0]);
|
||||
node::Utf8Value path(args[0]);
|
||||
int flags = args[1]->Int32Value();
|
||||
int mode = static_cast<int>(args[2]->Int32Value());
|
||||
|
||||
@@ -811,7 +812,7 @@ static Handle<Value> Chmod(const Arguments& args) {
|
||||
if(args.Length() < 2 || !args[0]->IsString() || !args[1]->IsInt32()) {
|
||||
return THROW_BAD_ARGS;
|
||||
}
|
||||
String::Utf8Value path(args[0]);
|
||||
node::Utf8Value path(args[0]);
|
||||
int mode = static_cast<int>(args[1]->Int32Value());
|
||||
|
||||
if(args[2]->IsFunction()) {
|
||||
@@ -858,7 +859,7 @@ static Handle<Value> Chown(const Arguments& args) {
|
||||
if (!args[1]->IsInt32()) return TYPE_ERROR("uid must be an int");
|
||||
if (!args[2]->IsInt32()) return TYPE_ERROR("gid must be an int");
|
||||
|
||||
String::Utf8Value path(args[0]);
|
||||
node::Utf8Value path(args[0]);
|
||||
int uid = static_cast<int>(args[1]->Int32Value());
|
||||
int gid = static_cast<int>(args[2]->Int32Value());
|
||||
|
||||
@@ -909,7 +910,7 @@ static Handle<Value> UTimes(const Arguments& args) {
|
||||
if (!args[1]->IsNumber()) return TYPE_ERROR("atime must be a number");
|
||||
if (!args[2]->IsNumber()) return TYPE_ERROR("mtime must be a number");
|
||||
|
||||
const String::Utf8Value path(args[0]);
|
||||
const node::Utf8Value path(args[0]);
|
||||
const double atime = static_cast<double>(args[1]->NumberValue());
|
||||
const double mtime = static_cast<double>(args[2]->NumberValue());
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#include "node_stat_watcher.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
@@ -104,7 +105,7 @@ Handle<Value> StatWatcher::Start(const Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
StatWatcher* wrap = ObjectWrap::Unwrap<StatWatcher>(args.Holder());
|
||||
String::Utf8Value path(args[0]);
|
||||
node::Utf8Value path(args[0]);
|
||||
const bool persistent = args[1]->BooleanValue();
|
||||
const uint32_t interval = args[2]->Uint32Value();
|
||||
|
||||
|
||||
+5
-4
@@ -25,6 +25,7 @@
|
||||
#include "tty_wrap.h"
|
||||
#include "tcp_wrap.h"
|
||||
#include "udp_wrap.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@@ -187,7 +188,7 @@ class ProcessWrap : public HandleWrap {
|
||||
|
||||
// options.file
|
||||
Local<Value> file_v = js_options->Get(String::NewSymbol("file"));
|
||||
String::Utf8Value file(file_v->IsString() ? file_v : Local<Value>());
|
||||
node::Utf8Value file(file_v->IsString() ? file_v : Local<Value>());
|
||||
if (file.length() > 0) {
|
||||
options.file = *file;
|
||||
} else {
|
||||
@@ -202,7 +203,7 @@ class ProcessWrap : public HandleWrap {
|
||||
// Heap allocate to detect errors. +1 is for NULL.
|
||||
options.args = new char*[argc + 1];
|
||||
for (int i = 0; i < argc; i++) {
|
||||
String::Utf8Value arg(js_argv->Get(i));
|
||||
node::Utf8Value arg(js_argv->Get(i));
|
||||
options.args[i] = strdup(*arg);
|
||||
}
|
||||
options.args[argc] = NULL;
|
||||
@@ -210,7 +211,7 @@ class ProcessWrap : public HandleWrap {
|
||||
|
||||
// options.cwd
|
||||
Local<Value> cwd_v = js_options->Get(String::NewSymbol("cwd"));
|
||||
String::Utf8Value cwd(cwd_v->IsString() ? cwd_v : Local<Value>());
|
||||
node::Utf8Value cwd(cwd_v->IsString() ? cwd_v : Local<Value>());
|
||||
if (cwd.length() > 0) {
|
||||
options.cwd = *cwd;
|
||||
}
|
||||
@@ -222,7 +223,7 @@ class ProcessWrap : public HandleWrap {
|
||||
int envc = env->Length();
|
||||
options.env = new char*[envc + 1]; // Heap allocated to detect errors.
|
||||
for (int i = 0; i < envc; i++) {
|
||||
String::Utf8Value pair(env->Get(i));
|
||||
node::Utf8Value pair(env->Get(i));
|
||||
options.env[i] = strdup(*pair);
|
||||
}
|
||||
options.env[envc] = NULL;
|
||||
|
||||
+5
-4
@@ -25,6 +25,7 @@
|
||||
#include "req_wrap.h"
|
||||
#include "handle_wrap.h"
|
||||
#include "udp_wrap.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -133,7 +134,7 @@ Handle<Value> UDPWrap::DoBind(const Arguments& args, int family) {
|
||||
// bind(ip, port, flags)
|
||||
assert(args.Length() == 3);
|
||||
|
||||
String::Utf8Value address(args[0]);
|
||||
node::Utf8Value address(args[0]);
|
||||
const int port = args[1]->Uint32Value();
|
||||
const int flags = args[2]->Uint32Value();
|
||||
|
||||
@@ -192,8 +193,8 @@ Handle<Value> UDPWrap::SetMembership(const Arguments& args,
|
||||
|
||||
assert(args.Length() == 2);
|
||||
|
||||
String::Utf8Value address(args[0]);
|
||||
String::Utf8Value iface(args[1]);
|
||||
node::Utf8Value address(args[0]);
|
||||
node::Utf8Value iface(args[1]);
|
||||
|
||||
const char* iface_cstr = *iface;
|
||||
if (args[1]->IsUndefined() || args[1]->IsNull()) {
|
||||
@@ -244,7 +245,7 @@ Handle<Value> UDPWrap::DoSend(const Arguments& args, int family) {
|
||||
length);
|
||||
|
||||
const unsigned short port = args[3]->Uint32Value();
|
||||
String::Utf8Value address(args[4]);
|
||||
node::Utf8Value address(args[4]);
|
||||
|
||||
switch (family) {
|
||||
case AF_INET:
|
||||
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||
// persons to whom the Software is furnished to do so, subject to the
|
||||
// following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#ifndef SRC_UTIL_H_
|
||||
#define SRC_UTIL_H_
|
||||
|
||||
#include "v8.h"
|
||||
#include "node_buffer.h"
|
||||
|
||||
namespace node {
|
||||
|
||||
class Utf8Value {
|
||||
public:
|
||||
explicit Utf8Value(v8::Handle<v8::Value> value)
|
||||
: length_(0), str_(NULL) {
|
||||
if (value.IsEmpty())
|
||||
return;
|
||||
|
||||
v8::Local<v8::String> val_ = value->ToString();
|
||||
|
||||
size_t len = val_->Length();
|
||||
|
||||
// In the presence of UTF allocate 3 bytes for each character
|
||||
if (val_->MayContainNonAscii())
|
||||
len = 3 * len;
|
||||
|
||||
// Make sure to include space for the null terminator
|
||||
len += 1;
|
||||
|
||||
char* str = static_cast<char*>(calloc(1, len));
|
||||
|
||||
int flags = WRITE_UTF8_FLAGS;
|
||||
flags |= ~v8::String::NO_NULL_TERMINATION;
|
||||
|
||||
length_ = val_->WriteUtf8(str,
|
||||
len,
|
||||
0,
|
||||
flags);
|
||||
|
||||
str_ = reinterpret_cast<char*>(str);
|
||||
}
|
||||
|
||||
~Utf8Value() {
|
||||
free(str_);
|
||||
}
|
||||
|
||||
char* operator*() {
|
||||
return str_;
|
||||
};
|
||||
|
||||
const char* operator*() const {
|
||||
return str_;
|
||||
};
|
||||
|
||||
size_t length() {
|
||||
return length_;
|
||||
};
|
||||
|
||||
private:
|
||||
size_t length_;
|
||||
char* str_;
|
||||
};
|
||||
|
||||
} // namespace node
|
||||
|
||||
#endif // SRC_UTIL_H_
|
||||
Reference in new issue
Block a user