Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2196)

Unified Diff: third_party/WebKit/Source/core/events/PopStateEvent.cpp

Issue 2850383002: Reland: Don't store ScriptValue in PopStateEvent (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/events/PopStateEvent.cpp
diff --git a/third_party/WebKit/Source/core/events/PopStateEvent.cpp b/third_party/WebKit/Source/core/events/PopStateEvent.cpp
index e56e126831aa9b8a4b4b7f65354e09f29a7f06b8..47640bc95ab3784e1d669d2ccf092e3d4e6382e2 100644
--- a/third_party/WebKit/Source/core/events/PopStateEvent.cpp
+++ b/third_party/WebKit/Source/core/events/PopStateEvent.cpp
@@ -32,23 +32,41 @@
namespace blink {
PopStateEvent::PopStateEvent()
- : serialized_state_(nullptr), history_(nullptr) {}
+ : serialized_state_(nullptr), state_(this), history_(nullptr) {}
-PopStateEvent::PopStateEvent(const AtomicString& type,
+PopStateEvent::PopStateEvent(ScriptState* script_state,
+ const AtomicString& type,
const PopStateEventInit& initializer)
- : Event(type, initializer), history_(nullptr) {
- if (initializer.hasState())
- state_ = initializer.state();
+ : Event(type, initializer), state_(this), history_(nullptr) {
+ if (initializer.hasState()) {
+ world_ = RefPtr<DOMWrapperWorld>(script_state->World());
+ state_.Set(initializer.state().GetIsolate(), initializer.state().V8Value());
+ }
}
PopStateEvent::PopStateEvent(PassRefPtr<SerializedScriptValue> serialized_state,
History* history)
: Event(EventTypeNames::popstate, false, true),
serialized_state_(std::move(serialized_state)),
+ state_(this),
history_(history) {}
PopStateEvent::~PopStateEvent() {}
+ScriptValue PopStateEvent::state(ScriptState* script_state) const {
+ if (state_.IsEmpty())
+ return ScriptValue();
+
+ v8::Isolate* isolate = script_state->GetIsolate();
+ if (world_->GetWorldId() != script_state->World().GetWorldId()) {
+ v8::Local<v8::Value> value = state_.NewLocal(isolate);
+ RefPtr<SerializedScriptValue> serialized =
+ SerializedScriptValue::SerializeAndSwallowExceptions(isolate, value);
+ return ScriptValue(script_state, serialized->Deserialize(isolate));
+ }
+ return ScriptValue(script_state, state_.NewLocal(isolate));
+}
+
PopStateEvent* PopStateEvent::Create() {
return new PopStateEvent;
}
@@ -59,9 +77,10 @@ PopStateEvent* PopStateEvent::Create(
return new PopStateEvent(std::move(serialized_state), history);
}
-PopStateEvent* PopStateEvent::Create(const AtomicString& type,
+PopStateEvent* PopStateEvent::Create(ScriptState* script_state,
+ const AtomicString& type,
const PopStateEventInit& initializer) {
- return new PopStateEvent(type, initializer);
+ return new PopStateEvent(script_state, type, initializer);
}
const AtomicString& PopStateEvent::InterfaceName() const {
@@ -73,4 +92,9 @@ DEFINE_TRACE(PopStateEvent) {
Event::Trace(visitor);
}
+DEFINE_TRACE_WRAPPERS(PopStateEvent) {
+ visitor->TraceWrappers(state_);
+ Event::TraceWrappers(visitor);
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/events/PopStateEvent.h ('k') | third_party/WebKit/Source/core/events/PopStateEvent.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698