Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: provide more V8 backwards compatibility #23158

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps/v8/include/v8-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define V8_MAJOR_VERSION 7
#define V8_MINOR_VERSION 0
#define V8_BUILD_NUMBER 276
#define V8_PATCH_LEVEL 22
#define V8_PATCH_LEVEL 24

// Use 1 for candidates and 0 otherwise.
// (Boolean macro values are not supported by all preprocessors.)
Expand Down
89 changes: 77 additions & 12 deletions deps/v8/include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,10 @@ class V8_EXPORT PrimitiveArray {
public:
static Local<PrimitiveArray> New(Isolate* isolate, int length);
int Length() const;
V8_DEPRECATED("Use Isolate* version",
void Set(int index, Local<Primitive> item));
V8_DEPRECATED("Use Isolate* version",
Local<Primitive> Get(int index));
void Set(Isolate* isolate, int index, Local<Primitive> item);
Local<Primitive> Get(Isolate* isolate, 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 @@ -2524,18 +2530,25 @@ class V8_EXPORT Value : public Data {
Local<Context> context) const;
V8_WARN_UNUSED_RESULT MaybeLocal<Int32> ToInt32(Local<Context> context) const;

V8_DEPRECATE_SOON("Use maybe version",
Local<Boolean> ToBoolean(Isolate* isolate) const);
V8_DEPRECATE_SOON("Use maybe version",
Local<Number> ToNumber(Isolate* isolate) const);
V8_DEPRECATE_SOON("Use maybe version",
Local<String> ToString(Isolate* isolate) const);
V8_DEPRECATE_SOON("Use maybe version",
Local<Object> ToObject(Isolate* isolate) const);
V8_DEPRECATE_SOON("Use maybe version",
Local<Integer> ToInteger(Isolate* isolate) const);
V8_DEPRECATE_SOON("Use maybe version",
Local<Int32> ToInt32(Isolate* isolate) const);
V8_DEPRECATED("Use maybe version",
Local<Boolean> ToBoolean(Isolate* isolate) const);
V8_DEPRECATED("Use maybe version",
Local<Number> ToNumber(Isolate* isolate) const);
V8_DEPRECATED("Use maybe version",
Local<String> ToString(Isolate* isolate) const);
V8_DEPRECATED("Use maybe version",
Local<Object> ToObject(Isolate* isolate) const);
V8_DEPRECATED("Use maybe version",
Local<Integer> ToInteger(Isolate* isolate) const);
V8_DEPRECATED("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.
Expand All @@ -2552,7 +2565,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 +2679,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 +2737,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 +2917,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 @@ -2952,6 +2988,8 @@ class V8_EXPORT String : public Name {
*/
class V8_EXPORT Utf8Value {
public:
V8_DEPRECATED("Use Isolate version",
explicit Utf8Value(Local<v8::Value> obj));
Utf8Value(Isolate* isolate, Local<v8::Value> obj);
~Utf8Value();
char* operator*() { return str_; }
Expand All @@ -2975,6 +3013,7 @@ class V8_EXPORT String : public Name {
*/
class V8_EXPORT Value {
public:
V8_DEPRECATED("Use Isolate version", explicit Value(Local<v8::Value> obj));
Value(Isolate* isolate, Local<v8::Value> obj);
~Value();
uint16_t* operator*() { return str_; }
Expand Down Expand Up @@ -5217,6 +5256,8 @@ class V8_EXPORT BooleanObject : public Object {
class V8_EXPORT StringObject : public Object {
public:
static Local<Value> New(Isolate* isolate, Local<String> value);
V8_DEPRECATED("Use Isolate* version",
static Local<Value> New(Local<String> value));

Local<String> ValueOf() const;

Expand Down Expand Up @@ -10216,6 +10257,30 @@ template <class T> Value* Value::Cast(T* 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
CheckCast(value);
Expand Down
88 changes: 88 additions & 0 deletions deps/v8/src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2157,6 +2157,10 @@ int PrimitiveArray::Length() const {
return array->length();
}

void PrimitiveArray::Set(int index, Local<Primitive> item) {
return Set(Isolate::GetCurrent(), index, item);
}

void PrimitiveArray::Set(Isolate* v8_isolate, int index,
Local<Primitive> item) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
Expand All @@ -2170,6 +2174,10 @@ void PrimitiveArray::Set(Isolate* v8_isolate, int index,
array->set(index, *i_item);
}

Local<Primitive> PrimitiveArray::Get(int index) {
return Get(Isolate::GetCurrent(), index);
}

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 Down Expand Up @@ -2900,6 +2908,10 @@ void Message::PrintCurrentStackTrace(Isolate* isolate, FILE* out) {

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

Local<StackFrame> StackTrace::GetFrame(uint32_t index) const {
return GetFrame(Isolate::GetCurrent(), index);
}

Local<StackFrame> StackTrace::GetFrame(Isolate* v8_isolate,
uint32_t index) const {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
Expand Down Expand Up @@ -3876,6 +3888,36 @@ void v8::RegExp::CheckCast(v8::Value* that) {
}


bool Value::BooleanValue() const {
return BooleanValue(Isolate::GetCurrent()->GetCurrentContext())
.FromJust();
}


double Value::NumberValue() const {
return NumberValue(Isolate::GetCurrent()->GetCurrentContext())
.FromMaybe(std::numeric_limits<double>::quiet_NaN());
}


int64_t Value::IntegerValue() const {
return NumberValue(Isolate::GetCurrent()->GetCurrentContext())
.FromMaybe(0);
}


uint32_t Value::Uint32Value() const {
return Uint32Value(Isolate::GetCurrent()->GetCurrentContext())
.FromMaybe(0);
}


int32_t Value::Int32Value() const {
return Int32Value(Isolate::GetCurrent()->GetCurrentContext())
.FromMaybe(0);
}


Maybe<bool> Value::BooleanValue(Local<Context> context) const {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
return Just(Utils::OpenHandle(this)->BooleanValue(isolate));
Expand Down Expand Up @@ -3964,6 +4006,12 @@ MaybeLocal<Uint32> Value::ToArrayIndex(Local<Context> context) const {
}


bool Value::Equals(Local<Value> that) const {
return Equals(Isolate::GetCurrent()->GetCurrentContext(), that)
.FromMaybe(false);
}


Maybe<bool> Value::Equals(Local<Context> context, Local<Value> that) const {
i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate();
auto self = Utils::OpenHandle(this);
Expand Down Expand Up @@ -5295,6 +5343,10 @@ bool String::ContainsOnlyOneByte() const {
return helper.Check(*str);
}

int String::Utf8Length() const {
return Utf8Length(Isolate::GetCurrent());
}

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 @@ -5518,6 +5570,14 @@ static bool RecursivelySerializeToUtf8(i::String* current,
return true;
}


int String::WriteUtf8(char* buffer, int capacity,
int* nchars_ref, int options) const {
return WriteUtf8(Isolate::GetCurrent(),
buffer, capacity, nchars_ref, options);
}


int String::WriteUtf8(Isolate* v8_isolate, char* buffer, int capacity,
int* nchars_ref, int options) const {
i::Handle<i::String> str = Utils::OpenHandle(this);
Expand Down Expand Up @@ -5585,6 +5645,18 @@ static inline int WriteHelper(i::Isolate* isolate, const String* string,
}


int String::WriteOneByte(uint8_t* buffer, int start,
int length, int options) const {
return WriteOneByte(Isolate::GetCurrent(), buffer, start, length, options);
}


int String::Write(uint16_t* buffer, int start, int length,
int options) const {
return Write(Isolate::GetCurrent(), 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,
Expand Down Expand Up @@ -6532,6 +6604,11 @@ MaybeLocal<String> String::NewFromTwoByte(Isolate* isolate,
return result;
}

Local<String> v8::String::Concat(Local<String> left,
Local<String> right) {
return Concat(Isolate::GetCurrent(), left, right);
}

Local<String> v8::String::Concat(Isolate* v8_isolate, Local<String> left,
Local<String> right) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
Expand Down Expand Up @@ -6758,6 +6835,11 @@ bool v8::BooleanObject::ValueOf() const {
}


Local<v8::Value> v8::StringObject::New(Local<String> value) {
return New(Isolate::GetCurrent(), value);
}


Local<v8::Value> v8::StringObject::New(Isolate* v8_isolate,
Local<String> value) {
i::Handle<i::String> string = Utils::OpenHandle(*value);
Expand Down Expand Up @@ -8893,6 +8975,9 @@ bool MicrotasksScope::IsRunningMicrotasks(Isolate* v8Isolate) {
return isolate->IsRunningMicrotasks();
}

String::Utf8Value::Utf8Value(v8::Local<v8::Value> obj)
: Utf8Value(Isolate::GetCurrent(), obj) {}

String::Utf8Value::Utf8Value(v8::Isolate* isolate, v8::Local<v8::Value> obj)
: str_(nullptr), length_(0) {
if (obj.IsEmpty()) return;
Expand All @@ -8912,6 +8997,9 @@ String::Utf8Value::~Utf8Value() {
i::DeleteArray(str_);
}

String::Value::Value(v8::Local<v8::Value> obj)
: Value(Isolate::GetCurrent(), obj) {}

String::Value::Value(v8::Isolate* isolate, v8::Local<v8::Value> obj)
: str_(nullptr), length_(0) {
if (obj.IsEmpty()) return;
Expand Down
6 changes: 5 additions & 1 deletion deps/v8/src/wasm/module-compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2203,6 +2203,11 @@ std::shared_ptr<StreamingDecoder> AsyncCompileJob::CreateStreamingDecoder() {
AsyncCompileJob::~AsyncCompileJob() {
background_task_manager_.CancelAndWait();
if (native_module_) native_module_->compilation_state()->Abort();
// Tell the streaming decoder that the AsyncCompileJob is not available
// anymore.
// TODO(ahaas): Is this notification really necessary? Check
// https://crbug.com/888170.
if (stream_) stream_->NotifyCompilationEnded();
CancelPendingForegroundTask();
for (auto d : deferred_handles_) delete d;
}
Expand All @@ -2228,7 +2233,6 @@ void AsyncCompileJob::FinishCompile() {
}

void AsyncCompileJob::AsyncCompileFailed(Handle<Object> error_reason) {
if (stream_) stream_->NotifyError();
// {job} keeps the {this} pointer alive.
std::shared_ptr<AsyncCompileJob> job =
isolate_->wasm_engine()->RemoveCompileJob(this);
Expand Down
9 changes: 7 additions & 2 deletions deps/v8/src/wasm/streaming-decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ class V8_EXPORT_PRIVATE StreamingDecoder {

void Abort();

// Notify the StreamingDecoder that there has been an compilation error.
void NotifyError() { ok_ = false; }
// Notify the StreamingDecoder that compilation ended and the
// StreamingProcessor should not be called anymore.
void NotifyCompilationEnded() {
// We set {ok_} to false to turn all future calls to the StreamingDecoder
// into no-ops.
ok_ = false;
}

private:
// TODO(ahaas): Put the whole private state of the StreamingDecoder into the
Expand Down