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/V8PrivateProperty.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>&); |
21 }; | 21 }; |
22 | 22 |
23 template <typename EventType, typename DictType> | 23 template <typename EventType, typename DictType> |
24 void V8ServiceWorkerMessageEventInternal::constructorCustom(const v8::FunctionCa
llbackInfo<v8::Value>& info) | 24 void V8ServiceWorkerMessageEventInternal::constructorCustom(const v8::FunctionCa
llbackInfo<v8::Value>& info) |
25 { | 25 { |
26 ExceptionState exceptionState(ExceptionState::ConstructionContext, V8TypeOf<
EventType>::Type::wrapperTypeInfo.interfaceName, info.Holder(), info.GetIsolate(
)); | 26 ExceptionState exceptionState(ExceptionState::ConstructionContext, V8TypeOf<
EventType>::Type::wrapperTypeInfo.interfaceName, info.Holder(), info.GetIsolate(
)); |
27 if (UNLIKELY(info.Length() < 1)) { | 27 if (UNLIKELY(info.Length() < 1)) { |
28 setMinimumArityTypeError(exceptionState, 1, info.Length()); | 28 setMinimumArityTypeError(exceptionState, 1, info.Length()); |
29 exceptionState.throwIfNeeded(); | |
30 return; | 29 return; |
31 } | 30 } |
32 | 31 |
33 V8StringResource<> type = info[0]; | 32 V8StringResource<> type = info[0]; |
34 if (!type.prepare()) | 33 if (!type.prepare()) |
35 return; | 34 return; |
36 | 35 |
37 DictType eventInitDict; | 36 DictType eventInitDict; |
38 if (!isUndefinedOrNull(info[1])) { | 37 if (!isUndefinedOrNull(info[1])) { |
39 if (!info[1]->IsObject()) { | 38 if (!info[1]->IsObject()) { |
40 exceptionState.throwTypeError("parameter 2 ('eventInitDict') is not
an object."); | 39 exceptionState.throwTypeError("parameter 2 ('eventInitDict') is not
an object."); |
41 exceptionState.throwIfNeeded(); | |
42 return; | 40 return; |
43 } | 41 } |
44 V8TypeOf<DictType>::Type::toImpl(info.GetIsolate(), info[1], eventInitDi
ct, exceptionState); | 42 V8TypeOf<DictType>::Type::toImpl(info.GetIsolate(), info[1], eventInitDi
ct, exceptionState); |
45 if (exceptionState.throwIfNeeded()) | 43 if (exceptionState.hadException()) |
46 return; | 44 return; |
47 } | 45 } |
48 | 46 |
49 EventType* impl = EventType::create(type, eventInitDict); | 47 EventType* impl = EventType::create(type, eventInitDict); |
50 v8::Local<v8::Object> wrapper = info.Holder(); | 48 v8::Local<v8::Object> wrapper = info.Holder(); |
51 wrapper = impl->associateWithWrapper(info.GetIsolate(), &V8TypeOf<EventType>
::Type::wrapperTypeInfo, wrapper); | 49 wrapper = impl->associateWithWrapper(info.GetIsolate(), &V8TypeOf<EventType>
::Type::wrapperTypeInfo, wrapper); |
52 | 50 |
53 // TODO(bashi): Workaround for http://crbug.com/529941. We need to store | 51 // TODO(bashi): Workaround for http://crbug.com/529941. We need to store |
54 // |data| as a private value to avoid cyclic references. | 52 // |data| as a private value to avoid cyclic references. |
55 if (eventInitDict.hasData()) { | 53 if (eventInitDict.hasData()) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 } | 87 } |
90 if (data.IsEmpty()) | 88 if (data.IsEmpty()) |
91 data = v8::Null(isolate); | 89 data = v8::Null(isolate); |
92 privateCachedData.set(scriptState->context(), info.Holder(), data); | 90 privateCachedData.set(scriptState->context(), info.Holder(), data); |
93 v8SetReturnValue(info, data); | 91 v8SetReturnValue(info, data); |
94 } | 92 } |
95 | 93 |
96 } // namespace blink | 94 } // namespace blink |
97 | 95 |
98 #endif // V8ServiceWorkerMessageEventInternal_h | 96 #endif // V8ServiceWorkerMessageEventInternal_h |
OLD | NEW |