Commit 21db60b8 authored by Henrique Ferreiro's avatar Henrique Ferreiro Committed by Commit Bot

Inline static Create() from renderer/bindings/core

This CL ports calls to Foo::Create() factory functions in
//third_party/blink/renderer/bindings/core to MakeGarbageCollected<Foo>.

Bug: 939691
Change-Id: Iee958f00400fd662c09e64371be97fc676341f6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1920825Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Henrique Ferreiro <hferreiro@igalia.com>
Cr-Commit-Position: refs/heads/master@{#716414}
parent b58f7f19
......@@ -51,55 +51,39 @@
namespace blink {
ScheduledAction* ScheduledAction::Create(
ScriptState* script_state,
ExecutionContext* target,
V8Function* handler,
const HeapVector<ScriptValue>& arguments) {
if (!script_state->World().IsWorkerWorld()) {
if (!BindingSecurity::ShouldAllowAccessToFrame(
EnteredDOMWindow(script_state->GetIsolate()),
To<Document>(target)->GetFrame(),
BindingSecurity::ErrorReportOption::kDoNotReport)) {
UseCounter::Count(target, WebFeature::kScheduledActionIgnored);
return MakeGarbageCollected<ScheduledAction>(script_state);
}
}
return MakeGarbageCollected<ScheduledAction>(script_state, handler,
arguments);
}
ScheduledAction* ScheduledAction::Create(ScriptState* script_state,
ExecutionContext* target,
const String& handler) {
if (!script_state->World().IsWorkerWorld()) {
if (!BindingSecurity::ShouldAllowAccessToFrame(
EnteredDOMWindow(script_state->GetIsolate()),
To<Document>(target)->GetFrame(),
BindingSecurity::ErrorReportOption::kDoNotReport)) {
UseCounter::Count(target, WebFeature::kScheduledActionIgnored);
return MakeGarbageCollected<ScheduledAction>(script_state);
}
}
return MakeGarbageCollected<ScheduledAction>(script_state, handler);
}
ScheduledAction::ScheduledAction(ScriptState* script_state,
V8Function* function,
ExecutionContext* target,
V8Function* handler,
const HeapVector<ScriptValue>& arguments)
: script_state_(
MakeGarbageCollected<ScriptStateProtectingContext>(script_state)),
function_(function),
arguments_(arguments) {}
ScheduledAction::ScheduledAction(ScriptState* script_state, const String& code)
: script_state_(
MakeGarbageCollected<ScriptStateProtectingContext>(script_state)),
code_(code) {}
MakeGarbageCollected<ScriptStateProtectingContext>(script_state)) {
if (script_state->World().IsWorkerWorld() ||
BindingSecurity::ShouldAllowAccessToFrame(
EnteredDOMWindow(script_state->GetIsolate()),
To<Document>(target)->GetFrame(),
BindingSecurity::ErrorReportOption::kDoNotReport)) {
function_ = handler;
arguments_ = arguments;
} else {
UseCounter::Count(target, WebFeature::kScheduledActionIgnored);
}
}
ScheduledAction::ScheduledAction(ScriptState* script_state)
ScheduledAction::ScheduledAction(ScriptState* script_state,
ExecutionContext* target,
const String& handler)
: script_state_(
MakeGarbageCollected<ScriptStateProtectingContext>(script_state)) {}
MakeGarbageCollected<ScriptStateProtectingContext>(script_state)) {
if (script_state->World().IsWorkerWorld() ||
BindingSecurity::ShouldAllowAccessToFrame(
EnteredDOMWindow(script_state->GetIsolate()),
To<Document>(target)->GetFrame(),
BindingSecurity::ErrorReportOption::kDoNotReport)) {
code_ = handler;
} else {
UseCounter::Count(target, WebFeature::kScheduledActionIgnored);
}
}
ScheduledAction::~ScheduledAction() {
// Verify that owning DOMTimer has eagerly disposed.
......
......@@ -52,20 +52,13 @@ class ScheduledAction final : public GarbageCollected<ScheduledAction>,
DISALLOW_COPY_AND_ASSIGN(ScheduledAction);
public:
static ScheduledAction* Create(ScriptState*,
ExecutionContext* target,
V8Function* handler,
const HeapVector<ScriptValue>& arguments);
static ScheduledAction* Create(ScriptState*,
ExecutionContext* target,
const String& handler);
explicit ScheduledAction(ScriptState*,
V8Function* handler,
const HeapVector<ScriptValue>& arguments);
explicit ScheduledAction(ScriptState*, const String& handler);
// Creates an empty ScheduledAction.
explicit ScheduledAction(ScriptState*);
ScheduledAction(ScriptState*,
ExecutionContext* target,
V8Function* handler,
const HeapVector<ScriptValue>& arguments);
ScheduledAction(ScriptState*,
ExecutionContext* target,
const String& handler);
~ScheduledAction();
......
......@@ -75,29 +75,10 @@ ScriptCustomElementDefinition* ScriptCustomElementDefinition::ForConstructor(
return static_cast<ScriptCustomElementDefinition*>(definition);
}
ScriptCustomElementDefinition* ScriptCustomElementDefinition::Create(
const ScriptCustomElementDefinitionData& data,
const CustomElementDescriptor& descriptor,
CustomElementDefinition::Id id) {
auto* definition =
MakeGarbageCollected<ScriptCustomElementDefinition>(data, descriptor);
// Tag the JavaScript constructor object with its ID.
ScriptState* script_state = data.script_state_;
v8::Local<v8::Value> id_value =
v8::Integer::NewFromUnsigned(script_state->GetIsolate(), id);
auto private_id =
script_state->PerContextData()->GetPrivateCustomElementDefinitionId();
CHECK(data.constructor_->CallbackObject()
->SetPrivate(script_state->GetContext(), private_id, id_value)
.ToChecked());
return definition;
}
ScriptCustomElementDefinition::ScriptCustomElementDefinition(
const ScriptCustomElementDefinitionData& data,
const CustomElementDescriptor& descriptor)
const CustomElementDescriptor& descriptor,
CustomElementDefinition::Id id)
: CustomElementDefinition(descriptor,
std::move(data.observed_attributes_),
data.disabled_features_,
......@@ -113,7 +94,17 @@ ScriptCustomElementDefinition::ScriptCustomElementDefinition(
form_associated_callback_(data.form_associated_callback_),
form_reset_callback_(data.form_reset_callback_),
form_disabled_callback_(data.form_disabled_callback_),
form_state_restore_callback_(data.form_state_restore_callback_) {}
form_state_restore_callback_(data.form_state_restore_callback_) {
// Tag the JavaScript constructor object with its ID.
ScriptState* script_state = data.script_state_;
v8::Local<v8::Value> id_value =
v8::Integer::NewFromUnsigned(script_state->GetIsolate(), id);
auto private_id =
script_state->PerContextData()->GetPrivateCustomElementDefinitionId();
CHECK(data.constructor_->CallbackObject()
->SetPrivate(script_state->GetContext(), private_id, id_value)
.ToChecked());
}
void ScriptCustomElementDefinition::Trace(Visitor* visitor) {
visitor->Trace(script_state_);
......
......@@ -34,13 +34,9 @@ class CORE_EXPORT ScriptCustomElementDefinition final
CustomElementRegistry*,
v8::Local<v8::Value> constructor);
static ScriptCustomElementDefinition* Create(
const ScriptCustomElementDefinitionData& data,
const CustomElementDescriptor&,
CustomElementDefinition::Id);
ScriptCustomElementDefinition(const ScriptCustomElementDefinitionData& data,
const CustomElementDescriptor&);
const CustomElementDescriptor&,
CustomElementDefinition::Id);
~ScriptCustomElementDefinition() override = default;
void Trace(Visitor*) override;
......
......@@ -21,6 +21,7 @@
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/bindings/v8_binding_macros.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
namespace blink {
......@@ -221,7 +222,8 @@ bool ScriptCustomElementDefinitionBuilder::RememberOriginalProperties() {
CustomElementDefinition* ScriptCustomElementDefinitionBuilder::Build(
const CustomElementDescriptor& descriptor,
CustomElementDefinition::Id id) {
return ScriptCustomElementDefinition::Create(data_, descriptor, id);
return MakeGarbageCollected<ScriptCustomElementDefinition>(data_, descriptor,
id);
}
v8::Isolate* ScriptCustomElementDefinitionBuilder::Isolate() {
......
......@@ -49,6 +49,7 @@
#include "third_party/blink/renderer/platform/bindings/v0_custom_element_binding.h"
#include "third_party/blink/renderer/platform/bindings/v8_per_context_data.h"
#include "third_party/blink/renderer/platform/bindings/v8_private_property.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h"
......@@ -163,7 +164,7 @@ V0CustomElementConstructorBuilder::CreateCallbacks() {
v8::MaybeLocal<v8::Function> attribute_changed =
RetrieveCallback("attributeChangedCallback");
callbacks_ = V8V0CustomElementLifecycleCallbacks::Create(
callbacks_ = MakeGarbageCollected<V8V0CustomElementLifecycleCallbacks>(
script_state_, prototype_, created, attached, detached,
attribute_changed);
return callbacks_.Get();
......
......@@ -48,36 +48,6 @@ namespace blink {
V(detached, DetachedCallback) \
V(attribute_changed, AttributeChangedCallback)
V8V0CustomElementLifecycleCallbacks*
V8V0CustomElementLifecycleCallbacks::Create(
ScriptState* script_state,
v8::Local<v8::Object> prototype,
v8::MaybeLocal<v8::Function> created,
v8::MaybeLocal<v8::Function> attached,
v8::MaybeLocal<v8::Function> detached,
v8::MaybeLocal<v8::Function> attribute_changed) {
v8::Isolate* isolate = script_state->GetIsolate();
// A given object can only be used as a Custom Element prototype
// once; see customElementIsInterfacePrototypeObject
#define SET_PRIVATE_PROPERTY(Maybe, Name) \
static const V8PrivateProperty::SymbolKey kPrivateProperty##Name; \
V8PrivateProperty::Symbol symbol##Name = \
V8PrivateProperty::GetSymbol(isolate, kPrivateProperty##Name); \
DCHECK(!symbol##Name.HasValue(prototype)); \
{ \
v8::Local<v8::Function> function; \
if (Maybe.ToLocal(&function)) \
symbol##Name.Set(prototype, function); \
}
CALLBACK_LIST(SET_PRIVATE_PROPERTY)
#undef SET_PRIVATE_PROPERTY
return MakeGarbageCollected<V8V0CustomElementLifecycleCallbacks>(
script_state, prototype, created, attached, detached, attribute_changed);
}
static V0CustomElementLifecycleCallbacks::CallbackType FlagSet(
v8::MaybeLocal<v8::Function> attached,
v8::MaybeLocal<v8::Function> detached,
......@@ -110,6 +80,22 @@ V8V0CustomElementLifecycleCallbacks::V8V0CustomElementLifecycleCallbacks(
prototype_(script_state->GetIsolate(), prototype){
v8::Isolate* isolate = script_state->GetIsolate();
v8::Local<v8::Function> function;
// A given object can only be used as a Custom Element prototype
// once; see customElementIsInterfacePrototypeObject
#define SET_PRIVATE_PROPERTY(Maybe, Name) \
static const V8PrivateProperty::SymbolKey kPrivateProperty##Name; \
V8PrivateProperty::Symbol symbol##Name = \
V8PrivateProperty::GetSymbol(isolate, kPrivateProperty##Name); \
DCHECK(!symbol##Name.HasValue(prototype)); \
{ \
if (Maybe.ToLocal(&function)) \
symbol##Name.Set(prototype, function); \
}
CALLBACK_LIST(SET_PRIVATE_PROPERTY)
#undef SET_PRIVATE_PROPERTY
#define SET_FIELD(maybe, ignored) \
if (maybe.ToLocal(&function)) \
maybe##_.Set(isolate, function);
......
......@@ -49,14 +49,6 @@ class V8PerContextData;
class V8V0CustomElementLifecycleCallbacks final
: public V0CustomElementLifecycleCallbacks {
public:
static V8V0CustomElementLifecycleCallbacks* Create(
ScriptState*,
v8::Local<v8::Object> prototype,
v8::MaybeLocal<v8::Function> created,
v8::MaybeLocal<v8::Function> attached,
v8::MaybeLocal<v8::Function> detached,
v8::MaybeLocal<v8::Function> attribute_changed);
V8V0CustomElementLifecycleCallbacks(
ScriptState*,
v8::Local<v8::Object> prototype,
......
......@@ -46,6 +46,7 @@
#include "third_party/blink/renderer/core/trustedtypes/trusted_types_util.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/weborigin/security_violation_reporting_policy.h"
#include "third_party/blink/renderer/platform/wtf/text/base64.h"
#include "third_party/blink/renderer/platform/wtf/text/string_utf8_adaptor.h"
......@@ -142,7 +143,7 @@ int WindowOrWorkerGlobalScope::setTimeout(
// be done using the scheduler instead.
V8GCForContextDispose::Instance().NotifyIdle();
}
ScheduledAction* action = ScheduledAction::Create(
auto* action = MakeGarbageCollected<ScheduledAction>(
script_state, execution_context, handler, arguments);
return DOMTimer::Install(execution_context, action,
base::TimeDelta::FromMilliseconds(timeout), true);
......@@ -185,8 +186,8 @@ int WindowOrWorkerGlobalScope::setTimeoutFromString(
// be done using the scheduler instead.
V8GCForContextDispose::Instance().NotifyIdle();
}
ScheduledAction* action =
ScheduledAction::Create(script_state, execution_context, handler);
auto* action = MakeGarbageCollected<ScheduledAction>(
script_state, execution_context, handler);
return DOMTimer::Install(execution_context, action,
base::TimeDelta::FromMilliseconds(timeout), true);
}
......@@ -200,7 +201,7 @@ int WindowOrWorkerGlobalScope::setInterval(
ExecutionContext* execution_context = event_target.GetExecutionContext();
if (!IsAllowed(execution_context, false, g_empty_string))
return 0;
ScheduledAction* action = ScheduledAction::Create(
auto* action = MakeGarbageCollected<ScheduledAction>(
script_state, execution_context, handler, arguments);
return DOMTimer::Install(execution_context, action,
base::TimeDelta::FromMilliseconds(timeout), false);
......@@ -238,8 +239,8 @@ int WindowOrWorkerGlobalScope::setIntervalFromString(
// performance issue.
if (handler.IsEmpty())
return 0;
ScheduledAction* action =
ScheduledAction::Create(script_state, execution_context, handler);
auto* action = MakeGarbageCollected<ScheduledAction>(
script_state, execution_context, handler);
return DOMTimer::Install(execution_context, action,
base::TimeDelta::FromMilliseconds(timeout), false);
}
......
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