Comments (5)
What you're running in to I think is that v8::String::NO_NULL_TERMINATION
is included in the default options so you're just overwriting it with an explicit v8::String::HINT_MANY_WRITES_EXPECTED
. I end up doing something similar pretty much every time I use NanFromV8String
, e.g.: https://github.com/rvagg/node-leveldown/blob/master/src/database.cc#L156
So this is a pain point for me too. We perhaps should either change the default or introduce an additional macro (with what name?) to generate proper null-terminated strings.
from nan.
The defaults were made to make it somewhat compatible with the StringBytes family of functions. You have to actually look at the sizes of returned buffers to know what to copy and what not to, as zero-termination is not used internally, sizes may change and the strings may contain null bytes. It should be easy to make a wrapper and call it NanCString or something.like that.
from nan.
yeah, NanCString
is a good name, tho that leads to an unfortunate disparity in naming, perhaps NanFromV8String
should be renamed too?
from nan.
I guess NanFromV8String
could be renamed (or aliased for backward compatibility) to NanCString
as it already returns a C string. You could then add more specialized macros, like: NanCNullTerminatedString
or NanGetCString
Not directly related, but is it possible for you to add a C++ std::string
version? I think it could be useful, especially when you are doing some string manipulation after.
Something like:
inline static std::string NanCppString(v8::Local<v8::Value> v8Str) {
char* str = NanFromV8String(v8Str, Nan::UTF8, NULL, NULL, 0, v8::String::NO_OPTIONS);
std::string cppStr(str);
delete[] cstr;
return cppStr;
}
Thanks!
from nan.
I guess we can close this now that everything but a std::string
version has been adressed.
from nan.
Related Issues (20)
- Copy *.node addon compiled file from compiling machine to another machine (client) same system
- How to convert an int64 to NodeJs BigInt. HOT 1
- Cross Compile for ARMv5 HOT 2
- Switching to NAN_MODULE_WORKER_ENABLED broke my native node module HOT 1
- strings-test.js fails on s390x
- `Nan::SetAccessor()` deprecation warning with V8 10.1 and nan 2.15.0 HOT 9
- nan_callbacks.h:55:23: error: ‘AccessorSignature’ is not a member of ‘v8’ HOT 16
- NAN_MODULE_INIT cast warning on Node v16 HOT 19
- Nan::SetProperty (const char * version of Nan::Set to match Nan::SetMethod) HOT 4
- 'IdleNotificationDeadline' is deprecated: Use MemoryPressureNotification() HOT 3
- v8 Fast API with NAN.h
- Use GitHub Actions and delete Travis / AppVeyor configuration HOT 2
- Native node module crashes due to ObjectWrap::Unwrap<> returning a different pointer than what was passed to ObjectWrap::Wrap<>
- can this node-gyp warning be dealt with? HOT 3
- Nan is enforcing wrong ~1GB kMaxLength for Nan::NewBuffer, should be 4GB
- v8 Fast Api with NAN
- Breaking code in ViteX Exchange HOT 2
- Can't compile simple program on Windows with Node.js 22 HOT 1
- Error when building NAN modules targeting Electron 31.0.0-beta.8 ('CopyablePersistentTraits': is not a member of 'v8') HOT 3
- Nan with Node 18 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nan.