| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 // adopted and so forth. The overloaded initializeScriptWrappableForInterfac
e() | 141 // adopted and so forth. The overloaded initializeScriptWrappableForInterfac
e() |
| 142 // functions are implemented by the generated V8 bindings code. Declaring th
e | 142 // functions are implemented by the generated V8 bindings code. Declaring th
e |
| 143 // extern function in the template avoids making a centralized header of all | 143 // extern function in the template avoids making a centralized header of all |
| 144 // the bindings in the universe. C++11's extern template feature may provide | 144 // the bindings in the universe. C++11's extern template feature may provide |
| 145 // a cleaner solution someday. | 145 // a cleaner solution someday. |
| 146 template <class C> static void init(C* object) | 146 template <class C> static void init(C* object) |
| 147 { | 147 { |
| 148 initializeScriptWrappableHelper(object); | 148 initializeScriptWrappableHelper(object); |
| 149 } | 149 } |
| 150 | 150 |
| 151 // Returns the WrapperTypeInfo of the instance. |
| 152 // |
| 153 // This method must be overridden by DEFINE_WRAPPERTYPEINFO macro. |
| 154 virtual const WrapperTypeInfo* wrapperTypeInfo() const = 0; |
| 155 |
| 156 // Creates and returns a new wrapper object. |
| 157 virtual v8::Handle<v8::Object> wrap(v8::Handle<v8::Object> creationContext,
v8::Isolate*); |
| 158 |
| 151 void setWrapper(v8::Handle<v8::Object> wrapper, v8::Isolate* isolate, const
WrapperTypeInfo* wrapperTypeInfo) | 159 void setWrapper(v8::Handle<v8::Object> wrapper, v8::Isolate* isolate, const
WrapperTypeInfo* wrapperTypeInfo) |
| 152 { | 160 { |
| 153 ASSERT(!containsWrapper()); | 161 ASSERT(!containsWrapper()); |
| 154 if (!*wrapper) { | 162 if (!*wrapper) { |
| 155 m_wrapperOrTypeInfo = 0; | 163 m_wrapperOrTypeInfo = 0; |
| 156 return; | 164 return; |
| 157 } | 165 } |
| 158 v8::Persistent<v8::Object> persistent(isolate, wrapper); | 166 v8::Persistent<v8::Object> persistent(isolate, wrapper); |
| 159 wrapperTypeInfo->configureWrapper(&persistent); | 167 wrapperTypeInfo->configureWrapper(&persistent); |
| 160 persistent.SetWeak(this, &setWeakCallback); | 168 persistent.SetWeak(this, &setWeakCallback); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 ASSERT(persistent == data.GetValue()); | 339 ASSERT(persistent == data.GetValue()); |
| 332 data.GetParameter()->disposeWrapper(data.GetValue()); | 340 data.GetParameter()->disposeWrapper(data.GetValue()); |
| 333 | 341 |
| 334 // FIXME: I noticed that 50%~ of minor GC cycle times can be consumed | 342 // FIXME: I noticed that 50%~ of minor GC cycle times can be consumed |
| 335 // inside data.GetParameter()->deref(), which causes Node destructions.
We should | 343 // inside data.GetParameter()->deref(), which causes Node destructions.
We should |
| 336 // make Node destructions incremental. | 344 // make Node destructions incremental. |
| 337 releaseObject(data.GetValue()); | 345 releaseObject(data.GetValue()); |
| 338 } | 346 } |
| 339 }; | 347 }; |
| 340 | 348 |
| 349 // Defines 'wrapperTypeInfo' virtual method which returns the WrapperTypeInfo of |
| 350 // the instance. Also declares a static member of type WrapperTypeInfo, of which |
| 351 // the definition is given by the IDL code generator. |
| 352 // |
| 353 // Every DOM Class T must meet either of the following conditions: |
| 354 // - T.idl inherits from [NotScriptWrappable] or has [NoInterfaceObject]. |
| 355 // - T inherits from ScriptWrappable and has DEFINE_WRAPPERTYPEINFO(). |
| 356 // |
| 357 // All the derived classes of ScriptWrappable, regardless of directly or |
| 358 // indirectly, must write this macro in the class definition except for the case |
| 359 // that the class is [NoInterfaceObject]. In the case of [NoInterfaceObject], |
| 360 // the IDL code generator does not generate V8T.cpp, so the definition of |
| 361 // T::s_wrapperTypeInfo will not be generated, either. |
| 362 // |
| 363 // If a DOM class T does not inherit from ScriptWrappable, you have to write |
| 364 // [NotScriptWrappable] in the IDL file as an extended attribute in order to let |
| 365 // IDL code generator know that T does not inherit from ScriptWrappable. Note |
| 366 // that [NotScriptWrappable] is inheritable. |
| 367 #define DEFINE_WRAPPERTYPEINFO() \ |
| 368 public: \ |
| 369 virtual const WrapperTypeInfo* wrapperTypeInfo() const OVERRIDE \ |
| 370 { \ |
| 371 return &s_wrapperTypeInfo; \ |
| 372 } \ |
| 373 private: \ |
| 374 static const WrapperTypeInfo& s_wrapperTypeInfo |
| 375 |
| 341 } // namespace blink | 376 } // namespace blink |
| 342 | 377 |
| 343 #endif // ScriptWrappable_h | 378 #endif // ScriptWrappable_h |
| OLD | NEW |