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" | |
8 #include "bindings/core/v8/SerializedScriptValueFactory.h" | |
9 #include "bindings/core/v8/V8HiddenValue.h" | |
10 #include "bindings/modules/v8/V8ServiceWorkerMessageEventInit.h" | 7 #include "bindings/modules/v8/V8ServiceWorkerMessageEventInit.h" |
| 8 #include "bindings/modules/v8/V8ServiceWorkerMessageEventInternal.h" |
11 | 9 |
12 namespace blink { | 10 namespace blink { |
13 | 11 |
14 void V8ServiceWorkerMessageEvent::constructorCustom(const v8::FunctionCallbackIn
fo<v8::Value>& info) | 12 void V8ServiceWorkerMessageEvent::constructorCustom(const v8::FunctionCallbackIn
fo<v8::Value>& info) |
15 { | 13 { |
16 ExceptionState exceptionState(ExceptionState::ConstructionContext, "ServiceW
orkerMessageEvent", info.Holder(), info.GetIsolate()); | 14 V8ServiceWorkerMessageEventInternal::constructorCustom<ServiceWorkerMessageE
vent, ServiceWorkerMessageEventInit>(info); |
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 } | 15 } |
53 | 16 |
54 void V8ServiceWorkerMessageEvent::dataAttributeGetterCustom(const v8::FunctionCa
llbackInfo<v8::Value>& info) | 17 void V8ServiceWorkerMessageEvent::dataAttributeGetterCustom(const v8::FunctionCa
llbackInfo<v8::Value>& info) |
55 { | 18 { |
56 ServiceWorkerMessageEvent* event = V8ServiceWorkerMessageEvent::toImpl(info.
Holder()); | 19 V8ServiceWorkerMessageEventInternal::dataAttributeGetterCustom<ServiceWorker
MessageEvent>(info); |
57 v8::Isolate* isolate = info.GetIsolate(); | |
58 ScriptState* scriptState = ScriptState::current(isolate); | |
59 v8::Local<v8::Value> result = V8HiddenValue::getHiddenValue(scriptState, inf
o.Holder(), V8HiddenValue::data(isolate)); | |
60 | |
61 if (!result.IsEmpty()) { | |
62 v8SetReturnValue(info, result); | |
63 return; | |
64 } | |
65 | |
66 v8::Local<v8::Value> data; | |
67 if (SerializedScriptValue* serializedValue = event->serializedData()) { | |
68 MessagePortArray ports = event->ports(); | |
69 data = serializedValue->deserialize(isolate, &ports); | |
70 } else if (DOMWrapperWorld::current(isolate).isIsolatedWorld()) { | |
71 v8::Local<v8::Value> mainWorldData = V8HiddenValue::getHiddenValueFromMa
inWorldWrapper(scriptState, event, V8HiddenValue::data(isolate)); | |
72 if (!mainWorldData.IsEmpty()) { | |
73 // TODO(bashi): Enter the main world's ScriptState::Scope while | |
74 // serializing the main world's value. | |
75 event->setSerializedData(SerializedScriptValueFactory::instance().cr
eateAndSwallowExceptions(info.GetIsolate(), mainWorldData)); | |
76 data = event->serializedData()->deserialize(); | |
77 } | |
78 } | |
79 if (data.IsEmpty()) | |
80 data = v8::Null(isolate); | |
81 V8HiddenValue::setHiddenValue(scriptState, info.Holder(), V8HiddenValue::dat
a(isolate), data); | |
82 v8SetReturnValue(info, data); | |
83 } | 20 } |
84 | 21 |
85 } // namespace blink | 22 } // namespace blink |
OLD | NEW |