| 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/V8HiddenValue.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 hidden value to avoid cycle 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 V8HiddenValue::setHiddenValue(ScriptState::current(info.GetIsolate()), w
rapper, V8HiddenValue::data(info.GetIsolate()), v8Data); |
| 58 if (DOMWrapperWorld::current(info.GetIsolate()).isIsolatedWorld()) | 58 if (DOMWrapperWorld::current(info.GetIsolate()).isIsolatedWorld()) |
| 59 impl->setSerializedData(SerializedScriptValueFactory::instance().cre
ateAndSwallowExceptions(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 v8::Local<v8::Value> result = V8HiddenValue::getHiddenValue(scriptState, inf
o.Holder(), V8HiddenValue::data(isolate)); |
| 71 | 71 |
| 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 = V8HiddenValue::getHiddenValueFromMa
inWorldWrapper(scriptState, event, V8HiddenValue::data(isolate)); |
| 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(SerializedScriptValueFactory::instance().cr
eateAndSwallowExceptions(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 V8HiddenValue::setHiddenValue(scriptState, info.Holder(), V8HiddenValue::dat
a(isolate), 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 |