Skip to content

Commit

Permalink
Put back deleted V8_DEPRECATE_SOON methods
Browse files Browse the repository at this point in the history
This partially reverts
https://chromium-review.googlesource.com/c/v8/v8/+/1177861,
which deleted many V8_DEPRECATE_SOON methods rather than moving them to
V8_DEPRECATED first. This puts them back and marks them V8_DEPRECATED.

Note V8_DEPRECATED that were deleted in the same CL stay deleted.

NOTRY=true
NOPRESUBMIT=true
NOTREECHECKS=true

Bug: v8:7786, v8:8240
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Change-Id: I00330036d957f98dab403465b25e30d8382aac22
Reviewed-on: https://chromium-review.googlesource.com/1251422
Commit-Queue: Dan Elphick <delphick@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Michael Hablich <hablich@chromium.org>
Cr-Commit-Position: refs/branch-heads/7.0@{#49}
Cr-Branched-From: 6e2adae-refs/heads/7.0.276@{#1}
Cr-Branched-From: bc08a86-refs/heads/master@{#55424}
  • Loading branch information
danelphick authored and Commit Bot committed Oct 2, 2018
1 parent 8d4a276 commit 9136dd8
Show file tree
Hide file tree
Showing 2 changed files with 175 additions and 0 deletions.
55 changes: 55 additions & 0 deletions include/v8.h
Expand Up @@ -1125,6 +1125,10 @@ class V8_EXPORT PrimitiveArray {
int Length() const;
void Set(Isolate* isolate, int index, Local<Primitive> item);
Local<Primitive> Get(Isolate* isolate, int index);

V8_DEPRECATED("Use Isolate version",
void Set(int index, Local<Primitive> item));
V8_DEPRECATED("Use Isolate version", Local<Primitive> Get(int index));
};

/**
Expand Down Expand Up @@ -1829,6 +1833,8 @@ class V8_EXPORT StackTrace {
/**
* Returns a StackFrame at a particular index.
*/
V8_DEPRECATED("Use Isolate version",
Local<StackFrame> GetFrame(uint32_t index) const);
Local<StackFrame> GetFrame(Isolate* isolate, uint32_t index) const;

/**
Expand Down Expand Up @@ -2537,6 +2543,11 @@ class V8_EXPORT Value : public Data {
V8_DEPRECATE_SOON("Use maybe version",
Local<Int32> ToInt32(Isolate* isolate) const);

inline V8_DEPRECATED("Use maybe version", Local<Boolean> ToBoolean() const);
inline V8_DEPRECATED("Use maybe version", Local<String> ToString() const);
inline V8_DEPRECATED("Use maybe version", Local<Object> ToObject() const);
inline V8_DEPRECATED("Use maybe version", Local<Integer> ToInteger() const);

/**
* Attempts to convert a string to an array index.
* Returns an empty handle if the conversion fails.
Expand All @@ -2552,7 +2563,14 @@ class V8_EXPORT Value : public Data {
Local<Context> context) const;
V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;

V8_DEPRECATED("Use maybe version", bool BooleanValue() const);
V8_DEPRECATED("Use maybe version", double NumberValue() const);
V8_DEPRECATED("Use maybe version", int64_t IntegerValue() const);
V8_DEPRECATED("Use maybe version", uint32_t Uint32Value() const);
V8_DEPRECATED("Use maybe version", int32_t Int32Value() const);

/** JS == */
V8_DEPRECATED("Use maybe version", bool Equals(Local<Value> that) const);
V8_WARN_UNUSED_RESULT Maybe<bool> Equals(Local<Context> context,
Local<Value> that) const;
bool StrictEquals(Local<Value> that) const;
Expand Down Expand Up @@ -2659,6 +2677,8 @@ class V8_EXPORT String : public Name {
* Returns the number of bytes in the UTF-8 encoded
* representation of this string.
*/
V8_DEPRECATED("Use Isolate version instead", int Utf8Length() const);

int Utf8Length(Isolate* isolate) const;

/**
Expand Down Expand Up @@ -2715,12 +2735,23 @@ class V8_EXPORT String : public Name {
// 16-bit character codes.
int Write(Isolate* isolate, uint16_t* buffer, int start = 0, int length = -1,
int options = NO_OPTIONS) const;
V8_DEPRECATED("Use Isolate* version",
int Write(uint16_t* buffer, int start = 0, int length = -1,
int options = NO_OPTIONS) const);
// One byte characters.
int WriteOneByte(Isolate* isolate, uint8_t* buffer, int start = 0,
int length = -1, int options = NO_OPTIONS) const;
V8_DEPRECATED("Use Isolate* version",
int WriteOneByte(uint8_t* buffer, int start = 0,
int length = -1, int options = NO_OPTIONS)
const);
// UTF-8 encoded characters.
int WriteUtf8(Isolate* isolate, char* buffer, int length = -1,
int* nchars_ref = NULL, int options = NO_OPTIONS) const;
V8_DEPRECATED("Use Isolate* version",
int WriteUtf8(char* buffer, int length = -1,
int* nchars_ref = NULL, int options = NO_OPTIONS)
const);

/**
* A zero length string.
Expand Down Expand Up @@ -2884,6 +2915,9 @@ class V8_EXPORT String : public Name {
*/
static Local<String> Concat(Isolate* isolate, Local<String> left,
Local<String> right);
static V8_DEPRECATED("Use Isolate* version",
Local<String> Concat(Local<String> left,
Local<String> right));

/**
* Creates a new external string using the data defined in the given
Expand Down Expand Up @@ -5217,6 +5251,8 @@ class V8_EXPORT BooleanObject : public Object {
class V8_EXPORT StringObject : public Object {
public:
static Local<Value> New(Isolate* isolate, Local<String> value);
static V8_DEPRECATED("Use Isolate* version",
Local<Value> New(Local<String> value));

Local<String> ValueOf() const;

Expand Down Expand Up @@ -10215,6 +10251,25 @@ template <class T> Value* Value::Cast(T* value) {
return static_cast<Value*>(value);
}

Local<Boolean> Value::ToBoolean() const {
return ToBoolean(Isolate::GetCurrent()->GetCurrentContext())
.FromMaybe(Local<Boolean>());
}

Local<String> Value::ToString() const {
return ToString(Isolate::GetCurrent()->GetCurrentContext())
.FromMaybe(Local<String>());
}

Local<Object> Value::ToObject() const {
return ToObject(Isolate::GetCurrent()->GetCurrentContext())
.FromMaybe(Local<Object>());
}

Local<Integer> Value::ToInteger() const {
return ToInteger(Isolate::GetCurrent()->GetCurrentContext())
.FromMaybe(Local<Integer>());
}

Boolean* Boolean::Cast(v8::Value* value) {
#ifdef V8_ENABLE_CHECKS
Expand Down
120 changes: 120 additions & 0 deletions src/api.cc
Expand Up @@ -219,6 +219,28 @@ Local<Context> ContextFromNeverReadOnlySpaceObject(
return reinterpret_cast<v8::Isolate*>(obj->GetIsolate())->GetCurrentContext();
}

// TODO(delphick): Remove this completely when the deprecated functions that use
// it are removed.
// DO NOT USE THIS IN NEW CODE!
i::Isolate* UnsafeIsolateFromHeapObject(i::Handle<i::HeapObject> obj) {
// Use MemoryChunk directly instead of Isolate::FromWritableHeapObject to
// temporarily allow isolate access from read-only space objects.
i::MemoryChunk* chunk = i::MemoryChunk::FromHeapObject(*obj);
return chunk->heap()->isolate();
}

// TODO(delphick): Remove this completely when the deprecated functions that use
// it are removed.
// DO NOT USE THIS IN NEW CODE!
Local<Context> UnsafeContextFromHeapObject(i::Handle<i::Object> obj) {
// Use MemoryChunk directly instead of Isolate::FromWritableHeapObject to
// temporarily allow isolate access from read-only space objects.
i::MemoryChunk* chunk =
i::MemoryChunk::FromHeapObject(i::HeapObject::cast(*obj));
return reinterpret_cast<Isolate*>(chunk->heap()->isolate())
->GetCurrentContext();
}

class InternalEscapableScope : public v8::EscapableHandleScope {
public:
explicit inline InternalEscapableScope(i::Isolate* isolate)
Expand Down Expand Up @@ -2170,6 +2192,12 @@ void PrimitiveArray::Set(Isolate* v8_isolate, int index,
array->set(index, *i_item);
}

void PrimitiveArray::Set(int index, Local<Primitive> item) {
i::Handle<i::FixedArray> array = Utils::OpenHandle(this);
i::Isolate* isolate = UnsafeIsolateFromHeapObject(array);
Set(reinterpret_cast<Isolate*>(isolate), index, item);
}

Local<Primitive> PrimitiveArray::Get(Isolate* v8_isolate, int index) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
i::Handle<i::FixedArray> array = Utils::OpenHandle(this);
Expand All @@ -2182,6 +2210,12 @@ Local<Primitive> PrimitiveArray::Get(Isolate* v8_isolate, int index) {
return ToApiHandle<Primitive>(i_item);
}

Local<Primitive> PrimitiveArray::Get(int index) {
i::Handle<i::FixedArray> array = Utils::OpenHandle(this);
i::Isolate* isolate = UnsafeIsolateFromHeapObject(array);
return Get(reinterpret_cast<Isolate*>(isolate), index);
}

Module::Status Module::GetStatus() const {
i::Handle<i::Module> self = Utils::OpenHandle(this);
switch (self->status()) {
Expand Down Expand Up @@ -2910,6 +2944,11 @@ Local<StackFrame> StackTrace::GetFrame(Isolate* v8_isolate,
return scope.Escape(Utils::StackFrameToLocal(info));
}

Local<StackFrame> StackTrace::GetFrame(uint32_t index) const {
i::Isolate* isolate = UnsafeIsolateFromHeapObject(Utils::OpenHandle(this));
return GetFrame(reinterpret_cast<Isolate*>(isolate), index);
}

int StackTrace::GetFrameCount() const {
return Utils::OpenHandle(this)->length();
}
Expand Down Expand Up @@ -3881,6 +3920,14 @@ Maybe<bool> Value::BooleanValue(Local<Context> context) const {
return Just(Utils::OpenHandle(this)->BooleanValue(isolate));
}

bool Value::BooleanValue() const {
auto obj = Utils::OpenHandle(this);
if (obj->IsSmi()) return *obj != i::Smi::kZero;
DCHECK(obj->IsHeapObject());
i::Isolate* isolate =
UnsafeIsolateFromHeapObject(i::Handle<i::HeapObject>::cast(obj));
return obj->BooleanValue(isolate);
}

Maybe<double> Value::NumberValue(Local<Context> context) const {
auto obj = Utils::OpenHandle(this);
Expand All @@ -3894,6 +3941,12 @@ Maybe<double> Value::NumberValue(Local<Context> context) const {
return Just(num->Number());
}

double Value::NumberValue() const {
auto obj = Utils::OpenHandle(this);
if (obj->IsNumber()) return obj->Number();
return NumberValue(UnsafeContextFromHeapObject(obj))
.FromMaybe(std::numeric_limits<double>::quiet_NaN());
}

Maybe<int64_t> Value::IntegerValue(Local<Context> context) const {
auto obj = Utils::OpenHandle(this);
Expand All @@ -3909,6 +3962,17 @@ Maybe<int64_t> Value::IntegerValue(Local<Context> context) const {
return Just(NumberToInt64(*num));
}

int64_t Value::IntegerValue() const {
auto obj = Utils::OpenHandle(this);
if (obj->IsNumber()) {
if (obj->IsSmi()) {
return i::Smi::ToInt(*obj);
} else {
return static_cast<int64_t>(obj->Number());
}
}
return IntegerValue(UnsafeContextFromHeapObject(obj)).FromMaybe(0);
}

Maybe<int32_t> Value::Int32Value(Local<Context> context) const {
auto obj = Utils::OpenHandle(this);
Expand All @@ -3923,6 +3987,11 @@ Maybe<int32_t> Value::Int32Value(Local<Context> context) const {
: static_cast<int32_t>(num->Number()));
}

int32_t Value::Int32Value() const {
auto obj = Utils::OpenHandle(this);
if (obj->IsNumber()) return NumberToInt32(*obj);
return Int32Value(UnsafeContextFromHeapObject(obj)).FromMaybe(0);
}

Maybe<uint32_t> Value::Uint32Value(Local<Context> context) const {
auto obj = Utils::OpenHandle(this);
Expand All @@ -3937,6 +4006,11 @@ Maybe<uint32_t> Value::Uint32Value(Local<Context> context) const {
: static_cast<uint32_t>(num->Number()));
}

uint32_t Value::Uint32Value() const {
auto obj = Utils::OpenHandle(this);
if (obj->IsNumber()) return NumberToUint32(*obj);
return Uint32Value(UnsafeContextFromHeapObject(obj)).FromMaybe(0);
}

MaybeLocal<Uint32> Value::ToArrayIndex(Local<Context> context) const {
auto self = Utils::OpenHandle(this);
Expand Down Expand Up @@ -3971,6 +4045,19 @@ Maybe<bool> Value::Equals(Local<Context> context, Local<Value> that) const {
return i::Object::Equals(isolate, self, other);
}

bool Value::Equals(Local<Value> that) const {
auto self = Utils::OpenHandle(this);
auto other = Utils::OpenHandle(*that);
if (self->IsSmi() && other->IsSmi()) {
return self->Number() == other->Number();
}
if (self->IsJSObject() && other->IsJSObject()) {
return *self == *other;
}
auto heap_object = self->IsSmi() ? other : self;
auto context = UnsafeContextFromHeapObject(heap_object);
return Equals(context, that).FromMaybe(false);
}

bool Value::StrictEquals(Local<Value> that) const {
auto self = Utils::OpenHandle(this);
Expand Down Expand Up @@ -5295,6 +5382,11 @@ bool String::ContainsOnlyOneByte() const {
return helper.Check(*str);
}

int String::Utf8Length() const {
i::Isolate* isolate = UnsafeIsolateFromHeapObject(Utils::OpenHandle(this));
return Utf8Length(reinterpret_cast<Isolate*>(isolate));
}

int String::Utf8Length(Isolate* isolate) const {
i::Handle<i::String> str = Utils::OpenHandle(this);
str = i::String::Flatten(reinterpret_cast<i::Isolate*>(isolate), str);
Expand Down Expand Up @@ -5563,6 +5655,14 @@ int String::WriteUtf8(Isolate* v8_isolate, char* buffer, int capacity,
return writer.CompleteWrite(write_null, nchars_ref);
}

int String::WriteUtf8(char* buffer, int capacity, int* nchars_ref,
int options) const {
i::Handle<i::String> str = Utils::OpenHandle(this);
i::Isolate* isolate = UnsafeIsolateFromHeapObject(str);
return WriteUtf8(reinterpret_cast<Isolate*>(isolate), buffer, capacity,
nchars_ref, options);
}

template <typename CharType>
static inline int WriteHelper(i::Isolate* isolate, const String* string,
CharType* buffer, int start, int length,
Expand All @@ -5584,13 +5684,22 @@ static inline int WriteHelper(i::Isolate* isolate, const String* string,
return end - start;
}

int String::WriteOneByte(uint8_t* buffer, int start, int length,
int options) const {
i::Isolate* isolate = UnsafeIsolateFromHeapObject(Utils::OpenHandle(this));
return WriteHelper(isolate, this, buffer, start, length, options);
}

int String::WriteOneByte(Isolate* isolate, uint8_t* buffer, int start,
int length, int options) const {
return WriteHelper(reinterpret_cast<i::Isolate*>(isolate), this, buffer,
start, length, options);
}

int String::Write(uint16_t* buffer, int start, int length, int options) const {
i::Isolate* isolate = UnsafeIsolateFromHeapObject(Utils::OpenHandle(this));
return WriteHelper(isolate, this, buffer, start, length, options);
}

int String::Write(Isolate* isolate, uint16_t* buffer, int start, int length,
int options) const {
Expand Down Expand Up @@ -6549,6 +6658,12 @@ Local<String> v8::String::Concat(Isolate* v8_isolate, Local<String> left,
return Utils::ToLocal(result);
}

Local<String> v8::String::Concat(Local<String> left, Local<String> right) {
i::Handle<i::String> left_string = Utils::OpenHandle(*left);
i::Isolate* isolate = UnsafeIsolateFromHeapObject(left_string);
return Concat(reinterpret_cast<Isolate*>(isolate), left, right);
}

MaybeLocal<String> v8::String::NewExternalTwoByte(
Isolate* isolate, v8::String::ExternalStringResource* resource) {
CHECK(resource && resource->data());
Expand Down Expand Up @@ -6757,6 +6872,11 @@ bool v8::BooleanObject::ValueOf() const {
return jsvalue->value()->IsTrue(isolate);
}

Local<v8::Value> v8::StringObject::New(Local<String> value) {
i::Handle<i::String> string = Utils::OpenHandle(*value);
i::Isolate* isolate = UnsafeIsolateFromHeapObject(string);
return New(reinterpret_cast<Isolate*>(isolate), value);
}

Local<v8::Value> v8::StringObject::New(Isolate* v8_isolate,
Local<String> value) {
Expand Down

0 comments on commit 9136dd8

Please sign in to comment.