From 3e3204ffe5a46682598e6a0f1867573210fda379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Tue, 2 Oct 2018 11:09:02 +0200 Subject: [PATCH 1/4] deps: patch V8 to 7.0.276.24 Refs: https://github.com/v8/v8/compare/7.0.276.22...7.0.276.24 --- deps/v8/include/v8-version.h | 2 +- deps/v8/include/v8.h | 55 ++++++++++++ deps/v8/src/api.cc | 120 +++++++++++++++++++++++++++ deps/v8/src/wasm/module-compiler.cc | 6 +- deps/v8/src/wasm/streaming-decoder.h | 9 +- 5 files changed, 188 insertions(+), 4 deletions(-) diff --git a/deps/v8/include/v8-version.h b/deps/v8/include/v8-version.h index a93cd9be0c6bed..06038eca3bd523 100644 --- a/deps/v8/include/v8-version.h +++ b/deps/v8/include/v8-version.h @@ -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.) diff --git a/deps/v8/include/v8.h b/deps/v8/include/v8.h index 63edc67edfd95f..a83305560c2ea3 100644 --- a/deps/v8/include/v8.h +++ b/deps/v8/include/v8.h @@ -1125,6 +1125,10 @@ class V8_EXPORT PrimitiveArray { int Length() const; void Set(Isolate* isolate, int index, Local item); Local Get(Isolate* isolate, int index); + + V8_DEPRECATED("Use Isolate version", + void Set(int index, Local item)); + V8_DEPRECATED("Use Isolate version", Local Get(int index)); }; /** @@ -1829,6 +1833,8 @@ class V8_EXPORT StackTrace { /** * Returns a StackFrame at a particular index. */ + V8_DEPRECATED("Use Isolate version", + Local GetFrame(uint32_t index) const); Local GetFrame(Isolate* isolate, uint32_t index) const; /** @@ -2537,6 +2543,11 @@ class V8_EXPORT Value : public Data { V8_DEPRECATE_SOON("Use maybe version", Local ToInt32(Isolate* isolate) const); + inline V8_DEPRECATED("Use maybe version", Local ToBoolean() const); + inline V8_DEPRECATED("Use maybe version", Local ToString() const); + inline V8_DEPRECATED("Use maybe version", Local ToObject() const); + inline V8_DEPRECATED("Use maybe version", Local ToInteger() const); + /** * Attempts to convert a string to an array index. * Returns an empty handle if the conversion fails. @@ -2552,7 +2563,14 @@ class V8_EXPORT Value : public Data { Local context) const; V8_WARN_UNUSED_RESULT Maybe Int32Value(Local 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 that) const); V8_WARN_UNUSED_RESULT Maybe Equals(Local context, Local that) const; bool StrictEquals(Local that) const; @@ -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; /** @@ -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. @@ -2884,6 +2915,9 @@ class V8_EXPORT String : public Name { */ static Local Concat(Isolate* isolate, Local left, Local right); + static V8_DEPRECATED("Use Isolate* version", + Local Concat(Local left, + Local right)); /** * Creates a new external string using the data defined in the given @@ -5217,6 +5251,8 @@ class V8_EXPORT BooleanObject : public Object { class V8_EXPORT StringObject : public Object { public: static Local New(Isolate* isolate, Local value); + static V8_DEPRECATED("Use Isolate* version", + Local New(Local value)); Local ValueOf() const; @@ -10215,6 +10251,25 @@ template Value* Value::Cast(T* value) { return static_cast(value); } +Local Value::ToBoolean() const { + return ToBoolean(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local()); +} + +Local Value::ToString() const { + return ToString(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local()); +} + +Local Value::ToObject() const { + return ToObject(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local()); +} + +Local Value::ToInteger() const { + return ToInteger(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local()); +} Boolean* Boolean::Cast(v8::Value* value) { #ifdef V8_ENABLE_CHECKS diff --git a/deps/v8/src/api.cc b/deps/v8/src/api.cc index d141496c5749cc..4eb31a447c3d2d 100644 --- a/deps/v8/src/api.cc +++ b/deps/v8/src/api.cc @@ -219,6 +219,28 @@ Local ContextFromNeverReadOnlySpaceObject( return reinterpret_cast(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 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 UnsafeContextFromHeapObject(i::Handle 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(chunk->heap()->isolate()) + ->GetCurrentContext(); +} + class InternalEscapableScope : public v8::EscapableHandleScope { public: explicit inline InternalEscapableScope(i::Isolate* isolate) @@ -2170,6 +2192,12 @@ void PrimitiveArray::Set(Isolate* v8_isolate, int index, array->set(index, *i_item); } +void PrimitiveArray::Set(int index, Local item) { + i::Handle array = Utils::OpenHandle(this); + i::Isolate* isolate = UnsafeIsolateFromHeapObject(array); + Set(reinterpret_cast(isolate), index, item); +} + Local PrimitiveArray::Get(Isolate* v8_isolate, int index) { i::Isolate* isolate = reinterpret_cast(v8_isolate); i::Handle array = Utils::OpenHandle(this); @@ -2182,6 +2210,12 @@ Local PrimitiveArray::Get(Isolate* v8_isolate, int index) { return ToApiHandle(i_item); } +Local PrimitiveArray::Get(int index) { + i::Handle array = Utils::OpenHandle(this); + i::Isolate* isolate = UnsafeIsolateFromHeapObject(array); + return Get(reinterpret_cast(isolate), index); +} + Module::Status Module::GetStatus() const { i::Handle self = Utils::OpenHandle(this); switch (self->status()) { @@ -2910,6 +2944,11 @@ Local StackTrace::GetFrame(Isolate* v8_isolate, return scope.Escape(Utils::StackFrameToLocal(info)); } +Local StackTrace::GetFrame(uint32_t index) const { + i::Isolate* isolate = UnsafeIsolateFromHeapObject(Utils::OpenHandle(this)); + return GetFrame(reinterpret_cast(isolate), index); +} + int StackTrace::GetFrameCount() const { return Utils::OpenHandle(this)->length(); } @@ -3881,6 +3920,14 @@ Maybe Value::BooleanValue(Local 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::cast(obj)); + return obj->BooleanValue(isolate); +} Maybe Value::NumberValue(Local context) const { auto obj = Utils::OpenHandle(this); @@ -3894,6 +3941,12 @@ Maybe Value::NumberValue(Local 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::quiet_NaN()); +} Maybe Value::IntegerValue(Local context) const { auto obj = Utils::OpenHandle(this); @@ -3909,6 +3962,17 @@ Maybe Value::IntegerValue(Local 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(obj->Number()); + } + } + return IntegerValue(UnsafeContextFromHeapObject(obj)).FromMaybe(0); +} Maybe Value::Int32Value(Local context) const { auto obj = Utils::OpenHandle(this); @@ -3923,6 +3987,11 @@ Maybe Value::Int32Value(Local context) const { : static_cast(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 Value::Uint32Value(Local context) const { auto obj = Utils::OpenHandle(this); @@ -3937,6 +4006,11 @@ Maybe Value::Uint32Value(Local context) const { : static_cast(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 Value::ToArrayIndex(Local context) const { auto self = Utils::OpenHandle(this); @@ -3971,6 +4045,19 @@ Maybe Value::Equals(Local context, Local that) const { return i::Object::Equals(isolate, self, other); } +bool Value::Equals(Local 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 that) const { auto self = Utils::OpenHandle(this); @@ -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)); +} + int String::Utf8Length(Isolate* isolate) const { i::Handle str = Utils::OpenHandle(this); str = i::String::Flatten(reinterpret_cast(isolate), str); @@ -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 str = Utils::OpenHandle(this); + i::Isolate* isolate = UnsafeIsolateFromHeapObject(str); + return WriteUtf8(reinterpret_cast(isolate), buffer, capacity, + nchars_ref, options); +} + template static inline int WriteHelper(i::Isolate* isolate, const String* string, CharType* buffer, int start, int length, @@ -5584,6 +5684,11 @@ 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 { @@ -5591,6 +5696,10 @@ int String::WriteOneByte(Isolate* isolate, uint8_t* buffer, int start, 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 { @@ -6549,6 +6658,12 @@ Local v8::String::Concat(Isolate* v8_isolate, Local left, return Utils::ToLocal(result); } +Local v8::String::Concat(Local left, Local right) { + i::Handle left_string = Utils::OpenHandle(*left); + i::Isolate* isolate = UnsafeIsolateFromHeapObject(left_string); + return Concat(reinterpret_cast(isolate), left, right); +} + MaybeLocal v8::String::NewExternalTwoByte( Isolate* isolate, v8::String::ExternalStringResource* resource) { CHECK(resource && resource->data()); @@ -6757,6 +6872,11 @@ bool v8::BooleanObject::ValueOf() const { return jsvalue->value()->IsTrue(isolate); } +Local v8::StringObject::New(Local value) { + i::Handle string = Utils::OpenHandle(*value); + i::Isolate* isolate = UnsafeIsolateFromHeapObject(string); + return New(reinterpret_cast(isolate), value); +} Local v8::StringObject::New(Isolate* v8_isolate, Local value) { diff --git a/deps/v8/src/wasm/module-compiler.cc b/deps/v8/src/wasm/module-compiler.cc index b143b631a1f945..b950c590b5c6b2 100644 --- a/deps/v8/src/wasm/module-compiler.cc +++ b/deps/v8/src/wasm/module-compiler.cc @@ -2203,6 +2203,11 @@ std::shared_ptr 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; } @@ -2228,7 +2233,6 @@ void AsyncCompileJob::FinishCompile() { } void AsyncCompileJob::AsyncCompileFailed(Handle error_reason) { - if (stream_) stream_->NotifyError(); // {job} keeps the {this} pointer alive. std::shared_ptr job = isolate_->wasm_engine()->RemoveCompileJob(this); diff --git a/deps/v8/src/wasm/streaming-decoder.h b/deps/v8/src/wasm/streaming-decoder.h index 7b986bc28b0be3..e14c32daf3925d 100644 --- a/deps/v8/src/wasm/streaming-decoder.h +++ b/deps/v8/src/wasm/streaming-decoder.h @@ -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 From a0fb22141a64644cb43b611b3acbc803ee3126e3 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 4 Oct 2018 14:38:59 -0700 Subject: [PATCH 2/4] deps: revert 9136dd8088a9 from upstream V8 Reverting this enables us to provide slower, but longer-lasting replacements for the deprecated APIs. Original commit message: Put back deleted V8_DEPRECATE_SOON methods 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 Reviewed-by: Yang Guo Reviewed-by: Michael Hablich Cr-Commit-Position: refs/branch-heads/7.0@{#49} Cr-Branched-From: 6e2adae6f7f8e891cfd01f3280482b20590427a6-refs/heads/7.0.276@{#1} Cr-Branched-From: bc08a8624cbbea7a2d30071472bc73ad9544eadf-refs/heads/master@{#55424} Refs: https://github.com/v8/v8/commit/9136dd8088a95484b059a0301b25235510fc2882 Refs: https://github.com/nodejs/node/issues/23122 --- deps/v8/include/v8.h | 55 -------------------- deps/v8/src/api.cc | 120 ------------------------------------------- 2 files changed, 175 deletions(-) diff --git a/deps/v8/include/v8.h b/deps/v8/include/v8.h index a83305560c2ea3..63edc67edfd95f 100644 --- a/deps/v8/include/v8.h +++ b/deps/v8/include/v8.h @@ -1125,10 +1125,6 @@ class V8_EXPORT PrimitiveArray { int Length() const; void Set(Isolate* isolate, int index, Local item); Local Get(Isolate* isolate, int index); - - V8_DEPRECATED("Use Isolate version", - void Set(int index, Local item)); - V8_DEPRECATED("Use Isolate version", Local Get(int index)); }; /** @@ -1833,8 +1829,6 @@ class V8_EXPORT StackTrace { /** * Returns a StackFrame at a particular index. */ - V8_DEPRECATED("Use Isolate version", - Local GetFrame(uint32_t index) const); Local GetFrame(Isolate* isolate, uint32_t index) const; /** @@ -2543,11 +2537,6 @@ class V8_EXPORT Value : public Data { V8_DEPRECATE_SOON("Use maybe version", Local ToInt32(Isolate* isolate) const); - inline V8_DEPRECATED("Use maybe version", Local ToBoolean() const); - inline V8_DEPRECATED("Use maybe version", Local ToString() const); - inline V8_DEPRECATED("Use maybe version", Local ToObject() const); - inline V8_DEPRECATED("Use maybe version", Local ToInteger() const); - /** * Attempts to convert a string to an array index. * Returns an empty handle if the conversion fails. @@ -2563,14 +2552,7 @@ class V8_EXPORT Value : public Data { Local context) const; V8_WARN_UNUSED_RESULT Maybe Int32Value(Local 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 that) const); V8_WARN_UNUSED_RESULT Maybe Equals(Local context, Local that) const; bool StrictEquals(Local that) const; @@ -2677,8 +2659,6 @@ 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; /** @@ -2735,23 +2715,12 @@ 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. @@ -2915,9 +2884,6 @@ class V8_EXPORT String : public Name { */ static Local Concat(Isolate* isolate, Local left, Local right); - static V8_DEPRECATED("Use Isolate* version", - Local Concat(Local left, - Local right)); /** * Creates a new external string using the data defined in the given @@ -5251,8 +5217,6 @@ class V8_EXPORT BooleanObject : public Object { class V8_EXPORT StringObject : public Object { public: static Local New(Isolate* isolate, Local value); - static V8_DEPRECATED("Use Isolate* version", - Local New(Local value)); Local ValueOf() const; @@ -10251,25 +10215,6 @@ template Value* Value::Cast(T* value) { return static_cast(value); } -Local Value::ToBoolean() const { - return ToBoolean(Isolate::GetCurrent()->GetCurrentContext()) - .FromMaybe(Local()); -} - -Local Value::ToString() const { - return ToString(Isolate::GetCurrent()->GetCurrentContext()) - .FromMaybe(Local()); -} - -Local Value::ToObject() const { - return ToObject(Isolate::GetCurrent()->GetCurrentContext()) - .FromMaybe(Local()); -} - -Local Value::ToInteger() const { - return ToInteger(Isolate::GetCurrent()->GetCurrentContext()) - .FromMaybe(Local()); -} Boolean* Boolean::Cast(v8::Value* value) { #ifdef V8_ENABLE_CHECKS diff --git a/deps/v8/src/api.cc b/deps/v8/src/api.cc index 4eb31a447c3d2d..d141496c5749cc 100644 --- a/deps/v8/src/api.cc +++ b/deps/v8/src/api.cc @@ -219,28 +219,6 @@ Local ContextFromNeverReadOnlySpaceObject( return reinterpret_cast(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 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 UnsafeContextFromHeapObject(i::Handle 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(chunk->heap()->isolate()) - ->GetCurrentContext(); -} - class InternalEscapableScope : public v8::EscapableHandleScope { public: explicit inline InternalEscapableScope(i::Isolate* isolate) @@ -2192,12 +2170,6 @@ void PrimitiveArray::Set(Isolate* v8_isolate, int index, array->set(index, *i_item); } -void PrimitiveArray::Set(int index, Local item) { - i::Handle array = Utils::OpenHandle(this); - i::Isolate* isolate = UnsafeIsolateFromHeapObject(array); - Set(reinterpret_cast(isolate), index, item); -} - Local PrimitiveArray::Get(Isolate* v8_isolate, int index) { i::Isolate* isolate = reinterpret_cast(v8_isolate); i::Handle array = Utils::OpenHandle(this); @@ -2210,12 +2182,6 @@ Local PrimitiveArray::Get(Isolate* v8_isolate, int index) { return ToApiHandle(i_item); } -Local PrimitiveArray::Get(int index) { - i::Handle array = Utils::OpenHandle(this); - i::Isolate* isolate = UnsafeIsolateFromHeapObject(array); - return Get(reinterpret_cast(isolate), index); -} - Module::Status Module::GetStatus() const { i::Handle self = Utils::OpenHandle(this); switch (self->status()) { @@ -2944,11 +2910,6 @@ Local StackTrace::GetFrame(Isolate* v8_isolate, return scope.Escape(Utils::StackFrameToLocal(info)); } -Local StackTrace::GetFrame(uint32_t index) const { - i::Isolate* isolate = UnsafeIsolateFromHeapObject(Utils::OpenHandle(this)); - return GetFrame(reinterpret_cast(isolate), index); -} - int StackTrace::GetFrameCount() const { return Utils::OpenHandle(this)->length(); } @@ -3920,14 +3881,6 @@ Maybe Value::BooleanValue(Local 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::cast(obj)); - return obj->BooleanValue(isolate); -} Maybe Value::NumberValue(Local context) const { auto obj = Utils::OpenHandle(this); @@ -3941,12 +3894,6 @@ Maybe Value::NumberValue(Local 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::quiet_NaN()); -} Maybe Value::IntegerValue(Local context) const { auto obj = Utils::OpenHandle(this); @@ -3962,17 +3909,6 @@ Maybe Value::IntegerValue(Local 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(obj->Number()); - } - } - return IntegerValue(UnsafeContextFromHeapObject(obj)).FromMaybe(0); -} Maybe Value::Int32Value(Local context) const { auto obj = Utils::OpenHandle(this); @@ -3987,11 +3923,6 @@ Maybe Value::Int32Value(Local context) const { : static_cast(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 Value::Uint32Value(Local context) const { auto obj = Utils::OpenHandle(this); @@ -4006,11 +3937,6 @@ Maybe Value::Uint32Value(Local context) const { : static_cast(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 Value::ToArrayIndex(Local context) const { auto self = Utils::OpenHandle(this); @@ -4045,19 +3971,6 @@ Maybe Value::Equals(Local context, Local that) const { return i::Object::Equals(isolate, self, other); } -bool Value::Equals(Local 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 that) const { auto self = Utils::OpenHandle(this); @@ -5382,11 +5295,6 @@ bool String::ContainsOnlyOneByte() const { return helper.Check(*str); } -int String::Utf8Length() const { - i::Isolate* isolate = UnsafeIsolateFromHeapObject(Utils::OpenHandle(this)); - return Utf8Length(reinterpret_cast(isolate)); -} - int String::Utf8Length(Isolate* isolate) const { i::Handle str = Utils::OpenHandle(this); str = i::String::Flatten(reinterpret_cast(isolate), str); @@ -5655,14 +5563,6 @@ 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 str = Utils::OpenHandle(this); - i::Isolate* isolate = UnsafeIsolateFromHeapObject(str); - return WriteUtf8(reinterpret_cast(isolate), buffer, capacity, - nchars_ref, options); -} - template static inline int WriteHelper(i::Isolate* isolate, const String* string, CharType* buffer, int start, int length, @@ -5684,11 +5584,6 @@ 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 { @@ -5696,10 +5591,6 @@ int String::WriteOneByte(Isolate* isolate, uint8_t* buffer, int start, 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 { @@ -6658,12 +6549,6 @@ Local v8::String::Concat(Isolate* v8_isolate, Local left, return Utils::ToLocal(result); } -Local v8::String::Concat(Local left, Local right) { - i::Handle left_string = Utils::OpenHandle(*left); - i::Isolate* isolate = UnsafeIsolateFromHeapObject(left_string); - return Concat(reinterpret_cast(isolate), left, right); -} - MaybeLocal v8::String::NewExternalTwoByte( Isolate* isolate, v8::String::ExternalStringResource* resource) { CHECK(resource && resource->data()); @@ -6872,11 +6757,6 @@ bool v8::BooleanObject::ValueOf() const { return jsvalue->value()->IsTrue(isolate); } -Local v8::StringObject::New(Local value) { - i::Handle string = Utils::OpenHandle(*value); - i::Isolate* isolate = UnsafeIsolateFromHeapObject(string); - return New(reinterpret_cast(isolate), value); -} Local v8::StringObject::New(Isolate* v8_isolate, Local value) { From 7a0dd5bded8db524cdca84d4842c943bc68f1ce9 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 28 Sep 2018 22:43:38 -0400 Subject: [PATCH 3/4] 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: https://github.com/nodejs/node/issues/23122 --- deps/v8/include/v8.h | 89 ++++++++++++++++++++++++++++++++++++++------ deps/v8/src/api.cc | 88 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+), 12 deletions(-) diff --git a/deps/v8/include/v8.h b/deps/v8/include/v8.h index 63edc67edfd95f..4a104e57d873b9 100644 --- a/deps/v8/include/v8.h +++ b/deps/v8/include/v8.h @@ -1123,6 +1123,10 @@ class V8_EXPORT PrimitiveArray { public: static Local New(Isolate* isolate, int length); int Length() const; + V8_DEPRECATED("Use Isolate* version", + void Set(int index, Local item)); + V8_DEPRECATED("Use Isolate* version", + Local Get(int index)); void Set(Isolate* isolate, int index, Local item); Local Get(Isolate* isolate, int index); }; @@ -1829,6 +1833,8 @@ class V8_EXPORT StackTrace { /** * Returns a StackFrame at a particular index. */ + V8_DEPRECATED("Use Isolate version", + Local GetFrame(uint32_t index) const); Local GetFrame(Isolate* isolate, uint32_t index) const; /** @@ -2524,18 +2530,25 @@ class V8_EXPORT Value : public Data { Local context) const; V8_WARN_UNUSED_RESULT MaybeLocal ToInt32(Local context) const; - V8_DEPRECATE_SOON("Use maybe version", - Local ToBoolean(Isolate* isolate) const); - V8_DEPRECATE_SOON("Use maybe version", - Local ToNumber(Isolate* isolate) const); - V8_DEPRECATE_SOON("Use maybe version", - Local ToString(Isolate* isolate) const); - V8_DEPRECATE_SOON("Use maybe version", - Local ToObject(Isolate* isolate) const); - V8_DEPRECATE_SOON("Use maybe version", - Local ToInteger(Isolate* isolate) const); - V8_DEPRECATE_SOON("Use maybe version", - Local ToInt32(Isolate* isolate) const); + V8_DEPRECATED("Use maybe version", + Local ToBoolean(Isolate* isolate) const); + V8_DEPRECATED("Use maybe version", + Local ToNumber(Isolate* isolate) const); + V8_DEPRECATED("Use maybe version", + Local ToString(Isolate* isolate) const); + V8_DEPRECATED("Use maybe version", + Local ToObject(Isolate* isolate) const); + V8_DEPRECATED("Use maybe version", + Local ToInteger(Isolate* isolate) const); + V8_DEPRECATED("Use maybe version", + Local ToInt32(Isolate* isolate) const); + + inline V8_DEPRECATED("Use maybe version", + Local ToBoolean() const); + inline V8_DEPRECATED("Use maybe version", Local ToString() const); + inline V8_DEPRECATED("Use maybe version", Local ToObject() const); + inline V8_DEPRECATED("Use maybe version", + Local ToInteger() const); /** * Attempts to convert a string to an array index. @@ -2552,7 +2565,14 @@ class V8_EXPORT Value : public Data { Local context) const; V8_WARN_UNUSED_RESULT Maybe Int32Value(Local 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 that) const); V8_WARN_UNUSED_RESULT Maybe Equals(Local context, Local that) const; bool StrictEquals(Local that) const; @@ -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; /** @@ -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. @@ -2884,6 +2917,9 @@ class V8_EXPORT String : public Name { */ static Local Concat(Isolate* isolate, Local left, Local right); + static V8_DEPRECATED("Use Isolate* version", + Local Concat(Local left, + Local right)); /** * Creates a new external string using the data defined in the given @@ -2952,6 +2988,8 @@ class V8_EXPORT String : public Name { */ class V8_EXPORT Utf8Value { public: + V8_DEPRECATED("Use Isolate version", + explicit Utf8Value(Local obj)); Utf8Value(Isolate* isolate, Local obj); ~Utf8Value(); char* operator*() { return str_; } @@ -2975,6 +3013,7 @@ class V8_EXPORT String : public Name { */ class V8_EXPORT Value { public: + V8_DEPRECATED("Use Isolate version", explicit Value(Local obj)); Value(Isolate* isolate, Local obj); ~Value(); uint16_t* operator*() { return str_; } @@ -5217,6 +5256,8 @@ class V8_EXPORT BooleanObject : public Object { class V8_EXPORT StringObject : public Object { public: static Local New(Isolate* isolate, Local value); + V8_DEPRECATED("Use Isolate* version", + static Local New(Local value)); Local ValueOf() const; @@ -10216,6 +10257,30 @@ template Value* Value::Cast(T* value) { } +Local Value::ToBoolean() const { + return ToBoolean(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local()); +} + + +Local Value::ToString() const { + return ToString(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local()); +} + + +Local Value::ToObject() const { + return ToObject(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local()); +} + + +Local Value::ToInteger() const { + return ToInteger(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local()); +} + + Boolean* Boolean::Cast(v8::Value* value) { #ifdef V8_ENABLE_CHECKS CheckCast(value); diff --git a/deps/v8/src/api.cc b/deps/v8/src/api.cc index d141496c5749cc..1272a7fb714021 100644 --- a/deps/v8/src/api.cc +++ b/deps/v8/src/api.cc @@ -2157,6 +2157,10 @@ int PrimitiveArray::Length() const { return array->length(); } +void PrimitiveArray::Set(int index, Local item) { + return Set(Isolate::GetCurrent(), index, item); +} + void PrimitiveArray::Set(Isolate* v8_isolate, int index, Local item) { i::Isolate* isolate = reinterpret_cast(v8_isolate); @@ -2170,6 +2174,10 @@ void PrimitiveArray::Set(Isolate* v8_isolate, int index, array->set(index, *i_item); } +Local PrimitiveArray::Get(int index) { + return Get(Isolate::GetCurrent(), index); +} + Local PrimitiveArray::Get(Isolate* v8_isolate, int index) { i::Isolate* isolate = reinterpret_cast(v8_isolate); i::Handle array = Utils::OpenHandle(this); @@ -2900,6 +2908,10 @@ void Message::PrintCurrentStackTrace(Isolate* isolate, FILE* out) { // --- S t a c k T r a c e --- +Local StackTrace::GetFrame(uint32_t index) const { + return GetFrame(Isolate::GetCurrent(), index); +} + Local StackTrace::GetFrame(Isolate* v8_isolate, uint32_t index) const { i::Isolate* isolate = reinterpret_cast(v8_isolate); @@ -3876,6 +3888,36 @@ void v8::RegExp::CheckCast(v8::Value* that) { } +bool Value::BooleanValue() const { + return BooleanValue(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(false); +} + + +double Value::NumberValue() const { + return NumberValue(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(0.0); +} + + +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 Value::BooleanValue(Local context) const { i::Isolate* isolate = reinterpret_cast(context->GetIsolate()); return Just(Utils::OpenHandle(this)->BooleanValue(isolate)); @@ -3964,6 +4006,12 @@ MaybeLocal Value::ToArrayIndex(Local context) const { } +bool Value::Equals(Local that) const { + return Equals(Isolate::GetCurrent()->GetCurrentContext(), that) + .FromMaybe(false); +} + + Maybe Value::Equals(Local context, Local that) const { i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate(); auto self = Utils::OpenHandle(this); @@ -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 str = Utils::OpenHandle(this); str = i::String::Flatten(reinterpret_cast(isolate), str); @@ -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 str = Utils::OpenHandle(this); @@ -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(isolate), this, buffer, @@ -6532,6 +6604,11 @@ MaybeLocal String::NewFromTwoByte(Isolate* isolate, return result; } +Local v8::String::Concat(Local left, + Local right) { + return Concat(Isolate::GetCurrent(), left, right); +} + Local v8::String::Concat(Isolate* v8_isolate, Local left, Local right) { i::Isolate* isolate = reinterpret_cast(v8_isolate); @@ -6758,6 +6835,11 @@ bool v8::BooleanObject::ValueOf() const { } +Local v8::StringObject::New(Local value) { + return New(Isolate::GetCurrent(), value); +} + + Local v8::StringObject::New(Isolate* v8_isolate, Local value) { i::Handle string = Utils::OpenHandle(*value); @@ -8893,6 +8975,9 @@ bool MicrotasksScope::IsRunningMicrotasks(Isolate* v8Isolate) { return isolate->IsRunningMicrotasks(); } +String::Utf8Value::Utf8Value(v8::Local obj) + : Utf8Value(Isolate::GetCurrent(), obj) {} + String::Utf8Value::Utf8Value(v8::Isolate* isolate, v8::Local obj) : str_(nullptr), length_(0) { if (obj.IsEmpty()) return; @@ -8912,6 +8997,9 @@ String::Utf8Value::~Utf8Value() { i::DeleteArray(str_); } +String::Value::Value(v8::Local obj) + : Value(Isolate::GetCurrent(), obj) {} + String::Value::Value(v8::Isolate* isolate, v8::Local obj) : str_(nullptr), length_(0) { if (obj.IsEmpty()) return; From cf7bb9707228241aa876281ce54f2c9f949b5e40 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 5 Oct 2018 00:01:50 -0700 Subject: [PATCH 4/4] fixup! deps: provide more V8 backwards compatibility --- deps/v8/src/api.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deps/v8/src/api.cc b/deps/v8/src/api.cc index 1272a7fb714021..5f1737b2a42b2d 100644 --- a/deps/v8/src/api.cc +++ b/deps/v8/src/api.cc @@ -3890,13 +3890,13 @@ void v8::RegExp::CheckCast(v8::Value* that) { bool Value::BooleanValue() const { return BooleanValue(Isolate::GetCurrent()->GetCurrentContext()) - .FromMaybe(false); + .FromJust(); } double Value::NumberValue() const { return NumberValue(Isolate::GetCurrent()->GetCurrentContext()) - .FromMaybe(0.0); + .FromMaybe(std::numeric_limits::quiet_NaN()); }