Skip to content

Commit 7c84489

Browse files
committed
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 PR-URL: nodejs#22531 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 30c7946 commit 7c84489

File tree

3 files changed

+46
-25
lines changed

3 files changed

+46
-25
lines changed

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

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

3434
# Enable disassembler for `--print-code` v8 options
3535
'v8_enable_disassembler': 1,

deps/v8/include/v8.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,20 +2728,25 @@ class V8_EXPORT String : public Name {
27282728
};
27292729

27302730
// 16-bit character codes.
2731-
int Write(uint16_t* buffer,
2732-
int start = 0,
2733-
int length = -1,
2731+
int Write(Isolate* isolate, uint16_t* buffer, int start = 0, int length = -1,
27342732
int options = NO_OPTIONS) const;
2733+
V8_DEPRECATE_SOON("Use Isolate* version",
2734+
int Write(uint16_t* buffer, int start = 0, int length = -1,
2735+
int options = NO_OPTIONS) const);
27352736
// One byte characters.
2736-
int WriteOneByte(uint8_t* buffer,
2737-
int start = 0,
2738-
int length = -1,
2739-
int options = NO_OPTIONS) const;
2737+
int WriteOneByte(Isolate* isolate, uint8_t* buffer, int start = 0,
2738+
int length = -1, int options = NO_OPTIONS) const;
2739+
V8_DEPRECATE_SOON("Use Isolate* version",
2740+
int WriteOneByte(uint8_t* buffer, int start = 0,
2741+
int length = -1, int options = NO_OPTIONS)
2742+
const);
27402743
// UTF-8 encoded characters.
2741-
int WriteUtf8(char* buffer,
2742-
int length = -1,
2743-
int* nchars_ref = NULL,
2744-
int options = NO_OPTIONS) const;
2744+
int WriteUtf8(Isolate* isolate, char* buffer, int length = -1,
2745+
int* nchars_ref = NULL, int options = NO_OPTIONS) const;
2746+
V8_DEPRECATE_SOON("Use Isolate* version",
2747+
int WriteUtf8(char* buffer, int length = -1,
2748+
int* nchars_ref = NULL,
2749+
int options = NO_OPTIONS) const);
27452750

27462751
/**
27472752
* A zero length string.

deps/v8/src/api.cc

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5710,12 +5710,10 @@ static bool RecursivelySerializeToUtf8(i::String* current,
57105710
}
57115711

57125712

5713-
int String::WriteUtf8(char* buffer,
5714-
int capacity,
5715-
int* nchars_ref,
5716-
int options) const {
5713+
int String::WriteUtf8(Isolate* v8_isolate, char* buffer, int capacity,
5714+
int* nchars_ref, int options) const {
57175715
i::Handle<i::String> str = Utils::OpenHandle(this);
5718-
i::Isolate* isolate = str->GetIsolate();
5716+
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
57195717
LOG_API(isolate, String, WriteUtf8);
57205718
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
57215719
str = i::String::Flatten(str); // Flatten the string for efficiency.
@@ -5756,14 +5754,18 @@ int String::WriteUtf8(char* buffer,
57565754
return writer.CompleteWrite(write_null, nchars_ref);
57575755
}
57585756

5757+
int String::WriteUtf8(char* buffer, int capacity, int* nchars_ref,
5758+
int options) const {
5759+
i::Handle<i::String> str = Utils::OpenHandle(this);
5760+
i::Isolate* isolate = str->GetIsolate();
5761+
return WriteUtf8(reinterpret_cast<Isolate*>(isolate), buffer, capacity,
5762+
nchars_ref, options);
5763+
}
57595764

5760-
template<typename CharType>
5761-
static inline int WriteHelper(const String* string,
5762-
CharType* buffer,
5763-
int start,
5764-
int length,
5765+
template <typename CharType>
5766+
static inline int WriteHelper(i::Isolate* isolate, const String* string,
5767+
CharType* buffer, int start, int length,
57655768
int options) {
5766-
i::Isolate* isolate = Utils::OpenHandle(string)->GetIsolate();
57675769
LOG_API(isolate, String, Write);
57685770
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
57695771
DCHECK(start >= 0 && length >= -1);
@@ -5786,15 +5788,29 @@ int String::WriteOneByte(uint8_t* buffer,
57865788
int start,
57875789
int length,
57885790
int options) const {
5789-
return WriteHelper(this, buffer, start, length, options);
5791+
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
5792+
return WriteHelper(isolate, this, buffer, start, length, options);
5793+
}
5794+
5795+
int String::WriteOneByte(Isolate* isolate, uint8_t* buffer, int start,
5796+
int length, int options) const {
5797+
return WriteHelper(reinterpret_cast<i::Isolate*>(isolate), this, buffer,
5798+
start, length, options);
57905799
}
57915800

57925801

57935802
int String::Write(uint16_t* buffer,
57945803
int start,
57955804
int length,
57965805
int options) const {
5797-
return WriteHelper(this, buffer, start, length, options);
5806+
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
5807+
return WriteHelper(isolate, this, buffer, start, length, options);
5808+
}
5809+
5810+
int String::Write(Isolate* isolate, uint16_t* buffer, int start, int length,
5811+
int options) const {
5812+
return WriteHelper(reinterpret_cast<i::Isolate*>(isolate), this, buffer,
5813+
start, length, options);
57985814
}
57995815

58005816

0 commit comments

Comments
 (0)