|
Lines 31-53
a/Source/WebCore/bindings/v8/custom/V8PopStateEventCustom.cpp_sec1
|
| 31 |
#include "config.h" |
31 |
#include "config.h" |
| 32 |
#include "V8PopStateEvent.h" |
32 |
#include "V8PopStateEvent.h" |
| 33 |
|
33 |
|
|
|
34 |
#include "History.h" |
| 34 |
#include "PopStateEvent.h" |
35 |
#include "PopStateEvent.h" |
| 35 |
#include "SerializedScriptValue.h" |
36 |
#include "SerializedScriptValue.h" |
|
|
37 |
#include "V8HiddenPropertyName.h" |
| 38 |
#include "V8History.h" |
| 36 |
#include "V8Proxy.h" |
39 |
#include "V8Proxy.h" |
| 37 |
|
40 |
|
| 38 |
namespace WebCore { |
41 |
namespace WebCore { |
| 39 |
|
42 |
|
|
|
43 |
// Save the state value to a hidden attribute in the V8PopStateEvent, and return it, for convenience. |
| 44 |
static v8::Handle<v8::Value> cacheState(v8::Handle<v8::Object> popStateEvent, v8::Handle<v8::Value> state) |
| 45 |
{ |
| 46 |
popStateEvent->SetHiddenValue(V8HiddenPropertyName::state(), state); |
| 47 |
return state; |
| 48 |
} |
| 49 |
|
| 40 |
v8::Handle<v8::Value> V8PopStateEvent::stateAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) |
50 |
v8::Handle<v8::Value> V8PopStateEvent::stateAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) |
| 41 |
{ |
51 |
{ |
| 42 |
INC_STATS("DOM.PopStateEvent.state"); |
52 |
INC_STATS("DOM.PopStateEvent.state"); |
| 43 |
|
53 |
|
|
|
54 |
v8::Handle<v8::Value> result = info.Holder()->GetHiddenValue(V8HiddenPropertyName::state()); |
| 55 |
|
| 56 |
if (!result.IsEmpty()) |
| 57 |
return result; |
| 58 |
|
| 44 |
PopStateEvent* event = V8PopStateEvent::toNative(info.Holder()); |
59 |
PopStateEvent* event = V8PopStateEvent::toNative(info.Holder()); |
| 45 |
SerializedScriptValue* serializedState = event->serializedState(); |
|
|
| 46 |
if (serializedState) |
| 47 |
return serializedState->deserialize(); |
| 48 |
if (!event->state().hasNoValue()) |
60 |
if (!event->state().hasNoValue()) |
| 49 |
return event->state().v8Value(); |
61 |
return cacheState(info.Holder(), event->state().v8Value()); |
| 50 |
return v8::Null(); |
62 |
|
|
|
63 |
History* history = event->history(); |
| 64 |
if (!history || !event->serializedState()) |
| 65 |
return cacheState(info.Holder(), v8::Null()); |
| 66 |
|
| 67 |
// There's no cached value from a previous invocation, nor a state value was provided by the |
| 68 |
// event, but there is a history object, so first we need to see if the state object has been |
| 69 |
// deserialized through the history object already. |
| 70 |
// The current history state object might've changed in the meantime, so we need to take care |
| 71 |
// of using the correct one, and always share the same deserialization with history.state. |
| 72 |
|
| 73 |
bool isSameState = history->isSameAsCurrentState(event->serializedState()); |
| 74 |
|
| 75 |
if (isSameState) { |
| 76 |
v8::Handle<v8::Object> v8History = toV8(history).As<v8::Object>(); |
| 77 |
if (!history->stateChanged()) { |
| 78 |
result = v8History->GetHiddenValue(V8HiddenPropertyName::state()); |
| 79 |
if (!result.IsEmpty()) |
| 80 |
return cacheState(info.Holder(), result); |
| 81 |
} |
| 82 |
result = event->serializedState()->deserialize(); |
| 83 |
v8History->SetHiddenValue(V8HiddenPropertyName::state(), result); |
| 84 |
} else |
| 85 |
result = event->serializedState()->deserialize(); |
| 86 |
|
| 87 |
return cacheState(info.Holder(), result); |
| 51 |
} |
88 |
} |
| 52 |
|
89 |
|
| 53 |
} // namespace WebCore |
90 |
} // namespace WebCore |