-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MERGE #3433 @kunalspathak] Jsrt: Modify signature of JsCopyString
Merge pull request #3433 from pr/kunalspathak/1.7 Modified signature of `JsCopyString` to also return actual count of UTF8 bytes present in jsString. With this information, host can simply allocate a buffer assuming all characters are ascii and based on `writtenLength` and `actualLength` values returned by the API, it can decide if the assumption was correct i.e. `writtenLength == actualLength` or it should take slow path to call `JsCopyString` again by passing bigger buffer equal to size of`actualLength`. Today, if host wants to copy UTF8 representation of javascript string into a buffer, here is how it is done: ```c++ size_t length = 0; JsCopyString(jsString, nullptr, 0, &length); char* buffer = malloc(length); size_t written = 0; JsCopyString(jsString, buffer, length, &written); assert(written == length); ``` can be changed to ```c++ size_t actualLength = 0; size_t writtenLength = 0; size_t strLength = 0; JsStringToPointer(strRef, nullptr, &strLength); char* buffer = malloc(strLength + 1); JsCopyString(jsString, buffer, strLength, &writtenLength, &actualLength); // slow path if jsString contains non-ascii characters if(writtenLength != actualLength) { free(buffer); buffer = malloc(actualLength + 1); JsCopyString(jsString, buffer, actualLength, &writtenLength, &actualLength); } ```
- Loading branch information
Showing
11 changed files
with
71 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters