Skip to content

Commit

Permalink
v8binding: Supports the new V8 Fast API mechanism
Browse files Browse the repository at this point in the history
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: Hitoshi Yoshida <peria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801457}
  • Loading branch information
yuki3 authored and Commit Bot committed Aug 25, 2020
1 parent 9d250d4 commit 44a1544
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 90 deletions.
Expand Up @@ -77,6 +77,7 @@ LenientThis
LogActivity=|GetterOnly|SetterOnly
LogAllWorlds
NewObject
NoAllocDirectCall
Measure
MeasureAs=*
NamedConstructor=*
Expand Down
Expand Up @@ -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;

Expand All @@ -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 ==
Expand Down Expand Up @@ -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,
Expand Down
60 changes: 48 additions & 12 deletions third_party/blink/renderer/bindings/core/v8/v8_dom_configuration.h
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 44a1544

Please sign in to comment.