Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 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 #include "bindings/modules/v8/V8ServiceWorkerMessageEvent.h" | 5 #include "bindings/modules/v8/V8ExtendableMessageEvent.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/SerializedScriptValue.h" | 7 #include "bindings/core/v8/SerializedScriptValue.h" |
| 8 #include "bindings/core/v8/SerializedScriptValueFactory.h" | 8 #include "bindings/core/v8/SerializedScriptValueFactory.h" |
| 9 #include "bindings/core/v8/V8HiddenValue.h" | 9 #include "bindings/core/v8/V8HiddenValue.h" |
| 10 #include "bindings/modules/v8/V8ServiceWorkerMessageEventInit.h" | 10 #include "bindings/modules/v8/V8ExtendableMessageEventInit.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 void V8ServiceWorkerMessageEvent::constructorCustom(const v8::FunctionCallbackIn fo<v8::Value>& info) | 14 void V8ExtendableMessageEvent::constructorCustom(const v8::FunctionCallbackInfo< v8::Value>& info) |
|
bashi
2016/02/10 08:23:03
Is it possible to share the implementation with V8
nhiroki
2016/02/10 09:48:41
Thank you for your suggestion. I'm now trying to t
bashi
2016/02/10 10:21:07
Oops, I'll add it. Sorry for inconvenience.
| |
| 15 { | 15 { |
| 16 ExceptionState exceptionState(ExceptionState::ConstructionContext, "ServiceW orkerMessageEvent", info.Holder(), info.GetIsolate()); | 16 ExceptionState exceptionState(ExceptionState::ConstructionContext, "Extendab leMessageEvent", info.Holder(), info.GetIsolate()); |
| 17 if (UNLIKELY(info.Length() < 1)) { | 17 if (UNLIKELY(info.Length() < 1)) { |
| 18 setMinimumArityTypeError(exceptionState, 1, info.Length()); | 18 setMinimumArityTypeError(exceptionState, 1, info.Length()); |
| 19 exceptionState.throwIfNeeded(); | 19 exceptionState.throwIfNeeded(); |
| 20 return; | 20 return; |
| 21 } | 21 } |
| 22 | 22 |
| 23 V8StringResource<> type = info[0]; | 23 V8StringResource<> type = info[0]; |
| 24 if (!type.prepare()) | 24 if (!type.prepare()) |
| 25 return; | 25 return; |
| 26 | 26 |
| 27 ServiceWorkerMessageEventInit eventInitDict; | 27 ExtendableMessageEventInit eventInitDict; |
| 28 if (!isUndefinedOrNull(info[1])) { | 28 if (!isUndefinedOrNull(info[1])) { |
| 29 if (!info[1]->IsObject()) { | 29 if (!info[1]->IsObject()) { |
| 30 exceptionState.throwTypeError("parameter 2 ('eventInitDict') is not an object."); | 30 exceptionState.throwTypeError("parameter 2 ('eventInitDict') is not an object."); |
| 31 exceptionState.throwIfNeeded(); | 31 exceptionState.throwIfNeeded(); |
| 32 return; | 32 return; |
| 33 } | 33 } |
| 34 V8ServiceWorkerMessageEventInit::toImpl(info.GetIsolate(), info[1], even tInitDict, exceptionState); | 34 V8ExtendableMessageEventInit::toImpl(info.GetIsolate(), info[1], eventIn itDict, exceptionState); |
| 35 if (exceptionState.throwIfNeeded()) | 35 if (exceptionState.throwIfNeeded()) |
| 36 return; | 36 return; |
| 37 } | 37 } |
| 38 | 38 |
| 39 RefPtrWillBeRawPtr<ServiceWorkerMessageEvent> impl = ServiceWorkerMessageEve nt::create(type, eventInitDict); | 39 RefPtrWillBeRawPtr<ExtendableMessageEvent> impl = ExtendableMessageEvent::cr eate(type, eventInitDict); |
| 40 v8::Local<v8::Object> wrapper = info.Holder(); | 40 v8::Local<v8::Object> wrapper = info.Holder(); |
| 41 wrapper = impl->associateWithWrapper(info.GetIsolate(), &V8ServiceWorkerMess ageEvent::wrapperTypeInfo, wrapper); | 41 wrapper = impl->associateWithWrapper(info.GetIsolate(), &V8ExtendableMessage Event::wrapperTypeInfo, wrapper); |
| 42 | 42 |
| 43 // TODO(bashi): Workaround for http://crbug.com/529941. We need to store | 43 // TODO(bashi): Workaround for http://crbug.com/529941. We need to store |
| 44 // |data| as a hidden value to avoid cycle references. | 44 // |data| as a hidden value to avoid cycle references. |
| 45 if (eventInitDict.hasData()) { | 45 if (eventInitDict.hasData()) { |
| 46 v8::Local<v8::Value> v8Data = eventInitDict.data().v8Value(); | 46 v8::Local<v8::Value> v8Data = eventInitDict.data().v8Value(); |
| 47 V8HiddenValue::setHiddenValue(ScriptState::current(info.GetIsolate()), w rapper, V8HiddenValue::data(info.GetIsolate()), v8Data); | 47 V8HiddenValue::setHiddenValue(ScriptState::current(info.GetIsolate()), w rapper, V8HiddenValue::data(info.GetIsolate()), v8Data); |
| 48 if (DOMWrapperWorld::current(info.GetIsolate()).isIsolatedWorld()) | 48 if (DOMWrapperWorld::current(info.GetIsolate()).isIsolatedWorld()) |
| 49 impl->setSerializedData(SerializedScriptValueFactory::instance().cre ateAndSwallowExceptions(info.GetIsolate(), v8Data)); | 49 impl->setSerializedData(SerializedScriptValueFactory::instance().cre ateAndSwallowExceptions(info.GetIsolate(), v8Data)); |
| 50 } | 50 } |
| 51 v8SetReturnValue(info, wrapper); | 51 v8SetReturnValue(info, wrapper); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void V8ServiceWorkerMessageEvent::dataAttributeGetterCustom(const v8::FunctionCa llbackInfo<v8::Value>& info) | 54 void V8ExtendableMessageEvent::dataAttributeGetterCustom(const v8::FunctionCallb ackInfo<v8::Value>& info) |
| 55 { | 55 { |
| 56 ServiceWorkerMessageEvent* event = V8ServiceWorkerMessageEvent::toImpl(info. Holder()); | 56 ExtendableMessageEvent* event = V8ExtendableMessageEvent::toImpl(info.Holder ()); |
| 57 v8::Isolate* isolate = info.GetIsolate(); | 57 v8::Isolate* isolate = info.GetIsolate(); |
| 58 ScriptState* scriptState = ScriptState::current(isolate); | 58 ScriptState* scriptState = ScriptState::current(isolate); |
| 59 v8::Local<v8::Value> result = V8HiddenValue::getHiddenValue(scriptState, inf o.Holder(), V8HiddenValue::data(isolate)); | 59 v8::Local<v8::Value> result = V8HiddenValue::getHiddenValue(scriptState, inf o.Holder(), V8HiddenValue::data(isolate)); |
| 60 | 60 |
| 61 if (!result.IsEmpty()) { | 61 if (!result.IsEmpty()) { |
| 62 v8SetReturnValue(info, result); | 62 v8SetReturnValue(info, result); |
| 63 return; | 63 return; |
| 64 } | 64 } |
| 65 | 65 |
| 66 v8::Local<v8::Value> data; | 66 v8::Local<v8::Value> data; |
| 67 if (SerializedScriptValue* serializedValue = event->serializedData()) { | 67 if (SerializedScriptValue* serializedValue = event->serializedData()) { |
| 68 MessagePortArray ports = event->ports(); | 68 MessagePortArray ports = event->ports(); |
| 69 data = serializedValue->deserialize(isolate, &ports); | 69 data = serializedValue->deserialize(isolate, &ports); |
| 70 } else if (DOMWrapperWorld::current(isolate).isIsolatedWorld()) { | 70 } else if (DOMWrapperWorld::current(isolate).isIsolatedWorld()) { |
| 71 v8::Local<v8::Value> mainWorldData = V8HiddenValue::getHiddenValueFromMa inWorldWrapper(scriptState, event, V8HiddenValue::data(isolate)); | 71 v8::Local<v8::Value> mainWorldData = V8HiddenValue::getHiddenValueFromMa inWorldWrapper(scriptState, event, V8HiddenValue::data(isolate)); |
| 72 if (!mainWorldData.IsEmpty()) { | 72 if (!mainWorldData.IsEmpty()) { |
| 73 // TODO(bashi): Enter the main world's ScriptState::Scope while | 73 // TODO(bashi): Enter the main world's ScriptState::Scope while |
| 74 // serializing the main world's value. | 74 // serializing the main world's value. |
| 75 event->setSerializedData(SerializedScriptValueFactory::instance().cr eateAndSwallowExceptions(info.GetIsolate(), mainWorldData)); | 75 event->setSerializedData(SerializedScriptValueFactory::instance().cr eateAndSwallowExceptions(info.GetIsolate(), mainWorldData)); |
| 76 data = event->serializedData()->deserialize(); | 76 data = event->serializedData()->deserialize(); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 if (data.IsEmpty()) | 79 if (data.IsEmpty()) |
| 80 data = v8::Null(isolate); | 80 data = v8::Null(isolate); |
| 81 V8HiddenValue::setHiddenValue(scriptState, info.Holder(), V8HiddenValue::dat a(isolate), data); | 81 V8HiddenValue::setHiddenValue(scriptState, info.Holder(), V8HiddenValue::dat a(isolate), data); |
| 82 v8SetReturnValue(info, data); | 82 v8SetReturnValue(info, data); |
| 83 } | 83 } |
| 84 | 84 |
| 85 } // namespace blink | 85 } // namespace blink |
| OLD | NEW |