Commit 32dfefac authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[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 <cbruni@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72076}
parent fe191e8d
...@@ -47,11 +47,12 @@ class BigIntObject; ...@@ -47,11 +47,12 @@ class BigIntObject;
class Boolean; class Boolean;
class BooleanObject; class BooleanObject;
class CFunction; class CFunction;
class CallHandlerHelper;
class Context; class Context;
class CppHeap; class CppHeap;
struct CppHeapCreateParams;
class Data; class Data;
class Date; class Date;
class EscapableHandleScope;
class External; class External;
class Function; class Function;
class FunctionTemplate; class FunctionTemplate;
...@@ -60,8 +61,7 @@ class ImplementationUtilities; ...@@ -60,8 +61,7 @@ class ImplementationUtilities;
class Int32; class Int32;
class Integer; class Integer;
class Isolate; class Isolate;
template <class T> class Isolate;
class Maybe;
class MicrotaskQueue; class MicrotaskQueue;
class Name; class Name;
class Number; class Number;
...@@ -71,6 +71,8 @@ class ObjectOperationDescriptor; ...@@ -71,6 +71,8 @@ class ObjectOperationDescriptor;
class ObjectTemplate; class ObjectTemplate;
class Platform; class Platform;
class Primitive; class Primitive;
class PrimitiveArray;
class Private;
class Promise; class Promise;
class PropertyDescriptor; class PropertyDescriptor;
class Proxy; class Proxy;
...@@ -78,75 +80,73 @@ class RawOperationDescriptor; ...@@ -78,75 +80,73 @@ class RawOperationDescriptor;
class Script; class Script;
class SharedArrayBuffer; class SharedArrayBuffer;
class Signature; class Signature;
class StartupData;
class StackFrame; class StackFrame;
class StackTrace; class StackTrace;
class StartupData;
class String; class String;
class StringObject; class StringObject;
class Symbol; class Symbol;
class SymbolObject; class SymbolObject;
class TracedReferenceBase; class TracedReferenceBase;
class PrimitiveArray;
class Private;
class Uint32; class Uint32;
class Utils; class Utils;
class Value; class Value;
class WasmMemoryObject; class WasmMemoryObject;
class WasmModuleObject; class WasmModuleObject;
template <class T> class Local; struct CppHeapCreateParams;
template <class T> template <class K, class V, class T>
class MaybeLocal; class GlobalValueMap;
template <class T> class Eternal; template <class K, class V, class T>
class PersistentValueMapBase;
template<class T> class NonCopyablePersistentTraits; template<class T> class NonCopyablePersistentTraits;
template<class T> class PersistentBase; template <class T, class M = NonCopyablePersistentTraits<T>>
template <class T, class M = NonCopyablePersistentTraits<T> >
class Persistent; class Persistent;
template <class T> template <class T>
class BasicTracedReference;
template <class T>
class Eternal;
template <class T>
class Global; class Global;
template <class T> template <class T>
class Local;
template <class T>
class Maybe;
template <class T>
class MaybeLocal;
template <class T>
class TracedGlobal; class TracedGlobal;
template <class T> template <class T>
class TracedReference; class TracedReference;
template <class T>
class BasicTracedReference;
template<class K, class V, class T> class PersistentValueMap; template<class K, class V, class T> class PersistentValueMap;
template <class K, class V, class T>
class PersistentValueMapBase;
template <class K, class V, class T>
class GlobalValueMap;
template<class V, class T> class PersistentValueVector;
template<class T, class P> class WeakCallbackObject; template<class T, class P> class WeakCallbackObject;
class FunctionTemplate; template <class T>
class ObjectTemplate; class PersistentBase;
template <class V, class T>
class PersistentValueVector;
template<typename T> class FunctionCallbackInfo; template<typename T> class FunctionCallbackInfo;
template<typename T> class PropertyCallbackInfo; template<typename T> class PropertyCallbackInfo;
class StackTrace;
class StackFrame;
class Isolate;
class CallHandlerHelper;
class EscapableHandleScope;
template<typename T> class ReturnValue; template<typename T> class ReturnValue;
namespace internal { namespace internal {
enum class ArgumentsType;
template <ArgumentsType>
class Arguments;
class BasicTracedReferenceExtractor; class BasicTracedReferenceExtractor;
template <typename T> class ExternalString;
class CustomArguments;
class FunctionCallbackArguments; class FunctionCallbackArguments;
class GlobalHandles; class GlobalHandles;
class Heap; class Heap;
class HeapObject; class HeapObject;
class ExternalString;
class Isolate; class Isolate;
class LocalEmbedderHeapTracer; class LocalEmbedderHeapTracer;
class MicrotaskQueue; class MicrotaskQueue;
class PropertyCallbackArguments; class PropertyCallbackArguments;
class ReadOnlyHeap; class ReadOnlyHeap;
class ScopedExternalStringLock; class ScopedExternalStringLock;
struct ScriptStreamingData;
class ThreadLocalTop; class ThreadLocalTop;
struct ScriptStreamingData;
enum class ArgumentsType;
template <ArgumentsType>
class Arguments;
template <typename T>
class CustomArguments;
namespace wasm { namespace wasm {
class NativeModule; class NativeModule;
......
...@@ -1314,9 +1314,9 @@ void Context::SetAlignedPointerInEmbedderData(int index, void* value) { ...@@ -1314,9 +1314,9 @@ void Context::SetAlignedPointerInEmbedderData(int index, void* value) {
// --- T e m p l a t e --- // --- T e m p l a t e ---
static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) { static void InitializeTemplate(i::TemplateInfo that, int type) {
that->set_number_of_properties(0); that.set_number_of_properties(0);
that->set_tag(type); that.set_tag(type);
} }
void Template::Set(v8::Local<Name> name, v8::Local<Data> value, void Template::Set(v8::Local<Name> name, v8::Local<Data> value,
...@@ -1364,10 +1364,9 @@ void Template::SetAccessorProperty(v8::Local<v8::Name> name, ...@@ -1364,10 +1364,9 @@ void Template::SetAccessorProperty(v8::Local<v8::Name> name,
} }
// --- F u n c t i o n T e m p l a t e --- // --- F u n c t i o n T e m p l a t e ---
static void InitializeFunctionTemplate( static void InitializeFunctionTemplate(i::FunctionTemplateInfo info) {
i::Handle<i::FunctionTemplateInfo> info) {
InitializeTemplate(info, Consts::FUNCTION_TEMPLATE); InitializeTemplate(info, Consts::FUNCTION_TEMPLATE);
info->set_flag(0); info.set_flag(0);
} }
static Local<ObjectTemplate> ObjectTemplateNew( static Local<ObjectTemplate> ObjectTemplateNew(
...@@ -1419,7 +1418,8 @@ void FunctionTemplate::Inherit(v8::Local<FunctionTemplate> value) { ...@@ -1419,7 +1418,8 @@ void FunctionTemplate::Inherit(v8::Local<FunctionTemplate> value) {
static Local<FunctionTemplate> FunctionTemplateNew( static Local<FunctionTemplate> FunctionTemplateNew(
i::Isolate* isolate, FunctionCallback callback, v8::Local<Value> data, i::Isolate* isolate, FunctionCallback callback, v8::Local<Value> data,
v8::Local<Signature> signature, int length, bool do_not_cache, v8::Local<Signature> signature, int length, ConstructorBehavior behavior,
bool do_not_cache,
v8::Local<Private> cached_property_name = v8::Local<Private>(), v8::Local<Private> cached_property_name = v8::Local<Private>(),
SideEffectType side_effect_type = SideEffectType::kHasSideEffect, SideEffectType side_effect_type = SideEffectType::kHasSideEffect,
const CFunction* c_function = nullptr) { const CFunction* c_function = nullptr) {
...@@ -1430,29 +1430,31 @@ static Local<FunctionTemplate> FunctionTemplateNew( ...@@ -1430,29 +1430,31 @@ static Local<FunctionTemplate> FunctionTemplateNew(
{ {
// Disallow GC until all fields of obj have acceptable types. // Disallow GC until all fields of obj have acceptable types.
i::DisallowGarbageCollection no_gc; i::DisallowGarbageCollection no_gc;
InitializeFunctionTemplate(obj); i::FunctionTemplateInfo raw = *obj;
obj->set_length(length); InitializeFunctionTemplate(raw);
obj->set_do_not_cache(do_not_cache); raw.set_length(length);
raw.set_do_not_cache(do_not_cache);
int next_serial_number = i::FunctionTemplateInfo::kInvalidSerialNumber; int next_serial_number = i::FunctionTemplateInfo::kInvalidSerialNumber;
if (!do_not_cache) { if (!do_not_cache) {
next_serial_number = isolate->heap()->GetNextTemplateSerialNumber(); next_serial_number = isolate->heap()->GetNextTemplateSerialNumber();
} }
obj->set_serial_number(next_serial_number); raw.set_serial_number(next_serial_number);
} raw.set_undetectable(false);
if (callback != nullptr) { raw.set_needs_access_check(false);
Utils::ToLocal(obj)->SetCallHandler(callback, data, side_effect_type, raw.set_accept_any_receiver(true);
c_function);
}
obj->set_undetectable(false);
obj->set_needs_access_check(false);
obj->set_accept_any_receiver(true);
if (!signature.IsEmpty()) { if (!signature.IsEmpty()) {
obj->set_signature(*Utils::OpenHandle(*signature)); raw.set_signature(*Utils::OpenHandle(*signature));
} }
obj->set_cached_property_name( raw.set_cached_property_name(
cached_property_name.IsEmpty() cached_property_name.IsEmpty()
? i::ReadOnlyRoots(isolate).the_hole_value() ? i::ReadOnlyRoots(isolate).the_hole_value()
: *Utils::OpenHandle(*cached_property_name)); : *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);
}
return Utils::ToLocal(obj); return Utils::ToLocal(obj);
} }
...@@ -1465,10 +1467,9 @@ Local<FunctionTemplate> FunctionTemplate::New( ...@@ -1465,10 +1467,9 @@ Local<FunctionTemplate> FunctionTemplate::New(
// function templates when the isolate is created for serialization. // function templates when the isolate is created for serialization.
LOG_API(i_isolate, FunctionTemplate, New); LOG_API(i_isolate, FunctionTemplate, New);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
auto templ = auto templ = FunctionTemplateNew(i_isolate, callback, data, signature, length,
FunctionTemplateNew(i_isolate, callback, data, signature, length, false, behavior, false, Local<Private>(),
Local<Private>(), side_effect_type, c_function); side_effect_type, c_function);
if (behavior == ConstructorBehavior::kThrow) templ->RemovePrototype();
return templ; return templ;
} }
...@@ -1480,7 +1481,8 @@ Local<FunctionTemplate> FunctionTemplate::NewWithCache( ...@@ -1480,7 +1481,8 @@ Local<FunctionTemplate> FunctionTemplate::NewWithCache(
LOG_API(i_isolate, FunctionTemplate, NewWithCache); LOG_API(i_isolate, FunctionTemplate, NewWithCache);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
return FunctionTemplateNew(i_isolate, callback, data, signature, length, return FunctionTemplateNew(i_isolate, callback, data, signature, length,
false, cache_property, side_effect_type); ConstructorBehavior::kAllow, false, cache_property,
side_effect_type);
} }
Local<Signature> Signature::New(Isolate* isolate, Local<Signature> Signature::New(Isolate* isolate,
...@@ -1651,16 +1653,18 @@ static Local<ObjectTemplate> ObjectTemplateNew( ...@@ -1651,16 +1653,18 @@ static Local<ObjectTemplate> ObjectTemplateNew(
{ {
// Disallow GC until all fields of obj have acceptable types. // Disallow GC until all fields of obj have acceptable types.
i::DisallowGarbageCollection no_gc; 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; int next_serial_number = 0;
if (!do_not_cache) { if (!do_not_cache) {
next_serial_number = isolate->heap()->GetNextTemplateSerialNumber(); next_serial_number = isolate->heap()->GetNextTemplateSerialNumber();
} }
obj->set_serial_number(next_serial_number); raw.set_serial_number(next_serial_number);
obj->set_data(0); if (!constructor.IsEmpty()) {
raw.set_constructor(*Utils::OpenHandle(*constructor));
}
} }
if (!constructor.IsEmpty())
obj->set_constructor(*Utils::OpenHandle(*constructor));
return Utils::ToLocal(obj); return Utils::ToLocal(obj);
} }
...@@ -5034,8 +5038,7 @@ MaybeLocal<Function> Function::New(Local<Context> context, ...@@ -5034,8 +5038,7 @@ MaybeLocal<Function> Function::New(Local<Context> context,
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
auto templ = auto templ =
FunctionTemplateNew(isolate, callback, data, Local<Signature>(), length, FunctionTemplateNew(isolate, callback, data, Local<Signature>(), length,
true, Local<Private>(), side_effect_type); behavior, true, Local<Private>(), side_effect_type);
if (behavior == ConstructorBehavior::kThrow) templ->RemovePrototype();
return templ->GetFunction(context); return templ->GetFunction(context);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment