crypto: root JS objects in HandleScope with Local<>

pull/24503/head
Ben Noordhuis 2012-03-26 06:55:08 -07:00
parent f86359cc3f
commit 9eacf93928
1 changed files with 10 additions and 11 deletions

View File

@ -4111,14 +4111,14 @@ EIO_PBKDF2After(uv_work_t* req) {
pbkdf2_req* request = (pbkdf2_req*)req->data; pbkdf2_req* request = (pbkdf2_req*)req->data;
delete req; delete req;
Handle<Value> argv[2]; Local<Value> argv[2];
if (request->err) { if (request->err) {
argv[0] = Undefined(); argv[0] = Local<Value>::New(Undefined());
argv[1] = Encode(request->key, request->keylen, BINARY); argv[1] = Encode(request->key, request->keylen, BINARY);
memset(request->key, 0, request->keylen); memset(request->key, 0, request->keylen);
} else { } else {
argv[0] = Exception::Error(String::New("PBKDF2 error")); argv[0] = Exception::Error(String::New("PBKDF2 error"));
argv[1] = Undefined(); argv[1] = Local<Value>::New(Undefined());
} }
TryCatch try_catch; TryCatch try_catch;
@ -4285,9 +4285,8 @@ void RandomBytesWork(uv_work_t* work_req) {
} }
void RandomBytesCheck(RandomBytesRequest* req, Handle<Value> argv[2]) { // don't call this function without a valid HandleScope
HandleScope scope; void RandomBytesCheck(RandomBytesRequest* req, Local<Value> argv[2]) {
if (req->error_) { if (req->error_) {
char errmsg[256] = "Operation not supported"; char errmsg[256] = "Operation not supported";
@ -4295,13 +4294,13 @@ void RandomBytesCheck(RandomBytesRequest* req, Handle<Value> argv[2]) {
ERR_error_string_n(req->error_, errmsg, sizeof errmsg); ERR_error_string_n(req->error_, errmsg, sizeof errmsg);
argv[0] = Exception::Error(String::New(errmsg)); argv[0] = Exception::Error(String::New(errmsg));
argv[1] = Null(); argv[1] = Local<Value>::New(Null());
} }
else { else {
// avoids the malloc + memcpy // avoids the malloc + memcpy
Buffer* buffer = Buffer::New(req->data_, req->size_, RandomBytesFree, NULL); Buffer* buffer = Buffer::New(req->data_, req->size_, RandomBytesFree, NULL);
argv[0] = Null(); argv[0] = Local<Value>::New(Null());
argv[1] = buffer->handle_; argv[1] = Local<Object>::New(buffer->handle_);
} }
} }
@ -4312,7 +4311,7 @@ void RandomBytesAfter(uv_work_t* work_req) {
container_of(work_req, RandomBytesRequest, work_req_); container_of(work_req, RandomBytesRequest, work_req_);
HandleScope scope; HandleScope scope;
Handle<Value> argv[2]; Local<Value> argv[2];
RandomBytesCheck(req, argv); RandomBytesCheck(req, argv);
TryCatch tc; TryCatch tc;
@ -4355,7 +4354,7 @@ Handle<Value> RandomBytes(const Arguments& args) {
return Undefined(); return Undefined();
} }
else { else {
Handle<Value> argv[2]; Local<Value> argv[2];
RandomBytesWork<generator>(&req->work_req_); RandomBytesWork<generator>(&req->work_req_);
RandomBytesCheck(req, argv); RandomBytesCheck(req, argv);
delete req; delete req;