Commit 44a1544c authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

v8binding: Supports the new V8 Fast API mechanism

Supports property installation of IDL operations with enabling
V8 Fast API mechanism.

This is a preparation of https://crrev.com/c/2315680 .

Bug: 1052746
Change-Id: I0f1a4ac0e12f32f2db32f161b3fe65198052a7cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2361939
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801457}
parent 9d250d4e
...@@ -77,6 +77,7 @@ LenientThis ...@@ -77,6 +77,7 @@ LenientThis
LogActivity=|GetterOnly|SetterOnly LogActivity=|GetterOnly|SetterOnly
LogAllWorlds LogAllWorlds
NewObject NewObject
NoAllocDirectCall
Measure Measure
MeasureAs=* MeasureAs=*
NamedConstructor=* NamedConstructor=*
......
...@@ -463,7 +463,8 @@ void InstallMethodInternal(v8::Isolate* isolate, ...@@ -463,7 +463,8 @@ void InstallMethodInternal(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> interface_template, v8::Local<v8::FunctionTemplate> interface_template,
v8::Local<v8::Signature> signature, v8::Local<v8::Signature> signature,
const Configuration& method, const Configuration& method,
const DOMWrapperWorld& world) { const DOMWrapperWorld& world,
const v8::CFunction* v8_c_function = nullptr) {
if (!WorldConfigurationApplies(method, world)) if (!WorldConfigurationApplies(method, world))
return; return;
...@@ -488,7 +489,7 @@ void InstallMethodInternal(v8::Isolate* isolate, ...@@ -488,7 +489,7 @@ void InstallMethodInternal(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> function_template = v8::Local<v8::FunctionTemplate> function_template =
v8::FunctionTemplate::New( v8::FunctionTemplate::New(
isolate, callback, v8::Local<v8::Value>(), signature, method.length, isolate, callback, v8::Local<v8::Value>(), signature, method.length,
v8::ConstructorBehavior::kAllow, side_effect_type); v8::ConstructorBehavior::kAllow, side_effect_type, v8_c_function);
function_template->RemovePrototype(); function_template->RemovePrototype();
function_template->SetAcceptAnyReceiver( function_template->SetAcceptAnyReceiver(
method.access_check_configuration == method.access_check_configuration ==
...@@ -792,6 +793,22 @@ void V8DOMConfiguration::InstallMethods( ...@@ -792,6 +793,22 @@ void V8DOMConfiguration::InstallMethods(
interface_template, signature, methods[i], world); interface_template, signature, methods[i], world);
} }
void V8DOMConfiguration::InstallMethods(
v8::Isolate* isolate,
const DOMWrapperWorld& world,
v8::Local<v8::ObjectTemplate> instance_template,
v8::Local<v8::ObjectTemplate> prototype_template,
v8::Local<v8::FunctionTemplate> interface_template,
v8::Local<v8::Signature> signature,
const NoAllocDirectCallMethodConfiguration* methods,
size_t method_count) {
for (size_t i = 0; i < method_count; ++i) {
InstallMethodInternal(
isolate, instance_template, prototype_template, interface_template,
signature, methods[i].method_config, world, &methods[i].v8_c_function);
}
}
void V8DOMConfiguration::InstallMethod( void V8DOMConfiguration::InstallMethod(
v8::Isolate* isolate, v8::Isolate* isolate,
const DOMWrapperWorld& world, const DOMWrapperWorld& world,
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/bindings/v8_dom_wrapper.h" #include "third_party/blink/renderer/platform/bindings/v8_dom_wrapper.h"
#include "third_party/blink/renderer/platform/bindings/v8_private_property.h" #include "third_party/blink/renderer/platform/bindings/v8_private_property.h"
#include "v8/include/v8-fast-api-calls.h"
#include "v8/include/v8.h" #include "v8/include/v8.h"
namespace blink { namespace blink {
...@@ -89,9 +90,12 @@ class CORE_EXPORT V8DOMConfiguration final { ...@@ -89,9 +90,12 @@ class CORE_EXPORT V8DOMConfiguration final {
// AttributeConfiguration translates into calls to SetNativeDataProperty() on // AttributeConfiguration translates into calls to SetNativeDataProperty() on
// either of instance or prototype object (or their object template). // either of instance or prototype object (or their object template).
struct AttributeConfiguration { struct AttributeConfiguration {
AttributeConfiguration& operator=(const AttributeConfiguration&) = delete;
DISALLOW_NEW(); DISALLOW_NEW();
const char* const name;
public:
AttributeConfiguration& operator=(const AttributeConfiguration&) = delete;
const char* name;
v8::AccessorNameGetterCallback getter; v8::AccessorNameGetterCallback getter;
v8::AccessorNameSetterCallback setter; v8::AccessorNameSetterCallback setter;
...@@ -140,9 +144,12 @@ class CORE_EXPORT V8DOMConfiguration final { ...@@ -140,9 +144,12 @@ class CORE_EXPORT V8DOMConfiguration final {
// either of instance, prototype, or interface object (or their object // either of instance, prototype, or interface object (or their object
// template). // template).
struct AccessorConfiguration { struct AccessorConfiguration {
AccessorConfiguration& operator=(const AccessorConfiguration&) = delete;
DISALLOW_NEW(); DISALLOW_NEW();
const char* const name;
public:
AccessorConfiguration& operator=(const AccessorConfiguration&) = delete;
const char* name;
v8::FunctionCallback getter; v8::FunctionCallback getter;
v8::FunctionCallback setter; v8::FunctionCallback setter;
// V8PrivateProperty::CachedAccessor // V8PrivateProperty::CachedAccessor
...@@ -211,6 +218,9 @@ class CORE_EXPORT V8DOMConfiguration final { ...@@ -211,6 +218,9 @@ class CORE_EXPORT V8DOMConfiguration final {
// object's constants. It sets the constant on both the FunctionTemplate and // object's constants. It sets the constant on both the FunctionTemplate and
// the ObjectTemplate. PropertyAttributes is always ReadOnly. // the ObjectTemplate. PropertyAttributes is always ReadOnly.
struct ConstantConfiguration { struct ConstantConfiguration {
DISALLOW_NEW();
public:
constexpr ConstantConfiguration(const char* name, constexpr ConstantConfiguration(const char* name,
ConstantType type, ConstantType type,
int value) int value)
...@@ -220,8 +230,8 @@ class CORE_EXPORT V8DOMConfiguration final { ...@@ -220,8 +230,8 @@ class CORE_EXPORT V8DOMConfiguration final {
double value) double value)
: name(name), type(type), dvalue(value) {} : name(name), type(type), dvalue(value) {}
ConstantConfiguration& operator=(const ConstantConfiguration&) = delete; ConstantConfiguration& operator=(const ConstantConfiguration&) = delete;
DISALLOW_NEW();
const char* const name; const char* name;
ConstantType type; ConstantType type;
union { union {
int ivalue; int ivalue;
...@@ -243,8 +253,8 @@ class CORE_EXPORT V8DOMConfiguration final { ...@@ -243,8 +253,8 @@ class CORE_EXPORT V8DOMConfiguration final {
ConstantCallbackConfiguration& operator=( ConstantCallbackConfiguration& operator=(
const ConstantCallbackConfiguration&) = delete; const ConstantCallbackConfiguration&) = delete;
const char* const name; const char* name;
const v8::AccessorNameGetterCallback getter; v8::AccessorNameGetterCallback getter;
}; };
// Constant installation // Constant installation
...@@ -296,13 +306,16 @@ class CORE_EXPORT V8DOMConfiguration final { ...@@ -296,13 +306,16 @@ class CORE_EXPORT V8DOMConfiguration final {
// object's callbacks. It sets a method on instance, prototype or // object's callbacks. It sets a method on instance, prototype or
// interface object (or their object tepmplate). // interface object (or their object tepmplate).
struct MethodConfiguration { struct MethodConfiguration {
MethodConfiguration& operator=(const MethodConfiguration&) = delete;
DISALLOW_NEW(); DISALLOW_NEW();
public:
MethodConfiguration& operator=(const MethodConfiguration&) = delete;
v8::Local<v8::String> MethodName(v8::Isolate* isolate) const { v8::Local<v8::String> MethodName(v8::Isolate* isolate) const {
return V8AtomicString(isolate, name); return V8AtomicString(isolate, name);
} }
const char* const name; const char* name;
v8::FunctionCallback callback; v8::FunctionCallback callback;
int length; int length;
// v8::PropertyAttribute // v8::PropertyAttribute
...@@ -320,15 +333,18 @@ class CORE_EXPORT V8DOMConfiguration final { ...@@ -320,15 +333,18 @@ class CORE_EXPORT V8DOMConfiguration final {
}; };
struct SymbolKeyedMethodConfiguration { struct SymbolKeyedMethodConfiguration {
DISALLOW_NEW();
public:
SymbolKeyedMethodConfiguration& operator=( SymbolKeyedMethodConfiguration& operator=(
const SymbolKeyedMethodConfiguration&) = delete; const SymbolKeyedMethodConfiguration&) = delete;
DISALLOW_NEW();
v8::Local<v8::Name> MethodName(v8::Isolate* isolate) const { v8::Local<v8::Name> MethodName(v8::Isolate* isolate) const {
return get_symbol(isolate); return get_symbol(isolate);
} }
v8::Local<v8::Symbol> (*get_symbol)(v8::Isolate*); v8::Local<v8::Symbol> (*get_symbol)(v8::Isolate*);
const char* const symbol_alias; const char* symbol_alias;
v8::FunctionCallback callback; v8::FunctionCallback callback;
// SymbolKeyedMethodConfiguration doesn't support per-world bindings. // SymbolKeyedMethodConfiguration doesn't support per-world bindings.
int length; int length;
...@@ -344,6 +360,17 @@ class CORE_EXPORT V8DOMConfiguration final { ...@@ -344,6 +360,17 @@ class CORE_EXPORT V8DOMConfiguration final {
unsigned side_effect_type : 1; unsigned side_effect_type : 1;
}; };
struct NoAllocDirectCallMethodConfiguration {
DISALLOW_NEW();
public:
NoAllocDirectCallMethodConfiguration& operator=(
const NoAllocDirectCallMethodConfiguration&) = delete;
MethodConfiguration method_config;
v8::CFunction v8_c_function;
};
static void InstallMethods(v8::Isolate*, static void InstallMethods(v8::Isolate*,
const DOMWrapperWorld&, const DOMWrapperWorld&,
v8::Local<v8::ObjectTemplate> instance_template, v8::Local<v8::ObjectTemplate> instance_template,
...@@ -352,6 +379,15 @@ class CORE_EXPORT V8DOMConfiguration final { ...@@ -352,6 +379,15 @@ class CORE_EXPORT V8DOMConfiguration final {
v8::Local<v8::Signature>, v8::Local<v8::Signature>,
const MethodConfiguration*, const MethodConfiguration*,
size_t method_count); size_t method_count);
static void InstallMethods(v8::Isolate*,
const DOMWrapperWorld&,
v8::Local<v8::ObjectTemplate> instance_template,
v8::Local<v8::ObjectTemplate> prototype_template,
v8::Local<v8::FunctionTemplate> interface_template,
v8::Local<v8::Signature>,
const NoAllocDirectCallMethodConfiguration*,
size_t method_count);
static void InstallMethod(v8::Isolate*, static void InstallMethod(v8::Isolate*,
const DOMWrapperWorld&, const DOMWrapperWorld&,
v8::Local<v8::ObjectTemplate> instance_template, v8::Local<v8::ObjectTemplate> instance_template,
......
...@@ -518,8 +518,8 @@ class IdlCompiler(object): ...@@ -518,8 +518,8 @@ class IdlCompiler(object):
def _propagate_extattrs_to_overload_group(self): def _propagate_extattrs_to_overload_group(self):
ANY_OF = ('CrossOrigin', 'Custom', 'LegacyUnforgeable', 'LenientThis', ANY_OF = ('CrossOrigin', 'Custom', 'LegacyUnforgeable', 'LenientThis',
'NotEnumerable', 'PerWorldBindings', 'SecureContext', 'NoAllocDirectCall', 'NotEnumerable', 'PerWorldBindings',
'Unscopable') 'SecureContext', 'Unscopable')
old_irs = self._ir_map.irs_of_kinds(IRMap.IR.Kind.INTERFACE, old_irs = self._ir_map.irs_of_kinds(IRMap.IR.Kind.INTERFACE,
IRMap.IR.Kind.NAMESPACE) IRMap.IR.Kind.NAMESPACE)
......
...@@ -187,6 +187,13 @@ inline T* GetInternalField(v8::Local<v8::Object> wrapper) { ...@@ -187,6 +187,13 @@ inline T* GetInternalField(v8::Local<v8::Object> wrapper) {
wrapper->GetAlignedPointerFromInternalField(offset)); wrapper->GetAlignedPointerFromInternalField(offset));
} }
template <typename T, int offset>
inline T* GetInternalField(v8::Object* wrapper) {
DCHECK_LT(offset, wrapper->InternalFieldCount());
return reinterpret_cast<T*>(
wrapper->GetAlignedPointerFromInternalField(offset));
}
// The return value can be null if |wrapper| is a global proxy, which points to // The return value can be null if |wrapper| is a global proxy, which points to
// nothing while a navigation. // nothing while a navigation.
inline ScriptWrappable* ToScriptWrappable( inline ScriptWrappable* ToScriptWrappable(
...@@ -203,6 +210,10 @@ inline ScriptWrappable* ToScriptWrappable(v8::Local<v8::Object> wrapper) { ...@@ -203,6 +210,10 @@ inline ScriptWrappable* ToScriptWrappable(v8::Local<v8::Object> wrapper) {
return GetInternalField<ScriptWrappable, kV8DOMWrapperObjectIndex>(wrapper); return GetInternalField<ScriptWrappable, kV8DOMWrapperObjectIndex>(wrapper);
} }
inline ScriptWrappable* ToScriptWrappable(v8::Object* wrapper) {
return GetInternalField<ScriptWrappable, kV8DOMWrapperObjectIndex>(wrapper);
}
inline CustomWrappable* ToCustomWrappable( inline CustomWrappable* ToCustomWrappable(
const v8::PersistentBase<v8::Object>& wrapper) { const v8::PersistentBase<v8::Object>& wrapper) {
return GetInternalField<CustomWrappable, kV8DOMWrapperObjectIndex>(wrapper); return GetInternalField<CustomWrappable, kV8DOMWrapperObjectIndex>(wrapper);
......
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