OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 #include "bindings/core/v8/ScopedPersistent.h" | 34 #include "bindings/core/v8/ScopedPersistent.h" |
35 #include "bindings/core/v8/V0CustomElementBinding.h" | 35 #include "bindings/core/v8/V0CustomElementBinding.h" |
36 #include "bindings/core/v8/V8GlobalValueMap.h" | 36 #include "bindings/core/v8/V8GlobalValueMap.h" |
37 #include "bindings/core/v8/WrapperTypeInfo.h" | 37 #include "bindings/core/v8/WrapperTypeInfo.h" |
38 #include "core/CoreExport.h" | 38 #include "core/CoreExport.h" |
39 #include "gin/public/context_holder.h" | 39 #include "gin/public/context_holder.h" |
40 #include "gin/public/gin_embedders.h" | 40 #include "gin/public/gin_embedders.h" |
41 #include "wtf/Allocator.h" | 41 #include "wtf/Allocator.h" |
42 #include "wtf/HashMap.h" | 42 #include "wtf/HashMap.h" |
| 43 #include "wtf/PassOwnPtr.h" |
43 #include "wtf/Vector.h" | 44 #include "wtf/Vector.h" |
44 #include "wtf/text/AtomicString.h" | 45 #include "wtf/text/AtomicString.h" |
45 #include "wtf/text/AtomicStringHash.h" | 46 #include "wtf/text/AtomicStringHash.h" |
46 #include <memory> | |
47 #include <v8.h> | 47 #include <v8.h> |
48 | 48 |
49 namespace blink { | 49 namespace blink { |
50 | 50 |
51 class V8DOMActivityLogger; | 51 class V8DOMActivityLogger; |
52 class V8PerContextData; | 52 class V8PerContextData; |
53 | 53 |
54 enum V8ContextEmbedderDataField { | 54 enum V8ContextEmbedderDataField { |
55 v8ContextPerContextDataIndex = static_cast<int>(gin::kPerContextDataStartInd
ex + gin::kEmbedderBlink), | 55 v8ContextPerContextDataIndex = static_cast<int>(gin::kPerContextDataStartInd
ex + gin::kEmbedderBlink), |
56 }; | 56 }; |
57 | 57 |
58 class CORE_EXPORT V8PerContextData final { | 58 class CORE_EXPORT V8PerContextData final { |
59 USING_FAST_MALLOC(V8PerContextData); | 59 USING_FAST_MALLOC(V8PerContextData); |
60 WTF_MAKE_NONCOPYABLE(V8PerContextData); | 60 WTF_MAKE_NONCOPYABLE(V8PerContextData); |
61 public: | 61 public: |
62 static std::unique_ptr<V8PerContextData> create(v8::Local<v8::Context>); | 62 static PassOwnPtr<V8PerContextData> create(v8::Local<v8::Context>); |
63 | 63 |
64 static V8PerContextData* from(v8::Local<v8::Context>); | 64 static V8PerContextData* from(v8::Local<v8::Context>); |
65 | 65 |
66 ~V8PerContextData(); | 66 ~V8PerContextData(); |
67 | 67 |
68 v8::Local<v8::Context> context() { return m_context.newLocal(m_isolate); } | 68 v8::Local<v8::Context> context() { return m_context.newLocal(m_isolate); } |
69 | 69 |
70 // To create JS Wrapper objects, we create a cache of a 'boiler plate' | 70 // To create JS Wrapper objects, we create a cache of a 'boiler plate' |
71 // object, and then simply Clone that object each time we need a new one. | 71 // object, and then simply Clone that object each time we need a new one. |
72 // This is faster than going through the full object creation process. | 72 // This is faster than going through the full object creation process. |
73 v8::Local<v8::Object> createWrapperFromCache(const WrapperTypeInfo* type) | 73 v8::Local<v8::Object> createWrapperFromCache(const WrapperTypeInfo* type) |
74 { | 74 { |
75 v8::Local<v8::Object> boilerplate = m_wrapperBoilerplates.Get(type); | 75 v8::Local<v8::Object> boilerplate = m_wrapperBoilerplates.Get(type); |
76 return !boilerplate.IsEmpty() ? boilerplate->Clone() : createWrapperFrom
CacheSlowCase(type); | 76 return !boilerplate.IsEmpty() ? boilerplate->Clone() : createWrapperFrom
CacheSlowCase(type); |
77 } | 77 } |
78 | 78 |
79 v8::Local<v8::Function> constructorForType(const WrapperTypeInfo* type) | 79 v8::Local<v8::Function> constructorForType(const WrapperTypeInfo* type) |
80 { | 80 { |
81 v8::Local<v8::Function> interfaceObject = m_constructorMap.Get(type); | 81 v8::Local<v8::Function> interfaceObject = m_constructorMap.Get(type); |
82 return (!interfaceObject.IsEmpty()) ? interfaceObject : constructorForTy
peSlowCase(type); | 82 return (!interfaceObject.IsEmpty()) ? interfaceObject : constructorForTy
peSlowCase(type); |
83 } | 83 } |
84 | 84 |
85 v8::Local<v8::Object> prototypeForType(const WrapperTypeInfo*); | 85 v8::Local<v8::Object> prototypeForType(const WrapperTypeInfo*); |
86 | 86 |
87 void addCustomElementBinding(std::unique_ptr<V0CustomElementBinding>); | 87 void addCustomElementBinding(PassOwnPtr<V0CustomElementBinding>); |
88 | 88 |
89 V8DOMActivityLogger* activityLogger() const { return m_activityLogger; } | 89 V8DOMActivityLogger* activityLogger() const { return m_activityLogger; } |
90 void setActivityLogger(V8DOMActivityLogger* activityLogger) { m_activityLogg
er = activityLogger; } | 90 void setActivityLogger(V8DOMActivityLogger* activityLogger) { m_activityLogg
er = activityLogger; } |
91 | 91 |
92 v8::Local<v8::Value> compiledPrivateScript(String); | 92 v8::Local<v8::Value> compiledPrivateScript(String); |
93 void setCompiledPrivateScript(String, v8::Local<v8::Value>); | 93 void setCompiledPrivateScript(String, v8::Local<v8::Value>); |
94 | 94 |
95 private: | 95 private: |
96 V8PerContextData(v8::Local<v8::Context>); | 96 V8PerContextData(v8::Local<v8::Context>); |
97 | 97 |
98 v8::Local<v8::Object> createWrapperFromCacheSlowCase(const WrapperTypeInfo*)
; | 98 v8::Local<v8::Object> createWrapperFromCacheSlowCase(const WrapperTypeInfo*)
; |
99 v8::Local<v8::Function> constructorForTypeSlowCase(const WrapperTypeInfo*); | 99 v8::Local<v8::Function> constructorForTypeSlowCase(const WrapperTypeInfo*); |
100 | 100 |
101 v8::Isolate* m_isolate; | 101 v8::Isolate* m_isolate; |
102 | 102 |
103 // For each possible type of wrapper, we keep a boilerplate object. | 103 // For each possible type of wrapper, we keep a boilerplate object. |
104 // The boilerplate is used to create additional wrappers of the same type. | 104 // The boilerplate is used to create additional wrappers of the same type. |
105 typedef V8GlobalValueMap<const WrapperTypeInfo*, v8::Object, v8::kNotWeak> W
rapperBoilerplateMap; | 105 typedef V8GlobalValueMap<const WrapperTypeInfo*, v8::Object, v8::kNotWeak> W
rapperBoilerplateMap; |
106 WrapperBoilerplateMap m_wrapperBoilerplates; | 106 WrapperBoilerplateMap m_wrapperBoilerplates; |
107 | 107 |
108 typedef V8GlobalValueMap<const WrapperTypeInfo*, v8::Function, v8::kNotWeak>
ConstructorMap; | 108 typedef V8GlobalValueMap<const WrapperTypeInfo*, v8::Function, v8::kNotWeak>
ConstructorMap; |
109 ConstructorMap m_constructorMap; | 109 ConstructorMap m_constructorMap; |
110 | 110 |
111 std::unique_ptr<gin::ContextHolder> m_contextHolder; | 111 OwnPtr<gin::ContextHolder> m_contextHolder; |
112 | 112 |
113 ScopedPersistent<v8::Context> m_context; | 113 ScopedPersistent<v8::Context> m_context; |
114 ScopedPersistent<v8::Value> m_errorPrototype; | 114 ScopedPersistent<v8::Value> m_errorPrototype; |
115 | 115 |
116 typedef Vector<std::unique_ptr<V0CustomElementBinding>> V0CustomElementBindi
ngList; | 116 typedef Vector<OwnPtr<V0CustomElementBinding>> V0CustomElementBindingList; |
117 V0CustomElementBindingList m_customElementBindings; | 117 V0CustomElementBindingList m_customElementBindings; |
118 | 118 |
119 // This is owned by a static hash map in V8DOMActivityLogger. | 119 // This is owned by a static hash map in V8DOMActivityLogger. |
120 V8DOMActivityLogger* m_activityLogger; | 120 V8DOMActivityLogger* m_activityLogger; |
121 | 121 |
122 V8GlobalValueMap<String, v8::Value, v8::kNotWeak> m_compiledPrivateScript; | 122 V8GlobalValueMap<String, v8::Value, v8::kNotWeak> m_compiledPrivateScript; |
123 }; | 123 }; |
124 | 124 |
125 } // namespace blink | 125 } // namespace blink |
126 | 126 |
127 #endif // V8PerContextData_h | 127 #endif // V8PerContextData_h |
OLD | NEW |