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,56 +51,40 @@ ...@@ -51,56 +51,40 @@
namespace blink { namespace blink {
ScheduledAction* ScheduledAction::Create( ScheduledAction::ScheduledAction(ScriptState* script_state,
ScriptState* script_state,
ExecutionContext* target, ExecutionContext* target,
V8Function* handler, V8Function* handler,
const HeapVector<ScriptValue>& arguments) { const HeapVector<ScriptValue>& arguments)
if (!script_state->World().IsWorkerWorld()) { : script_state_(
if (!BindingSecurity::ShouldAllowAccessToFrame( MakeGarbageCollected<ScriptStateProtectingContext>(script_state)) {
if (script_state->World().IsWorkerWorld() ||
BindingSecurity::ShouldAllowAccessToFrame(
EnteredDOMWindow(script_state->GetIsolate()), EnteredDOMWindow(script_state->GetIsolate()),
To<Document>(target)->GetFrame(), To<Document>(target)->GetFrame(),
BindingSecurity::ErrorReportOption::kDoNotReport)) { BindingSecurity::ErrorReportOption::kDoNotReport)) {
function_ = handler;
arguments_ = arguments;
} else {
UseCounter::Count(target, WebFeature::kScheduledActionIgnored); UseCounter::Count(target, WebFeature::kScheduledActionIgnored);
return MakeGarbageCollected<ScheduledAction>(script_state);
}
} }
return MakeGarbageCollected<ScheduledAction>(script_state, handler,
arguments);
} }
ScheduledAction* ScheduledAction::Create(ScriptState* script_state, ScheduledAction::ScheduledAction(ScriptState* script_state,
ExecutionContext* target, ExecutionContext* target,
const String& handler) { const String& handler)
if (!script_state->World().IsWorkerWorld()) { : script_state_(
if (!BindingSecurity::ShouldAllowAccessToFrame( MakeGarbageCollected<ScriptStateProtectingContext>(script_state)) {
if (script_state->World().IsWorkerWorld() ||
BindingSecurity::ShouldAllowAccessToFrame(
EnteredDOMWindow(script_state->GetIsolate()), EnteredDOMWindow(script_state->GetIsolate()),
To<Document>(target)->GetFrame(), To<Document>(target)->GetFrame(),
BindingSecurity::ErrorReportOption::kDoNotReport)) { BindingSecurity::ErrorReportOption::kDoNotReport)) {
code_ = handler;
} else {
UseCounter::Count(target, WebFeature::kScheduledActionIgnored); UseCounter::Count(target, WebFeature::kScheduledActionIgnored);
return MakeGarbageCollected<ScheduledAction>(script_state);
}
} }
return MakeGarbageCollected<ScheduledAction>(script_state, handler);
} }
ScheduledAction::ScheduledAction(ScriptState* script_state,
V8Function* function,
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) {}
ScheduledAction::ScheduledAction(ScriptState* script_state)
: script_state_(
MakeGarbageCollected<ScriptStateProtectingContext>(script_state)) {}
ScheduledAction::~ScheduledAction() { ScheduledAction::~ScheduledAction() {
// Verify that owning DOMTimer has eagerly disposed. // Verify that owning DOMTimer has eagerly disposed.
DCHECK(!script_state_); DCHECK(!script_state_);
......
...@@ -52,21 +52,14 @@ class ScheduledAction final : public GarbageCollected<ScheduledAction>, ...@@ -52,21 +52,14 @@ class ScheduledAction final : public GarbageCollected<ScheduledAction>,
DISALLOW_COPY_AND_ASSIGN(ScheduledAction); DISALLOW_COPY_AND_ASSIGN(ScheduledAction);
public: public:
static ScheduledAction* Create(ScriptState*, ScheduledAction(ScriptState*,
ExecutionContext* target, ExecutionContext* target,
V8Function* handler, V8Function* handler,
const HeapVector<ScriptValue>& arguments); const HeapVector<ScriptValue>& arguments);
static ScheduledAction* Create(ScriptState*, ScheduledAction(ScriptState*,
ExecutionContext* target, ExecutionContext* target,
const String& handler); 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(); ~ScheduledAction();
void Dispose(); void Dispose();
......
...@@ -75,29 +75,10 @@ ScriptCustomElementDefinition* ScriptCustomElementDefinition::ForConstructor( ...@@ -75,29 +75,10 @@ ScriptCustomElementDefinition* ScriptCustomElementDefinition::ForConstructor(
return static_cast<ScriptCustomElementDefinition*>(definition); 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( ScriptCustomElementDefinition::ScriptCustomElementDefinition(
const ScriptCustomElementDefinitionData& data, const ScriptCustomElementDefinitionData& data,
const CustomElementDescriptor& descriptor) const CustomElementDescriptor& descriptor,
CustomElementDefinition::Id id)
: CustomElementDefinition(descriptor, : CustomElementDefinition(descriptor,
std::move(data.observed_attributes_), std::move(data.observed_attributes_),
data.disabled_features_, data.disabled_features_,
...@@ -113,7 +94,17 @@ ScriptCustomElementDefinition::ScriptCustomElementDefinition( ...@@ -113,7 +94,17 @@ ScriptCustomElementDefinition::ScriptCustomElementDefinition(
form_associated_callback_(data.form_associated_callback_), form_associated_callback_(data.form_associated_callback_),
form_reset_callback_(data.form_reset_callback_), form_reset_callback_(data.form_reset_callback_),
form_disabled_callback_(data.form_disabled_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) { void ScriptCustomElementDefinition::Trace(Visitor* visitor) {
visitor->Trace(script_state_); visitor->Trace(script_state_);
......
...@@ -34,13 +34,9 @@ class CORE_EXPORT ScriptCustomElementDefinition final ...@@ -34,13 +34,9 @@ class CORE_EXPORT ScriptCustomElementDefinition final
CustomElementRegistry*, CustomElementRegistry*,
v8::Local<v8::Value> constructor); v8::Local<v8::Value> constructor);
static ScriptCustomElementDefinition* Create( ScriptCustomElementDefinition(const ScriptCustomElementDefinitionData& data,
const ScriptCustomElementDefinitionData& data,
const CustomElementDescriptor&, const CustomElementDescriptor&,
CustomElementDefinition::Id); CustomElementDefinition::Id);
ScriptCustomElementDefinition(const ScriptCustomElementDefinitionData& data,
const CustomElementDescriptor&);
~ScriptCustomElementDefinition() override = default; ~ScriptCustomElementDefinition() override = default;
void Trace(Visitor*) override; void Trace(Visitor*) override;
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "third_party/blink/renderer/platform/bindings/exception_state.h" #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/script_state.h"
#include "third_party/blink/renderer/platform/bindings/v8_binding_macros.h" #include "third_party/blink/renderer/platform/bindings/v8_binding_macros.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
namespace blink { namespace blink {
...@@ -221,7 +222,8 @@ bool ScriptCustomElementDefinitionBuilder::RememberOriginalProperties() { ...@@ -221,7 +222,8 @@ bool ScriptCustomElementDefinitionBuilder::RememberOriginalProperties() {
CustomElementDefinition* ScriptCustomElementDefinitionBuilder::Build( CustomElementDefinition* ScriptCustomElementDefinitionBuilder::Build(
const CustomElementDescriptor& descriptor, const CustomElementDescriptor& descriptor,
CustomElementDefinition::Id id) { CustomElementDefinition::Id id) {
return ScriptCustomElementDefinition::Create(data_, descriptor, id); return MakeGarbageCollected<ScriptCustomElementDefinition>(data_, descriptor,
id);
} }
v8::Isolate* ScriptCustomElementDefinitionBuilder::Isolate() { v8::Isolate* ScriptCustomElementDefinitionBuilder::Isolate() {
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include "third_party/blink/renderer/platform/bindings/v0_custom_element_binding.h" #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_per_context_data.h"
#include "third_party/blink/renderer/platform/bindings/v8_private_property.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/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h" #include "third_party/blink/renderer/platform/wtf/assertions.h"
...@@ -163,7 +164,7 @@ V0CustomElementConstructorBuilder::CreateCallbacks() { ...@@ -163,7 +164,7 @@ V0CustomElementConstructorBuilder::CreateCallbacks() {
v8::MaybeLocal<v8::Function> attribute_changed = v8::MaybeLocal<v8::Function> attribute_changed =
RetrieveCallback("attributeChangedCallback"); RetrieveCallback("attributeChangedCallback");
callbacks_ = V8V0CustomElementLifecycleCallbacks::Create( callbacks_ = MakeGarbageCollected<V8V0CustomElementLifecycleCallbacks>(
script_state_, prototype_, created, attached, detached, script_state_, prototype_, created, attached, detached,
attribute_changed); attribute_changed);
return callbacks_.Get(); return callbacks_.Get();
......
...@@ -48,36 +48,6 @@ namespace blink { ...@@ -48,36 +48,6 @@ namespace blink {
V(detached, DetachedCallback) \ V(detached, DetachedCallback) \
V(attribute_changed, AttributeChangedCallback) 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( static V0CustomElementLifecycleCallbacks::CallbackType FlagSet(
v8::MaybeLocal<v8::Function> attached, v8::MaybeLocal<v8::Function> attached,
v8::MaybeLocal<v8::Function> detached, v8::MaybeLocal<v8::Function> detached,
...@@ -110,6 +80,22 @@ V8V0CustomElementLifecycleCallbacks::V8V0CustomElementLifecycleCallbacks( ...@@ -110,6 +80,22 @@ V8V0CustomElementLifecycleCallbacks::V8V0CustomElementLifecycleCallbacks(
prototype_(script_state->GetIsolate(), prototype){ prototype_(script_state->GetIsolate(), prototype){
v8::Isolate* isolate = script_state->GetIsolate(); v8::Isolate* isolate = script_state->GetIsolate();
v8::Local<v8::Function> function; 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) \ #define SET_FIELD(maybe, ignored) \
if (maybe.ToLocal(&function)) \ if (maybe.ToLocal(&function)) \
maybe##_.Set(isolate, function); maybe##_.Set(isolate, function);
......
...@@ -49,14 +49,6 @@ class V8PerContextData; ...@@ -49,14 +49,6 @@ class V8PerContextData;
class V8V0CustomElementLifecycleCallbacks final class V8V0CustomElementLifecycleCallbacks final
: public V0CustomElementLifecycleCallbacks { : public V0CustomElementLifecycleCallbacks {
public: 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( V8V0CustomElementLifecycleCallbacks(
ScriptState*, ScriptState*,
v8::Local<v8::Object> prototype, v8::Local<v8::Object> prototype,
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include "third_party/blink/renderer/core/trustedtypes/trusted_types_util.h" #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/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.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/weborigin/security_violation_reporting_policy.h"
#include "third_party/blink/renderer/platform/wtf/text/base64.h" #include "third_party/blink/renderer/platform/wtf/text/base64.h"
#include "third_party/blink/renderer/platform/wtf/text/string_utf8_adaptor.h" #include "third_party/blink/renderer/platform/wtf/text/string_utf8_adaptor.h"
...@@ -142,7 +143,7 @@ int WindowOrWorkerGlobalScope::setTimeout( ...@@ -142,7 +143,7 @@ int WindowOrWorkerGlobalScope::setTimeout(
// be done using the scheduler instead. // be done using the scheduler instead.
V8GCForContextDispose::Instance().NotifyIdle(); V8GCForContextDispose::Instance().NotifyIdle();
} }
ScheduledAction* action = ScheduledAction::Create( auto* action = MakeGarbageCollected<ScheduledAction>(
script_state, execution_context, handler, arguments); script_state, execution_context, handler, arguments);
return DOMTimer::Install(execution_context, action, return DOMTimer::Install(execution_context, action,
base::TimeDelta::FromMilliseconds(timeout), true); base::TimeDelta::FromMilliseconds(timeout), true);
...@@ -185,8 +186,8 @@ int WindowOrWorkerGlobalScope::setTimeoutFromString( ...@@ -185,8 +186,8 @@ int WindowOrWorkerGlobalScope::setTimeoutFromString(
// be done using the scheduler instead. // be done using the scheduler instead.
V8GCForContextDispose::Instance().NotifyIdle(); V8GCForContextDispose::Instance().NotifyIdle();
} }
ScheduledAction* action = auto* action = MakeGarbageCollected<ScheduledAction>(
ScheduledAction::Create(script_state, execution_context, handler); script_state, execution_context, handler);
return DOMTimer::Install(execution_context, action, return DOMTimer::Install(execution_context, action,
base::TimeDelta::FromMilliseconds(timeout), true); base::TimeDelta::FromMilliseconds(timeout), true);
} }
...@@ -200,7 +201,7 @@ int WindowOrWorkerGlobalScope::setInterval( ...@@ -200,7 +201,7 @@ int WindowOrWorkerGlobalScope::setInterval(
ExecutionContext* execution_context = event_target.GetExecutionContext(); ExecutionContext* execution_context = event_target.GetExecutionContext();
if (!IsAllowed(execution_context, false, g_empty_string)) if (!IsAllowed(execution_context, false, g_empty_string))
return 0; return 0;
ScheduledAction* action = ScheduledAction::Create( auto* action = MakeGarbageCollected<ScheduledAction>(
script_state, execution_context, handler, arguments); script_state, execution_context, handler, arguments);
return DOMTimer::Install(execution_context, action, return DOMTimer::Install(execution_context, action,
base::TimeDelta::FromMilliseconds(timeout), false); base::TimeDelta::FromMilliseconds(timeout), false);
...@@ -238,8 +239,8 @@ int WindowOrWorkerGlobalScope::setIntervalFromString( ...@@ -238,8 +239,8 @@ int WindowOrWorkerGlobalScope::setIntervalFromString(
// performance issue. // performance issue.
if (handler.IsEmpty()) if (handler.IsEmpty())
return 0; return 0;
ScheduledAction* action = auto* action = MakeGarbageCollected<ScheduledAction>(
ScheduledAction::Create(script_state, execution_context, handler); script_state, execution_context, handler);
return DOMTimer::Install(execution_context, action, return DOMTimer::Install(execution_context, action,
base::TimeDelta::FromMilliseconds(timeout), false); 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