1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_IDL_MEMBER_INSTALLER_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_IDL_MEMBER_INSTALLER_H_
#include "base/containers/span.h"
#include "base/memory/raw_ptr.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "v8/include/v8-fast-api-calls.h"
#include "v8/include/v8.h"
namespace blink {
class DOMWrapperWorld;
namespace bindings {
// IDLMemberInstaller is a set of utility functions to define IDL members as
// ES properties.
class PLATFORM_EXPORT IDLMemberInstaller final {
STATIC_ONLY(IDLMemberInstaller);
public:
// On which object the property is defined
enum class FlagLocation {
kInstance,
kPrototype,
kInterface,
};
// In which world the property is defined
enum class FlagWorld {
kMainWorld = 1 << 0,
kNonMainWorlds = 1 << 1,
kAllWorlds = kMainWorld | kNonMainWorlds,
};
// v8::Signature check against the receiver object
enum class FlagReceiverCheck {
kCheck,
kDoNotCheck,
};
// Cross origin access check
enum class FlagCrossOriginCheck {
kCheck,
kDoNotCheck,
};
// Web IDL attribute
struct AttributeConfig {
AttributeConfig& operator=(const AttributeConfig&) = delete;
const char* property_name;
v8::FunctionCallback callback_for_get;
v8::FunctionCallback callback_for_set;
unsigned v8_property_attribute : 3; // v8::PropertyAttribute
unsigned location : 2; // FlagLocation
unsigned world : 2; // FlagWorld
unsigned receiver_check : 1; // FlagReceiverCheck
unsigned cross_origin_check_for_get : 1; // FlagCrossOriginCheck
unsigned cross_origin_check_for_set : 1; // FlagCrossOriginCheck
unsigned v8_side_effect : 2; // v8::SideEffectType
unsigned v8_cached_accessor : 2; // V8PrivateProperty::CachedAccessor
};
static void InstallAttributes(v8::Isolate* isolate,
const DOMWrapperWorld& world,
v8::Local<v8::Template> instance_template,
v8::Local<v8::Template> prototype_template,
v8::Local<v8::Template> interface_template,
v8::Local<v8::Signature> signature,
const char* interface_name,
base::span<const AttributeConfig> configs);
static void InstallAttributes(v8::Isolate* isolate,
const DOMWrapperWorld& world,
v8::Local<v8::Object> instance_object,
v8::Local<v8::Object> prototype_object,
v8::Local<v8::Object> interface_object,
v8::Local<v8::Signature> signature,
const char* interface_name,
base::span<const AttributeConfig> configs);
struct NoAllocDirectCallAttributeConfig {
NoAllocDirectCallAttributeConfig& operator=(
const NoAllocDirectCallAttributeConfig&) = delete;
AttributeConfig attribute_config;
raw_ptr<const v8::CFunction> v8_cfunction_for_set;
};
static void InstallAttributes(
v8::Isolate* isolate,
const DOMWrapperWorld& world,
v8::Local<v8::Template> instance_template,
v8::Local<v8::Template> prototype_template,
v8::Local<v8::Template> interface_template,
v8::Local<v8::Signature> signature,
const char* interface_name,
base::span<const NoAllocDirectCallAttributeConfig> configs);
static void InstallAttributes(
v8::Isolate* isolate,
const DOMWrapperWorld& world,
v8::Local<v8::Object> instance_object,
v8::Local<v8::Object> prototype_object,
v8::Local<v8::Object> interface_object,
v8::Local<v8::Signature> signature,
const char* interface_name,
base::span<const NoAllocDirectCallAttributeConfig> configs);
struct ConstantValueConfig {
ConstantValueConfig& operator=(const ConstantValueConfig&) = delete;
const char* name;
int64_t value;
};
static void InstallConstants(v8::Isolate* isolate,
const DOMWrapperWorld& world,
v8::Local<v8::Template> instance_template,
v8::Local<v8::Template> prototype_template,
v8::Local<v8::Template> interface_template,
v8::Local<v8::Signature> signature,
base::span<const ConstantValueConfig> configs);
// Web IDL operation
struct OperationConfig {
OperationConfig& operator=(const OperationConfig&) = delete;
const char* property_name;
v8::FunctionCallback callback;
unsigned length : 8;
unsigned v8_property_attribute : 3; // v8::PropertyAttribute
unsigned location : 2; // FlagLocation
unsigned world : 2; // FlagWorld
unsigned receiver_check : 1; // FlagReceiverCheck
unsigned cross_origin_check : 1; // FlagCrossOriginCheck
unsigned v8_side_effect : 2; // v8::SideEffectType
};
static void InstallOperations(v8::Isolate* isolate,
const DOMWrapperWorld& world,
v8::Local<v8::Template> instance_template,
v8::Local<v8::Template> prototype_template,
v8::Local<v8::Template> interface_template,
v8::Local<v8::Signature> signature,
const char* interface_name,
base::span<const OperationConfig> configs);
static void InstallOperations(v8::Isolate* isolate,
const DOMWrapperWorld& world,
v8::Local<v8::Object> instance_object,
v8::Local<v8::Object> prototype_object,
v8::Local<v8::Object> interface_object,
v8::Local<v8::Signature> signature,
const char* interface_name,
base::span<const OperationConfig> configs);
struct NoAllocDirectCallOperationConfig {
OperationConfig operation_config;
raw_ptr<const v8::CFunction> v8_cfunction_table_data;
uint32_t v8_cfunction_table_size;
};
static void InstallOperations(
v8::Isolate* isolate,
const DOMWrapperWorld& world,
v8::Local<v8::Template> instance_template,
v8::Local<v8::Template> prototype_template,
v8::Local<v8::Template> interface_template,
v8::Local<v8::Signature> signature,
const char* interface_name,
base::span<const NoAllocDirectCallOperationConfig> configs);
static void InstallOperations(
v8::Isolate* isolate,
const DOMWrapperWorld& world,
v8::Local<v8::Object> instance_object,
v8::Local<v8::Object> prototype_object,
v8::Local<v8::Object> interface_object,
v8::Local<v8::Signature> signature,
const char* interface_name,
base::span<const NoAllocDirectCallOperationConfig> configs);
// Global property reference
// https://webidl.spec.whatwg.org/#define-the-global-property-references
// [LegacyNamespace]
// https://webidl.spec.whatwg.org/#LegacyNamespace
struct ExposedConstructConfig {
ExposedConstructConfig& operator=(const ExposedConstructConfig&) = delete;
const char* name;
v8::AccessorNameGetterCallback callback;
};
static void InstallExposedConstructs(
v8::Isolate* isolate,
const DOMWrapperWorld& world,
v8::Local<v8::Template> instance_template,
v8::Local<v8::Template> prototype_template,
v8::Local<v8::Template> interface_template,
v8::Local<v8::Signature> signature,
base::span<const ExposedConstructConfig> configs);
static void InstallExposedConstructs(
v8::Isolate* isolate,
const DOMWrapperWorld& world,
v8::Local<v8::Object> instance_object,
v8::Local<v8::Object> prototype_object,
v8::Local<v8::Object> interface_object,
v8::Local<v8::Signature> signature,
base::span<const ExposedConstructConfig> configs);
};
} // namespace bindings
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_IDL_MEMBER_INSTALLER_H_
|