[explicit isolates] Remove nearly all GetIsolates in api.cc

This marks the following methods as V8_DEPRECATE_SOON and adds new
versions that take Isolate* as their first parameter:
PrimitiveArray::Set
PrimitiveArray::Get
StackTrace::GetFrame
String::Write
String::WriteOneByte
String::WriteUtf8
String::Concat
StringObject::New

Additionally StackFrameInfo, Module and TemplateInfo are marked as
NeverReadOnlySpaceObject so their GetIsolates calls are safe.

In api.cc, ContextFromHeapObject is split into
ContextFromNeverReadOnlySpaceObject and UnsafeContextFromHeapObject,
where the latter uses the deprecated methods but is only called from
methods that were themselves already marked V8_DEPRECATE_SOON.

Deprecation warnings for using HeapObject::GetHeap/GetIsolate are
suppressed for all the uses in V8_DEPRECATE_SOON methods so that stats
produced using tools/collect_deprecation_stats.sh don't show them.

Bug: v8:7786
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Change-Id: I48799b5599711661b14d0cd04f21a0a00322da4a
Reviewed-on: https://chromium-review.googlesource.com/1136641
Commit-Queue: Dan Elphick <delphick@chromium.org>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54469}
This commit is contained in:
Dan Elphick 2018-07-16 14:28:49 +01:00 committed by Commit Bot
parent 087cc34788
commit 8a011b57d8
6 changed files with 258 additions and 100 deletions

View File

