Skip to content

Commit 4fcfa9d

Browse files
addaleaxjasnell
authored andcommitted
deps: provide more V8 backwards compatibility
Add back a number deprecated APIs, using shims that should work well enough at least for the duration of Node 11 and do not come with significant maintenance overhead. Refs: #23122 PR-URL: #23158 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Yang Guo <yangguo@chromium.org> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent ef85f08 commit 4fcfa9d

File tree

2 files changed

+165
-12
lines changed

2 files changed

+165
-12
lines changed

deps/v8/include/v8.h

+77-12
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,10 @@ class V8_EXPORT PrimitiveArray {
11231123
public:
11241124
static Local<PrimitiveArray> New(Isolate* isolate, int length);
11251125
int Length() const;
1126+
V8_DEPRECATED("Use Isolate* version",
1127+
void Set(int index, Local<Primitive> item));
1128+
V8_DEPRECATED("Use Isolate* version",
1129+
Local<Primitive> Get(int index));
11261130
void Set(Isolate* isolate, int index, Local<Primitive> item);
11271131
Local<Primitive> Get(Isolate* isolate, int index);
11281132
};
@@ -1829,6 +1833,8 @@ class V8_EXPORT StackTrace {
18291833
/**
18301834
* Returns a StackFrame at a particular index.
18311835
*/
1836+
V8_DEPRECATED("Use Isolate version",
1837+
Local<StackFrame> GetFrame(uint32_t index) const);
18321838
Local<StackFrame> GetFrame(Isolate* isolate, uint32_t index) const;
18331839

18341840
/**
@@ -2524,18 +2530,25 @@ class V8_EXPORT Value : public Data {
25242530
Local<Context> context) const;
25252531
V8_WARN_UNUSED_RESULT MaybeLocal<Int32> ToInt32(Local<Context> context) const;
25262532

2527-
V8_DEPRECATE_SOON("Use maybe version",
2528-
Local<Boolean> ToBoolean(Isolate* isolate) const);
2529-
V8_DEPRECATE_SOON("Use maybe version",
2530-
Local<Number> ToNumber(Isolate* isolate) const);
2531-
V8_DEPRECATE_SOON("Use maybe version",
2532-
Local<String> ToString(Isolate* isolate) const);
2533-
V8_DEPRECATE_SOON("Use maybe version",
2534-
Local<Object> ToObject(Isolate* isolate) const);
2535-
V8_DEPRECATE_SOON("Use maybe version",
2536-
Local<Integer> ToInteger(Isolate* isolate) const);
2537-
V8_DEPRECATE_SOON("Use maybe version",
2538-
Local<Int32> ToInt32(Isolate* isolate) const);
2533+
V8_DEPRECATED("Use maybe version",
2534+
Local<Boolean> ToBoolean(Isolate* isolate) const);
2535+
V8_DEPRECATED("Use maybe version",
2536+
Local<Number> ToNumber(Isolate* isolate) const);
2537+
V8_DEPRECATED("Use maybe version",
2538+
Local<String> ToString(Isolate* isolate) const);
2539+
V8_DEPRECATED("Use maybe version",
2540+
Local<Object> ToObject(Isolate* isolate) const);
2541+
V8_DEPRECATED("Use maybe version",
2542+
Local<Integer> ToInteger(Isolate* isolate) const);
2543+
V8_DEPRECATED("Use maybe version",
2544+
Local<Int32> ToInt32(Isolate* isolate) const);
2545+
2546+
inline V8_DEPRECATED("Use maybe version",
2547+
Local<Boolean> ToBoolean() const);
2548+
inline V8_DEPRECATED("Use maybe version", Local<String> ToString() const);
2549+
inline V8_DEPRECATED("Use maybe version", Local<Object> ToObject() const);
2550+
inline V8_DEPRECATED("Use maybe version",
2551+
Local<Integer> ToInteger() const);
25392552

25402553
/**
25412554
* Attempts to convert a string to an array index.
@@ -2552,7 +2565,14 @@ class V8_EXPORT Value : public Data {
25522565
Local<Context> context) const;
25532566
V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
25542567

2568+
V8_DEPRECATED("Use maybe version", bool BooleanValue() const);
2569+
V8_DEPRECATED("Use maybe version", double NumberValue() const);
2570+
V8_DEPRECATED("Use maybe version", int64_t IntegerValue() const);
2571+
V8_DEPRECATED("Use maybe version", uint32_t Uint32Value() const);
2572+
V8_DEPRECATED("Use maybe version", int32_t Int32Value() const);
2573+
25552574
/** JS == */
2575+
V8_DEPRECATED("Use maybe version", bool Equals(Local<Value> that) const);
25562576
V8_WARN_UNUSED_RESULT Maybe<bool> Equals(Local<Context> context,
25572577
Local<Value> that) const;
25582578
bool StrictEquals(Local<Value> that) const;
@@ -2659,6 +2679,8 @@ class V8_EXPORT String : public Name {
26592679
* Returns the number of bytes in the UTF-8 encoded
26602680
* representation of this string.
26612681
*/
2682+
V8_DEPRECATED("Use Isolate version instead", int Utf8Length() const);
2683+
26622684
int Utf8Length(Isolate* isolate) const;
26632685

26642686
/**
@@ -2715,12 +2737,23 @@ class V8_EXPORT String : public Name {
27152737
// 16-bit character codes.
27162738
int Write(Isolate* isolate, uint16_t* buffer, int start = 0, int length = -1,
27172739
int options = NO_OPTIONS) const;
2740+
V8_DEPRECATED("Use Isolate* version",
2741+
int Write(uint16_t* buffer, int start = 0, int length = -1,
2742+
int options = NO_OPTIONS) const);
27182743
// One byte characters.
27192744
int WriteOneByte(Isolate* isolate, uint8_t* buffer, int start = 0,
27202745
int length = -1, int options = NO_OPTIONS) const;
2746+
V8_DEPRECATED("Use Isolate* version",
2747+
int WriteOneByte(uint8_t* buffer, int start = 0,
2748+
int length = -1, int options = NO_OPTIONS)
2749+
const);
27212750
// UTF-8 encoded characters.
27222751
int WriteUtf8(Isolate* isolate, char* buffer, int length = -1,
27232752
int* nchars_ref = NULL, int options = NO_OPTIONS) const;
2753+
V8_DEPRECATED("Use Isolate* version",
2754+
int WriteUtf8(char* buffer, int length = -1,
2755+
int* nchars_ref = NULL,
2756+
int options = NO_OPTIONS) const);
27242757

27252758
/**
27262759
* A zero length string.
@@ -2884,6 +2917,9 @@ class V8_EXPORT String : public Name {
28842917
*/
28852918
static Local<String> Concat(Isolate* isolate, Local<String> left,
28862919
Local<String> right);
2920+
static V8_DEPRECATED("Use Isolate* version",
2921+
Local<String> Concat(Local<String> left,
2922+
Local<String> right));
28872923

28882924
/**
28892925
* Creates a new external string using the data defined in the given
@@ -2952,6 +2988,8 @@ class V8_EXPORT String : public Name {
29522988
*/
29532989
class V8_EXPORT Utf8Value {
29542990
public:
2991+
V8_DEPRECATED("Use Isolate version",
2992+
explicit Utf8Value(Local<v8::Value> obj));
29552993
Utf8Value(Isolate* isolate, Local<v8::Value> obj);
29562994
~Utf8Value();
29572995
char* operator*() { return str_; }
@@ -2975,6 +3013,7 @@ class V8_EXPORT String : public Name {
29753013
*/
29763014
class V8_EXPORT Value {
29773015
public:
3016+
V8_DEPRECATED("Use Isolate version", explicit Value(Local<v8::Value> obj));
29783017
Value(Isolate* isolate, Local<v8::Value> obj);
29793018
~Value();
29803019
uint16_t* operator*() { return str_; }
@@ -5217,6 +5256,8 @@ class V8_EXPORT BooleanObject : public Object {
52175256
class V8_EXPORT StringObject : public Object {
52185257
public:
52195258
static Local<Value> New(Isolate* isolate, Local<String> value);
5259+
V8_DEPRECATED("Use Isolate* version",
5260+
static Local<Value> New(Local<String> value));
52205261

52215262
Local<String> ValueOf() const;
52225263

@@ -10216,6 +10257,30 @@ template <class T> Value* Value::Cast(T* value) {
1021610257
}
1021710258

1021810259

10260+
Local<Boolean> Value::ToBoolean() const {
10261+
return ToBoolean(Isolate::GetCurrent()->GetCurrentContext())
10262+
.FromMaybe(Local<Boolean>());
10263+
}
10264+
10265+
10266+
Local<String> Value::ToString() const {
10267+
return ToString(Isolate::GetCurrent()->GetCurrentContext())
10268+
.FromMaybe(Local<String>());
10269+
}
10270+
10271+
10272+
Local<Object> Value::ToObject() const {
10273+
return ToObject(Isolate::GetCurrent()->GetCurrentContext())
10274+
.FromMaybe(Local<Object>());
10275+
}
10276+
10277+
10278+
Local<Integer> Value::ToInteger() const {
10279+
return ToInteger(Isolate::GetCurrent()->GetCurrentContext())
10280+
.FromMaybe(Local<Integer>());
10281+
}
10282+
10283+
1021910284
Boolean* Boolean::Cast(v8::Value* value) {
1022010285
#ifdef V8_ENABLE_CHECKS
1022110286
CheckCast(value);

deps/v8/src/api.cc

+88
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,10 @@ int PrimitiveArray::Length() const {
21572157
return array->length();
21582158
}
21592159

2160+
void PrimitiveArray::Set(int index, Local<Primitive> item) {
2161+
return Set(Isolate::GetCurrent(), index, item);
2162+
}
2163+
21602164
void PrimitiveArray::Set(Isolate* v8_isolate, int index,
21612165
Local<Primitive> item) {
21622166
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
@@ -2170,6 +2174,10 @@ void PrimitiveArray::Set(Isolate* v8_isolate, int index,
21702174
array->set(index, *i_item);
21712175
}
21722176

2177+
Local<Primitive> PrimitiveArray::Get(int index) {
2178+
return Get(Isolate::GetCurrent(), index);
2179+
}
2180+
21732181
Local<Primitive> PrimitiveArray::Get(Isolate* v8_isolate, int index) {
21742182
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
21752183
i::Handle<i::FixedArray> array = Utils::OpenHandle(this);
@@ -2900,6 +2908,10 @@ void Message::PrintCurrentStackTrace(Isolate* isolate, FILE* out) {
29002908

29012909
// --- S t a c k T r a c e ---
29022910

2911+
Local<StackFrame> StackTrace::GetFrame(uint32_t index) const {
2912+
return GetFrame(Isolate::GetCurrent(), index);
2913+
}
2914+
29032915
Local<StackFrame> StackTrace::GetFrame(Isolate* v8_isolate,
29042916
uint32_t index) const {
29052917
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
@@ -3876,6 +3888,36 @@ void v8::RegExp::CheckCast(v8::Value* that) {
38763888
}
38773889

38783890

3891+
bool Value::BooleanValue() const {
3892+
return BooleanValue(Isolate::GetCurrent()->GetCurrentContext())
3893+
.FromJust();
3894+
}
3895+
3896+
3897+
double Value::NumberValue() const {
3898+
return NumberValue(Isolate::GetCurrent()->GetCurrentContext())
3899+
.FromMaybe(std::numeric_limits<double>::quiet_NaN());
3900+
}
3901+
3902+
3903+
int64_t Value::IntegerValue() const {
3904+
return NumberValue(Isolate::GetCurrent()->GetCurrentContext())
3905+
.FromMaybe(0);
3906+
}
3907+
3908+
3909+
uint32_t Value::Uint32Value() const {
3910+
return Uint32Value(Isolate::GetCurrent()->GetCurrentContext())
3911+
.FromMaybe(0);
3912+
}
3913+
3914+
3915+
int32_t Value::Int32Value() const {
3916+
return Int32Value(Isolate::GetCurrent()->GetCurrentContext())
3917+
.FromMaybe(0);
3918+
}
3919+
3920+
38793921
Maybe<bool> Value::BooleanValue(Local<Context> context) const {
38803922
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
38813923
return Just(Utils::OpenHandle(this)->BooleanValue(isolate));
@@ -3964,6 +4006,12 @@ MaybeLocal<Uint32> Value::ToArrayIndex(Local<Context> context) const {
39644006
}
39654007

39664008

4009+
bool Value::Equals(Local<Value> that) const {
4010+
return Equals(Isolate::GetCurrent()->GetCurrentContext(), that)
4011+
.FromMaybe(false);
4012+
}
4013+
4014+
39674015
Maybe<bool> Value::Equals(Local<Context> context, Local<Value> that) const {
39684016
i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate();
39694017
auto self = Utils::OpenHandle(this);
@@ -5295,6 +5343,10 @@ bool String::ContainsOnlyOneByte() const {
52955343
return helper.Check(*str);
52965344
}
52975345

5346+
int String::Utf8Length() const {
5347+
return Utf8Length(Isolate::GetCurrent());
5348+
}
5349+
52985350
int String::Utf8Length(Isolate* isolate) const {
52995351
i::Handle<i::String> str = Utils::OpenHandle(this);
53005352
str = i::String::Flatten(reinterpret_cast<i::Isolate*>(isolate), str);
@@ -5518,6 +5570,14 @@ static bool RecursivelySerializeToUtf8(i::String* current,
55185570
return true;
55195571
}
55205572

5573+
5574+
int String::WriteUtf8(char* buffer, int capacity,
5575+
int* nchars_ref, int options) const {
5576+
return WriteUtf8(Isolate::GetCurrent(),
5577+
buffer, capacity, nchars_ref, options);
5578+
}
5579+
5580+
55215581
int String::WriteUtf8(Isolate* v8_isolate, char* buffer, int capacity,
55225582
int* nchars_ref, int options) const {
55235583
i::Handle<i::String> str = Utils::OpenHandle(this);
@@ -5585,6 +5645,18 @@ static inline int WriteHelper(i::Isolate* isolate, const String* string,
55855645
}
55865646

55875647

5648+
int String::WriteOneByte(uint8_t* buffer, int start,
5649+
int length, int options) const {
5650+
return WriteOneByte(Isolate::GetCurrent(), buffer, start, length, options);
5651+
}
5652+
5653+
5654+
int String::Write(uint16_t* buffer, int start, int length,
5655+
int options) const {
5656+
return Write(Isolate::GetCurrent(), buffer, start, length, options);
5657+
}
5658+
5659+
55885660
int String::WriteOneByte(Isolate* isolate, uint8_t* buffer, int start,
55895661
int length, int options) const {
55905662
return WriteHelper(reinterpret_cast<i::Isolate*>(isolate), this, buffer,
@@ -6532,6 +6604,11 @@ MaybeLocal<String> String::NewFromTwoByte(Isolate* isolate,
65326604
return result;
65336605
}
65346606

6607+
Local<String> v8::String::Concat(Local<String> left,
6608+
Local<String> right) {
6609+
return Concat(Isolate::GetCurrent(), left, right);
6610+
}
6611+
65356612
Local<String> v8::String::Concat(Isolate* v8_isolate, Local<String> left,
65366613
Local<String> right) {
65376614
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
@@ -6758,6 +6835,11 @@ bool v8::BooleanObject::ValueOf() const {
67586835
}
67596836

67606837

6838+
Local<v8::Value> v8::StringObject::New(Local<String> value) {
6839+
return New(Isolate::GetCurrent(), value);
6840+
}
6841+
6842+
67616843
Local<v8::Value> v8::StringObject::New(Isolate* v8_isolate,
67626844
Local<String> value) {
67636845
i::Handle<i::String> string = Utils::OpenHandle(*value);
@@ -8893,6 +8975,9 @@ bool MicrotasksScope::IsRunningMicrotasks(Isolate* v8Isolate) {
88938975
return isolate->IsRunningMicrotasks();
88948976
}
88958977

8978+
String::Utf8Value::Utf8Value(v8::Local<v8::Value> obj)
8979+
: Utf8Value(Isolate::GetCurrent(), obj) {}
8980+
88968981
String::Utf8Value::Utf8Value(v8::Isolate* isolate, v8::Local<v8::Value> obj)
88978982
: str_(nullptr), length_(0) {
88988983
if (obj.IsEmpty()) return;
@@ -8912,6 +8997,9 @@ String::Utf8Value::~Utf8Value() {
89128997
i::DeleteArray(str_);
89138998
}
89148999

9000+
String::Value::Value(v8::Local<v8::Value> obj)
9001+
: Value(Isolate::GetCurrent(), obj) {}
9002+
89159003
String::Value::Value(v8::Isolate* isolate, v8::Local<v8::Value> obj)
89169004
: str_(nullptr), length_(0) {
89179005
if (obj.IsEmpty()) return;

0 commit comments

Comments
 (0)