OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/V8ServiceWorkerMessageEvent.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/V8HiddenValue.h" | 9 #include "bindings/core/v8/V8HiddenValue.h" |
10 #include "bindings/modules/v8/V8ServiceWorkerMessageEventInit.h" | |
9 | 11 |
10 namespace blink { | 12 namespace blink { |
11 | 13 |
14 void V8ServiceWorkerMessageEvent::constructorCustom(const v8::FunctionCallbackIn fo<v8::Value>& info) | |
15 { | |
16 ExceptionState exceptionState(ExceptionState::ConstructionContext, "ServiceW orkerMessageEvent", info.Holder(), info.GetIsolate()); | |
17 if (UNLIKELY(info.Length() < 1)) { | |
18 setMinimumArityTypeError(exceptionState, 1, info.Length()); | |
19 exceptionState.throwIfNeeded(); | |
20 return; | |
21 } | |
22 | |
23 V8StringResource<> type = info[0]; | |
24 if (!type.prepare()) | |
25 return; | |
26 | |
27 ServiceWorkerMessageEventInit eventInitDict; | |
28 if (!isUndefinedOrNull(info[1])) { | |
29 if (!info[1]->IsObject()) { | |
30 exceptionState.throwTypeError("parameter 2 ('eventInitDict') is not an object."); | |
31 exceptionState.throwIfNeeded(); | |
32 return; | |
33 } | |
34 V8ServiceWorkerMessageEventInit::toImpl(info.GetIsolate(), info[1], even tInitDict, exceptionState); | |
35 if (exceptionState.throwIfNeeded()) | |
36 return; | |
37 } | |
38 | |
39 RefPtrWillBeRawPtr<ServiceWorkerMessageEvent> impl = ServiceWorkerMessageEve nt::create(type, eventInitDict); | |
40 v8::Local<v8::Object> wrapper = info.Holder(); | |
41 wrapper = impl->associateWithWrapper(info.GetIsolate(), &V8ServiceWorkerMess ageEvent::wrapperTypeInfo, wrapper); | |
42 | |
43 // TODO(bashi): Workaround for http://crbug.com/529941. We need to store | |
44 // |data| as a hidden value to avoid cycle references. | |
45 if (eventInitDict.hasData()) { | |
46 v8::Local<v8::Value> v8Data = eventInitDict.data().v8Value(); | |
47 V8HiddenValue::setHiddenValue(ScriptState::current(info.GetIsolate()), w rapper, V8HiddenValue::data(info.GetIsolate()), v8Data); | |
48 if (DOMWrapperWorld::current(info.GetIsolate()).isIsolatedWorld()) | |
49 impl->setSerializedData(SerializedScriptValueFactory::instance().cre ateAndSwallowExceptions(info.GetIsolate(), v8Data)); | |
50 } | |
51 v8SetReturnValue(info, wrapper); | |
52 } | |
53 | |
12 void V8ServiceWorkerMessageEvent::dataAttributeGetterCustom(const v8::FunctionCa llbackInfo<v8::Value>& info) | 54 void V8ServiceWorkerMessageEvent::dataAttributeGetterCustom(const v8::FunctionCa llbackInfo<v8::Value>& info) |
13 { | 55 { |
14 ServiceWorkerMessageEvent* event = V8ServiceWorkerMessageEvent::toImpl(info. Holder()); | 56 ServiceWorkerMessageEvent* event = V8ServiceWorkerMessageEvent::toImpl(info. Holder()); |
15 v8::Isolate* isolate = info.GetIsolate(); | 57 v8::Isolate* isolate = info.GetIsolate(); |
16 ScriptState* scriptState = ScriptState::current(isolate); | 58 ScriptState* scriptState = ScriptState::current(isolate); |
17 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)); |
18 | 60 |
19 if (!result.IsEmpty()) { | 61 if (!result.IsEmpty()) { |
20 v8SetReturnValue(info, result); | 62 v8SetReturnValue(info, result); |
21 return; | 63 return; |
22 } | 64 } |
23 | 65 |
24 v8::Local<v8::Value> data; | 66 v8::Local<v8::Value> data; |
25 if (SerializedScriptValue* serializedValue = event->serializedData()) { | 67 if (SerializedScriptValue* serializedValue = event->serializedData()) { |
26 MessagePortArray ports = event->ports(); | 68 MessagePortArray ports = event->ports(); |
27 data = serializedValue->deserialize(isolate, &ports); | 69 data = serializedValue->deserialize(isolate, &ports); |
28 } else { | 70 } else if (DOMWrapperWorld::current(isolate).isIsolatedWorld()) { |
29 data = event->data().v8ValueFor(scriptState); | 71 v8::Local<v8::Value> mainWorldData = V8HiddenValue::getHiddenValueFromMa inWorldWrapper(scriptState, event, V8HiddenValue::data(isolate)); |
72 if (!mainWorldData.IsEmpty()) { | |
73 event->setSerializedData(SerializedScriptValueFactory::instance().cr eateAndSwallowExceptions(info.GetIsolate(), mainWorldData)); | |
haraken
2016/02/10 04:13:07
Not directly related to your CL, I think we should
bashi
2016/02/10 04:43:38
I see. Will do that in a follow-up CL (including o
| |
74 data = event->serializedData()->deserialize(); | |
75 } | |
30 } | 76 } |
31 if (data.IsEmpty()) | 77 if (data.IsEmpty()) |
32 data = v8::Null(isolate); | 78 data = v8::Null(isolate); |
33 V8HiddenValue::setHiddenValue(scriptState, info.Holder(), V8HiddenValue::dat a(isolate), data); | 79 V8HiddenValue::setHiddenValue(scriptState, info.Holder(), V8HiddenValue::dat a(isolate), data); |
34 v8SetReturnValue(info, data); | 80 v8SetReturnValue(info, data); |
35 } | 81 } |
36 | 82 |
37 } // namespace blink | 83 } // namespace blink |
OLD | NEW |