Skip to content

Commit

Permalink
deps: backport String::Write{OneByte,Utf8} with isolate
Browse files Browse the repository at this point in the history
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

PR-URL: #22531
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Daniel Bevenius <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
targos committed Sep 3, 2018
1 parent 9478f29 commit d50e1ff
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 25 deletions.
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 @@ -2634,20 +2634,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 @@ -5702,12 +5702,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 @@ -5748,14 +5746,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 @@ -5778,15 +5780,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

0 comments on commit d50e1ff

Please sign in to comment.