X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fthird_party%2FWebKit%2FSource%2Fbindings%2Fv8%2FDOMDataStore.h;h=8e2f60becdde8411194a7d88166ee83da30e0f02;hb=ff3e2503a20db9193d323c1d19c38c68004dec4a;hp=a75d38f02d5861fbc7f9b426a269361b0c76cf04;hpb=7338fba38ba696536d1cc9d389afd716a6ab2fe6;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/third_party/WebKit/Source/bindings/v8/DOMDataStore.h b/src/third_party/WebKit/Source/bindings/v8/DOMDataStore.h index a75d38f..8e2f60b 100644 --- a/src/third_party/WebKit/Source/bindings/v8/DOMDataStore.h +++ b/src/third_party/WebKit/Source/bindings/v8/DOMDataStore.h @@ -51,19 +51,30 @@ public: static DOMDataStore& current(v8::Isolate*); + // We can use a wrapper stored in a ScriptWrappable when we're in the main world. + // This method does the fast check if we're in the main world. If this method returns true, + // it is guaranteed that we're in the main world. On the other hand, if this method returns + // false, nothing is guaranteed (we might be in the main world). + template + static bool canUseScriptWrappable(T* object) + { + return !DOMWrapperWorld::isolatedWorldsExist() + && !canExistInWorker(object) + && ScriptWrappable::wrapperCanBeStoredInObject(object); + } + template static bool setReturnValueFromWrapperFast(v8::ReturnValue returnValue, T* object, v8::Local holder, Wrappable* wrappable) { - // What we'd really like to check here is whether we're in the - // main world or in an isolated world. The fastest way to do that - // is to check that there is no isolated world and the 'object' - // is an object that can exist in the main world. The second fastest - // way is to check whether the wrappable's wrapper is the same as - // the holder. - if ((!DOMWrapperWorld::isolatedWorldsExist() && !canExistInWorker(object)) || holderContainsWrapper(holder, wrappable)) { + if (canUseScriptWrappable(object)) + return ScriptWrappable::setReturnValueWithSecurityCheck(returnValue, object); + // The second fastest way to check if we're in the main world is to check if + // the wrappable's wrapper is the same as the holder. + // FIXME: Investigate if it's worth having this check for performance. + if (holderContainsWrapper(holder, wrappable)) { if (ScriptWrappable::wrapperCanBeStoredInObject(object)) return ScriptWrappable::setReturnValueWithSecurityCheck(returnValue, object); - return mainWorldStore().m_wrapperMap.setReturnValueFrom(returnValue, V8T::toInternalPointer(object)); + return DOMWrapperWorld::mainWorld()->domDataStore().m_wrapperMap.setReturnValueFrom(returnValue, V8T::toInternalPointer(object)); } return current(returnValue.GetIsolate()).template setReturnValueFrom(returnValue, object); } @@ -71,10 +82,8 @@ public: template static bool setReturnValueFromWrapper(v8::ReturnValue returnValue, T* object) { - if (ScriptWrappable::wrapperCanBeStoredInObject(object) && !canExistInWorker(object)) { - if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist())) - return ScriptWrappable::setReturnValueWithSecurityCheck(returnValue, object); - } + if (canUseScriptWrappable(object)) + return ScriptWrappable::setReturnValueWithSecurityCheck(returnValue, object); return current(returnValue.GetIsolate()).template setReturnValueFrom(returnValue, object); } @@ -83,19 +92,17 @@ public: { if (ScriptWrappable::wrapperCanBeStoredInObject(object)) return ScriptWrappable::setReturnValue(returnValue, object); - return mainWorldStore().m_wrapperMap.setReturnValueFrom(returnValue, V8T::toInternalPointer(object)); + return DOMWrapperWorld::mainWorld()->domDataStore().m_wrapperMap.setReturnValueFrom(returnValue, V8T::toInternalPointer(object)); } template static v8::Handle getWrapper(T* object, v8::Isolate* isolate) { - if (ScriptWrappable::wrapperCanBeStoredInObject(object) && !canExistInWorker(object)) { - if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist())) { - v8::Handle result = ScriptWrappable::getUnsafeWrapperFromObject(object).newLocal(isolate); - // Security: always guard against malicious tampering. - RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(result.IsEmpty() || result->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex) == V8T::toInternalPointer(object)); - return result; - } + if (canUseScriptWrappable(object)) { + v8::Handle result = ScriptWrappable::getUnsafeWrapperFromObject(object).newLocal(isolate); + // Security: always guard against malicious tampering. + RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(result.IsEmpty() || result->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex) == V8T::toInternalPointer(object)); + return result; } return current(isolate).template get(object, isolate); } @@ -103,13 +110,12 @@ public: template static void setWrapperReference(const v8::Persistent& parent, T* child, v8::Isolate* isolate) { - if (ScriptWrappable::wrapperCanBeStoredInObject(child) && !canExistInWorker(child)) { - if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist())) { - UnsafePersistent unsafePersistent = ScriptWrappable::getUnsafeWrapperFromObject(child); - // Security: always guard against malicious tampering. - RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(unsafePersistent.isEmpty() || unsafePersistent.value()->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex) == V8T::toInternalPointer(child)); - unsafePersistent.setReferenceFrom(parent, isolate); - } + if (canUseScriptWrappable(child)) { + UnsafePersistent unsafePersistent = ScriptWrappable::getUnsafeWrapperFromObject(child); + // Security: always guard against malicious tampering. + RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(unsafePersistent.isEmpty() || unsafePersistent.value()->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex) == V8T::toInternalPointer(child)); + unsafePersistent.setReferenceFrom(parent, isolate); + return; } current(isolate).template setReference(parent, child, isolate); } @@ -117,11 +123,9 @@ public: template static void setWrapper(T* object, v8::Handle wrapper, v8::Isolate* isolate, const WrapperConfiguration& configuration) { - if (ScriptWrappable::wrapperCanBeStoredInObject(object) && !canExistInWorker(object)) { - if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist())) { - ScriptWrappable::setWrapperInObject(object, wrapper, isolate, configuration); - return; - } + if (canUseScriptWrappable(object)) { + ScriptWrappable::setWrapperInObject(object, wrapper, isolate, configuration); + return; } return current(isolate).template set(object, wrapper, isolate, configuration); } @@ -179,8 +183,6 @@ private: m_wrapperMap.set(V8T::toInternalPointer(object), wrapper, configuration); } - static DOMDataStore& mainWorldStore(); - static bool canExistInWorker(void*) { return true; } static bool canExistInWorker(Node*) { return false; }