-
Notifications
You must be signed in to change notification settings - Fork 30.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src: fix StringBytes::Write() #1042
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f5b7e18
src: remove unused code
bnoordhuis 826cde8
src: fix gc heuristic for external twobyte strings
bnoordhuis 364cc7e
src: remove NODE_INVALID_UTF8 environment variable
bnoordhuis c9ee654
src: simplify node::Utf8Value()
bnoordhuis 4aea16f
src: rename confusingly named local variable
bnoordhuis e2fb733
test: simplify parallel/test-stringbytes-external
bnoordhuis 2eda2d6
src: fix external string length calculation
bnoordhuis 1640ded
src: fix ucs-2 buffer encoding regression
bnoordhuis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,6 @@ | |
|
||
namespace node { | ||
|
||
extern int WRITE_UTF8_FLAGS; | ||
|
||
class StringBytes { | ||
public: | ||
class InlineDecoder { | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,28 @@ | ||
#include "util.h" | ||
|
||
#include "string_bytes.h" | ||
|
||
namespace node { | ||
|
||
Utf8Value::Utf8Value(v8::Isolate* isolate, v8::Handle<v8::Value> value) | ||
: length_(0), str_(nullptr) { | ||
: length_(0), str_(str_st_) { | ||
if (value.IsEmpty()) | ||
return; | ||
|
||
v8::Local<v8::String> val_ = value->ToString(isolate); | ||
if (val_.IsEmpty()) | ||
v8::Local<v8::String> string = value->ToString(isolate); | ||
if (string.IsEmpty()) | ||
return; | ||
|
||
// Allocate enough space to include the null terminator | ||
size_t len = StringBytes::StorageSize(val_, UTF8) + 1; | ||
|
||
char* str; | ||
if (len > kStorageSize) | ||
str = static_cast<char*>(malloc(len)); | ||
else | ||
str = str_st_; | ||
CHECK_NE(str, NULL); | ||
|
||
int flags = WRITE_UTF8_FLAGS; | ||
|
||
length_ = val_->WriteUtf8(str, | ||
len, | ||
0, | ||
flags); | ||
str[length_] = '\0'; | ||
|
||
str_ = reinterpret_cast<char*>(str); | ||
size_t len = StringBytes::StorageSize(string, UTF8) + 1; | ||
if (len > sizeof(str_st_)) { | ||
str_ = static_cast<char*>(malloc(len)); | ||
CHECK_NE(str_, nullptr); | ||
} | ||
|
||
const int flags = | ||
v8::String::NO_NULL_TERMINATION | v8::String::REPLACE_INVALID_UTF8; | ||
length_ = string->WriteUtf8(str_, len, 0, flags); | ||
str_[length_] = '\0'; | ||
} | ||
|
||
} // namespace node |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint didn't catch this before?