Chromium Code Reviews| 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)); |
|
haraken
2017/05/02 04:44:32
What happens if:
1) an isolated world stores stat
bashi
2017/05/02 05:08:52
Yeah, that's a valid concern when we remove custom
|
| + } |
| + 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 |