create_string.cpp 446 B

123456789101112131415161718192021
  1. #include <nan.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "create_string.h"
  5. char* create_string(Nan::MaybeLocal<v8::Value> maybevalue) {
  6. v8::Local<v8::Value> value;
  7. if (maybevalue.ToLocal(&value)) {
  8. if (value->IsNull() || !value->IsString()) {
  9. return 0;
  10. }
  11. } else {
  12. return 0;
  13. }
  14. v8::String::Utf8Value string(value);
  15. char *str = (char *)malloc(string.length() + 1);
  16. strcpy(str, *string);
  17. return str;
  18. }