Commit ccffbeec authored by bashi's avatar bashi Committed by Commit bot

Reland: Don't store ScriptValue in PopStateEvent

Fix compilation errors (rebased).

Original description:

Use TraceWrapperV8Reference instead. This CL doesn't remove
custom getter of PopStateEvent.state as more work will be
needed to remove custom bindings.

BUG=501866

Review-Url: https://codereview.chromium.org/2850383002
Cr-Commit-Position: refs/heads/master@{#468582}
parent c9ab01cc
......@@ -77,7 +77,7 @@ void V8PopStateEvent::stateAttributeGetterCustom(
if (event->SerializedState())
result = event->SerializedState()->Deserialize(isolate);
else
result = event->state().V8ValueFor(script_state);
result = event->state(script_state).V8Value();
if (result.IsEmpty())
result = v8::Null(isolate);
V8SetReturnValue(info, CacheState(script_state, info.Holder(), result));
......
......@@ -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
......@@ -27,8 +27,10 @@
#ifndef PopStateEvent_h
#define PopStateEvent_h
#include "bindings/core/v8/TraceWrapperV8Reference.h"
#include "core/events/Event.h"
#include "core/events/PopStateEventInit.h"
#include "platform/bindings/DOMWrapperWorld.h"
#include "platform/heap/Handle.h"
namespace blink {
......@@ -43,9 +45,11 @@ class PopStateEvent final : public Event {
~PopStateEvent() override;
static PopStateEvent* Create();
static PopStateEvent* Create(PassRefPtr<SerializedScriptValue>, History*);
static PopStateEvent* Create(const AtomicString&, const PopStateEventInit&);
static PopStateEvent* Create(ScriptState*,
const AtomicString&,
const PopStateEventInit&);
ScriptValue state() const { return state_; }
ScriptValue state(ScriptState*) const;
SerializedScriptValue* SerializedState() const {
return serialized_state_.Get();
}
......@@ -59,13 +63,16 @@ class PopStateEvent final : public Event {
DECLARE_VIRTUAL_TRACE();
DECLARE_VIRTUAL_TRACE_WRAPPERS();
private:
PopStateEvent();
PopStateEvent(const AtomicString&, const PopStateEventInit&);
PopStateEvent(ScriptState*, const AtomicString&, const PopStateEventInit&);
PopStateEvent(PassRefPtr<SerializedScriptValue>, History*);
RefPtr<SerializedScriptValue> serialized_state_;
ScriptValue state_;
RefPtr<DOMWrapperWorld> world_;
TraceWrapperV8Reference<v8::Value> state_;
Member<History> history_;
};
......
......@@ -28,6 +28,7 @@
[
Constructor(DOMString type, optional PopStateEventInit eventInitDict),
ConstructorCallWith=ScriptState
// TODO(foolip): Exposed=(Window,Worker)
] interface PopStateEvent : Event {
[Custom=Getter] readonly attribute any state;
......
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