Skip to content
Browse files

Edits after Meshula's review

  • Loading branch information...
1 parent bb5222b commit 1c06ee25ed7eff6ca8dd7df1d030f358ff3a2bda @jedp jedp committed Jul 7, 2011
Showing with 11 additions and 6 deletions.
  1. +1 −1 package.json
  2. +10 −5 src/rot13.cpp
View
2 package.json
@@ -1,7 +1,7 @@
{"name": "rot13",
"description": "Sync/Async rot13 encoding via C++ extension",
"author": "Jed Parsons <jed@jedparsons.com> (http://jedparsons.com)",
- "version": "0.1.1",
+ "version": "0.1.2",
"repository": {
"type": "git",
View
15 src/rot13.cpp
@@ -24,10 +24,10 @@ using namespace std;
String::New("Argument " #I " must be a function"))); \
Local<Function> VAR = Local<Function>::Cast(args[I])
-// Convert a v8 value to a std string
-string ObjectToString(Local<Value> value) {
+void ObjectToString(const Local<Value>& value, std::string& converted)
+{
String::Utf8Value utf8_value(value);
- return std::string(*utf8_value);
+ converted = *utf8_value;
}
char rotate_ch(const char ch)
@@ -115,8 +115,10 @@ class Rot13: ObjectWrap
HandleScope scope;
REQ_STR_ARG(0, source);
+ std::string as_string;
std::string rotated;
- rotate_str(ObjectToString(source).c_str(), rotated);
+ ObjectToString(source, as_string);
+ rotate_str(as_string, rotated);
// Convert to std::string for rotating, then back into v8 String
Local<String> result = String::New(rotated.c_str()); //rotated);
@@ -130,11 +132,14 @@ class Rot13: ObjectWrap
REQ_STR_ARG(0, source);
REQ_FUN_ARG(1, callback);
+ std::string as_string;
+ ObjectToString(source, as_string);
+
Rot13 *rot13 = ObjectWrap::Unwrap<Rot13>(args.This());
baton_t *baton = new baton_t();
baton->rot13 = rot13;
- baton->source = ObjectToString(source);
+ baton->source = as_string;
baton->callback = Persistent<Function>::New(callback);
// Add refcount so we won't get gc'd while running in another thread

0 comments on commit 1c06ee2

Please sign in to comment.
Something went wrong with that request. Please try again.