Skip to content

Commit

Permalink
Fix CustomEvent use of EnvironmentSettings. (youtube#529)
Browse files Browse the repository at this point in the history
* Fix CustomEvent use of EnvironmentSettings.

Don't store the EnvironmentSettings, but pass it only where needed to
set_detail(), including from Document.createEvent().

b/236142860
b/274788091

* Address comments.
  • Loading branch information
jellefoks committed Jun 5, 2023
1 parent abf4cea commit 1b3a19f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
24 changes: 11 additions & 13 deletions cobalt/web/custom_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class CustomEvent : public web::Event {
public:
explicit CustomEvent(script::EnvironmentSettings* environment_settings,
const std::string& type)
: Event(type), environment_settings_(environment_settings) {}
: Event(type) {}
CustomEvent(script::EnvironmentSettings* environment_settings,
const std::string& type, const CustomEventInit& init_dict)
: Event(type, init_dict), environment_settings_(environment_settings) {
set_detail(init_dict.detail());
: Event(type, init_dict) {
set_detail(environment_settings, init_dict.detail());
}

// Creates an event with its "initialized flag" unset.
Expand All @@ -46,17 +46,18 @@ class CustomEvent : public web::Event {

// Web API: CustomEvent
//
void InitCustomEvent(const std::string& type, bool bubbles, bool cancelable,
void InitCustomEvent(script::EnvironmentSettings* environment_settings,
const std::string& type, bool bubbles, bool cancelable,
const script::ValueHandleHolder& detail) {
InitEvent(type, bubbles, cancelable);
set_detail(&detail);
set_detail(environment_settings, &detail);
}

void set_detail(const script::ValueHandleHolder* detail) {
void set_detail(script::EnvironmentSettings* environment_settings,
const script::ValueHandleHolder* detail) {
if (detail) {
auto* wrappable = environment_settings_
? get_global_wrappable(environment_settings_)
: this;
DCHECK(environment_settings);
auto* wrappable = get_global_wrappable(environment_settings);
detail_.reset(
new script::ValueHandleHolder::Reference(wrappable, *detail));
} else {
Expand All @@ -75,12 +76,9 @@ class CustomEvent : public web::Event {
DEFINE_WRAPPABLE_TYPE(CustomEvent);

protected:
~CustomEvent() override { environment_settings_ = nullptr; }
~CustomEvent() override {}

std::unique_ptr<script::ValueHandleHolder::Reference> detail_;

private:
script::EnvironmentSettings* environment_settings_ = nullptr;
};

} // namespace web
Expand Down
2 changes: 1 addition & 1 deletion cobalt/web/custom_event.idl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
] interface CustomEvent : Event {
readonly attribute any detail;

void initCustomEvent(DOMString type,
[CallWith=EnvironmentSettings] void initCustomEvent(DOMString type,
boolean bubbles,
boolean cancelable,
any detail);
Expand Down

0 comments on commit 1b3a19f

Please sign in to comment.