OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8ServiceWorkerMessageEventInternal_h | 5 #ifndef V8ServiceWorkerMessageEventInternal_h |
6 #define V8ServiceWorkerMessageEventInternal_h | 6 #define V8ServiceWorkerMessageEventInternal_h |
7 | 7 |
8 #include "bindings/core/v8/SerializedScriptValue.h" | 8 #include "bindings/core/v8/SerializedScriptValue.h" |
9 #include "bindings/core/v8/SerializedScriptValueFactory.h" | 9 #include "bindings/core/v8/SerializedScriptValueFactory.h" |
10 #include "bindings/core/v8/V8HiddenValue.h" | 10 #include "bindings/core/v8/V8PrivateProperty.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 class V8ServiceWorkerMessageEventInternal { | 14 class V8ServiceWorkerMessageEventInternal { |
15 public: | 15 public: |
16 template <typename EventType, typename DictType> | 16 template <typename EventType, typename DictType> |
17 static void constructorCustom(const v8::FunctionCallbackInfo<v8::Value>&); | 17 static void constructorCustom(const v8::FunctionCallbackInfo<v8::Value>&); |
18 | 18 |
19 template <typename EventType> | 19 template <typename EventType> |
20 static void dataAttributeGetterCustom(const v8::FunctionCallbackInfo<v8::Val
ue>&); | 20 static void dataAttributeGetterCustom(const v8::FunctionCallbackInfo<v8::Val
ue>&); |
(...skipping 23 matching lines...) Expand all Loading... |
44 V8TypeOf<DictType>::Type::toImpl(info.GetIsolate(), info[1], eventInitDi
ct, exceptionState); | 44 V8TypeOf<DictType>::Type::toImpl(info.GetIsolate(), info[1], eventInitDi
ct, exceptionState); |
45 if (exceptionState.throwIfNeeded()) | 45 if (exceptionState.throwIfNeeded()) |
46 return; | 46 return; |
47 } | 47 } |
48 | 48 |
49 EventType* impl = EventType::create(type, eventInitDict); | 49 EventType* impl = EventType::create(type, eventInitDict); |
50 v8::Local<v8::Object> wrapper = info.Holder(); | 50 v8::Local<v8::Object> wrapper = info.Holder(); |
51 wrapper = impl->associateWithWrapper(info.GetIsolate(), &V8TypeOf<EventType>
::Type::wrapperTypeInfo, wrapper); | 51 wrapper = impl->associateWithWrapper(info.GetIsolate(), &V8TypeOf<EventType>
::Type::wrapperTypeInfo, wrapper); |
52 | 52 |
53 // TODO(bashi): Workaround for http://crbug.com/529941. We need to store | 53 // TODO(bashi): Workaround for http://crbug.com/529941. We need to store |
54 // |data| as a hidden value to avoid cycle references. | 54 // |data| as a private value to avoid cyclic references. |
55 if (eventInitDict.hasData()) { | 55 if (eventInitDict.hasData()) { |
56 v8::Local<v8::Value> v8Data = eventInitDict.data().v8Value(); | 56 v8::Local<v8::Value> v8Data = eventInitDict.data().v8Value(); |
57 V8HiddenValue::setHiddenValue(ScriptState::current(info.GetIsolate()), w
rapper, V8HiddenValue::data(info.GetIsolate()), v8Data); | 57 V8PrivateProperty::getMessageEventCachedData(info.GetIsolate()).set(info
.GetIsolate()->GetCurrentContext(), wrapper, v8Data); |
58 if (DOMWrapperWorld::current(info.GetIsolate()).isIsolatedWorld()) | 58 if (DOMWrapperWorld::current(info.GetIsolate()).isIsolatedWorld()) |
59 impl->setSerializedData(SerializedScriptValue::serializeAndSwallowEx
ceptions(info.GetIsolate(), v8Data)); | 59 impl->setSerializedData(SerializedScriptValue::serializeAndSwallowEx
ceptions(info.GetIsolate(), v8Data)); |
60 } | 60 } |
61 v8SetReturnValue(info, wrapper); | 61 v8SetReturnValue(info, wrapper); |
62 } | 62 } |
63 | 63 |
64 template <typename EventType> | 64 template <typename EventType> |
65 void V8ServiceWorkerMessageEventInternal::dataAttributeGetterCustom(const v8::Fu
nctionCallbackInfo<v8::Value>& info) | 65 void V8ServiceWorkerMessageEventInternal::dataAttributeGetterCustom(const v8::Fu
nctionCallbackInfo<v8::Value>& info) |
66 { | 66 { |
67 EventType* event = V8TypeOf<EventType>::Type::toImpl(info.Holder()); | 67 EventType* event = V8TypeOf<EventType>::Type::toImpl(info.Holder()); |
68 v8::Isolate* isolate = info.GetIsolate(); | 68 v8::Isolate* isolate = info.GetIsolate(); |
69 ScriptState* scriptState = ScriptState::current(isolate); | 69 ScriptState* scriptState = ScriptState::current(isolate); |
70 v8::Local<v8::Value> result = V8HiddenValue::getHiddenValue(scriptState, inf
o.Holder(), V8HiddenValue::data(isolate)); | 70 auto privateCachedData = V8PrivateProperty::getMessageEventCachedData(isolat
e); |
71 | 71 v8::Local<v8::Value> result = privateCachedData.get(scriptState->context(),
info.Holder()); |
72 if (!result.IsEmpty()) { | 72 if (!result.IsEmpty()) { |
73 v8SetReturnValue(info, result); | 73 v8SetReturnValue(info, result); |
74 return; | 74 return; |
75 } | 75 } |
76 | 76 |
77 v8::Local<v8::Value> data; | 77 v8::Local<v8::Value> data; |
78 if (SerializedScriptValue* serializedValue = event->serializedData()) { | 78 if (SerializedScriptValue* serializedValue = event->serializedData()) { |
79 MessagePortArray ports = event->ports(); | 79 MessagePortArray ports = event->ports(); |
80 data = serializedValue->deserialize(isolate, &ports); | 80 data = serializedValue->deserialize(isolate, &ports); |
81 } else if (DOMWrapperWorld::current(isolate).isIsolatedWorld()) { | 81 } else if (DOMWrapperWorld::current(isolate).isIsolatedWorld()) { |
82 v8::Local<v8::Value> mainWorldData = V8HiddenValue::getHiddenValueFromMa
inWorldWrapper(scriptState, event, V8HiddenValue::data(isolate)); | 82 v8::Local<v8::Value> mainWorldData = privateCachedData.getFromMainWorld(
scriptState, event); |
83 if (!mainWorldData.IsEmpty()) { | 83 if (!mainWorldData.IsEmpty()) { |
84 // TODO(bashi): Enter the main world's ScriptState::Scope while | 84 // TODO(bashi): Enter the main world's ScriptState::Scope while |
85 // serializing the main world's value. | 85 // serializing the main world's value. |
86 event->setSerializedData(SerializedScriptValue::serializeAndSwallowE
xceptions(info.GetIsolate(), mainWorldData)); | 86 event->setSerializedData(SerializedScriptValue::serializeAndSwallowE
xceptions(info.GetIsolate(), mainWorldData)); |
87 data = event->serializedData()->deserialize(); | 87 data = event->serializedData()->deserialize(); |
88 } | 88 } |
89 } | 89 } |
90 if (data.IsEmpty()) | 90 if (data.IsEmpty()) |
91 data = v8::Null(isolate); | 91 data = v8::Null(isolate); |
92 V8HiddenValue::setHiddenValue(scriptState, info.Holder(), V8HiddenValue::dat
a(isolate), data); | 92 privateCachedData.set(scriptState->context(), info.Holder(), data); |
93 v8SetReturnValue(info, data); | 93 v8SetReturnValue(info, data); |
94 } | 94 } |
95 | 95 |
96 } // namespace blink | 96 } // namespace blink |
97 | 97 |
98 #endif // V8ServiceWorkerMessageEventInternal_h | 98 #endif // V8ServiceWorkerMessageEventInternal_h |
OLD | NEW |