Commit 2ce65f04 authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

bind-gen: Reimplement V8DOMConfiguration as IDLMemberInstaller

Implements the same features of V8DOMConfiguration as a new
class IDLMemberInstaller with refactoring and clean-up.

V8DOMConfiguration remains unchanged in order to make the old
bindings generator workable as much as possible.

IDLMemberInstaller gets rid of old and unnecessary burden, and
the APK size will be reduced by 30 KBytes.

IDL constants of origin trial features are removed because
1) It's not used in production, it's used only in testing.
2) IDL constants themselves are (a sort of) obsolete.
Overall, it's unlikely that we'll need IDL constants of origin
trial features.

Bug: 839389
Change-Id: I7bd876c779542c4889edbec6d9f6d4150e0bfec3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2448570
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarIan Clelland <iclelland@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816470}
parent 874bd97e
...@@ -202,7 +202,8 @@ def generate_callback_interface(callback_interface_identifier): ...@@ -202,7 +202,8 @@ def generate_callback_interface(callback_interface_identifier):
]) ])
installer_function_defs.accumulate( installer_function_defs.accumulate(
CodeGenAccumulator.require_include_headers([ CodeGenAccumulator.require_include_headers([
"third_party/blink/renderer/bindings/core/v8/v8_dom_configuration.h" "third_party/blink/renderer/bindings/core/v8/v8_dom_configuration.h",
"third_party/blink/renderer/platform/bindings/idl_member_installer.h",
])) ]))
# WrapperTypeInfo # WrapperTypeInfo
......
...@@ -7,7 +7,6 @@ interface OriginTrialsTest { ...@@ -7,7 +7,6 @@ interface OriginTrialsTest {
[RuntimeEnabled=OriginTrialsSampleAPI] static readonly attribute boolean staticAttribute; [RuntimeEnabled=OriginTrialsSampleAPI] static readonly attribute boolean staticAttribute;
[RuntimeEnabled=OriginTrialsSampleAPI] boolean normalMethod(); [RuntimeEnabled=OriginTrialsSampleAPI] boolean normalMethod();
[RuntimeEnabled=OriginTrialsSampleAPI] static boolean staticMethod(); [RuntimeEnabled=OriginTrialsSampleAPI] static boolean staticMethod();
[RuntimeEnabled=OriginTrialsSampleAPI] const unsigned short CONSTANT = 1;
// This attribute uses native code to test whether the trial is enabled, // This attribute uses native code to test whether the trial is enabled,
// and throws an exception in JavaScript if it is not. // and throws an exception in JavaScript if it is not.
...@@ -27,7 +26,6 @@ interface OriginTrialsTest { ...@@ -27,7 +26,6 @@ interface OriginTrialsTest {
boolean unconditionalMethod(); boolean unconditionalMethod();
void unconditionalDictionaryMethod(OriginTrialsTestDictionary dict); void unconditionalDictionaryMethod(OriginTrialsTestDictionary dict);
static boolean staticUnconditionalMethod(); static boolean staticUnconditionalMethod();
const unsigned short UNCONDITIONAL_CONSTANT = 99;
// These are available whether or not the trial is enabled, but only in a // These are available whether or not the trial is enabled, but only in a
// secure context. // secure context.
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
ImplementedAs=OriginTrialsTestPartial, ImplementedAs=OriginTrialsTestPartial,
RuntimeEnabled=OriginTrialsSampleAPI RuntimeEnabled=OriginTrialsSampleAPI
] partial interface OriginTrialsTest { ] partial interface OriginTrialsTest {
const unsigned short CONSTANT_PARTIAL = 2;
readonly attribute boolean normalAttributePartial; readonly attribute boolean normalAttributePartial;
static readonly attribute boolean staticAttributePartial; static readonly attribute boolean staticAttributePartial;
boolean normalMethodPartial(); boolean normalMethodPartial();
......
...@@ -418,6 +418,8 @@ component("platform") { ...@@ -418,6 +418,8 @@ component("platform") {
"bindings/exception_messages.h", "bindings/exception_messages.h",
"bindings/exception_state.cc", "bindings/exception_state.cc",
"bindings/exception_state.h", "bindings/exception_state.h",
"bindings/idl_member_installer.cc",
"bindings/idl_member_installer.h",
"bindings/microtask.cc", "bindings/microtask.cc",
"bindings/microtask.h", "bindings/microtask.h",
"bindings/name_client.h", "bindings/name_client.h",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// 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 "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* 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,
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,
base::span<const AttributeConfig> configs);
// Web IDL constant
struct ConstantCallbackConfig {
ConstantCallbackConfig& operator=(const ConstantCallbackConfig&) = delete;
const char* name;
v8::AccessorNameGetterCallback callback;
};
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 ConstantCallbackConfig> 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* 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,
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,
base::span<const OperationConfig> configs);
struct NoAllocDirectCallOperationConfig {
OperationConfig operation_config;
v8::CFunction v8_c_function;
};
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,
base::span<const NoAllocDirectCallOperationConfig> configs);
// Global property reference
// https://heycam.github.io/webidl/#define-the-global-property-references
// [LegacyNamespace]
// https://heycam.github.io/webidl/#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_
...@@ -37,11 +37,6 @@ expect_failure_worker = () => { ...@@ -37,11 +37,6 @@ expect_failure_worker = () => {
assert_false('normalAttribute' in testObject); assert_false('normalAttribute' in testObject);
assert_equals(testObject.normalAttribute, undefined); assert_equals(testObject.normalAttribute, undefined);
}, 'Attribute should not exist in ' + worker_type + ' worker'); }, 'Attribute should not exist in ' + worker_type + ' worker');
test(() => {
var testObject = self.internals.originTrialsTest();
assert_false('CONSTANT' in testObject);
assert_equals(testObject.CONSTANT, undefined);
}, 'Constant should not exist in ' + worker_type + ' worker');
done(); done();
} }
...@@ -119,17 +114,6 @@ expect_success_worker = () => { ...@@ -119,17 +114,6 @@ expect_success_worker = () => {
assert_idl_attribute(testObject, 'normalAttribute'); assert_idl_attribute(testObject, 'normalAttribute');
assert_true(testObject.normalAttribute, 'Attribute should return boolean value'); assert_true(testObject.normalAttribute, 'Attribute should return boolean value');
}, 'Attribute should exist and return value in ' + worker_type + ' worker'); }, 'Attribute should exist and return value in ' + worker_type + ' worker');
test(() => {
var testObject = self.internals.originTrialsTest();
assert_idl_attribute(testObject, 'CONSTANT');
assert_equals(testObject.CONSTANT, 1, 'Constant should return integer value');
}, 'Constant should exist and return value in ' + worker_type + ' worker');
test(() => {
var testObject = self.internals.originTrialsTest();
assert_idl_attribute(testObject, 'CONSTANT');
testObject.CONSTANT = 10;
assert_equals(testObject.CONSTANT, 1, 'Constant should not be modifiable');
}, 'Constant should exist and not be modifiable in ' + worker_type + ' worker');
done(); done();
} }
......
...@@ -83,19 +83,6 @@ expect_css_media = (feature_name) => { ...@@ -83,19 +83,6 @@ expect_css_media = (feature_name) => {
assert_true(media_list.mediaText.indexOf("not all") === -1); assert_true(media_list.mediaText.indexOf("not all") === -1);
} }
// Verify that the given constant exists, and returns the expected value, and
// is not modifiable.
expect_constant = (constant_name, constant_value, get_value_func) => {
var testObject = internals.originTrialsTest();
var testInterface = testObject.constructor;
assert_own_property(testInterface, constant_name);
assert_equals(get_value_func(testInterface), constant_value,
'Constant should return expected value');
testInterface[constant_name] = constant_value + 1;
assert_equals(get_value_func(testInterface), constant_value,
'Constant should not be modifiable');
}
// Verify that given member does not exist, and does not provide a value // Verify that given member does not exist, and does not provide a value
// (i.e. is undefined). // (i.e. is undefined).
expect_member_fails = (member_name) => { expect_member_fails = (member_name) => {
...@@ -186,10 +173,6 @@ expect_failure = (skip_worker) => { ...@@ -186,10 +173,6 @@ expect_failure = (skip_worker) => {
expect_member_fails('normalAttribute'); expect_member_fails('normalAttribute');
}, 'Attribute should not exist, with trial disabled'); }, 'Attribute should not exist, with trial disabled');
test(() => {
expect_static_member_fails('CONSTANT');
}, 'Constant should not exist, with trial disabled');
if (!skip_worker) { if (!skip_worker) {
fetch_tests_from_worker(new Worker('resources/disabled-worker.js')); fetch_tests_from_worker(new Worker('resources/disabled-worker.js'));
} }
...@@ -278,12 +261,6 @@ expect_success = () => { ...@@ -278,12 +261,6 @@ expect_success = () => {
}); });
}, 'Attribute should exist on object and return value'); }, 'Attribute should exist on object and return value');
test(() => {
expect_constant('CONSTANT', 1, (testObject) => {
return testObject.CONSTANT;
});
}, 'Constant should exist on interface and return value');
fetch_tests_from_worker(new Worker('resources/enabled-worker.js')); fetch_tests_from_worker(new Worker('resources/enabled-worker.js'));
}; };
...@@ -384,12 +361,6 @@ expect_always_bindings = (insecure_context, opt_description_suffix) => { ...@@ -384,12 +361,6 @@ expect_always_bindings = (insecure_context, opt_description_suffix) => {
}); });
}, 'Static method should exist and return value, regardless of trial' + description_suffix); }, 'Static method should exist and return value, regardless of trial' + description_suffix);
test(() => {
expect_constant('UNCONDITIONAL_CONSTANT', 99, (testObject) => {
return testObject.UNCONDITIONAL_CONSTANT;
});
}, 'Constant should exist on interface and return value, regardless of trial' + description_suffix);
test(() => { test(() => {
expect_dictionary_member('unconditionalBool'); expect_dictionary_member('unconditionalBool');
}, 'Dictionary output from method should return member value, regardless of trial' + description_suffix); }, 'Dictionary output from method should return member value, regardless of trial' + description_suffix);
...@@ -539,12 +510,6 @@ expect_success_bindings = (insecure_context) => { ...@@ -539,12 +510,6 @@ expect_success_bindings = (insecure_context) => {
}); });
}, 'Static method should exist on partial interface and return value'); }, 'Static method should exist on partial interface and return value');
test(() => {
expect_constant('CONSTANT_PARTIAL', 2, (testObject) => {
return testObject.CONSTANT_PARTIAL;
});
}, 'Constant should exist on partial interface and return value');
// Tests for combination of [RuntimeEnabled] and [SecureContext] // Tests for combination of [RuntimeEnabled] and [SecureContext]
test(() => { test(() => {
expect_member('secureAttribute', (testObject) => { expect_member('secureAttribute', (testObject) => {
...@@ -645,9 +610,6 @@ expect_failure_bindings_impl = (insecure_context, description_suffix) => { ...@@ -645,9 +610,6 @@ expect_failure_bindings_impl = (insecure_context, description_suffix) => {
test(() => { test(() => {
expect_static_member_fails('staticMethodPartial'); expect_static_member_fails('staticMethodPartial');
}, 'Static method should not exist on partial interface, with trial disabled'); }, 'Static method should not exist on partial interface, with trial disabled');
test(() => {
expect_static_member_fails('CONSTANT_PARTIAL');
}, 'Constant should not exist on partial interface, with trial disabled');
// Tests for combination of [RuntimeEnabled] and [SecureContext] // Tests for combination of [RuntimeEnabled] and [SecureContext]
test(() => { test(() => {
......
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