class NativeString { char *data; size_t length; char utf8ValueMemory[sizeof(String::Utf8Value)]; String::Utf8Value *utf8Value = nullptr; public: NativeString(Isolate *isolate, const Local &value) { if (value->IsUndefined()) { data = nullptr; length = 0; } else if (value->IsString()) { utf8Value = new (utf8ValueMemory) String::Utf8Value(isolate, value); data = (**utf8Value); length = utf8Value->length(); } else if (value->IsTypedArray()) { Local arrayBufferView = Local::Cast(value); ArrayBuffer::Contents contents = arrayBufferView->Buffer()->GetContents(); length = contents.ByteLength(); data = (char *) contents.Data(); } else if (value->IsArrayBuffer()) { Local arrayBuffer = Local::Cast(value); ArrayBuffer::Contents contents = arrayBuffer->GetContents(); length = contents.ByteLength(); data = (char *) contents.Data(); } else { static char empty[] = ""; data = empty; length = 0; } } char *getData() {return data;} size_t getLength() {return length;} ~NativeString() { if (utf8Value) { utf8Value->~Utf8Value(); } } };