Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 virtual v8::Handle<v8::Object> associateWithWrapper(v8::Isolate*, const Wrap perTypeInfo*, v8::Handle<v8::Object> wrapper); | 78 virtual v8::Handle<v8::Object> associateWithWrapper(v8::Isolate*, const Wrap perTypeInfo*, v8::Handle<v8::Object> wrapper); |
| 79 | 79 |
| 80 void setWrapper(v8::Handle<v8::Object> wrapper, v8::Isolate* isolate, const WrapperTypeInfo* wrapperTypeInfo) | 80 void setWrapper(v8::Handle<v8::Object> wrapper, v8::Isolate* isolate, const WrapperTypeInfo* wrapperTypeInfo) |
| 81 { | 81 { |
| 82 ASSERT(!containsWrapper()); | 82 ASSERT(!containsWrapper()); |
| 83 if (!*wrapper) | 83 if (!*wrapper) |
| 84 return; | 84 return; |
| 85 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(toScriptWrappable(wrapper) == t his); | 85 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(toScriptWrappable(wrapper) == t his); |
| 86 m_wrapper.Reset(isolate, wrapper); | 86 m_wrapper.Reset(isolate, wrapper); |
| 87 wrapperTypeInfo->configureWrapper(&m_wrapper); | 87 wrapperTypeInfo->configureWrapper(&m_wrapper); |
| 88 m_wrapper.SetWeak(this, &setWeakCallback); | 88 m_wrapper.SetPhantom(&setWeakCallback, v8DOMWrapperTypeIndex, v8DOMWrapp erObjectIndex); |
| 89 ASSERT(containsWrapper()); | 89 ASSERT(containsWrapper()); |
| 90 } | 90 } |
| 91 | 91 |
| 92 v8::Local<v8::Object> newLocalWrapper(v8::Isolate* isolate) const | 92 v8::Local<v8::Object> newLocalWrapper(v8::Isolate* isolate) const |
| 93 { | 93 { |
| 94 return v8::Local<v8::Object>::New(isolate, m_wrapper); | 94 return v8::Local<v8::Object>::New(isolate, m_wrapper); |
| 95 } | 95 } |
| 96 | 96 |
| 97 bool isEqualTo(const v8::Local<v8::Object>& other) const | 97 bool isEqualTo(const v8::Local<v8::Object>& other) const |
| 98 { | 98 { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 // With Oilpan we don't need a ScriptWrappable destructor. | 152 // With Oilpan we don't need a ScriptWrappable destructor. |
| 153 // | 153 // |
| 154 // - 'RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!containsWrapper())' is not n eeded | 154 // - 'RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!containsWrapper())' is not n eeded |
| 155 // because Oilpan is not using reference counting at all. If containsWrapper () is true, | 155 // because Oilpan is not using reference counting at all. If containsWrapper () is true, |
| 156 // it means that ScriptWrappable still has a wrapper. In this case, the dest ructor | 156 // it means that ScriptWrappable still has a wrapper. In this case, the dest ructor |
| 157 // must not be called since the wrapper has a persistent handle back to this ScriptWrappable object. | 157 // must not be called since the wrapper has a persistent handle back to this ScriptWrappable object. |
| 158 // Assuming that Oilpan's GC is correct (If we cannot assume this, a lot of more things are | 158 // Assuming that Oilpan's GC is correct (If we cannot assume this, a lot of more things are |
| 159 // already broken), we must not hit the RELEASE_ASSERT. | 159 // already broken), we must not hit the RELEASE_ASSERT. |
| 160 | 160 |
| 161 private: | 161 private: |
| 162 void disposeWrapper(v8::Local<v8::Object> wrapper) | 162 static void setWeakCallback(const v8::InternalFieldsCallbackData<WrapperType Info, ScriptWrappable>& data) |
| 163 { | 163 { |
| 164 ASSERT(containsWrapper()); | |
| 165 ASSERT(wrapper == m_wrapper); | |
| 166 m_wrapper.Reset(); | |
| 167 } | |
| 168 | |
| 169 static void setWeakCallback(const v8::WeakCallbackData<v8::Object, ScriptWra ppable>& data) | |
| 170 { | |
| 171 data.GetParameter()->disposeWrapper(data.GetValue()); | |
| 172 | |
| 173 // FIXME: I noticed that 50%~ of minor GC cycle times can be consumed | 164 // FIXME: I noticed that 50%~ of minor GC cycle times can be consumed |
| 174 // inside data.GetParameter()->deref(), which causes Node destructions. We should | 165 // inside data.GetParameter()->deref(), which causes Node destructions. We should |
| 175 // make Node destructions incremental. | 166 // make Node destructions incremental. |
| 176 releaseObject(data.GetValue()); | 167 WrapperTypeInfo* wrapperTypeInfo = reinterpret_cast<WrapperTypeInfo*>(da ta.GetInternalField1()); |
| 168 ScriptWrappable* scriptWrappable = reinterpret_cast<ScriptWrappable*>(da ta.GetInternalField2()); | |
| 169 scriptWrappable->m_wrapper.Empty(); | |
|
haraken
2015/01/07 15:51:41
Do we go with Empty, whereas other similar V8 APIs
Erik Corry Chromium.org
2015/01/07 16:07:56
Empty is to match the preexisting IsEmpty(). Rese
| |
| 170 wrapperTypeInfo->derefObject(scriptWrappable); | |
| 177 } | 171 } |
| 178 | 172 |
| 179 v8::Persistent<v8::Object> m_wrapper; | 173 v8::Persistent<v8::Object> m_wrapper; |
| 180 }; | 174 }; |
| 181 | 175 |
| 182 // Defines 'wrapperTypeInfo' virtual method which returns the WrapperTypeInfo of | 176 // Defines 'wrapperTypeInfo' virtual method which returns the WrapperTypeInfo of |
| 183 // the instance. Also declares a static member of type WrapperTypeInfo, of which | 177 // the instance. Also declares a static member of type WrapperTypeInfo, of which |
| 184 // the definition is given by the IDL code generator. | 178 // the definition is given by the IDL code generator. |
| 185 // | 179 // |
| 186 // All the derived classes of ScriptWrappable, regardless of directly or | 180 // All the derived classes of ScriptWrappable, regardless of directly or |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 210 { \ | 204 { \ |
| 211 ASSERT_NOT_REACHED(); \ | 205 ASSERT_NOT_REACHED(); \ |
| 212 return 0; \ | 206 return 0; \ |
| 213 } \ | 207 } \ |
| 214 private: \ | 208 private: \ |
| 215 typedef void end_of_define_wrappertypeinfo_not_reached_t | 209 typedef void end_of_define_wrappertypeinfo_not_reached_t |
| 216 | 210 |
| 217 } // namespace blink | 211 } // namespace blink |
| 218 | 212 |
| 219 #endif // ScriptWrappable_h | 213 #endif // ScriptWrappable_h |
| OLD | NEW |