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
LogActivity=|GetterOnly|SetterOnly
LogAllWorlds
NewObject
NoAllocDirectCall
Measure
MeasureAs=*
NamedConstructor=*
......
......@@ -463,7 +463,8 @@ void InstallMethodInternal(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> interface_template,
v8::Local<v8::Signature> signature,
const Configuration& method,
const DOMWrapperWorld& world) {
const DOMWrapperWorld& world,
const v8::CFunction* v8_c_function = nullptr) {
if (!WorldConfigurationApplies(method, world))
return;
......@@ -488,7 +489,7 @@ void InstallMethodInternal(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> function_template =
v8::FunctionTemplate::New(
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->SetAcceptAnyReceiver(
method.access_check_configuration ==
......@@ -792,6 +793,22 @@ void V8DOMConfiguration::InstallMethods(
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(
v8::Isolate* isolate,
const DOMWrapperWorld& world,
......
......@@ -34,6 +34,7 @@
#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_private_property.h"
#include "v8/include/v8-fast-api-calls.h"
#include "v8/include/v8.h"
namespace blink {
......@@ -89,9 +90,12 @@ class CORE_EXPORT V8DOMConfiguration final {
// AttributeConfiguration translates into calls to SetNativeDataProperty() on
// either of instance or prototype object (or their object template).
struct AttributeConfiguration {
AttributeConfiguration& operator=(const AttributeConfiguration&) = delete;
DISALLOW_NEW();
const char* const name;
public:
AttributeConfiguration& operator=(const AttributeConfiguration&) = delete;
const char* name;
v8::AccessorNameGetterCallback getter;
v8::AccessorNameSetterCallback setter;
......@@ -140,9 +144,12 @@ class CORE_EXPORT V8DOMConfiguration final {
// either of instance, prototype, or interface object (or their object
// template).
struct AccessorConfiguration {
AccessorConfiguration& operator=(const AccessorConfiguration&) = delete;
DISALLOW_NEW();
const char* const name;
public:
AccessorConfiguration& operator=(const AccessorConfiguration&) = delete;
const char* name;
v8::FunctionCallback getter;
v8::FunctionCallback setter;
// V8PrivateProperty::CachedAccessor
......@@ -211,6 +218,9 @@ class CORE_EXPORT V8DOMConfiguration final {
// object's constants. It sets the constant on both the FunctionTemplate and
// the ObjectTemplate. PropertyAttributes is always ReadOnly.
struct ConstantConfiguration {
DISALLOW_NEW();
public:
constexpr ConstantConfiguration(const char* name,
ConstantType type,
int value)
......@@ -220,8 +230,8 @@ class CORE_EXPORT V8DOMConfiguration final {
double value)
: name(name), type(type), dvalue(value) {}
ConstantConfiguration& operator=(const ConstantConfiguration&) = delete;
DISALLOW_NEW();
const char* const name;
const char* name;
ConstantType type;
union {
int ivalue;
......@@ -243,8 +253,8 @@ class CORE_EXPORT V8DOMConfiguration final {
ConstantCallbackConfiguration& operator=(
const ConstantCallbackConfiguration&) = delete;
const char* const name;
const v8::AccessorNameGetterCallback getter;
const char* name;
v8::AccessorNameGetterCallback getter;
};
// Constant installation
......@@ -296,13 +306,16 @@ class CORE_EXPORT V8DOMConfiguration final {
// object's callbacks. It sets a method on instance, prototype or
// interface object (or their object tepmplate).
struct MethodConfiguration {
MethodConfiguration& operator=(const MethodConfiguration&) = delete;
DISALLOW_NEW();
public:
MethodConfiguration& operator=(const MethodConfiguration&) = delete;
v8::Local<v8::String> MethodName(v8::Isolate* isolate) const {
return V8AtomicString(isolate, name);
}
const char* const name;
const char* name;
v8::FunctionCallback callback;
int length;
// v8::PropertyAttribute
......@@ -320,15 +333,18 @@ class CORE_EXPORT V8DOMConfiguration final {
};
struct SymbolKeyedMethodConfiguration {
DISALLOW_NEW();
public:
SymbolKeyedMethodConfiguration& operator=(
const SymbolKeyedMethodConfiguration&) = delete;
DISALLOW_NEW();
v8::Local<v8::Name> MethodName(v8::Isolate* isolate) const {
return get_symbol(isolate);
}
v8::Local<v8::Symbol> (*get_symbol)(v8::Isolate*);
const char* const symbol_alias;
const char* symbol_alias;
v8::FunctionCallback callback;
// SymbolKeyedMethodConfiguration doesn't support per-world bindings.
int length;
......@@ -344,6 +360,17 @@ class CORE_EXPORT V8DOMConfiguration final {
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*,
const DOMWrapperWorld&,
v8::Local<v8::ObjectTemplate> instance_template,
......@@ -352,6 +379,15 @@ class CORE_EXPORT V8DOMConfiguration final {
v8::Local<v8::Signature>,
const MethodConfiguration*,
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*,
const DOMWrapperWorld&,
v8::Local<v8::ObjectTemplate> instance_template,
......
......@@ -518,8 +518,8 @@ class IdlCompiler(object):
def _propagate_extattrs_to_overload_group(self):
ANY_OF = ('CrossOrigin', 'Custom', 'LegacyUnforgeable', 'LenientThis',
'NotEnumerable', 'PerWorldBindings', 'SecureContext',
'Unscopable')
'NoAllocDirectCall', 'NotEnumerable', 'PerWorldBindings',
'SecureContext', 'Unscopable')
old_irs = self._ir_map.irs_of_kinds(IRMap.IR.Kind.INTERFACE,
IRMap.IR.Kind.NAMESPACE)
......
......@@ -187,6 +187,13 @@ inline T* GetInternalField(v8::Local<v8::Object> wrapper) {
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
// nothing while a navigation.
inline ScriptWrappable* ToScriptWrappable(
......@@ -203,6 +210,10 @@ inline ScriptWrappable* ToScriptWrappable(v8::Local<v8::Object> wrapper) {
return GetInternalField<ScriptWrappable, kV8DOMWrapperObjectIndex>(wrapper);
}
inline ScriptWrappable* ToScriptWrappable(v8::Object* wrapper) {
return GetInternalField<ScriptWrappable, kV8DOMWrapperObjectIndex>(wrapper);
}
inline CustomWrappable* ToCustomWrappable(
const v8::PersistentBase<v8::Object>& 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