You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2020/04/15 21:31:28 UTC
[GitHub] [couchdb] davisp commented on a change in pull request #2786: Fix
couchjs utf8 conversions
davisp commented on a change in pull request #2786: Fix couchjs utf8 conversions
URL: https://github.com/apache/couchdb/pull/2786#discussion_r409145941
##########
File path: src/couch/priv/couch_js/60/util.cpp
##########
@@ -30,36 +32,32 @@ js_to_string(JSContext* cx, JS::HandleValue val)
JS::UniqueChars chars(JS_EncodeStringToUTF8(cx, sval));
if(!chars) {
JS_ClearPendingException(cx);
- fprintf(stderr, "Error converting value to string.\n");
- exit(3);
+ return std::string();
}
return chars.get();
}
-std::string
-js_to_string(JSContext* cx, JSString *str)
+JSString*
+string_to_js(JSContext* cx, const std::string& raw)
{
- JS::UniqueChars chars(JS_EncodeString(cx, str));
- if(!chars) {
- JS_ClearPendingException(cx);
- fprintf(stderr, "Error converting to string.\n");
- exit(3);
+ JS::UTF8Chars utf8(raw.c_str(), raw.size());
+ JS::UniqueTwoByteChars utf16;
+ size_t len;
+
+ utf16.reset(JS::UTF8CharsToNewTwoByteCharsZ(cx, utf8, &len).get());
+ if(!utf16) {
+ return nullptr;
}
- return chars.get();
-}
+ JSString* ret = JS_NewUCString(cx, utf16.get(), len);
-JSString*
-string_to_js(JSContext* cx, const std::string& s)
-{
- JSString* ret = JS_NewStringCopyN(cx, s.c_str(), s.size());
- if(ret != nullptr) {
- return ret;
+ if(ret) {
+ // JS_NewUCString took ownership on succses
+ mozilla::Unused << utf16.release();
Review comment:
double free in CI output with this? Or from the other thing we talked about?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services