From 32dfefac49da56ef9fea27d690d10b500d2406bf Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Tue, 12 Jan 2021 15:12:18 +0100 Subject: [PATCH] [api] Dehandlify FunctionTemplate initialization Drive-by-fix: Sort forward declarations in v8.h Bug: v8:11263 Change-Id: I2d1b5324e0cddd54a1bec440e1aebcebef393a6d Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2581958 Commit-Queue: Camillo Bruni Reviewed-by: Leszek Swirski Cr-Commit-Position: refs/heads/master@{#72076} --- include/v8.h | 66 +++++++++++++++++++++++------------------------ src/api/api.cc | 69 ++++++++++++++++++++++++++------------------------ 2 files changed, 69 insertions(+), 66 deletions(-) diff --git a/include/v8.h b/include/v8.h index cc633ba2ac..439613c3c9 100644 --- a/include/v8.h +++ b/include/v8.h @@ -47,11 +47,12 @@ class BigIntObject; class Boolean; class BooleanObject; class CFunction; +class CallHandlerHelper; class Context; class CppHeap; -struct CppHeapCreateParams; class Data; class Date; +class EscapableHandleScope; class External; class Function; class FunctionTemplate; @@ -60,8 +61,7 @@ class ImplementationUtilities; class Int32; class Integer; class Isolate; -template -class Maybe; +class Isolate; class MicrotaskQueue; class Name; class Number; @@ -71,6 +71,8 @@ class ObjectOperationDescriptor; class ObjectTemplate; class Platform; class Primitive; +class PrimitiveArray; +class Private; class Promise; class PropertyDescriptor; class Proxy; @@ -78,75 +80,73 @@ class RawOperationDescriptor; class Script; class SharedArrayBuffer; class Signature; -class StartupData; class StackFrame; class StackTrace; +class StartupData; class String; class StringObject; class Symbol; class SymbolObject; class TracedReferenceBase; -class PrimitiveArray; -class Private; class Uint32; class Utils; class Value; class WasmMemoryObject; class WasmModuleObject; -template class Local; -template -class MaybeLocal; -template class Eternal; +struct CppHeapCreateParams; +template +class GlobalValueMap; +template +class PersistentValueMapBase; template class NonCopyablePersistentTraits; -template class PersistentBase; -template > +template > class Persistent; template +class BasicTracedReference; +template +class Eternal; +template class Global; template +class Local; +template +class Maybe; +template +class MaybeLocal; +template class TracedGlobal; template class TracedReference; -template -class BasicTracedReference; template class PersistentValueMap; -template -class PersistentValueMapBase; -template -class GlobalValueMap; -template class PersistentValueVector; template class WeakCallbackObject; -class FunctionTemplate; -class ObjectTemplate; +template +class PersistentBase; +template +class PersistentValueVector; template class FunctionCallbackInfo; template class PropertyCallbackInfo; -class StackTrace; -class StackFrame; -class Isolate; -class CallHandlerHelper; -class EscapableHandleScope; template class ReturnValue; namespace internal { -enum class ArgumentsType; -template -class Arguments; class BasicTracedReferenceExtractor; -template -class CustomArguments; +class ExternalString; class FunctionCallbackArguments; class GlobalHandles; class Heap; class HeapObject; -class ExternalString; class Isolate; class LocalEmbedderHeapTracer; class MicrotaskQueue; class PropertyCallbackArguments; class ReadOnlyHeap; class ScopedExternalStringLock; -struct ScriptStreamingData; class ThreadLocalTop; +struct ScriptStreamingData; +enum class ArgumentsType; +template +class Arguments; +template +class CustomArguments; namespace wasm { class NativeModule; diff --git a/src/api/api.cc b/src/api/api.cc index 325a25fa1e..bace7f4fbd 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -1314,9 +1314,9 @@ void Context::SetAlignedPointerInEmbedderData(int index, void* value) { // --- T e m p l a t e --- -static void InitializeTemplate(i::Handle that, int type) { - that->set_number_of_properties(0); - that->set_tag(type); +static void InitializeTemplate(i::TemplateInfo that, int type) { + that.set_number_of_properties(0); + that.set_tag(type); } void Template::Set(v8::Local name, v8::Local value, @@ -1364,10 +1364,9 @@ void Template::SetAccessorProperty(v8::Local name, } // --- F u n c t i o n T e m p l a t e --- -static void InitializeFunctionTemplate( - i::Handle info) { +static void InitializeFunctionTemplate(i::FunctionTemplateInfo info) { InitializeTemplate(info, Consts::FUNCTION_TEMPLATE); - info->set_flag(0); + info.set_flag(0); } static Local ObjectTemplateNew( @@ -1419,7 +1418,8 @@ void FunctionTemplate::Inherit(v8::Local value) { static Local FunctionTemplateNew( i::Isolate* isolate, FunctionCallback callback, v8::Local data, - v8::Local signature, int length, bool do_not_cache, + v8::Local signature, int length, ConstructorBehavior behavior, + bool do_not_cache, v8::Local cached_property_name = v8::Local(), SideEffectType side_effect_type = SideEffectType::kHasSideEffect, const CFunction* c_function = nullptr) { @@ -1430,29 +1430,31 @@ static Local FunctionTemplateNew( { // Disallow GC until all fields of obj have acceptable types. i::DisallowGarbageCollection no_gc; - InitializeFunctionTemplate(obj); - obj->set_length(length); - obj->set_do_not_cache(do_not_cache); + i::FunctionTemplateInfo raw = *obj; + InitializeFunctionTemplate(raw); + raw.set_length(length); + raw.set_do_not_cache(do_not_cache); int next_serial_number = i::FunctionTemplateInfo::kInvalidSerialNumber; if (!do_not_cache) { next_serial_number = isolate->heap()->GetNextTemplateSerialNumber(); } - obj->set_serial_number(next_serial_number); + raw.set_serial_number(next_serial_number); + raw.set_undetectable(false); + raw.set_needs_access_check(false); + raw.set_accept_any_receiver(true); + if (!signature.IsEmpty()) { + raw.set_signature(*Utils::OpenHandle(*signature)); + } + raw.set_cached_property_name( + cached_property_name.IsEmpty() + ? i::ReadOnlyRoots(isolate).the_hole_value() + : *Utils::OpenHandle(*cached_property_name)); + if (behavior == ConstructorBehavior::kThrow) raw.set_remove_prototype(true); } if (callback != nullptr) { Utils::ToLocal(obj)->SetCallHandler(callback, data, side_effect_type, c_function); } - obj->set_undetectable(false); - obj->set_needs_access_check(false); - obj->set_accept_any_receiver(true); - if (!signature.IsEmpty()) { - obj->set_signature(*Utils::OpenHandle(*signature)); - } - obj->set_cached_property_name( - cached_property_name.IsEmpty() - ? i::ReadOnlyRoots(isolate).the_hole_value() - : *Utils::OpenHandle(*cached_property_name)); return Utils::ToLocal(obj); } @@ -1465,10 +1467,9 @@ Local FunctionTemplate::New( // function templates when the isolate is created for serialization. LOG_API(i_isolate, FunctionTemplate, New); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); - auto templ = - FunctionTemplateNew(i_isolate, callback, data, signature, length, false, - Local(), side_effect_type, c_function); - if (behavior == ConstructorBehavior::kThrow) templ->RemovePrototype(); + auto templ = FunctionTemplateNew(i_isolate, callback, data, signature, length, + behavior, false, Local(), + side_effect_type, c_function); return templ; } @@ -1480,7 +1481,8 @@ Local FunctionTemplate::NewWithCache( LOG_API(i_isolate, FunctionTemplate, NewWithCache); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); return FunctionTemplateNew(i_isolate, callback, data, signature, length, - false, cache_property, side_effect_type); + ConstructorBehavior::kAllow, false, cache_property, + side_effect_type); } Local Signature::New(Isolate* isolate, @@ -1651,16 +1653,18 @@ static Local ObjectTemplateNew( { // Disallow GC until all fields of obj have acceptable types. i::DisallowGarbageCollection no_gc; - InitializeTemplate(obj, Consts::OBJECT_TEMPLATE); + i::ObjectTemplateInfo raw = *obj; + InitializeTemplate(raw, Consts::OBJECT_TEMPLATE); + raw.set_data(0); int next_serial_number = 0; if (!do_not_cache) { next_serial_number = isolate->heap()->GetNextTemplateSerialNumber(); } - obj->set_serial_number(next_serial_number); - obj->set_data(0); + raw.set_serial_number(next_serial_number); + if (!constructor.IsEmpty()) { + raw.set_constructor(*Utils::OpenHandle(*constructor)); + } } - if (!constructor.IsEmpty()) - obj->set_constructor(*Utils::OpenHandle(*constructor)); return Utils::ToLocal(obj); } @@ -5034,8 +5038,7 @@ MaybeLocal Function::New(Local context, ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); auto templ = FunctionTemplateNew(isolate, callback, data, Local(), length, - true, Local(), side_effect_type); - if (behavior == ConstructorBehavior::kThrow) templ->RemovePrototype(); + behavior, true, Local(), side_effect_type); return templ->GetFunction(context); }