@@ -219,6 +219,28 @@ Local<Context> ContextFromNeverReadOnlySpaceObject(
219219 return reinterpret_cast <v8::Isolate*>(obj->GetIsolate ())->GetCurrentContext ();
220220}
221221
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+
222244class InternalEscapableScope : public v8 ::EscapableHandleScope {
223245 public:
224246 explicit inline InternalEscapableScope (i::Isolate* isolate)
@@ -2170,6 +2192,12 @@ void PrimitiveArray::Set(Isolate* v8_isolate, int index,
21702192 array->set (index, *i_item);
21712193}
21722194
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+
21732201Local<Primitive> PrimitiveArray::Get (Isolate* v8_isolate, int index) {
21742202 i::Isolate* isolate = reinterpret_cast <i::Isolate*>(v8_isolate);
21752203 i::Handle<i::FixedArray> array = Utils::OpenHandle (this );
@@ -2182,6 +2210,12 @@ Local<Primitive> PrimitiveArray::Get(Isolate* v8_isolate, int index) {
21822210 return ToApiHandle<Primitive>(i_item);
21832211}
21842212
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+
21852219Module::Status Module::GetStatus () const {
21862220 i::Handle<i::Module> self = Utils::OpenHandle (this );
21872221 switch (self->status ()) {
@@ -2910,6 +2944,11 @@ Local<StackFrame> StackTrace::GetFrame(Isolate* v8_isolate,
29102944 return scope.Escape (Utils::StackFrameToLocal (info));
29112945}
29122946
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+
29132952int StackTrace::GetFrameCount () const {
29142953 return Utils::OpenHandle (this )->length ();
29152954}
@@ -3881,6 +3920,14 @@ Maybe<bool> Value::BooleanValue(Local<Context> context) const {
38813920 return Just (Utils::OpenHandle (this )->BooleanValue (isolate));
38823921}
38833922
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+ }
38843931
38853932Maybe<double > Value::NumberValue (Local<Context> context) const {
38863933 auto obj = Utils::OpenHandle (this );
@@ -3894,6 +3941,12 @@ Maybe<double> Value::NumberValue(Local<Context> context) const {
38943941 return Just (num->Number ());
38953942}
38963943
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+ }
38973950
38983951Maybe<int64_t > Value::IntegerValue (Local<Context> context) const {
38993952 auto obj = Utils::OpenHandle (this );
@@ -3909,6 +3962,17 @@ Maybe<int64_t> Value::IntegerValue(Local<Context> context) const {
39093962 return Just (NumberToInt64 (*num));
39103963}
39113964
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+ }
39123976
39133977Maybe<int32_t > Value::Int32Value (Local<Context> context) const {
39143978 auto obj = Utils::OpenHandle (this );
@@ -3923,6 +3987,11 @@ Maybe<int32_t> Value::Int32Value(Local<Context> context) const {
39233987 : static_cast <int32_t >(num->Number ()));
39243988}
39253989
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+ }
39263995
39273996Maybe<uint32_t > Value::Uint32Value (Local<Context> context) const {
39283997 auto obj = Utils::OpenHandle (this );
@@ -3937,6 +4006,11 @@ Maybe<uint32_t> Value::Uint32Value(Local<Context> context) const {
39374006 : static_cast <uint32_t >(num->Number ()));
39384007}
39394008
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+ }
39404014
39414015MaybeLocal<Uint32> Value::ToArrayIndex (Local<Context> context) const {
39424016 auto self = Utils::OpenHandle (this );
@@ -3971,6 +4045,19 @@ Maybe<bool> Value::Equals(Local<Context> context, Local<Value> that) const {
39714045 return i::Object::Equals (isolate, self, other);
39724046}
39734047
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+ }
39744061
39754062bool Value::StrictEquals (Local<Value> that) const {
39764063 auto self = Utils::OpenHandle (this );
@@ -5295,6 +5382,11 @@ bool String::ContainsOnlyOneByte() const {
52955382 return helper.Check (*str);
52965383}
52975384
5385+ int String::Utf8Length () const {
5386+ i::Isolate* isolate = UnsafeIsolateFromHeapObject (Utils::OpenHandle (this ));
5387+ return Utf8Length (reinterpret_cast <Isolate*>(isolate));
5388+ }
5389+
52985390int String::Utf8Length (Isolate* isolate) const {
52995391 i::Handle<i::String> str = Utils::OpenHandle (this );
53005392 str = i::String::Flatten (reinterpret_cast <i::Isolate*>(isolate), str);
@@ -5563,6 +5655,14 @@ int String::WriteUtf8(Isolate* v8_isolate, char* buffer, int capacity,
55635655 return writer.CompleteWrite (write_null, nchars_ref);
55645656}
55655657
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+
55665666template <typename CharType>
55675667static inline int WriteHelper (i::Isolate* isolate, const String* string,
55685668 CharType* buffer, int start, int length,
@@ -5584,13 +5684,22 @@ static inline int WriteHelper(i::Isolate* isolate, const String* string,
55845684 return end - start;
55855685}
55865686
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+ }
55875692
55885693int String::WriteOneByte (Isolate* isolate, uint8_t * buffer, int start,
55895694 int length, int options) const {
55905695 return WriteHelper (reinterpret_cast <i::Isolate*>(isolate), this , buffer,
55915696 start, length, options);
55925697}
55935698
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+ }
55945703
55955704int String::Write (Isolate* isolate, uint16_t * buffer, int start, int length,
55965705 int options) const {
@@ -6549,6 +6658,12 @@ Local<String> v8::String::Concat(Isolate* v8_isolate, Local<String> left,
65496658 return Utils::ToLocal (result);
65506659}
65516660
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+
65526667MaybeLocal<String> v8::String::NewExternalTwoByte (
65536668 Isolate* isolate, v8::String::ExternalStringResource* resource) {
65546669 CHECK (resource && resource->data ());
@@ -6757,6 +6872,11 @@ bool v8::BooleanObject::ValueOf() const {
67576872 return jsvalue->value ()->IsTrue (isolate);
67586873}
67596874
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+ }
67606880
67616881Local<v8::Value> v8::StringObject::New (Isolate* v8_isolate,
67626882 Local<String> value) {
0 commit comments