Skip to content

Commit b383efb

Browse files
addaleaxwuzhiming
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: nodejs/node#23122 PR-URL: nodejs/node#23158 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Yang Guo <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Patch-Filename: deps_provide_more_v8_backwards_compatibility.patch
1 parent c6e3833 commit b383efb

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed

include/v8.h

+65
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,10 @@ class V8_EXPORT PrimitiveArray {
996996
public:
997997
static Local<PrimitiveArray> New(Isolate* isolate, int length);
998998
int Length() const;
999+
V8_DEPRECATED("Use Isolate* version",
1000+
void Set(int index, Local<Primitive> item));
1001+
V8_DEPRECATED("Use Isolate* version",
1002+
Local<Primitive> Get(int index));
9991003
void Set(Isolate* isolate, int index, Local<Primitive> item);
10001004
Local<Primitive> Get(Isolate* isolate, int index);
10011005
};
@@ -1699,6 +1703,8 @@ class V8_EXPORT StackTrace {
16991703
/**
17001704
* Returns a StackFrame at a particular index.
17011705
*/
1706+
V8_DEPRECATED("Use Isolate version",
1707+
Local<StackFrame> GetFrame(uint32_t index) const);
17021708
Local<StackFrame> GetFrame(Isolate* isolate, uint32_t index) const;
17031709

17041710
/**
@@ -2407,6 +2413,13 @@ class V8_EXPORT Value : public Data {
24072413
V8_DEPRECATE_SOON("Use maybe version",
24082414
Local<Int32> ToInt32(Isolate* isolate) const);
24092415

2416+
inline V8_DEPRECATED("Use maybe version",
2417+
Local<Boolean> ToBoolean() const);
2418+
inline V8_DEPRECATED("Use maybe version", Local<String> ToString() const);
2419+
inline V8_DEPRECATED("Use maybe version", Local<Object> ToObject() const);
2420+
inline V8_DEPRECATED("Use maybe version",
2421+
Local<Integer> ToInteger() const);
2422+
24102423
/**
24112424
* Attempts to convert a string to an array index.
24122425
* Returns an empty handle if the conversion fails.
@@ -2426,7 +2439,14 @@ class V8_EXPORT Value : public Data {
24262439
Local<Context> context) const;
24272440
V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
24282441

2442+
V8_DEPRECATED("Use maybe version", bool BooleanValue() const);
2443+
V8_DEPRECATED("Use maybe version", double NumberValue() const);
2444+
V8_DEPRECATED("Use maybe version", int64_t IntegerValue() const);
2445+
V8_DEPRECATED("Use maybe version", uint32_t Uint32Value() const);
2446+
V8_DEPRECATED("Use maybe version", int32_t Int32Value() const);
2447+
24292448
/** JS == */
2449+
V8_DEPRECATED("Use maybe version", bool Equals(Local<Value> that) const);
24302450
V8_WARN_UNUSED_RESULT Maybe<bool> Equals(Local<Context> context,
24312451
Local<Value> that) const;
24322452
bool StrictEquals(Local<Value> that) const;
@@ -2533,6 +2553,8 @@ class V8_EXPORT String : public Name {
25332553
* Returns the number of bytes in the UTF-8 encoded
25342554
* representation of this string.
25352555
*/
2556+
V8_DEPRECATED("Use Isolate version instead", int Utf8Length() const);
2557+
25362558
int Utf8Length(Isolate* isolate) const;
25372559

25382560
/**
@@ -2589,12 +2611,23 @@ class V8_EXPORT String : public Name {
25892611
// 16-bit character codes.
25902612
int Write(Isolate* isolate, uint16_t* buffer, int start = 0, int length = -1,
25912613
int options = NO_OPTIONS) const;
2614+
V8_DEPRECATED("Use Isolate* version",
2615+
int Write(uint16_t* buffer, int start = 0, int length = -1,
2616+
int options = NO_OPTIONS) const);
25922617
// One byte characters.
25932618
int WriteOneByte(Isolate* isolate, uint8_t* buffer, int start = 0,
25942619
int length = -1, int options = NO_OPTIONS) const;
2620+
V8_DEPRECATED("Use Isolate* version",
2621+
int WriteOneByte(uint8_t* buffer, int start = 0,
2622+
int length = -1, int options = NO_OPTIONS)
2623+
const);
25952624
// UTF-8 encoded characters.
25962625
int WriteUtf8(Isolate* isolate, char* buffer, int length = -1,
25972626
int* nchars_ref = nullptr, int options = NO_OPTIONS) const;
2627+
V8_DEPRECATED("Use Isolate* version",
2628+
int WriteUtf8(char* buffer, int length = -1,
2629+
int* nchars_ref = nullptr,
2630+
int options = NO_OPTIONS) const);
25982631

25992632
/**
26002633
* A zero length string.
@@ -2786,6 +2819,9 @@ class V8_EXPORT String : public Name {
27862819
*/
27872820
static Local<String> Concat(Isolate* isolate, Local<String> left,
27882821
Local<String> right);
2822+
static V8_DEPRECATED("Use Isolate* version",
2823+
Local<String> Concat(Local<String> left,
2824+
Local<String> right));
27892825

27902826
/**
27912827
* Creates a new external string using the data defined in the given
@@ -2854,6 +2890,8 @@ class V8_EXPORT String : public Name {
28542890
*/
28552891
class V8_EXPORT Utf8Value {
28562892
public:
2893+
V8_DEPRECATED("Use Isolate version",
2894+
explicit Utf8Value(Local<v8::Value> obj));
28572895
Utf8Value(Isolate* isolate, Local<v8::Value> obj);
28582896
~Utf8Value();
28592897
char* operator*() { return str_; }
@@ -2877,6 +2915,7 @@ class V8_EXPORT String : public Name {
28772915
*/
28782916
class V8_EXPORT Value {
28792917
public:
2918+
V8_DEPRECATED("Use Isolate version", explicit Value(Local<v8::Value> obj));
28802919
Value(Isolate* isolate, Local<v8::Value> obj);
28812920
~Value();
28822921
uint16_t* operator*() { return str_; }
@@ -5271,6 +5310,8 @@ class V8_EXPORT BooleanObject : public Object {
52715310
class V8_EXPORT StringObject : public Object {
52725311
public:
52735312
static Local<Value> New(Isolate* isolate, Local<String> value);
5313+
V8_DEPRECATED("Use Isolate* version",
5314+
static Local<Value> New(Local<String> value));
52745315

52755316
Local<String> ValueOf() const;
52765317

@@ -10127,6 +10168,30 @@ template <class T> Value* Value::Cast(T* value) {
1012710168
}
1012810169

1012910170

10171+
Local<Boolean> Value::ToBoolean() const {
10172+
return ToBoolean(Isolate::GetCurrent()->GetCurrentContext())
10173+
.FromMaybe(Local<Boolean>());
10174+
}
10175+
10176+
10177+
Local<String> Value::ToString() const {
10178+
return ToString(Isolate::GetCurrent()->GetCurrentContext())
10179+
.FromMaybe(Local<String>());
10180+
}
10181+
10182+
10183+
Local<Object> Value::ToObject() const {
10184+
return ToObject(Isolate::GetCurrent()->GetCurrentContext())
10185+
.FromMaybe(Local<Object>());
10186+
}
10187+
10188+
10189+
Local<Integer> Value::ToInteger() const {
10190+
return ToInteger(Isolate::GetCurrent()->GetCurrentContext())
10191+
.FromMaybe(Local<Integer>());
10192+
}
10193+
10194+
1013010195
Boolean* Boolean::Cast(v8::Value* value) {
1013110196
#ifdef V8_ENABLE_CHECKS
1013210197
CheckCast(value);

src/api.cc

+88
Original file line numberDiff line numberDiff line change
@@ -2181,6 +2181,10 @@ int PrimitiveArray::Length() const {
21812181
return array->length();
21822182
}
21832183

2184+
void PrimitiveArray::Set(int index, Local<Primitive> item) {
2185+
return Set(Isolate::GetCurrent(), index, item);
2186+
}
2187+
21842188
void PrimitiveArray::Set(Isolate* v8_isolate, int index,
21852189
Local<Primitive> item) {
21862190
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
@@ -2194,6 +2198,10 @@ void PrimitiveArray::Set(Isolate* v8_isolate, int index,
21942198
array->set(index, *i_item);
21952199
}
21962200

2201+
Local<Primitive> PrimitiveArray::Get(int index) {
2202+
return Get(Isolate::GetCurrent(), index);
2203+
}
2204+
21972205
Local<Primitive> PrimitiveArray::Get(Isolate* v8_isolate, int index) {
21982206
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
21992207
i::Handle<i::FixedArray> array = Utils::OpenHandle(this);
@@ -2899,6 +2907,10 @@ void Message::PrintCurrentStackTrace(Isolate* isolate, FILE* out) {
28992907

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

2910+
Local<StackFrame> StackTrace::GetFrame(uint32_t index) const {
2911+
return GetFrame(Isolate::GetCurrent(), index);
2912+
}
2913+
29022914
Local<StackFrame> StackTrace::GetFrame(Isolate* v8_isolate,
29032915
uint32_t index) const {
29042916
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
@@ -3858,6 +3870,36 @@ void v8::RegExp::CheckCast(v8::Value* that) {
38583870
}
38593871

38603872

3873+
bool Value::BooleanValue() const {
3874+
return BooleanValue(Isolate::GetCurrent()->GetCurrentContext())
3875+
.FromJust();
3876+
}
3877+
3878+
3879+
double Value::NumberValue() const {
3880+
return NumberValue(Isolate::GetCurrent()->GetCurrentContext())
3881+
.FromMaybe(std::numeric_limits<double>::quiet_NaN());
3882+
}
3883+
3884+
3885+
int64_t Value::IntegerValue() const {
3886+
return NumberValue(Isolate::GetCurrent()->GetCurrentContext())
3887+
.FromMaybe(0);
3888+
}
3889+
3890+
3891+
uint32_t Value::Uint32Value() const {
3892+
return Uint32Value(Isolate::GetCurrent()->GetCurrentContext())
3893+
.FromMaybe(0);
3894+
}
3895+
3896+
3897+
int32_t Value::Int32Value() const {
3898+
return Int32Value(Isolate::GetCurrent()->GetCurrentContext())
3899+
.FromMaybe(0);
3900+
}
3901+
3902+
38613903
Maybe<bool> Value::BooleanValue(Local<Context> context) const {
38623904
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
38633905
return Just(Utils::OpenHandle(this)->BooleanValue(isolate));
@@ -3946,6 +3988,12 @@ MaybeLocal<Uint32> Value::ToArrayIndex(Local<Context> context) const {
39463988
}
39473989

39483990

3991+
bool Value::Equals(Local<Value> that) const {
3992+
return Equals(Isolate::GetCurrent()->GetCurrentContext(), that)
3993+
.FromMaybe(false);
3994+
}
3995+
3996+
39493997
Maybe<bool> Value::Equals(Local<Context> context, Local<Value> that) const {
39503998
i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate();
39513999
auto self = Utils::OpenHandle(this);
@@ -5269,6 +5317,10 @@ bool String::ContainsOnlyOneByte() const {
52695317
return helper.Check(*str);
52705318
}
52715319

5320+
int String::Utf8Length() const {
5321+
return Utf8Length(Isolate::GetCurrent());
5322+
}
5323+
52725324
int String::Utf8Length(Isolate* isolate) const {
52735325
i::Handle<i::String> str = Utils::OpenHandle(this);
52745326
str = i::String::Flatten(reinterpret_cast<i::Isolate*>(isolate), str);
@@ -5421,6 +5473,14 @@ static int WriteUtf8Impl(i::Vector<const Char> string, char* write_start,
54215473
}
54225474
} // anonymous namespace
54235475

5476+
5477+
int String::WriteUtf8(char* buffer, int capacity,
5478+
int* nchars_ref, int options) const {
5479+
return WriteUtf8(Isolate::GetCurrent(),
5480+
buffer, capacity, nchars_ref, options);
5481+
}
5482+
5483+
54245484
int String::WriteUtf8(Isolate* v8_isolate, char* buffer, int capacity,
54255485
int* nchars_ref, int options) const {
54265486
i::Handle<i::String> str = Utils::OpenHandle(this);
@@ -5461,6 +5521,18 @@ static inline int WriteHelper(i::Isolate* isolate, const String* string,
54615521
}
54625522

54635523

5524+
int String::WriteOneByte(uint8_t* buffer, int start,
5525+
int length, int options) const {
5526+
return WriteOneByte(Isolate::GetCurrent(), buffer, start, length, options);
5527+
}
5528+
5529+
5530+
int String::Write(uint16_t* buffer, int start, int length,
5531+
int options) const {
5532+
return Write(Isolate::GetCurrent(), buffer, start, length, options);
5533+
}
5534+
5535+
54645536
int String::WriteOneByte(Isolate* isolate, uint8_t* buffer, int start,
54655537
int length, int options) const {
54665538
return WriteHelper(reinterpret_cast<i::Isolate*>(isolate), this, buffer,
@@ -6430,6 +6502,11 @@ MaybeLocal<String> String::NewFromTwoByte(Isolate* isolate,
64306502
return result;
64316503
}
64326504

6505+
Local<String> v8::String::Concat(Local<String> left,
6506+
Local<String> right) {
6507+
return Concat(Isolate::GetCurrent(), left, right);
6508+
}
6509+
64336510
Local<String> v8::String::Concat(Isolate* v8_isolate, Local<String> left,
64346511
Local<String> right) {
64356512
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
@@ -6713,6 +6790,11 @@ bool v8::BooleanObject::ValueOf() const {
67136790
}
67146791

67156792

6793+
Local<v8::Value> v8::StringObject::New(Local<String> value) {
6794+
return New(Isolate::GetCurrent(), value);
6795+
}
6796+
6797+
67166798
Local<v8::Value> v8::StringObject::New(Isolate* v8_isolate,
67176799
Local<String> value) {
67186800
i::Handle<i::String> string = Utils::OpenHandle(*value);
@@ -8925,6 +9007,9 @@ bool MicrotasksScope::IsRunningMicrotasks(Isolate* v8Isolate) {
89259007
return isolate->default_microtask_queue()->IsRunningMicrotasks();
89269008
}
89279009

9010+
String::Utf8Value::Utf8Value(v8::Local<v8::Value> obj)
9011+
: Utf8Value(Isolate::GetCurrent(), obj) {}
9012+
89289013
String::Utf8Value::Utf8Value(v8::Isolate* isolate, v8::Local<v8::Value> obj)
89299014
: str_(nullptr), length_(0) {
89309015
if (obj.IsEmpty()) return;
@@ -8944,6 +9029,9 @@ String::Utf8Value::~Utf8Value() {
89449029
i::DeleteArray(str_);
89459030
}
89469031

9032+
String::Value::Value(v8::Local<v8::Value> obj)
9033+
: Value(Isolate::GetCurrent(), obj) {}
9034+
89479035
String::Value::Value(v8::Isolate* isolate, v8::Local<v8::Value> obj)
89489036
: str_(nullptr), length_(0) {
89499037
if (obj.IsEmpty()) return;

0 commit comments

Comments
 (0)