diff options
author | Michaël Zasso <targos@protonmail.com> | 2018-12-04 08:20:37 +0100 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2018-12-06 15:23:33 +0100 |
commit | 9b4bf7de6c9a7c25f116c7a502384c20b5cfaea3 (patch) | |
tree | 2b0c843168dafb939d8df8a15b2aa72b76dee51d /deps/v8/src/api.cc | |
parent | b8fbe69db1292307adb2c2b2e0d5ef48c4ab2faf (diff) | |
download | android-node-v8-9b4bf7de6c9a7c25f116c7a502384c20b5cfaea3.tar.gz android-node-v8-9b4bf7de6c9a7c25f116c7a502384c20b5cfaea3.tar.bz2 android-node-v8-9b4bf7de6c9a7c25f116c7a502384c20b5cfaea3.zip |
deps: update V8 to 7.1.302.28
PR-URL: https://github.com/nodejs/node/pull/23423
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Diffstat (limited to 'deps/v8/src/api.cc')
-rw-r--r-- | deps/v8/src/api.cc | 456 |
1 files changed, 206 insertions, 250 deletions
diff --git a/deps/v8/src/api.cc b/deps/v8/src/api.cc index 5ac9aec047..3f62a23d43 100644 --- a/deps/v8/src/api.cc +++ b/deps/v8/src/api.cc @@ -58,7 +58,9 @@ #include "src/objects/js-regexp-inl.h" #include "src/objects/module-inl.h" #include "src/objects/ordered-hash-table-inl.h" +#include "src/objects/stack-frame-info-inl.h" #include "src/objects/templates.h" +#include "src/parsing/parse-info.h" #include "src/parsing/parser.h" #include "src/parsing/scanner-character-streams.h" #include "src/pending-compilation-error-handler.h" @@ -834,6 +836,7 @@ StartupData SnapshotCreator::CreateBlob( } data->created_ = true; + DCHECK(i::Snapshot::VerifyChecksum(&result)); return result; } @@ -876,12 +879,12 @@ void RegisteredExtension::UnregisterAll() { namespace { class ExtensionResource : public String::ExternalOneByteStringResource { public: - ExtensionResource() : data_(0), length_(0) {} + ExtensionResource() : data_(nullptr), length_(0) {} ExtensionResource(const char* data, size_t length) : data_(data), length_(length) {} - const char* data() const { return data_; } - size_t length() const { return length_; } - virtual void Dispose() {} + const char* data() const override { return data_; } + size_t length() const override { return length_; } + void Dispose() override {} private: const char* data_; @@ -1391,7 +1394,7 @@ static Local<FunctionTemplate> FunctionTemplateNew( next_serial_number = isolate->heap()->GetNextTemplateSerialNumber(); } obj->set_serial_number(i::Smi::FromInt(next_serial_number)); - if (callback != 0) { + if (callback != nullptr) { Utils::ToLocal(obj)->SetCallHandler(callback, data, side_effect_type); } obj->set_length(length); @@ -1676,7 +1679,8 @@ static void TemplateSetAccessor( Template* template_obj, v8::Local<Name> name, Getter getter, Setter setter, Data data, AccessControl settings, PropertyAttribute attribute, v8::Local<AccessorSignature> signature, bool is_special_data_property, - bool replace_on_access, SideEffectType getter_side_effect_type) { + bool replace_on_access, SideEffectType getter_side_effect_type, + SideEffectType setter_side_effect_type) { auto info = Utils::OpenHandle(template_obj); auto isolate = info->GetIsolate(); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); @@ -1686,8 +1690,8 @@ static void TemplateSetAccessor( is_special_data_property, replace_on_access); accessor_info->set_initial_property_attributes( static_cast<i::PropertyAttributes>(attribute)); - accessor_info->set_has_no_side_effect(getter_side_effect_type == - SideEffectType::kHasNoSideEffect); + accessor_info->set_getter_side_effect_type(getter_side_effect_type); + accessor_info->set_setter_side_effect_type(setter_side_effect_type); i::ApiNatives::AddNativeDataProperty(isolate, info, accessor_info); } @@ -1695,29 +1699,34 @@ void Template::SetNativeDataProperty( v8::Local<String> name, AccessorGetterCallback getter, AccessorSetterCallback setter, v8::Local<Value> data, PropertyAttribute attribute, v8::Local<AccessorSignature> signature, - AccessControl settings, SideEffectType getter_side_effect_type) { + AccessControl settings, SideEffectType getter_side_effect_type, + SideEffectType setter_side_effect_type) { TemplateSetAccessor(this, name, getter, setter, data, settings, attribute, - signature, true, false, getter_side_effect_type); + signature, true, false, getter_side_effect_type, + setter_side_effect_type); } void Template::SetNativeDataProperty( v8::Local<Name> name, AccessorNameGetterCallback getter, AccessorNameSetterCallback setter, v8::Local<Value> data, PropertyAttribute attribute, v8::Local<AccessorSignature> signature, - AccessControl settings, SideEffectType getter_side_effect_type) { + AccessControl settings, SideEffectType getter_side_effect_type, + SideEffectType setter_side_effect_type) { TemplateSetAccessor(this, name, getter, setter, data, settings, attribute, - signature, true, false, getter_side_effect_type); + signature, true, false, getter_side_effect_type, + setter_side_effect_type); } void Template::SetLazyDataProperty(v8::Local<Name> name, AccessorNameGetterCallback getter, v8::Local<Value> data, PropertyAttribute attribute, - SideEffectType getter_side_effect_type) { + SideEffectType getter_side_effect_type, + SideEffectType setter_side_effect_type) { TemplateSetAccessor(this, name, getter, static_cast<AccessorNameSetterCallback>(nullptr), data, DEFAULT, attribute, Local<AccessorSignature>(), true, - true, getter_side_effect_type); + true, getter_side_effect_type, setter_side_effect_type); } void Template::SetIntrinsicDataProperty(Local<Name> name, Intrinsic intrinsic, @@ -1737,10 +1746,11 @@ void ObjectTemplate::SetAccessor(v8::Local<String> name, v8::Local<Value> data, AccessControl settings, PropertyAttribute attribute, v8::Local<AccessorSignature> signature, - SideEffectType getter_side_effect_type) { + SideEffectType getter_side_effect_type, + SideEffectType setter_side_effect_type) { TemplateSetAccessor(this, name, getter, setter, data, settings, attribute, signature, i::FLAG_disable_old_api_accessors, false, - getter_side_effect_type); + getter_side_effect_type, setter_side_effect_type); } void ObjectTemplate::SetAccessor(v8::Local<Name> name, @@ -1749,10 +1759,11 @@ void ObjectTemplate::SetAccessor(v8::Local<Name> name, v8::Local<Value> data, AccessControl settings, PropertyAttribute attribute, v8::Local<AccessorSignature> signature, - SideEffectType getter_side_effect_type) { + SideEffectType getter_side_effect_type, + SideEffectType setter_side_effect_type) { TemplateSetAccessor(this, name, getter, setter, data, settings, attribute, signature, i::FLAG_disable_old_api_accessors, false, - getter_side_effect_type); + getter_side_effect_type, setter_side_effect_type); } template <typename Getter, typename Setter, typename Query, typename Descriptor, @@ -1765,15 +1776,15 @@ static i::Handle<i::InterceptorInfo> CreateInterceptorInfo( isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE, i::TENURED)); obj->set_flags(0); - if (getter != 0) SET_FIELD_WRAPPED(isolate, obj, set_getter, getter); - if (setter != 0) SET_FIELD_WRAPPED(isolate, obj, set_setter, setter); - if (query != 0) SET_FIELD_WRAPPED(isolate, obj, set_query, query); - if (descriptor != 0) + if (getter != nullptr) SET_FIELD_WRAPPED(isolate, obj, set_getter, getter); + if (setter != nullptr) SET_FIELD_WRAPPED(isolate, obj, set_setter, setter); + if (query != nullptr) SET_FIELD_WRAPPED(isolate, obj, set_query, query); + if (descriptor != nullptr) SET_FIELD_WRAPPED(isolate, obj, set_descriptor, descriptor); - if (remover != 0) SET_FIELD_WRAPPED(isolate, obj, set_deleter, remover); - if (enumerator != 0) + if (remover != nullptr) SET_FIELD_WRAPPED(isolate, obj, set_deleter, remover); + if (enumerator != nullptr) SET_FIELD_WRAPPED(isolate, obj, set_enumerator, enumerator); - if (definer != 0) SET_FIELD_WRAPPED(isolate, obj, set_definer, definer); + if (definer != nullptr) SET_FIELD_WRAPPED(isolate, obj, set_definer, definer); obj->set_can_intercept_symbols( !(static_cast<int>(flags) & static_cast<int>(PropertyHandlerFlags::kOnlyInterceptStrings))); @@ -2001,24 +2012,15 @@ ScriptCompiler::CachedData::~CachedData() { } } - bool ScriptCompiler::ExternalSourceStream::SetBookmark() { return false; } - void ScriptCompiler::ExternalSourceStream::ResetToBookmark() { UNREACHABLE(); } ScriptCompiler::StreamedSource::StreamedSource(ExternalSourceStream* stream, Encoding encoding) : impl_(new i::ScriptStreamingData(stream, encoding)) {} -ScriptCompiler::StreamedSource::~StreamedSource() { delete impl_; } - - -const ScriptCompiler::CachedData* -ScriptCompiler::StreamedSource::GetCachedData() const { - return impl_->cached_data.get(); -} - +ScriptCompiler::StreamedSource::~StreamedSource() = default; Local<Script> UnboundScript::BindToCurrentContext() { auto function_info = @@ -2030,7 +2032,6 @@ Local<Script> UnboundScript::BindToCurrentContext() { return ToApiHandle<Script>(function); } - int UnboundScript::GetId() { auto function_info = i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this)); @@ -2157,10 +2158,6 @@ 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); @@ -2174,10 +2171,6 @@ 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); @@ -2534,6 +2527,7 @@ MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext( RETURN_ESCAPED(Utils::CallableToLocal(result)); } +void ScriptCompiler::ScriptStreamingTask::Run() { data_->task->Run(); } ScriptCompiler::ScriptStreamingTask* ScriptCompiler::StartStreamingScript( Isolate* v8_isolate, StreamedSource* source, CompileOptions options) { @@ -2544,10 +2538,13 @@ ScriptCompiler::ScriptStreamingTask* ScriptCompiler::StartStreamingScript( // TODO(rmcilroy): remove CompileOptions from the API. CHECK(options == ScriptCompiler::kNoCompileOptions); i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); - return i::Compiler::NewBackgroundCompileTask(source->impl(), isolate); + i::ScriptStreamingData* data = source->impl(); + std::unique_ptr<i::BackgroundCompileTask> task = + base::make_unique<i::BackgroundCompileTask>(data, isolate); + data->task = std::move(task); + return new ScriptCompiler::ScriptStreamingTask(data); } - MaybeLocal<Script> ScriptCompiler::Compile(Local<Context> context, StreamedSource* v8_source, Local<String> full_source_string, @@ -2562,11 +2559,11 @@ MaybeLocal<Script> ScriptCompiler::Compile(Local<Context> context, isolate, origin.ResourceName(), origin.ResourceLineOffset(), origin.ResourceColumnOffset(), origin.SourceMapUrl(), origin.HostDefinedOptions()); - i::ScriptStreamingData* streaming_data = v8_source->impl(); + i::ScriptStreamingData* data = v8_source->impl(); i::MaybeHandle<i::SharedFunctionInfo> maybe_function_info = i::Compiler::GetSharedFunctionInfoForStreamedScript( - isolate, str, script_details, origin.Options(), streaming_data); + isolate, str, script_details, origin.Options(), data); i::Handle<i::SharedFunctionInfo> result; has_pending_exception = !maybe_function_info.ToHandle(&result); @@ -2908,10 +2905,6 @@ 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); @@ -3572,17 +3565,20 @@ MaybeLocal<BigInt> Value::ToBigInt(Local<Context> context) const { RETURN_ESCAPED(result); } +bool Value::BooleanValue(Isolate* v8_isolate) const { + return Utils::OpenHandle(this)->BooleanValue( + reinterpret_cast<i::Isolate*>(v8_isolate)); +} + MaybeLocal<Boolean> Value::ToBoolean(Local<Context> context) const { - auto obj = Utils::OpenHandle(this); - if (obj->IsBoolean()) return ToApiHandle<Boolean>(obj); - auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate()); - auto val = isolate->factory()->ToBoolean(obj->BooleanValue(isolate)); - return ToApiHandle<Boolean>(val); + return ToBoolean(context->GetIsolate()); } Local<Boolean> Value::ToBoolean(Isolate* v8_isolate) const { - return ToBoolean(v8_isolate->GetCurrentContext()).ToLocalChecked(); + auto isolate = reinterpret_cast<i::Isolate*>(v8_isolate); + return ToApiHandle<Boolean>( + isolate->factory()->ToBoolean(BooleanValue(v8_isolate))); } @@ -3888,36 +3884,6 @@ 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 IntegerValue(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)); @@ -4006,12 +3972,6 @@ 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); @@ -4063,7 +4023,8 @@ Maybe<bool> v8::Object::Set(v8::Local<v8::Context> context, auto value_obj = Utils::OpenHandle(*value); has_pending_exception = i::Runtime::SetObjectProperty(isolate, self, key_obj, value_obj, - i::LanguageMode::kSloppy) + i::LanguageMode::kSloppy, + i::StoreOrigin::kMaybeKeyed) .is_null(); RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); return Just(true); @@ -4617,8 +4578,8 @@ static Maybe<bool> ObjectSetAccessor( Local<Context> context, Object* self, Local<Name> name, Getter getter, Setter setter, Data data, AccessControl settings, PropertyAttribute attributes, bool is_special_data_property, - bool replace_on_access, - SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect) { + bool replace_on_access, SideEffectType getter_side_effect_type, + SideEffectType setter_side_effect_type) { auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate()); ENTER_V8_NO_SCRIPT(isolate, context, Object, SetAccessor, Nothing<bool>(), i::HandleScope); @@ -4629,8 +4590,8 @@ static Maybe<bool> ObjectSetAccessor( i::Handle<i::AccessorInfo> info = MakeAccessorInfo(isolate, name, getter, setter, data, settings, signature, is_special_data_property, replace_on_access); - info->set_has_no_side_effect(getter_side_effect_type == - SideEffectType::kHasNoSideEffect); + info->set_getter_side_effect_type(getter_side_effect_type); + info->set_setter_side_effect_type(setter_side_effect_type); if (info.is_null()) return Nothing<bool>(); bool fast = obj->HasFastProperties(); i::Handle<i::Object> result; @@ -4653,11 +4614,12 @@ Maybe<bool> Object::SetAccessor(Local<Context> context, Local<Name> name, AccessorNameSetterCallback setter, MaybeLocal<Value> data, AccessControl settings, PropertyAttribute attribute, - SideEffectType getter_side_effect_type) { + SideEffectType getter_side_effect_type, + SideEffectType setter_side_effect_type) { return ObjectSetAccessor(context, this, name, getter, setter, data.FromMaybe(Local<Value>()), settings, attribute, i::FLAG_disable_old_api_accessors, false, - getter_side_effect_type); + getter_side_effect_type, setter_side_effect_type); } @@ -4684,19 +4646,22 @@ Maybe<bool> Object::SetNativeDataProperty( v8::Local<v8::Context> context, v8::Local<Name> name, AccessorNameGetterCallback getter, AccessorNameSetterCallback setter, v8::Local<Value> data, PropertyAttribute attributes, - SideEffectType getter_side_effect_type) { + SideEffectType getter_side_effect_type, + SideEffectType setter_side_effect_type) { return ObjectSetAccessor(context, this, name, getter, setter, data, DEFAULT, - attributes, true, false, getter_side_effect_type); + attributes, true, false, getter_side_effect_type, + setter_side_effect_type); } Maybe<bool> Object::SetLazyDataProperty( v8::Local<v8::Context> context, v8::Local<Name> name, AccessorNameGetterCallback getter, v8::Local<Value> data, - PropertyAttribute attributes, SideEffectType getter_side_effect_type) { + PropertyAttribute attributes, SideEffectType getter_side_effect_type, + SideEffectType setter_side_effect_type) { return ObjectSetAccessor(context, this, name, getter, static_cast<AccessorNameSetterCallback>(nullptr), data, DEFAULT, attributes, true, true, - getter_side_effect_type); + getter_side_effect_type, setter_side_effect_type); } Maybe<bool> v8::Object::HasOwnProperty(Local<Context> context, @@ -5343,10 +5308,6 @@ 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); @@ -5570,14 +5531,6 @@ 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); @@ -5645,18 +5598,6 @@ 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, @@ -6010,16 +5951,16 @@ HeapStatistics::HeapStatistics() malloced_memory_(0), external_memory_(0), peak_malloced_memory_(0), - does_zap_garbage_(0), + does_zap_garbage_(false), number_of_native_contexts_(0), number_of_detached_contexts_(0) {} -HeapSpaceStatistics::HeapSpaceStatistics(): space_name_(0), - space_size_(0), - space_used_size_(0), - space_available_size_(0), - physical_space_size_(0) { } - +HeapSpaceStatistics::HeapSpaceStatistics() + : space_name_(nullptr), + space_size_(0), + space_used_size_(0), + space_available_size_(0), + physical_space_size_(0) {} HeapObjectStatistics::HeapObjectStatistics() : object_type_(nullptr), @@ -6604,11 +6545,6 @@ 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); @@ -6793,7 +6729,6 @@ double v8::NumberObject::ValueOf() const { } Local<v8::Value> v8::BigIntObject::New(Isolate* isolate, int64_t value) { - CHECK(i::FLAG_harmony_bigint); i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); LOG_API(i_isolate, BigIntObject, New); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); @@ -6835,11 +6770,6 @@ 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); @@ -6981,23 +6911,6 @@ Local<v8::Array> v8::Array::New(Isolate* isolate, int length) { return Utils::ToLocal(obj); } -Local<v8::Array> v8::Array::New(Isolate* isolate, Local<Value>* elements, - size_t length) { - i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); - i::Factory* factory = i_isolate->factory(); - LOG_API(i_isolate, Array, New); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); - int len = static_cast<int>(length); - - i::Handle<i::FixedArray> result = factory->NewFixedArray(len); - for (int i = 0; i < len; i++) { - i::Handle<i::Object> element = Utils::OpenHandle(*elements[i]); - result->set(i, *element); - } - - return Utils::ToLocal( - factory->NewJSArrayWithElements(result, i::PACKED_ELEMENTS, len)); -} uint32_t v8::Array::Length() const { i::Handle<i::JSArray> obj = Utils::OpenHandle(this); @@ -7103,30 +7016,30 @@ i::Handle<i::JSArray> MapAsArray(i::Isolate* isolate, i::Object* table_obj, i::Factory* factory = isolate->factory(); i::Handle<i::OrderedHashMap> table(i::OrderedHashMap::cast(table_obj), isolate); - const bool collect_keys = - kind == MapAsArrayKind::kEntries || kind == MapAsArrayKind::kKeys; - const bool collect_values = - kind == MapAsArrayKind::kEntries || kind == MapAsArrayKind::kValues; - int capacity = table->UsedCapacity(); - int max_length = - (capacity - offset) * ((collect_keys && collect_values) ? 2 : 1); - i::Handle<i::FixedArray> result = factory->NewFixedArray(max_length); + if (offset >= table->NumberOfElements()) return factory->NewJSArray(0); + int length = (table->NumberOfElements() - offset) * + (kind == MapAsArrayKind::kEntries ? 2 : 1); + i::Handle<i::FixedArray> result = factory->NewFixedArray(length); int result_index = 0; { i::DisallowHeapAllocation no_gc; + int capacity = table->UsedCapacity(); i::Oddball* the_hole = i::ReadOnlyRoots(isolate).the_hole_value(); - for (int i = offset; i < capacity; ++i) { + for (int i = 0; i < capacity; ++i) { i::Object* key = table->KeyAt(i); if (key == the_hole) continue; - if (collect_keys) result->set(result_index++, key); - if (collect_values) result->set(result_index++, table->ValueAt(i)); + if (offset-- > 0) continue; + if (kind == MapAsArrayKind::kEntries || kind == MapAsArrayKind::kKeys) { + result->set(result_index++, key); + } + if (kind == MapAsArrayKind::kEntries || kind == MapAsArrayKind::kValues) { + result->set(result_index++, table->ValueAt(i)); + } } } - DCHECK_GE(max_length, result_index); - if (result_index == 0) return factory->NewJSArray(0); - result->Shrink(isolate, result_index); - return factory->NewJSArrayWithElements(result, i::PACKED_ELEMENTS, - result_index); + DCHECK_EQ(result_index, result->length()); + DCHECK_EQ(result_index, length); + return factory->NewJSArrayWithElements(result, i::PACKED_ELEMENTS, length); } } // namespace @@ -7211,26 +7124,24 @@ i::Handle<i::JSArray> SetAsArray(i::Isolate* isolate, i::Object* table_obj, i::Factory* factory = isolate->factory(); i::Handle<i::OrderedHashSet> table(i::OrderedHashSet::cast(table_obj), isolate); - // Elements skipped by |offset| may already be deleted. - int capacity = table->UsedCapacity(); - int max_length = capacity - offset; - if (max_length == 0) return factory->NewJSArray(0); - i::Handle<i::FixedArray> result = factory->NewFixedArray(max_length); + int length = table->NumberOfElements() - offset; + if (length <= 0) return factory->NewJSArray(0); + i::Handle<i::FixedArray> result = factory->NewFixedArray(length); int result_index = 0; { i::DisallowHeapAllocation no_gc; + int capacity = table->UsedCapacity(); i::Oddball* the_hole = i::ReadOnlyRoots(isolate).the_hole_value(); - for (int i = offset; i < capacity; ++i) { + for (int i = 0; i < capacity; ++i) { i::Object* key = table->KeyAt(i); if (key == the_hole) continue; + if (offset-- > 0) continue; result->set(result_index++, key); } } - DCHECK_GE(max_length, result_index); - if (result_index == 0) return factory->NewJSArray(0); - result->Shrink(isolate, result_index); - return factory->NewJSArrayWithElements(result, i::PACKED_ELEMENTS, - result_index); + DCHECK_EQ(result_index, result->length()); + DCHECK_EQ(result_index, length); + return factory->NewJSArrayWithElements(result, i::PACKED_ELEMENTS, length); } } // namespace @@ -7501,7 +7412,7 @@ class AsyncCompilationResolver : public i::wasm::CompilationResultResolver { reinterpret_cast<i::Isolate*>(isolate)->global_handles()->Create( *Utils::OpenHandle(*promise))) {} - ~AsyncCompilationResolver() { + ~AsyncCompilationResolver() override { i::GlobalHandles::Destroy(i::Handle<i::Object>::cast(promise_).location()); } @@ -7540,9 +7451,6 @@ void WasmModuleObjectBuilderStreaming::Finish() { void WasmModuleObjectBuilderStreaming::Abort(MaybeLocal<Value> exception) { } -WasmModuleObjectBuilderStreaming::~WasmModuleObjectBuilderStreaming() { -} - // static v8::ArrayBuffer::Allocator* v8::ArrayBuffer::Allocator::NewDefaultAllocator() { return new ArrayBufferAllocator(); @@ -7602,9 +7510,8 @@ void ArrayBufferDeleter(void* buffer, size_t length, void* info) { v8::ArrayBuffer::Contents v8::ArrayBuffer::GetContents() { i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle(this); - size_t byte_length = static_cast<size_t>(self->byte_length()->Number()); Contents contents( - self->backing_store(), byte_length, self->allocation_base(), + self->backing_store(), self->byte_length(), self->allocation_base(), self->allocation_length(), self->is_wasm_memory() ? Allocator::AllocationMode::kReservation : Allocator::AllocationMode::kNormal, @@ -7632,7 +7539,7 @@ void v8::ArrayBuffer::Neuter() { size_t v8::ArrayBuffer::ByteLength() const { i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this); - return static_cast<size_t>(obj->byte_length()->Number()); + return obj->byte_length(); } @@ -7656,6 +7563,7 @@ Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, void* data, ArrayBufferCreationMode mode) { // Embedders must guarantee that the external backing store is valid. CHECK(byte_length == 0 || data != nullptr); + CHECK_LE(byte_length, i::JSArrayBuffer::kMaxByteLength); i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); LOG_API(i_isolate, ArrayBuffer, New); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); @@ -7687,9 +7595,8 @@ Local<ArrayBuffer> v8::ArrayBufferView::Buffer() { size_t v8::ArrayBufferView::CopyContents(void* dest, size_t byte_length) { i::Handle<i::JSArrayBufferView> self = Utils::OpenHandle(this); - size_t byte_offset = i::NumberToSize(self->byte_offset()); - size_t bytes_to_copy = - i::Min(byte_length, i::NumberToSize(self->byte_length())); + size_t byte_offset = self->byte_offset(); + size_t bytes_to_copy = i::Min(byte_length, self->byte_length()); if (bytes_to_copy) { i::DisallowHeapAllocation no_gc; i::Isolate* isolate = self->GetIsolate(); @@ -7720,19 +7627,19 @@ bool v8::ArrayBufferView::HasBuffer() const { size_t v8::ArrayBufferView::ByteOffset() { i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); - return static_cast<size_t>(obj->byte_offset()->Number()); + return obj->WasNeutered() ? 0 : obj->byte_offset(); } size_t v8::ArrayBufferView::ByteLength() { i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); - return static_cast<size_t>(obj->byte_length()->Number()); + return obj->WasNeutered() ? 0 : obj->byte_length(); } size_t v8::TypedArray::Length() { i::Handle<i::JSTypedArray> obj = Utils::OpenHandle(this); - return obj->length_value(); + return obj->WasNeutered() ? 0 : obj->length_value(); } static_assert(v8::TypedArray::kMaxLength == i::Smi::kMaxValue, @@ -7840,9 +7747,8 @@ v8::SharedArrayBuffer::Contents::Contents( v8::SharedArrayBuffer::Contents v8::SharedArrayBuffer::GetContents() { i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle(this); - size_t byte_length = static_cast<size_t>(self->byte_length()->Number()); Contents contents( - self->backing_store(), byte_length, self->allocation_base(), + self->backing_store(), self->byte_length(), self->allocation_base(), self->allocation_length(), self->is_wasm_memory() ? ArrayBuffer::Allocator::AllocationMode::kReservation @@ -7858,7 +7764,7 @@ v8::SharedArrayBuffer::Contents v8::SharedArrayBuffer::GetContents() { size_t v8::SharedArrayBuffer::ByteLength() const { i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this); - return static_cast<size_t>(obj->byte_length()->Number()); + return obj->byte_length(); } Local<SharedArrayBuffer> v8::SharedArrayBuffer::New(Isolate* isolate, @@ -7912,8 +7818,8 @@ Local<Symbol> v8::Symbol::New(Isolate* isolate, Local<String> name) { Local<Symbol> v8::Symbol::For(Isolate* isolate, Local<String> name) { i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); i::Handle<i::String> i_name = Utils::OpenHandle(*name); - return Utils::ToLocal(i_isolate->SymbolFor( - i::Heap::kPublicSymbolTableRootIndex, i_name, false)); + return Utils::ToLocal( + i_isolate->SymbolFor(i::RootIndex::kPublicSymbolTable, i_name, false)); } @@ -7921,10 +7827,11 @@ Local<Symbol> v8::Symbol::ForApi(Isolate* isolate, Local<String> name) { i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); i::Handle<i::String> i_name = Utils::OpenHandle(*name); return Utils::ToLocal( - i_isolate->SymbolFor(i::Heap::kApiSymbolTableRootIndex, i_name, false)); + i_isolate->SymbolFor(i::RootIndex::kApiSymbolTable, i_name, false)); } #define WELL_KNOWN_SYMBOLS(V) \ + V(AsyncIterator, async_iterator) \ V(HasInstance, has_instance) \ V(IsConcatSpreadable, is_concat_spreadable) \ V(Iterator, iterator) \ @@ -7961,8 +7868,8 @@ Local<Private> v8::Private::New(Isolate* isolate, Local<String> name) { Local<Private> v8::Private::ForApi(Isolate* isolate, Local<String> name) { i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); i::Handle<i::String> i_name = Utils::OpenHandle(*name); - Local<Symbol> result = Utils::ToLocal(i_isolate->SymbolFor( - i::Heap::kApiPrivateSymbolTableRootIndex, i_name, true)); + Local<Symbol> result = Utils::ToLocal( + i_isolate->SymbolFor(i::RootIndex::kApiPrivateSymbolTable, i_name, true)); return v8::Local<Private>(reinterpret_cast<Private*>(*result)); } @@ -8003,7 +7910,6 @@ Local<Integer> v8::Integer::NewFromUnsigned(Isolate* isolate, uint32_t value) { } Local<BigInt> v8::BigInt::New(Isolate* isolate, int64_t value) { - CHECK(i::FLAG_harmony_bigint); i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(internal_isolate); i::Handle<i::BigInt> result = i::BigInt::FromInt64(internal_isolate, value); @@ -8011,7 +7917,6 @@ Local<BigInt> v8::BigInt::New(Isolate* isolate, int64_t value) { } Local<BigInt> v8::BigInt::NewFromUnsigned(Isolate* isolate, uint64_t value) { - CHECK(i::FLAG_harmony_bigint); i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(internal_isolate); i::Handle<i::BigInt> result = i::BigInt::FromUint64(internal_isolate, value); @@ -8021,7 +7926,6 @@ Local<BigInt> v8::BigInt::NewFromUnsigned(Isolate* isolate, uint64_t value) { MaybeLocal<BigInt> v8::BigInt::NewFromWords(Local<Context> context, int sign_bit, int word_count, const uint64_t* words) { - CHECK(i::FLAG_harmony_bigint); i::Isolate* isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate()); ENTER_V8_NO_SCRIPT(isolate, context, BigInt, NewFromWords, MaybeLocal<BigInt>(), InternalEscapableScope); @@ -8186,6 +8090,11 @@ void Isolate::SetEmbedderHeapTracer(EmbedderHeapTracer* tracer) { isolate->heap()->SetEmbedderHeapTracer(tracer); } +EmbedderHeapTracer* Isolate::GetEmbedderHeapTracer() { + i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); + return isolate->heap()->GetEmbedderHeapTracer(); +} + void Isolate::SetGetExternallyAllocatedMemoryInBytesCallback( GetExternallyAllocatedMemoryInBytesCallback callback) { i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); @@ -8225,9 +8134,9 @@ void Isolate::RequestGarbageCollectionForTesting(GarbageCollectionType type) { kGCCallbackFlagForced); } else { DCHECK_EQ(kFullGarbageCollection, type); - reinterpret_cast<i::Isolate*>(this)->heap()->CollectAllGarbage( - i::Heap::kAbortIncrementalMarkingMask, - i::GarbageCollectionReason::kTesting, kGCCallbackFlagForced); + reinterpret_cast<i::Isolate*>(this)->heap()->PreciseCollectAllGarbage( + i::Heap::kNoGCFlags, i::GarbageCollectionReason::kTesting, + kGCCallbackFlagForced); } } @@ -8296,7 +8205,11 @@ void Isolate::Initialize(Isolate* isolate, if (params.entry_hook || !i::Snapshot::Initialize(i_isolate)) { // If snapshot data was provided and we failed to deserialize it must // have been corrupted. - CHECK_NULL(i_isolate->snapshot_blob()); + if (i_isolate->snapshot_blob() != nullptr) { + FATAL( + "Failed to deserialize the V8 snapshot blob. This can mean that the " + "snapshot blob file is corrupted or missing."); + } base::ElapsedTimer timer; if (i::FLAG_profile_deserialization) timer.Start(); i_isolate->Init(nullptr); @@ -8366,6 +8279,11 @@ void Isolate::SetHostInitializeImportMetaObjectCallback( isolate->SetHostInitializeImportMetaObjectCallback(callback); } +void Isolate::SetPrepareStackTraceCallback(PrepareStackTraceCallback callback) { + i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); + isolate->SetPrepareStackTraceCallback(callback); +} + Isolate::DisallowJavascriptExecutionScope::DisallowJavascriptExecutionScope( Isolate* isolate, Isolate::DisallowJavascriptExecutionScope::OnFailure on_failure) @@ -8791,17 +8709,17 @@ void Isolate::SetStackLimit(uintptr_t stack_limit) { void Isolate::GetCodeRange(void** start, size_t* length_in_bytes) { i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); - if (isolate->heap()->memory_allocator()->code_range()->valid()) { - *start = reinterpret_cast<void*>( - isolate->heap()->memory_allocator()->code_range()->start()); - *length_in_bytes = - isolate->heap()->memory_allocator()->code_range()->size(); - } else { - *start = nullptr; - *length_in_bytes = 0; - } + const base::AddressRegion& code_range = + isolate->heap()->memory_allocator()->code_range(); + *start = reinterpret_cast<void*>(code_range.begin()); + *length_in_bytes = code_range.size(); } +MemoryRange Isolate::GetEmbeddedCodeRange() { + i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); + return {reinterpret_cast<const void*>(isolate->embedded_blob()), + isolate->embedded_blob_size()}; +} #define CALLBACK_SETTER(ExternalName, Type, InternalName) \ void Isolate::Set##ExternalName(Type callback) { \ @@ -8986,9 +8904,6 @@ 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; @@ -9008,9 +8923,6 @@ 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; @@ -9192,7 +9104,10 @@ int debug::Script::ColumnOffset() const { std::vector<int> debug::Script::LineEnds() const { i::Handle<i::Script> script = Utils::OpenHandle(this); - if (script->type() == i::Script::TYPE_WASM) return std::vector<int>(); + if (script->type() == i::Script::TYPE_WASM && + this->SourceMappingURL().IsEmpty()) { + return std::vector<int>(); + } i::Isolate* isolate = script->GetIsolate(); i::HandleScope scope(isolate); i::Script::InitLineEnds(script); @@ -9281,7 +9196,8 @@ bool debug::Script::GetPossibleBreakpoints( std::vector<debug::BreakLocation>* locations) const { CHECK(!start.IsEmpty()); i::Handle<i::Script> script = Utils::OpenHandle(this); - if (script->type() == i::Script::TYPE_WASM) { + if (script->type() == i::Script::TYPE_WASM && + this->SourceMappingURL().IsEmpty()) { i::WasmModuleObject* module_object = i::WasmModuleObject::cast(script->wasm_module_object()); return module_object->GetPossibleBreakpoints(start, end, locations); @@ -9332,9 +9248,13 @@ bool debug::Script::GetPossibleBreakpoints( int debug::Script::GetSourceOffset(const debug::Location& location) const { i::Handle<i::Script> script = Utils::OpenHandle(this); if (script->type() == i::Script::TYPE_WASM) { - return i::WasmModuleObject::cast(script->wasm_module_object()) - ->GetFunctionOffset(location.GetLineNumber()) + - location.GetColumnNumber(); + if (this->SourceMappingURL().IsEmpty()) { + return i::WasmModuleObject::cast(script->wasm_module_object()) + ->GetFunctionOffset(location.GetLineNumber()) + + location.GetColumnNumber(); + } + DCHECK_EQ(0, location.GetLineNumber()); + return location.GetColumnNumber(); } int line = std::max(location.GetLineNumber() - script->line_offset(), 0); @@ -9777,10 +9697,10 @@ int debug::GetNativeAccessorDescriptor(v8::Local<v8::Context> context, } auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate()); int result = 0; -#define IS_BUILTIN_ACESSOR(name, _) \ +#define IS_BUILTIN_ACESSOR(_, name, ...) \ if (*structure == *isolate->factory()->name##_accessor()) \ result |= static_cast<int>(debug::NativeAccessorType::IsBuiltin); - ACCESSOR_INFO_LIST(IS_BUILTIN_ACESSOR) + ACCESSOR_INFO_LIST_GENERATOR(IS_BUILTIN_ACESSOR, /* not used */) #undef IS_BUILTIN_ACESSOR i::Handle<i::AccessorInfo> accessor_info = i::Handle<i::AccessorInfo>::cast(structure); @@ -9826,7 +9746,7 @@ debug::PostponeInterruptsScope::PostponeInterruptsScope(v8::Isolate* isolate) new i::PostponeInterruptsScope(reinterpret_cast<i::Isolate*>(isolate), i::StackGuard::API_INTERRUPT)) {} -debug::PostponeInterruptsScope::~PostponeInterruptsScope() {} +debug::PostponeInterruptsScope::~PostponeInterruptsScope() = default; Local<String> CpuProfileNode::GetFunctionName() const { const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); @@ -9950,6 +9870,47 @@ debug::TypeProfile::ScriptData debug::TypeProfile::GetScriptData( return ScriptData(i, type_profile_); } +v8::MaybeLocal<v8::Value> debug::WeakMap::Get(v8::Local<v8::Context> context, + v8::Local<v8::Value> key) { + PREPARE_FOR_EXECUTION(context, WeakMap, Get, Value); + auto self = Utils::OpenHandle(this); + Local<Value> result; + i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)}; + has_pending_exception = + !ToLocal<Value>(i::Execution::Call(isolate, isolate->weakmap_get(), self, + arraysize(argv), argv), + &result); + RETURN_ON_FAILED_EXECUTION(Value); + RETURN_ESCAPED(result); +} + +v8::MaybeLocal<debug::WeakMap> debug::WeakMap::Set( + v8::Local<v8::Context> context, v8::Local<v8::Value> key, + v8::Local<v8::Value> value) { + PREPARE_FOR_EXECUTION(context, WeakMap, Set, WeakMap); + auto self = Utils::OpenHandle(this); + i::Handle<i::Object> result; + i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key), + Utils::OpenHandle(*value)}; + has_pending_exception = !i::Execution::Call(isolate, isolate->weakmap_set(), + self, arraysize(argv), argv) + .ToHandle(&result); + RETURN_ON_FAILED_EXECUTION(WeakMap); + RETURN_ESCAPED(Local<WeakMap>::Cast(Utils::ToLocal(result))); +} + +Local<debug::WeakMap> debug::WeakMap::New(v8::Isolate* isolate) { + i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); + LOG_API(i_isolate, WeakMap, New); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); + i::Handle<i::JSWeakMap> obj = i_isolate->factory()->NewJSWeakMap(); + return ToApiHandle<debug::WeakMap>(obj); +} + +debug::WeakMap* debug::WeakMap::Cast(v8::Value* value) { + return static_cast<debug::WeakMap*>(value); +} + const char* CpuProfileNode::GetFunctionNameStr() const { const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); return node->entry()->name(); @@ -10134,11 +10095,6 @@ void CpuProfiler::SetIdle(bool is_idle) { isolate->SetIdle(is_idle); } -void CpuProfiler::UseDetailedSourcePositionsForProfiling(Isolate* isolate) { - reinterpret_cast<i::Isolate*>(isolate) - ->set_detailed_source_positions_for_profiling(true); -} - uintptr_t CodeEvent::GetCodeStartAddress() { return reinterpret_cast<i::CodeEvent*>(this)->code_start_address; } @@ -10546,9 +10502,9 @@ void EmbedderHeapTracer::GarbageCollectionForTesting( CHECK(i::FLAG_expose_gc); i::Heap* const heap = reinterpret_cast<i::Isolate*>(isolate_)->heap(); heap->SetEmbedderStackStateForNextFinalizaton(stack_state); - heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask, - i::GarbageCollectionReason::kTesting, - kGCCallbackFlagForced); + heap->PreciseCollectAllGarbage(i::Heap::kNoGCFlags, + i::GarbageCollectionReason::kTesting, + kGCCallbackFlagForced); } bool EmbedderHeapTracer::AdvanceTracing(double deadline_in_ms) { |