Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
deps: backport String::Write{OneByte,Utf8} with isolate
These overloads were added in V8 6.9 and the ones without the isolate
parameter were removed in V8 7.0.

Refs: v8/v8@8a011b5
  • Loading branch information
targos committed Aug 29, 2018
commit 845bf71993b5962fe0518dc0568fc5a256c5f033
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.20',
'v8_embedder_string': '-node.21',

# Enable disassembler for `--print-code` v8 options
'v8_enable_disassembler': 1,
Expand Down
27 changes: 16 additions & 11 deletions deps/v8/include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -2728,20 +2728,25 @@ class V8_EXPORT String : public Name {
};

// 16-bit character codes.
int Write(uint16_t* buffer,
int start = 0,
int length = -1,
int Write(Isolate* isolate, uint16_t* buffer, int start = 0, int length = -1,
int options = NO_OPTIONS) const;
V8_DEPRECATE_SOON("Use Isolate* version",
int Write(uint16_t* buffer, int start = 0, int length = -1,
int options = NO_OPTIONS) const);
// One byte characters.
int WriteOneByte(uint8_t* buffer,
int start = 0,
int length = -1,
int options = NO_OPTIONS) const;
int WriteOneByte(Isolate* isolate, uint8_t* buffer, int start = 0,
int length = -1, int options = NO_OPTIONS) const;
V8_DEPRECATE_SOON("Use Isolate* version",
int WriteOneByte(uint8_t* buffer, int start = 0,
int length = -1, int options = NO_OPTIONS)
const);
// UTF-8 encoded characters.
int WriteUtf8(char* buffer,
int length = -1,
int* nchars_ref = NULL,
int options = NO_OPTIONS) const;
int WriteUtf8(Isolate* isolate, char* buffer, int length = -1,
int* nchars_ref = NULL, int options = NO_OPTIONS) const;
V8_DEPRECATE_SOON("Use Isolate* version",
int WriteUtf8(char* buffer, int length = -1,
int* nchars_ref = NULL,
int options = NO_OPTIONS) const);

/**
* A zero length string.
Expand Down
42 changes: 29 additions & 13 deletions deps/v8/src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5710,12 +5710,10 @@ static bool RecursivelySerializeToUtf8(i::String* current,
}


int String::WriteUtf8(char* buffer,
int capacity,
int* nchars_ref,
int options) const {
int String::WriteUtf8(Isolate* v8_isolate, char* buffer, int capacity,
int* nchars_ref, int options) const {
i::Handle<i::String> str = Utils::OpenHandle(this);
i::Isolate* isolate = str->GetIsolate();
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
LOG_API(isolate, String, WriteUtf8);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
str = i::String::Flatten(str); // Flatten the string for efficiency.
Expand Down Expand Up @@ -5756,14 +5754,18 @@ int String::WriteUtf8(char* buffer,
return writer.CompleteWrite(write_null, nchars_ref);
}

int String::WriteUtf8(char* buffer, int capacity, int* nchars_ref,
int options) const {
i::Handle<i::String> str = Utils::OpenHandle(this);
i::Isolate* isolate = str->GetIsolate();
return WriteUtf8(reinterpret_cast<Isolate*>(isolate), buffer, capacity,
nchars_ref, options);
}

template<typename CharType>
static inline int WriteHelper(const String* string,
CharType* buffer,
int start,
int length,
template <typename CharType>
static inline int WriteHelper(i::Isolate* isolate, const String* string,
CharType* buffer, int start, int length,
int options) {
i::Isolate* isolate = Utils::OpenHandle(string)->GetIsolate();
LOG_API(isolate, String, Write);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
DCHECK(start >= 0 && length >= -1);
Expand All @@ -5786,15 +5788,29 @@ int String::WriteOneByte(uint8_t* buffer,
int start,
int length,
int options) const {
return WriteHelper(this, buffer, start, length, options);
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
return WriteHelper(isolate, this, buffer, start, length, options);
}

int String::WriteOneByte(Isolate* isolate, uint8_t* buffer, int start,
int length, int options) const {
return WriteHelper(reinterpret_cast<i::Isolate*>(isolate), this, buffer,
start, length, options);
}


int String::Write(uint16_t* buffer,
int start,
int length,
int options) const {
return WriteHelper(this, buffer, start, length, options);
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
return WriteHelper(isolate, this, buffer, start, length, options);
}

int String::Write(Isolate* isolate, uint16_t* buffer, int start, int length,
int options) const {
return WriteHelper(reinterpret_cast<i::Isolate*>(isolate), this, buffer,
start, length, options);
}


Expand Down