| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "sky/engine/config.h" | |
| 6 #include "sky/engine/bindings/core/v8/ScriptWrappable.h" | |
| 7 | |
| 8 #include "sky/engine/bindings/core/v8/DOMDataStore.h" | |
| 9 #include "sky/engine/bindings/core/v8/V8DOMWrapper.h" | |
| 10 | |
| 11 namespace blink { | |
| 12 | |
| 13 struct SameSizeAsScriptWrappableBase { }; | |
| 14 | |
| 15 COMPILE_ASSERT(sizeof(ScriptWrappableBase) <= sizeof(SameSizeAsScriptWrappableBa
se), ScriptWrappableBase_should_stay_small); | |
| 16 | |
| 17 struct SameSizeAsScriptWrappable : public ScriptWrappableBase { | |
| 18 virtual ~SameSizeAsScriptWrappable() { } | |
| 19 uintptr_t m_wrapperOrTypeInfo; | |
| 20 }; | |
| 21 | |
| 22 COMPILE_ASSERT(sizeof(ScriptWrappable) <= sizeof(SameSizeAsScriptWrappable), Scr
iptWrappable_should_stay_small); | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 class ScriptWrappableBaseProtector { | |
| 27 WTF_MAKE_NONCOPYABLE(ScriptWrappableBaseProtector); | |
| 28 public: | |
| 29 ScriptWrappableBaseProtector(ScriptWrappableBase* scriptWrappableBase, const
WrapperTypeInfo* wrapperTypeInfo) | |
| 30 : m_scriptWrappableBase(scriptWrappableBase), m_wrapperTypeInfo(wrapperT
ypeInfo) | |
| 31 { | |
| 32 m_wrapperTypeInfo->refObject(m_scriptWrappableBase); | |
| 33 } | |
| 34 ~ScriptWrappableBaseProtector() | |
| 35 { | |
| 36 m_wrapperTypeInfo->derefObject(m_scriptWrappableBase); | |
| 37 } | |
| 38 | |
| 39 private: | |
| 40 ScriptWrappableBase* m_scriptWrappableBase; | |
| 41 const WrapperTypeInfo* m_wrapperTypeInfo; | |
| 42 }; | |
| 43 | |
| 44 } // namespace | |
| 45 | |
| 46 v8::Handle<v8::Object> ScriptWrappable::wrap(v8::Handle<v8::Object> creationCont
ext, v8::Isolate* isolate) | |
| 47 { | |
| 48 const WrapperTypeInfo* wrapperTypeInfo = this->wrapperTypeInfo(); | |
| 49 | |
| 50 // It's possible that no one except for the new wrapper owns this object at | |
| 51 // this moment, so we have to prevent GC to collect this object until the | |
| 52 // object gets associated with the wrapper. | |
| 53 ScriptWrappableBaseProtector protect(this, wrapperTypeInfo); | |
| 54 | |
| 55 ASSERT(!DOMDataStore::containsWrapperNonTemplate(this, isolate)); | |
| 56 | |
| 57 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext
, wrapperTypeInfo, toScriptWrappableBase(), isolate); | |
| 58 if (UNLIKELY(wrapper.IsEmpty())) | |
| 59 return wrapper; | |
| 60 | |
| 61 wrapperTypeInfo->installConditionallyEnabledProperties(wrapper, isolate); | |
| 62 return associateWithWrapper(wrapperTypeInfo, wrapper, isolate); | |
| 63 } | |
| 64 | |
| 65 v8::Handle<v8::Object> ScriptWrappable::associateWithWrapper(const WrapperTypeIn
fo* wrapperTypeInfo, v8::Handle<v8::Object> wrapper, v8::Isolate* isolate) | |
| 66 { | |
| 67 return V8DOMWrapper::associateObjectWithWrapperNonTemplate(this, wrapperType
Info, wrapper, isolate); | |
| 68 } | |
| 69 | |
| 70 } // namespace blink | |
| OLD | NEW |