@@ -219,6 +219,28 @@ Local<Context> ContextFromNeverReadOnlySpaceObject(
219
219
return reinterpret_cast <v8::Isolate*>(obj->GetIsolate ())->GetCurrentContext ();
220
220
}
221
221
222
+ // TODO(delphick): Remove this completely when the deprecated functions that use
223
+ // it are removed.
224
+ // DO NOT USE THIS IN NEW CODE!
225
+ i::Isolate* UnsafeIsolateFromHeapObject (i::Handle <i::HeapObject> obj) {
226
+ // Use MemoryChunk directly instead of Isolate::FromWritableHeapObject to
227
+ // temporarily allow isolate access from read-only space objects.
228
+ i::MemoryChunk* chunk = i::MemoryChunk::FromHeapObject (*obj);
229
+ return chunk->heap ()->isolate ();
230
+ }
231
+
232
+ // TODO(delphick): Remove this completely when the deprecated functions that use
233
+ // it are removed.
234
+ // DO NOT USE THIS IN NEW CODE!
235
+ Local<Context> UnsafeContextFromHeapObject (i::Handle <i::Object> obj) {
236
+ // Use MemoryChunk directly instead of Isolate::FromWritableHeapObject to
237
+ // temporarily allow isolate access from read-only space objects.
238
+ i::MemoryChunk* chunk =
239
+ i::MemoryChunk::FromHeapObject (i::HeapObject::cast (*obj));
240
+ return reinterpret_cast <Isolate*>(chunk->heap ()->isolate ())
241
+ ->GetCurrentContext ();
242
+ }
243
+
222
244
class InternalEscapableScope : public v8 ::EscapableHandleScope {
223
245
public:
224
246
explicit inline InternalEscapableScope (i::Isolate* isolate)
@@ -2170,6 +2192,12 @@ void PrimitiveArray::Set(Isolate* v8_isolate, int index,
2170
2192
array->set (index , *i_item);
2171
2193
}
2172
2194
2195
+ void PrimitiveArray::Set (int index, Local<Primitive> item) {
2196
+ i::Handle <i::FixedArray> array = Utils::OpenHandle (this );
2197
+ i::Isolate* isolate = UnsafeIsolateFromHeapObject (array);
2198
+ Set (reinterpret_cast <Isolate*>(isolate), index , item);
2199
+ }
2200
+
2173
2201
Local<Primitive> PrimitiveArray::Get (Isolate* v8_isolate, int index) {
2174
2202
i::Isolate* isolate = reinterpret_cast <i::Isolate*>(v8_isolate);
2175
2203
i::Handle <i::FixedArray> array = Utils::OpenHandle (this );
@@ -2182,6 +2210,12 @@ Local<Primitive> PrimitiveArray::Get(Isolate* v8_isolate, int index) {
2182
2210
return ToApiHandle<Primitive>(i_item);
2183
2211
}
2184
2212
2213
+ Local<Primitive> PrimitiveArray::Get (int index) {
2214
+ i::Handle <i::FixedArray> array = Utils::OpenHandle (this );
2215
+ i::Isolate* isolate = UnsafeIsolateFromHeapObject (array);
2216
+ return Get (reinterpret_cast <Isolate*>(isolate), index );
2217
+ }
2218
+
2185
2219
Module::Status Module::GetStatus () const {
2186
2220
i::Handle <i::Module> self = Utils::OpenHandle (this );
2187
2221
switch (self->status ()) {
@@ -2910,6 +2944,11 @@ Local<StackFrame> StackTrace::GetFrame(Isolate* v8_isolate,
2910
2944
return scope.Escape (Utils::StackFrameToLocal (info));
2911
2945
}
2912
2946
2947
+ Local<StackFrame> StackTrace::GetFrame (uint32_t index) const {
2948
+ i::Isolate* isolate = UnsafeIsolateFromHeapObject (Utils::OpenHandle (this ));
2949
+ return GetFrame (reinterpret_cast <Isolate*>(isolate), index );
2950
+ }
2951
+
2913
2952
int StackTrace::GetFrameCount () const {
2914
2953
return Utils::OpenHandle (this )->length ();
2915
2954
}
@@ -3881,6 +3920,14 @@ Maybe<bool> Value::BooleanValue(Local<Context> context) const {
3881
3920
return Just (Utils::OpenHandle (this )->BooleanValue (isolate));
3882
3921
}
3883
3922
3923
+ bool Value::BooleanValue () const {
3924
+ auto obj = Utils::OpenHandle (this );
3925
+ if (obj->IsSmi ()) return *obj != i::Smi::kZero ;
3926
+ DCHECK (obj->IsHeapObject ());
3927
+ i::Isolate* isolate =
3928
+ UnsafeIsolateFromHeapObject (i::Handle <i::HeapObject>::cast (obj));
3929
+ return obj->BooleanValue (isolate);
3930
+ }
3884
3931
3885
3932
Maybe<double > Value::NumberValue (Local<Context> context) const {
3886
3933
auto obj = Utils::OpenHandle (this );
@@ -3894,6 +3941,12 @@ Maybe<double> Value::NumberValue(Local<Context> context) const {
3894
3941
return Just (num->Number ());
3895
3942
}
3896
3943
3944
+ double Value::NumberValue () const {
3945
+ auto obj = Utils::OpenHandle (this );
3946
+ if (obj->IsNumber ()) return obj->Number ();
3947
+ return NumberValue (UnsafeContextFromHeapObject (obj))
3948
+ .FromMaybe (std::numeric_limits<double >::quiet_NaN ());
3949
+ }
3897
3950
3898
3951
Maybe<int64_t > Value::IntegerValue (Local<Context> context) const {
3899
3952
auto obj = Utils::OpenHandle (this );
@@ -3909,6 +3962,17 @@ Maybe<int64_t> Value::IntegerValue(Local<Context> context) const {
3909
3962
return Just (NumberToInt64 (*num));
3910
3963
}
3911
3964
3965
+ int64_t Value::IntegerValue () const {
3966
+ auto obj = Utils::OpenHandle (this );
3967
+ if (obj->IsNumber ()) {
3968
+ if (obj->IsSmi ()) {
3969
+ return i::Smi::ToInt (*obj);
3970
+ } else {
3971
+ return static_cast <int64_t >(obj->Number ());
3972
+ }
3973
+ }
3974
+ return IntegerValue (UnsafeContextFromHeapObject (obj)).FromMaybe (0 );
3975
+ }
3912
3976
3913
3977
Maybe<int32_t > Value::Int32Value (Local<Context> context) const {
3914
3978
auto obj = Utils::OpenHandle (this );
@@ -3923,6 +3987,11 @@ Maybe<int32_t> Value::Int32Value(Local<Context> context) const {
3923
3987
: static_cast <int32_t >(num->Number ()));
3924
3988
}
3925
3989
3990
+ int32_t Value::Int32Value () const {
3991
+ auto obj = Utils::OpenHandle (this );
3992
+ if (obj->IsNumber ()) return NumberToInt32 (*obj);
3993
+ return Int32Value (UnsafeContextFromHeapObject (obj)).FromMaybe (0 );
3994
+ }
3926
3995
3927
3996
Maybe<uint32_t > Value::Uint32Value (Local<Context> context) const {
3928
3997
auto obj = Utils::OpenHandle (this );
@@ -3937,6 +4006,11 @@ Maybe<uint32_t> Value::Uint32Value(Local<Context> context) const {
3937
4006
: static_cast <uint32_t >(num->Number ()));
3938
4007
}
3939
4008
4009
+ uint32_t Value::Uint32Value () const {
4010
+ auto obj = Utils::OpenHandle (this );
4011
+ if (obj->IsNumber ()) return NumberToUint32 (*obj);
4012
+ return Uint32Value (UnsafeContextFromHeapObject (obj)).FromMaybe (0 );
4013
+ }
3940
4014
3941
4015
MaybeLocal<Uint32> Value::ToArrayIndex (Local<Context> context) const {
3942
4016
auto self = Utils::OpenHandle (this );
@@ -3971,6 +4045,19 @@ Maybe<bool> Value::Equals(Local<Context> context, Local<Value> that) const {
3971
4045
return i::Object::Equals (isolate, self, other);
3972
4046
}
3973
4047
4048
+ bool Value::Equals (Local<Value> that) const {
4049
+ auto self = Utils::OpenHandle (this );
4050
+ auto other = Utils::OpenHandle (*that);
4051
+ if (self->IsSmi () && other->IsSmi ()) {
4052
+ return self->Number () == other->Number ();
4053
+ }
4054
+ if (self->IsJSObject () && other->IsJSObject ()) {
4055
+ return *self == *other;
4056
+ }
4057
+ auto heap_object = self->IsSmi () ? other : self;
4058
+ auto context = UnsafeContextFromHeapObject (heap_object);
4059
+ return Equals (context, that).FromMaybe (false );
4060
+ }
3974
4061
3975
4062
bool Value::StrictEquals (Local<Value> that) const {
3976
4063
auto self = Utils::OpenHandle (this );
@@ -5295,6 +5382,11 @@ bool String::ContainsOnlyOneByte() const {
5295
5382
return helper.Check (*str);
5296
5383
}
5297
5384
5385
+ int String::Utf8Length () const {
5386
+ i::Isolate* isolate = UnsafeIsolateFromHeapObject (Utils::OpenHandle (this ));
5387
+ return Utf8Length (reinterpret_cast <Isolate*>(isolate));
5388
+ }
5389
+
5298
5390
int String::Utf8Length (Isolate* isolate) const {
5299
5391
i::Handle <i::String> str = Utils::OpenHandle (this );
5300
5392
str = i::String::Flatten (reinterpret_cast <i::Isolate*>(isolate), str);
@@ -5563,6 +5655,14 @@ int String::WriteUtf8(Isolate* v8_isolate, char* buffer, int capacity,
5563
5655
return writer.CompleteWrite (write_null, nchars_ref);
5564
5656
}
5565
5657
5658
+ int String::WriteUtf8 (char * buffer, int capacity, int * nchars_ref,
5659
+ int options) const {
5660
+ i::Handle <i::String> str = Utils::OpenHandle (this );
5661
+ i::Isolate* isolate = UnsafeIsolateFromHeapObject (str);
5662
+ return WriteUtf8 (reinterpret_cast <Isolate*>(isolate), buffer, capacity,
5663
+ nchars_ref, options);
5664
+ }
5665
+
5566
5666
template <typename CharType>
5567
5667
static inline int WriteHelper (i::Isolate* isolate, const String* string,
5568
5668
CharType* buffer, int start, int length,
@@ -5584,13 +5684,22 @@ static inline int WriteHelper(i::Isolate* isolate, const String* string,
5584
5684
return end - start;
5585
5685
}
5586
5686
5687
+ int String::WriteOneByte (uint8_t * buffer, int start, int length,
5688
+ int options) const {
5689
+ i::Isolate* isolate = UnsafeIsolateFromHeapObject (Utils::OpenHandle (this ));
5690
+ return WriteHelper (isolate, this , buffer, start, length, options);
5691
+ }
5587
5692
5588
5693
int String::WriteOneByte (Isolate* isolate, uint8_t * buffer, int start,
5589
5694
int length, int options) const {
5590
5695
return WriteHelper (reinterpret_cast <i::Isolate*>(isolate), this , buffer,
5591
5696
start, length, options);
5592
5697
}
5593
5698
5699
+ int String::Write (uint16_t * buffer, int start, int length, int options) const {
5700
+ i::Isolate* isolate = UnsafeIsolateFromHeapObject (Utils::OpenHandle (this ));
5701
+ return WriteHelper (isolate, this , buffer, start, length, options);
5702
+ }
5594
5703
5595
5704
int String::Write (Isolate* isolate, uint16_t * buffer, int start, int length,
5596
5705
int options) const {
@@ -6549,6 +6658,12 @@ Local<String> v8::String::Concat(Isolate* v8_isolate, Local<String> left,
6549
6658
return Utils::ToLocal (result);
6550
6659
}
6551
6660
6661
+ Local<String> v8::String::Concat (Local<String> left, Local<String> right) {
6662
+ i::Handle <i::String> left_string = Utils::OpenHandle (*left);
6663
+ i::Isolate* isolate = UnsafeIsolateFromHeapObject (left_string);
6664
+ return Concat (reinterpret_cast <Isolate*>(isolate), left, right);
6665
+ }
6666
+
6552
6667
MaybeLocal<String> v8::String::NewExternalTwoByte (
6553
6668
Isolate* isolate, v8::String::ExternalStringResource* resource) {
6554
6669
CHECK (resource && resource->data ());
@@ -6757,6 +6872,11 @@ bool v8::BooleanObject::ValueOf() const {
6757
6872
return jsvalue->value ()->IsTrue (isolate);
6758
6873
}
6759
6874
6875
+ Local<v8::Value> v8::StringObject::New (Local<String> value) {
6876
+ i::Handle <i::String> string = Utils::OpenHandle (*value);
6877
+ i::Isolate* isolate = UnsafeIsolateFromHeapObject (string);
6878
+ return New (reinterpret_cast <Isolate*>(isolate), value);
6879
+ }
6760
6880
6761
6881
Local<v8::Value> v8::StringObject::New (Isolate* v8_isolate,
6762
6882
Local<String> value) {
0 commit comments