Chromium Code Reviews| Index: third_party/WebKit/Source/bindings/core/v8/custom/V8PopStateEventCustom.cpp |
| diff --git a/third_party/WebKit/Source/bindings/core/v8/custom/V8PopStateEventCustom.cpp b/third_party/WebKit/Source/bindings/core/v8/custom/V8PopStateEventCustom.cpp |
| index 141a8426f20404c2afa61835d9fdbd345b6510c0..cc62b5f4f247fee86321eedc47911cc72b8eda46 100644 |
| --- a/third_party/WebKit/Source/bindings/core/v8/custom/V8PopStateEventCustom.cpp |
| +++ b/third_party/WebKit/Source/bindings/core/v8/custom/V8PopStateEventCustom.cpp |
| @@ -32,21 +32,25 @@ |
| #include "bindings/core/v8/SerializedScriptValue.h" |
| #include "bindings/core/v8/SerializedScriptValueFactory.h" |
| -#include "bindings/core/v8/V8HiddenValue.h" |
| #include "bindings/core/v8/V8History.h" |
| +#include "bindings/core/v8/V8PrivateProperty.h" |
| #include "core/events/PopStateEvent.h" |
| #include "core/frame/History.h" |
| namespace blink { |
| +namespace { |
| +// kSymbolKey must be equal to the key in generated V8History.cpp |
| +constexpr char kSymbolKey[] = "History#State"; |
|
Yuki
2017/03/31 13:38:29
Could you add a TODO comment, here?
This is abuse
peria
2017/04/03 04:58:43
Done.
|
| +} |
| + |
| // Save the state value to a hidden attribute in the V8PopStateEvent, and return |
| // it, for convenience. |
| static v8::Local<v8::Value> cacheState(ScriptState* scriptState, |
| v8::Local<v8::Object> popStateEvent, |
| v8::Local<v8::Value> state) { |
| - V8HiddenValue::setHiddenValue(scriptState, popStateEvent, |
| - V8HiddenValue::state(scriptState->isolate()), |
| - state); |
| + V8PrivateProperty::createSymbol(scriptState->isolate(), kSymbolKey) |
|
Yuki
2017/03/31 13:38:29
We don't need to kSymbolKey for |popStateEvent| or
peria
2017/04/03 04:58:43
Done.
|
| + .set(popStateEvent, state); |
| return state; |
| } |
| @@ -54,10 +58,11 @@ void V8PopStateEvent::stateAttributeGetterCustom( |
| const v8::FunctionCallbackInfo<v8::Value>& info) { |
| v8::Isolate* isolate = info.GetIsolate(); |
| ScriptState* scriptState = ScriptState::current(isolate); |
| - v8::Local<v8::Value> result = V8HiddenValue::getHiddenValue( |
| - scriptState, info.Holder(), V8HiddenValue::state(isolate)); |
| + V8PrivateProperty::Symbol propertySymbol = |
| + V8PrivateProperty::createSymbol(isolate, kSymbolKey); |
| + v8::Local<v8::Value> result = propertySymbol.getOrUndefined(info.Holder()); |
| - if (!result.IsEmpty()) { |
| + if (!result->IsUndefined()) { |
|
Yuki
2017/03/31 13:38:29
Are you sure that the state attribute never be und
peria
2017/04/03 04:58:43
State must be a serializable object, and "undefine
|
| v8SetReturnValue(info, result); |
| return; |
| } |
| @@ -93,17 +98,14 @@ void V8PopStateEvent::stateAttributeGetterCustom( |
| if (v8HistoryValue.IsEmpty()) |
| return; |
| v8::Local<v8::Object> v8History = v8HistoryValue.As<v8::Object>(); |
| - if (!history->stateChanged()) { |
| - result = V8HiddenValue::getHiddenValue(scriptState, v8History, |
| - V8HiddenValue::state(isolate)); |
| - if (!result.IsEmpty()) { |
| - v8SetReturnValue(info, cacheState(scriptState, info.Holder(), result)); |
| - return; |
| - } |
| + if (!history->stateChanged() && propertySymbol.hasValue(v8History)) { |
|
Yuki
2017/03/31 13:38:29
I don't think that this part is performance sensit
peria
2017/04/03 04:58:43
Acknowledged.
|
| + v8SetReturnValue(info, |
| + cacheState(scriptState, info.Holder(), |
| + propertySymbol.getOrUndefined(v8History))); |
| + return; |
| } |
| result = event->serializedState()->deserialize(isolate); |
| - V8HiddenValue::setHiddenValue(scriptState, v8History, |
| - V8HiddenValue::state(isolate), result); |
| + propertySymbol.set(v8History, result); |
| } else { |
| result = event->serializedState()->deserialize(isolate); |
| } |