You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2020/04/14 18:54:56 UTC

[couchdb] branch fix-couchjs-utf8-conversions created (now 0767ebb)

This is an automated email from the ASF dual-hosted git repository.

davisp pushed a change to branch fix-couchjs-utf8-conversions
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


      at 0767ebb  Set UTF-8 encoding when compiling scripts

This branch includes the following new commits:

     new 23529d3  Remove unused string conversion function
     new 79f7b04  Encode strings manually for JavaScript
     new ba27871  Encode JavaScript strings as UTF-8 for printing
     new 0767ebb  Set UTF-8 encoding when compiling scripts

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[couchdb] 01/04: Remove unused string conversion function

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch fix-couchjs-utf8-conversions
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 23529d3b5324e4593630f4c4c69f8ca0e4e7a68c
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue Apr 14 13:21:01 2020 -0500

    Remove unused string conversion function
---
 src/couch/priv/couch_js/60/util.cpp | 13 -------------
 src/couch/priv/couch_js/60/util.h   |  1 -
 2 files changed, 14 deletions(-)

diff --git a/src/couch/priv/couch_js/60/util.cpp b/src/couch/priv/couch_js/60/util.cpp
index 92c6cbf..ad68f26 100644
--- a/src/couch/priv/couch_js/60/util.cpp
+++ b/src/couch/priv/couch_js/60/util.cpp
@@ -37,19 +37,6 @@ js_to_string(JSContext* cx, JS::HandleValue val)
     return chars.get();
 }
 
-std::string
-js_to_string(JSContext* cx, JSString *str)
-{
-    JS::UniqueChars chars(JS_EncodeString(cx, str));
-    if(!chars) {
-        JS_ClearPendingException(cx);
-        fprintf(stderr, "Error converting  to string.\n");
-        exit(3);
-    }
-
-    return chars.get();
-}
-
 JSString*
 string_to_js(JSContext* cx, const std::string& s)
 {
diff --git a/src/couch/priv/couch_js/60/util.h b/src/couch/priv/couch_js/60/util.h
index 407e3e6..0c9f0f8 100644
--- a/src/couch/priv/couch_js/60/util.h
+++ b/src/couch/priv/couch_js/60/util.h
@@ -26,7 +26,6 @@ typedef struct {
 } couch_args;
 
 std::string js_to_string(JSContext* cx, JS::HandleValue val);
-std::string js_to_string(JSContext* cx, JSString *str);
 JSString* string_to_js(JSContext* cx, const std::string& s);
 
 couch_args* couch_parse_args(int argc, const char* argv[]);


[couchdb] 04/04: Set UTF-8 encoding when compiling scripts

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch fix-couchjs-utf8-conversions
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 0767ebbd86991e4aea1ad61b4ef8f5fcaed70869
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue Apr 14 13:39:17 2020 -0500

    Set UTF-8 encoding when compiling scripts
---
 src/couch/priv/couch_js/60/main.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/couch/priv/couch_js/60/main.cpp b/src/couch/priv/couch_js/60/main.cpp
index b6157ed..db2157d 100644
--- a/src/couch/priv/couch_js/60/main.cpp
+++ b/src/couch/priv/couch_js/60/main.cpp
@@ -473,6 +473,7 @@ main(int argc, const char* argv[])
         // Compile and run
         JS::CompileOptions options(cx);
         options.setFileAndLine(args->scripts[i], 1);
+        options.setUTF8(true);
         JS::RootedScript script(cx);
 
         if(!JS_CompileScript(cx, scriptsrc, slen, options, &script)) {


[couchdb] 02/04: Encode strings manually for JavaScript

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch fix-couchjs-utf8-conversions
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 79f7b04a64ab5e765a94311497951ed17b1bc60a
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue Apr 14 13:22:28 2020 -0500

    Encode strings manually for JavaScript
    
    The string creation functions in JavaScript apparently don't handle
    UTF-8 so we need t handle that on our own.
---
 src/couch/priv/couch_js/60/util.cpp | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/src/couch/priv/couch_js/60/util.cpp b/src/couch/priv/couch_js/60/util.cpp
index ad68f26..ae93e09 100644
--- a/src/couch/priv/couch_js/60/util.cpp
+++ b/src/couch/priv/couch_js/60/util.cpp
@@ -40,13 +40,7 @@ js_to_string(JSContext* cx, JS::HandleValue val)
 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;
-    }
-
-    fprintf(stderr, "Unable to allocate string object.\n");
-    exit(3);
+    return dec_string(cx, s.c_str(), s.size());
 }
 
 size_t


[couchdb] 03/04: Encode JavaScript strings as UTF-8 for printing

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch fix-couchjs-utf8-conversions
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit ba278713b87c550abb2a637b1cda645ae9f6fbd2
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue Apr 14 13:23:48 2020 -0500

    Encode JavaScript strings as UTF-8 for printing
---
 src/couch/priv/couch_js/60/util.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/couch/priv/couch_js/60/util.cpp b/src/couch/priv/couch_js/60/util.cpp
index ae93e09..ae0a215 100644
--- a/src/couch/priv/couch_js/60/util.cpp
+++ b/src/couch/priv/couch_js/60/util.cpp
@@ -228,9 +228,8 @@ couch_print(JSContext* cx, unsigned int argc, JS::CallArgs argv)
         if (argc > 1 && argv[1].isTrue()) {
           stream = stderr;
         }
-        JSString* str = JS::ToString(cx, argv.get(0));
-        bytes = reinterpret_cast<uint8_t*>(JS_EncodeString(cx, str));
-        fprintf(stream, "%s", bytes);
+        std::string val = js_to_string(cx, argv.get(0));
+        fprintf(stream, "%s", val.c_str());
         JS_free(cx, bytes);
     }