@ -146,6 +146,7 @@ class Heap;
class HeapObject;
class Isolate;
class LocalEmbedderHeapTracer;
class NeverReadOnlySpaceObject;
class Object;
struct ScriptStreamingData;
template<typename T> class CustomArguments;
@ -994,8 +995,8 @@ class V8_EXPORT HandleScope {
void operator delete[](void*, size_t);
// Uses heap_object to obtain the current Isolate.
static internal::Object** CreateHandle(internal::HeapObject* heap_object,
internal::Object* value);
static internal::Object** CreateHandle(
internal::NeverReadOnlySpaceObject* heap_object, internal::Object* value);
internal::Isolate* isolate_;
internal::Object** prev_next_;
@ -1122,8 +1123,12 @@ class V8_EXPORT PrimitiveArray {
public:
static Local<PrimitiveArray> New(Isolate* isolate, int length);
int Length() const;
void Set(int index, Local<Primitive> item);
Local<Primitive> Get(int index);
void Set(Isolate* isolate, int index, Local<Primitive> item);
Local<Primitive> Get(Isolate* isolate, int index);
V8_DEPRECATE_SOON("Use Isolate version",
void Set(int index, Local<Primitive> item));
V8_DEPRECATE_SOON("Use Isolate version", Local<Primitive> Get(int index));
};
/**
@ -1848,7 +1853,9 @@ class V8_EXPORT StackTrace {
/**
* Returns a StackFrame at a particular index.
*/
Local<StackFrame> GetFrame(uint32_t index) const;
V8_DEPRECATE_SOON("Use Isolate version",
Local<StackFrame> GetFrame(uint32_t index) const);
Local<StackFrame> GetFrame(Isolate* isolate, uint32_t index) const;
/**
* Returns the number of StackFrames.
@ -2746,20 +2753,25 @@ class V8_EXPORT String : public Name {
};
// 16-bit character codes.
int Write(uint16_t* buffer,
int start = 0,
int length = -1,
int Write(Isolate* isolate, uint16_t* buffer, int start = 0, int length = -1,
int options = NO_OPTIONS) const;
V8_DEPRECATE_SOON("Use Isolate* version",
int Write(uint16_t* buffer, int start = 0, int length = -1,
int options = NO_OPTIONS) const);
// One byte characters.
int WriteOneByte(uint8_t* buffer,
int start = 0,
int length = -1,
int options = NO_OPTIONS) const;
int WriteOneByte(Isolate* isolate, uint8_t* buffer, int start = 0,
int length = -1, int options = NO_OPTIONS) const;
V8_DEPRECATE_SOON("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(char* buffer,
int length = -1,
int* nchars_ref = NULL,
int options = NO_OPTIONS) const;
int WriteUtf8(Isolate* isolate, char* buffer, int length = -1,
int* nchars_ref = NULL, int options = NO_OPTIONS) const;
V8_DEPRECATE_SOON("Use Isolate* version",
int WriteUtf8(char* buffer, int length = -1,
int* nchars_ref = NULL,
int options = NO_OPTIONS) const);
/**
* A zero length string.
@ -2921,7 +2933,11 @@ class V8_EXPORT String : public Name {
* Creates a new string by concatenating the left and the right strings
* passed in as parameters.
*/
static Local<String> Concat(Local<String> left, Local<String> right);
static Local<String> Concat(Isolate* isolate, Local<String> left,
Local<String> right);
static V8_DEPRECATE_SOON("Use Isolate* version",
Local<String> Concat(Local<String> left,
Local<String> right));
/**
* Creates a new external string using the data defined in the given
@ -5220,7 +5236,9 @@ class V8_EXPORT BooleanObject : public Object {
*/
class V8_EXPORT StringObject : public Object {
public:
static Local<Value> New(Local<String> value);
static Local<Value> New(Isolate* isolate, Local<String> value);
static V8_DEPRECATE_SOON("Use Isolate* version",
Local<Value> New(Local<String> value));
Local<String> ValueOf() const;
@ -10090,7 +10108,6 @@ AccessorSignature* AccessorSignature::Cast(Data* data) {
Local<Value> Object::GetInternalField(int index) {
#ifndef V8_ENABLE_CHECKS
typedef internal::Object O;
typedef internal::HeapObject HO;
typedef internal::Internals I;
O* obj = *reinterpret_cast<O**>(this);
// Fast path: If the object is a plain JSObject, which is the common case, we
@ -10101,7 +10118,8 @@ Local<Value> Object::GetInternalField(int index) {
instance_type == I::kJSSpecialApiObjectType) {
int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
O* value = I::ReadField<O*>(obj, offset);
O** result = HandleScope::CreateHandle(reinterpret_cast<HO*>(obj), value);
O** result = HandleScope::CreateHandle(
reinterpret_cast<internal::NeverReadOnlySpaceObject*>(obj), value);
return Local<Value>(reinterpret_cast<Value*>(result));
}
#endif
@ -10741,9 +10759,8 @@ int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(
Local<Value> Context::GetEmbedderData(int index) {
#ifndef V8_ENABLE_CHECKS
typedef internal::Object O;
typedef internal::HeapObject HO;
typedef internal::Internals I;
HO* context = *reinterpret_cast<HO**>(this);
auto* context = *reinterpret_cast<internal::NeverReadOnlySpaceObject**>(this);
O** result =
HandleScope::CreateHandle(context, I::ReadEmbedderData<O*>(this, index));
return Local<Value>(reinterpret_cast<Value*>(result));

View File

@ -207,12 +207,35 @@ namespace v8 {
#define RETURN_ESCAPED(value) return handle_scope.Escape(value);
// TODO(v8:7786): Remove this when HeapObject::GetIsolate is removed.
#ifdef DEPRECATE_GET_ISOLATE
#define DISABLE_DEPRECATED_WARNINGS \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wdeprecated\"")
#define RESET_DEPRECATED_WARNINGS _Pragma("clang diagnostic pop")
#else
#define DISABLE_DEPRECATED_WARNINGS
#define RESET_DEPRECATED_WARNINGS
#endif
namespace {
Local<Context> ContextFromHeapObject(i::Handle<i::Object> obj) {
Local<Context> ContextFromNeverReadOnlySpaceObject(
i::Handle<i::NeverReadOnlySpaceObject> obj) {
return reinterpret_cast<v8::Isolate*>(obj->GetIsolate())->GetCurrentContext();
}
// This is unsafe because obj could be in RO_SPACE which would not be tied to a
// particular isolate.
#ifdef DEPRECATE_GET_ISOLATE
[[deprecated("Pass Context explicitly or use a NeverReadOnlySpaceObject")]]
#endif
Local<Context>
UnsafeContextFromHeapObject(i::Handle<i::Object> obj) {
DISABLE_DEPRECATED_WARNINGS
return reinterpret_cast<v8::Isolate*>(i::HeapObject::cast(*obj)->GetIsolate())
->GetCurrentContext();
RESET_DEPRECATED_WARNINGS
}
class InternalEscapableScope : public v8::EscapableHandleScope {
@ -1186,11 +1209,10 @@ i::Object** HandleScope::CreateHandle(i::Isolate* isolate, i::Object* value) {
return i::HandleScope::CreateHandle(isolate, value);
}
i::Object** HandleScope::CreateHandle(i::HeapObject* heap_object,
i::Object* value) {
DCHECK(heap_object->IsHeapObject());
return i::HandleScope::CreateHandle(heap_object->GetIsolate(), value);
i::Object** HandleScope::CreateHandle(
i::NeverReadOnlySpaceObject* writable_object, i::Object* value) {
DCHECK(reinterpret_cast<i::HeapObject*>(writable_object)->IsHeapObject());
return i::HandleScope::CreateHandle(writable_object->GetIsolate(), value);
}
@ -1332,7 +1354,9 @@ v8::Local<v8::Value> Context::SlowGetEmbedderData(int index) {
const char* location = "v8::Context::GetEmbedderData()";
i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, false, location);
if (data.is_null()) return Local<Value>();
i::Handle<i::Object> result(data->get(index), data->GetIsolate());
i::Handle<i::Object> result(
data->get(index),
reinterpret_cast<i::Isolate*>(Utils::OpenHandle(this)->GetIsolate()));
return Utils::ToLocal(result);
}
@ -2131,11 +2155,9 @@ ScriptCompiler::StreamedSource::GetCachedData() const {
Local<Script> UnboundScript::BindToCurrentContext() {
i::Handle<i::HeapObject> obj =
i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
i::Isolate* isolate = obj->GetIsolate();
i::Handle<i::SharedFunctionInfo> function_info(
i::SharedFunctionInfo::cast(*obj), isolate);
auto function_info =
i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
i::Isolate* isolate = function_info->GetIsolate();
i::Handle<i::JSFunction> function =
isolate->factory()->NewFunctionFromSharedFunctionInfo(
function_info, isolate->native_context());
@ -2144,13 +2166,11 @@ Local<Script> UnboundScript::BindToCurrentContext() {
int UnboundScript::GetId() {
i::Handle<i::HeapObject> obj =
i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
i::Isolate* isolate = obj->GetIsolate();
auto function_info =
i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
i::Isolate* isolate = function_info->GetIsolate();
LOG_API(isolate, UnboundScript, GetId);
i::HandleScope scope(isolate);
i::Handle<i::SharedFunctionInfo> function_info(
i::SharedFunctionInfo::cast(*obj), isolate);
i::Handle<i::Script> script(i::Script::cast(function_info->script()),
isolate);
return script->id();
@ -2238,7 +2258,7 @@ Local<Value> Script::Run() {
// If execution is terminating, Compile(..)->Run() requires this
// check.
if (self.is_null()) return Local<Value>();
auto context = ContextFromHeapObject(self);
auto context = ContextFromNeverReadOnlySpaceObject(self);
RETURN_TO_LOCAL_UNCHECKED(Run(context), Value);
}
@ -2277,14 +2297,13 @@ Local<PrimitiveArray> PrimitiveArray::New(Isolate* v8_isolate, int length) {
int PrimitiveArray::Length() const {
i::Handle<i::FixedArray> array = Utils::OpenHandle(this);
i::Isolate* isolate = array->GetIsolate();
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
return array->length();
}
void PrimitiveArray::Set(int index, Local<Primitive> item) {
void PrimitiveArray::Set(Isolate* v8_isolate, int index,
Local<Primitive> item) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
i::Handle<i::FixedArray> array = Utils::OpenHandle(this);
i::Isolate* isolate = array->GetIsolate();
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
Utils::ApiCheck(index >= 0 && index < array->length(),
"v8::PrimitiveArray::Set",
@ -2294,9 +2313,17 @@ void PrimitiveArray::Set(int index, Local<Primitive> item) {
array->set(index, *i_item);
}
Local<Primitive> PrimitiveArray::Get(int index) {
void PrimitiveArray::Set(int index, Local<Primitive> item) {
i::Handle<i::FixedArray> array = Utils::OpenHandle(this);
DISABLE_DEPRECATED_WARNINGS
i::Isolate* isolate = array->GetIsolate();
RESET_DEPRECATED_WARNINGS
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);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
Utils::ApiCheck(index >= 0 && index < array->length(),
"v8::PrimitiveArray::Get",
@ -2306,6 +2333,14 @@ Local<Primitive> PrimitiveArray::Get(int index) {
return ToApiHandle<Primitive>(i_item);
}
Local<Primitive> PrimitiveArray::Get(int index) {
i::Handle<i::FixedArray> array = Utils::OpenHandle(this);
DISABLE_DEPRECATED_WARNINGS
i::Isolate* isolate = array->GetIsolate();
RESET_DEPRECATED_WARNINGS
return Get(reinterpret_cast<Isolate*>(isolate), index);
}
Module::Status Module::GetStatus() const {
i::Handle<i::Module> self = Utils::OpenHandle(this);
switch (self->status()) {
@ -2767,7 +2802,9 @@ MaybeLocal<Script> Script::Compile(Local<Context> context, Local<String> source,
Local<Script> Script::Compile(v8::Local<String> source,
v8::ScriptOrigin* origin) {
auto str = Utils::OpenHandle(*source);
auto context = ContextFromHeapObject(str);
DISABLE_DEPRECATED_WARNINGS
auto context = UnsafeContextFromHeapObject(str);
RESET_DEPRECATED_WARNINGS
RETURN_TO_LOCAL_UNCHECKED(Compile(context, source, origin), Script);
}
@ -2775,7 +2812,9 @@ Local<Script> Script::Compile(v8::Local<String> source,
Local<Script> Script::Compile(v8::Local<String> source,
v8::Local<String> file_name) {
auto str = Utils::OpenHandle(*source);
auto context = ContextFromHeapObject(str);
DISABLE_DEPRECATED_WARNINGS
auto context = UnsafeContextFromHeapObject(str);
RESET_DEPRECATED_WARNINGS
ScriptOrigin origin(file_name);
return Compile(context, source, &origin).FromMaybe(Local<Script>());
}
@ -2983,7 +3022,7 @@ Maybe<int> Message::GetLineNumber(Local<Context> context) const {
int Message::GetLineNumber() const {
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
return GetLineNumber(context).FromMaybe(0);
}
@ -3062,7 +3101,7 @@ MaybeLocal<String> Message::GetSourceLine(Local<Context> context) const {
Local<String> Message::GetSourceLine() const {
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
RETURN_TO_LOCAL_UNCHECKED(GetSourceLine(context), String)
}
@ -3076,15 +3115,22 @@ 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 {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
Local<StackFrame> StackTrace::GetFrame(Isolate* v8_isolate,
uint32_t index) const {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
EscapableHandleScope scope(v8_isolate);
auto obj = handle(Utils::OpenHandle(this)->get(index), isolate);
auto info = i::Handle<i::StackFrameInfo>::cast(obj);
return scope.Escape(Utils::StackFrameToLocal(info));
}
Local<StackFrame> StackTrace::GetFrame(uint32_t index) const {
DISABLE_DEPRECATED_WARNINGS
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
RESET_DEPRECATED_WARNINGS
return GetFrame(reinterpret_cast<Isolate*>(isolate), index);
}
int StackTrace::GetFrameCount() const {
return Utils::OpenHandle(this)->length();
@ -3609,12 +3655,16 @@ bool Value::IsBoolean() const {
return Utils::OpenHandle(this)->IsBoolean();
}
bool Value::IsExternal() const {
i::Handle<i::Object> obj = Utils::OpenHandle(this);
if (!obj->IsHeapObject()) return false;
i::Handle<i::HeapObject> heap_obj = i::Handle<i::HeapObject>::cast(obj);
return heap_obj->IsExternal(heap_obj->GetIsolate());
// Check the instance type is JS_OBJECT (instance type of Externals) before
// attempting to get the Isolate since that guarantees the object is writable
// and GetIsolate will work.
if (heap_obj->map()->instance_type() != i::JS_OBJECT_TYPE) return false;
i::Isolate* isolate = i::JSObject::cast(*heap_obj)->GetIsolate();
return heap_obj->IsExternal(isolate);
}
@ -4070,7 +4120,9 @@ bool Value::BooleanValue() const {
auto obj = Utils::OpenHandle(this);
if (obj->IsSmi()) return *obj != i::Smi::kZero;
DCHECK(obj->IsHeapObject());
DISABLE_DEPRECATED_WARNINGS
i::Isolate* isolate = i::Handle<i::HeapObject>::cast(obj)->GetIsolate();
RESET_DEPRECATED_WARNINGS
return obj->BooleanValue(isolate);
}
@ -4091,8 +4143,10 @@ Maybe<double> Value::NumberValue(Local<Context> context) const {
double Value::NumberValue() const {
auto obj = Utils::OpenHandle(this);
if (obj->IsNumber()) return obj->Number();
return NumberValue(ContextFromHeapObject(obj))
DISABLE_DEPRECATED_WARNINGS
return NumberValue(UnsafeContextFromHeapObject(obj))
.FromMaybe(std::numeric_limits<double>::quiet_NaN());
RESET_DEPRECATED_WARNINGS
}
@ -4120,7 +4174,9 @@ int64_t Value::IntegerValue() const {
return static_cast<int64_t>(obj->Number());
}
}
return IntegerValue(ContextFromHeapObject(obj)).FromMaybe(0);
DISABLE_DEPRECATED_WARNINGS
return IntegerValue(UnsafeContextFromHeapObject(obj)).FromMaybe(0);
RESET_DEPRECATED_WARNINGS
}
@ -4141,7 +4197,9 @@ Maybe<int32_t> Value::Int32Value(Local<Context> context) const {
int32_t Value::Int32Value() const {
auto obj = Utils::OpenHandle(this);
if (obj->IsNumber()) return NumberToInt32(*obj);
return Int32Value(ContextFromHeapObject(obj)).FromMaybe(0);
DISABLE_DEPRECATED_WARNINGS
return Int32Value(UnsafeContextFromHeapObject(obj)).FromMaybe(0);
RESET_DEPRECATED_WARNINGS
}
@ -4162,7 +4220,9 @@ Maybe<uint32_t> Value::Uint32Value(Local<Context> context) const {
uint32_t Value::Uint32Value() const {
auto obj = Utils::OpenHandle(this);
if (obj->IsNumber()) return NumberToUint32(*obj);
return Uint32Value(ContextFromHeapObject(obj)).FromMaybe(0);
DISABLE_DEPRECATED_WARNINGS
return Uint32Value(UnsafeContextFromHeapObject(obj)).FromMaybe(0);
RESET_DEPRECATED_WARNINGS
}
@ -4210,7 +4270,9 @@ bool Value::Equals(Local<Value> that) const {
return *self == *other;
}
auto heap_object = self->IsSmi() ? other : self;
auto context = ContextFromHeapObject(heap_object);
DISABLE_DEPRECATED_WARNINGS
auto context = UnsafeContextFromHeapObject(heap_object);
RESET_DEPRECATED_WARNINGS
return Equals(context, that).FromMaybe(false);
}
@ -4266,7 +4328,7 @@ Maybe<bool> v8::Object::Set(v8::Local<v8::Context> context,
bool v8::Object::Set(v8::Local<Value> key, v8::Local<Value> value) {
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
return Set(context, key, value).FromMaybe(false);
}
@ -4286,7 +4348,7 @@ Maybe<bool> v8::Object::Set(v8::Local<v8::Context> context, uint32_t index,
bool v8::Object::Set(uint32_t index, v8::Local<Value> value) {
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
return Set(context, index, value).FromMaybe(false);
}
@ -4513,7 +4575,7 @@ MaybeLocal<Value> v8::Object::Get(Local<v8::Context> context,
Local<Value> v8::Object::Get(v8::Local<Value> key) {
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
RETURN_TO_LOCAL_UNCHECKED(Get(context, key), Value);
}
@ -4530,7 +4592,7 @@ MaybeLocal<Value> v8::Object::Get(Local<Context> context, uint32_t index) {
Local<Value> v8::Object::Get(uint32_t index) {
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
RETURN_TO_LOCAL_UNCHECKED(Get(context, index), Value);
}
@ -4654,7 +4716,7 @@ MaybeLocal<Array> v8::Object::GetPropertyNames(
Local<Array> v8::Object::GetPropertyNames() {
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
RETURN_TO_LOCAL_UNCHECKED(GetPropertyNames(context), Array);
}
@ -4664,7 +4726,7 @@ MaybeLocal<Array> v8::Object::GetOwnPropertyNames(Local<Context> context) {
}
Local<Array> v8::Object::GetOwnPropertyNames() {
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
RETURN_TO_LOCAL_UNCHECKED(GetOwnPropertyNames(context), Array);
}
@ -4734,7 +4796,7 @@ Maybe<bool> v8::Object::Delete(Local<Context> context, Local<Value> key) {
}
bool v8::Object::Delete(v8::Local<Value> key) {
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
return Delete(context, key).FromMaybe(false);
}
@ -4778,7 +4840,7 @@ Maybe<bool> v8::Object::Has(Local<Context> context, Local<Value> key) {
bool v8::Object::Has(v8::Local<Value> key) {
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
return Has(context, key).FromMaybe(false);
}
@ -4937,7 +4999,7 @@ Maybe<bool> v8::Object::HasRealNamedProperty(Local<Context> context,
bool v8::Object::HasRealNamedProperty(Local<String> key) {
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
return HasRealNamedProperty(context, key).FromMaybe(false);
}
@ -4958,7 +5020,7 @@ Maybe<bool> v8::Object::HasRealIndexedProperty(Local<Context> context,
bool v8::Object::HasRealIndexedProperty(uint32_t index) {
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
return HasRealIndexedProperty(context, index).FromMaybe(false);
}
@ -4980,7 +5042,7 @@ Maybe<bool> v8::Object::HasRealNamedCallbackProperty(Local<Context> context,
bool v8::Object::HasRealNamedCallbackProperty(Local<String> key) {
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
return HasRealNamedCallbackProperty(context, key).FromMaybe(false);
}
@ -5256,7 +5318,7 @@ MaybeLocal<v8::Value> Function::Call(Local<Context> context,
Local<v8::Value> Function::Call(v8::Local<v8::Value> recv, int argc,
v8::Local<v8::Value> argv[]) {
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
RETURN_TO_LOCAL_UNCHECKED(Call(context, recv, argc, argv), Value);
}
@ -5765,13 +5827,10 @@ static bool RecursivelySerializeToUtf8(i::String* current,
return true;
}
int String::WriteUtf8(char* buffer,
int capacity,
int* nchars_ref,
int options) const {
int String::WriteUtf8(Isolate* v8_isolate, char* buffer, int capacity,
int* nchars_ref, int options) const {
i::Handle<i::String> str = Utils::OpenHandle(this);
i::Isolate* isolate = str->GetIsolate();
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
LOG_API(isolate, String, WriteUtf8);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
str = i::String::Flatten(isolate, str); // Flatten the string for efficiency.
@ -5812,14 +5871,20 @@ int String::WriteUtf8(char* buffer,
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);
DISABLE_DEPRECATED_WARNINGS
i::Isolate* isolate = str->GetIsolate();
RESET_DEPRECATED_WARNINGS
return WriteUtf8(reinterpret_cast<Isolate*>(isolate), buffer, capacity,
nchars_ref, options);
}
template<typename CharType>
static inline int WriteHelper(const String* string,
CharType* buffer,
int start,
int length,
template <typename CharType>
static inline int WriteHelper(i::Isolate* isolate, const String* string,
CharType* buffer, int start, int length,
int options) {
i::Isolate* isolate = Utils::OpenHandle(string)->GetIsolate();
LOG_API(isolate, String, Write);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
DCHECK(start >= 0 && length >= -1);
@ -5842,7 +5907,16 @@ int String::WriteOneByte(uint8_t* buffer,
int start,
int length,
int options) const {
return WriteHelper(this, buffer, start, length, options);
DISABLE_DEPRECATED_WARNINGS
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
RESET_DEPRECATED_WARNINGS
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);
}
@ -5850,7 +5924,16 @@ int String::Write(uint16_t* buffer,
int start,
int length,
int options) const {
return WriteHelper(this, buffer, start, length, options);
DISABLE_DEPRECATED_WARNINGS
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
RESET_DEPRECATED_WARNINGS
return WriteHelper(isolate, this, buffer, start, length, options);
}
int String::Write(Isolate* isolate, uint16_t* buffer, int start, int length,
int options) const {
return WriteHelper(reinterpret_cast<i::Isolate*>(isolate), this, buffer,
start, length, options);
}
@ -5919,7 +6002,19 @@ v8::String::GetExternalOneByteStringResource() const {
Local<Value> Symbol::Name() const {
i::Handle<i::Symbol> sym = Utils::OpenHandle(this);
i::Handle<i::Object> name(sym->name(), sym->GetIsolate());
i::MemoryChunk* chunk = i::MemoryChunk::FromHeapObject(*sym);
// If the Symbol is in RO_SPACE, then its name must be too. Since RO_SPACE
// objects are immovable we can use the Handle(T**) constructor with the
// address of the name field in the Symbol object without needing an isolate.
if (chunk->owner()->identity() == i::RO_SPACE) {
i::Handle<i::HeapObject> ro_name(reinterpret_cast<i::HeapObject**>(
sym->GetFieldAddress(i::Symbol::kNameOffset)));
return Utils::ToLocal(ro_name);
}
i::Handle<i::Object> name(sym->name(), chunk->heap()->isolate());
return Utils::ToLocal(name);
}
@ -6488,7 +6583,7 @@ MaybeLocal<v8::Object> ObjectTemplate::NewInstance(Local<Context> context) {
Local<v8::Object> ObjectTemplate::NewInstance() {
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
RETURN_TO_LOCAL_UNCHECKED(NewInstance(context), Object);
}
@ -6528,7 +6623,7 @@ MaybeLocal<v8::Function> FunctionTemplate::GetFunction(Local<Context> context) {
Local<v8::Function> FunctionTemplate::GetFunction() {
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
RETURN_TO_LOCAL_UNCHECKED(GetFunction(context), Function);
}
@ -6709,10 +6804,10 @@ MaybeLocal<String> String::NewFromTwoByte(Isolate* isolate,
return result;
}
Local<String> v8::String::Concat(Local<String> left, Local<String> right) {
Local<String> v8::String::Concat(Isolate* v8_isolate, Local<String> left,
Local<String> right) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
i::Handle<i::String> left_string = Utils::OpenHandle(*left);
i::Isolate* isolate = left_string->GetIsolate();
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
LOG_API(isolate, String, Concat);
i::Handle<i::String> right_string = Utils::OpenHandle(*right);
@ -6726,6 +6821,13 @@ Local<String> v8::String::Concat(Local<String> left, Local<String> right) {
return Utils::ToLocal(result);
}
Local<String> v8::String::Concat(Local<String> left, Local<String> right) {
i::Handle<i::String> left_string = Utils::OpenHandle(*left);
DISABLE_DEPRECATED_WARNINGS
i::Isolate* isolate = left_string->GetIsolate();
RESET_DEPRECATED_WARNINGS
return Concat(reinterpret_cast<Isolate*>(isolate), left, right);
}
MaybeLocal<String> v8::String::NewExternalTwoByte(
Isolate* isolate, v8::String::ExternalStringResource* resource) {
@ -6781,7 +6883,13 @@ Local<String> v8::String::NewExternal(
bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
i::Handle<i::String> obj = Utils::OpenHandle(this);
i::Isolate* isolate = obj->GetIsolate();
// RO_SPACE strings cannot be externalized.
i::MemoryChunk* chunk = i::MemoryChunk::FromHeapObject(*obj);
if (chunk->owner()->identity() == i::RO_SPACE) {
return false;
}
i::Isolate* isolate = chunk->heap()->isolate();
if (i::StringShape(*obj).IsExternal()) {
return false; // Already an external string.
}
@ -6804,7 +6912,14 @@ bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
bool v8::String::MakeExternal(
v8::String::ExternalOneByteStringResource* resource) {
i::Handle<i::String> obj = Utils::OpenHandle(this);
i::Isolate* isolate = obj->GetIsolate();
// RO_SPACE strings cannot be externalized.
i::MemoryChunk* chunk = i::MemoryChunk::FromHeapObject(*obj);
if (chunk->owner()->identity() == i::RO_SPACE) {
return false;
}
i::Isolate* isolate = chunk->heap()->isolate();
if (i::StringShape(*obj).IsExternal()) {
return false; // Already an external string.
}
@ -6915,7 +7030,16 @@ bool v8::BooleanObject::ValueOf() const {
Local<v8::Value> v8::StringObject::New(Local<String> value) {
i::Handle<i::String> string = Utils::OpenHandle(*value);
DISABLE_DEPRECATED_WARNINGS
i::Isolate* isolate = string->GetIsolate();
RESET_DEPRECATED_WARNINGS
return New(reinterpret_cast<Isolate*>(isolate), value);
}
Local<v8::Value> v8::StringObject::New(Isolate* v8_isolate,
Local<String> value) {
i::Handle<i::String> string = Utils::OpenHandle(*value);
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
LOG_API(isolate, StringObject, New);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
i::Handle<i::Object> obj =
@ -7346,7 +7470,7 @@ Maybe<bool> Promise::Resolver::Resolve(Local<Context> context,
void Promise::Resolver::Resolve(Local<Value> value) {
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
USE(Resolve(context, value));
}
@ -7371,7 +7495,7 @@ Maybe<bool> Promise::Resolver::Reject(Local<Context> context,
void Promise::Resolver::Reject(Local<Value> value) {
auto context = ContextFromHeapObject(Utils::OpenHandle(this));
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
USE(Reject(context, value));
}
@ -10845,6 +10969,8 @@ void InvokeFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info,
#undef SET_FIELD_WRAPPED
#undef NEW_STRING
#undef CALLBACK_SETTER
#undef DISABLE_DEPRECATED_WARNINGS
#undef RESET_DEPRECATED_WARNINGS
} // namespace internal
} // namespace v8

View File

@ -1838,6 +1838,10 @@ bool HeapObject::NeedsRehashing() const {
}
}
Address HeapObject::GetFieldAddress(int field_offset) const {
return FIELD_ADDR(this, field_offset);
}
void PropertyArray::set(int index, Object* value, WriteBarrierMode mode) {
DCHECK_GE(index, 0);
DCHECK_LT(index, this->length());

View File

@ -1520,14 +1520,14 @@ class HeapObject: public Object {
// The Heap the object was allocated in. Used also to access Isolate.
#ifdef DEPRECATE_GET_ISOLATE
[[deprecated("Pass Heap explicitly or use a NeverReadOnlyHeapObject")]]
[[deprecated("Pass Heap explicitly or use a NeverReadOnlySpaceObject")]]
#endif
inline Heap*
GetHeap() const;
// Convenience method to get current isolate.
#ifdef DEPRECATE_GET_ISOLATE
[[deprecated("Pass Isolate explicitly or use a NeverReadOnlyHeapObject")]]
[[deprecated("Pass Isolate explicitly or use a NeverReadOnlySpaceObject")]]
#endif
inline Isolate*
GetIsolate() const;
@ -1658,6 +1658,8 @@ class HeapObject: public Object {
STATIC_ASSERT(kMapOffset == Internals::kHeapObjectMapOffset);
inline Address GetFieldAddress(int field_offset) const;
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject);
};
@ -4260,8 +4262,11 @@ class AccessorPair: public Struct {
DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorPair);
};
class StackFrameInfo : public Struct {
class StackFrameInfo : public Struct, public NeverReadOnlySpaceObject {
public:
using NeverReadOnlySpaceObject::GetHeap;
using NeverReadOnlySpaceObject::GetIsolate;
DECL_INT_ACCESSORS(line_number)
DECL_INT_ACCESSORS(column_number)
DECL_INT_ACCESSORS(script_id)

View File

@ -25,8 +25,11 @@ class String;
class Zone;
// The runtime representation of an ECMAScript module.
class Module : public Struct {
class Module : public Struct, public NeverReadOnlySpaceObject {
public:
using NeverReadOnlySpaceObject::GetHeap;
using NeverReadOnlySpaceObject::GetIsolate;
DECL_CAST(Module)
DECL_VERIFIER(Module)
DECL_PRINTER(Module)

View File

@ -13,8 +13,11 @@
namespace v8 {
namespace internal {
class TemplateInfo : public Struct {
class TemplateInfo : public Struct, public NeverReadOnlySpaceObject {
public:
using NeverReadOnlySpaceObject::GetHeap;
using NeverReadOnlySpaceObject::GetIsolate;
DECL_ACCESSORS(tag, Object)
DECL_ACCESSORS(serial_number, Object)
DECL_INT_ACCESSORS(number_of_properties)