diff options
Diffstat (limited to 'WebCore/bindings/v8')
140 files changed, 4397 insertions, 2846 deletions
diff --git a/WebCore/bindings/v8/DOMData.cpp b/WebCore/bindings/v8/DOMData.cpp index ec9a938..417426f 100644 --- a/WebCore/bindings/v8/DOMData.cpp +++ b/WebCore/bindings/v8/DOMData.cpp @@ -33,6 +33,7 @@ #include "ChildThreadDOMData.h" #include "MainThreadDOMData.h" +#include "WebGLContextAttributes.h" #include "WebGLUniformLocation.h" namespace WebCore { diff --git a/WebCore/bindings/v8/DOMData.h b/WebCore/bindings/v8/DOMData.h index 4947e82..7fa9e7d 100644 --- a/WebCore/bindings/v8/DOMData.h +++ b/WebCore/bindings/v8/DOMData.h @@ -51,7 +51,7 @@ namespace WebCore { virtual DOMDataStore& getStore() = 0; template<typename T> - static void handleWeakObject(DOMDataStore::DOMWrapperMapType, v8::Handle<v8::Object>, T* domObject); + static void handleWeakObject(DOMDataStore::DOMWrapperMapType, v8::Persistent<v8::Object>, T* domObject); void forgetDelayedObject(void* object) { m_delayedObjectMap.take(object); } @@ -62,7 +62,7 @@ namespace WebCore { void derefDelayedObjects(); template<typename T> - static void removeObjectsFromWrapperMap(DOMWrapperMap<T>& domMap); + static void removeObjectsFromWrapperMap(AbstractWeakReferenceMap<T, v8::Object>& domMap); ThreadIdentifier owningThread() const { return m_owningThread; } @@ -72,6 +72,17 @@ namespace WebCore { void ensureDeref(V8ClassIndex::V8WrapperType type, void* domObject); static void derefObject(V8ClassIndex::V8WrapperType type, void* domObject); + template<typename T> + class WrapperMapObjectRemover : public WeakReferenceMap<T, v8::Object>::Visitor { + public: + virtual void visitDOMWrapper(T* domObject, v8::Persistent<v8::Object> v8Object) + { + V8ClassIndex::V8WrapperType type = V8DOMWrapper::domWrapperType(v8Object); + derefObject(type, domObject); + v8Object.Dispose(); + } + }; + // Stores all the DOM objects that are delayed to be processed when the // owning thread gains control. DelayedObjectMap m_delayedObjectMap; @@ -85,7 +96,7 @@ namespace WebCore { }; template<typename T> - void DOMData::handleWeakObject(DOMDataStore::DOMWrapperMapType mapType, v8::Handle<v8::Object> v8Object, T* domObject) + void DOMData::handleWeakObject(DOMDataStore::DOMWrapperMapType mapType, v8::Persistent<v8::Object> v8Object, T* domObject) { ASSERT(WTF::isMainThread()); DOMDataList& list = DOMDataStore::allStores(); @@ -94,10 +105,7 @@ namespace WebCore { DOMDataStore::InternalDOMWrapperMap<T>* domMap = static_cast<DOMDataStore::InternalDOMWrapperMap<T>*>(store->getDOMWrapperMap(mapType)); - v8::Handle<v8::Object> wrapper = domMap->get(domObject); - if (*wrapper == *v8Object) { - // Clear the JS reference. - domMap->forgetOnly(domObject); + if (domMap->removeIfPresent(domObject, v8Object)) { ASSERT(store->domData()->owningThread() == WTF::currentThread()); store->domData()->derefObject(V8DOMWrapper::domWrapperType(v8Object), domObject); } @@ -105,21 +113,11 @@ namespace WebCore { } template<typename T> - void DOMData::removeObjectsFromWrapperMap(DOMWrapperMap<T>& domMap) + void DOMData::removeObjectsFromWrapperMap(AbstractWeakReferenceMap<T, v8::Object>& domMap) { - for (typename WTF::HashMap<T*, v8::Object*>::iterator iter(domMap.impl().begin()); iter != domMap.impl().end(); ++iter) { - T* domObject = static_cast<T*>(iter->first); - v8::Persistent<v8::Object> v8Object(iter->second); - - V8ClassIndex::V8WrapperType type = V8DOMWrapper::domWrapperType(v8::Handle<v8::Object>::Cast(v8Object)); - - // Deref the DOM object. - derefObject(type, domObject); - - // Clear the JS wrapper. - v8Object.Dispose(); - } - domMap.impl().clear(); + WrapperMapObjectRemover<T> remover; + domMap.visit(&remover); + domMap.clear(); } } // namespace WebCore diff --git a/WebCore/bindings/v8/DOMDataStore.cpp b/WebCore/bindings/v8/DOMDataStore.cpp index a76ca53..e181ebc 100644 --- a/WebCore/bindings/v8/DOMDataStore.cpp +++ b/WebCore/bindings/v8/DOMDataStore.cpp @@ -146,14 +146,14 @@ void DOMDataStore::weakDOMObjectCallback(v8::Persistent<v8::Value> v8Object, voi { v8::HandleScope scope; ASSERT(v8Object->IsObject()); - DOMData::handleWeakObject(DOMDataStore::DOMObjectMap, v8::Handle<v8::Object>::Cast(v8Object), domObject); + DOMData::handleWeakObject(DOMDataStore::DOMObjectMap, v8::Persistent<v8::Object>::Cast(v8Object), domObject); } void DOMDataStore::weakActiveDOMObjectCallback(v8::Persistent<v8::Value> v8Object, void* domObject) { v8::HandleScope scope; ASSERT(v8Object->IsObject()); - DOMData::handleWeakObject(DOMDataStore::ActiveDOMObjectMap, v8::Handle<v8::Object>::Cast(v8Object), domObject); + DOMData::handleWeakObject(DOMDataStore::ActiveDOMObjectMap, v8::Persistent<v8::Object>::Cast(v8Object), domObject); } void DOMDataStore::weakNodeCallback(v8::Persistent<v8::Value> v8Object, void* domObject) @@ -166,32 +166,42 @@ void DOMDataStore::weakNodeCallback(v8::Persistent<v8::Value> v8Object, void* do DOMDataList& list = DOMDataStore::allStores(); for (size_t i = 0; i < list.size(); ++i) { DOMDataStore* store = list[i]; - HashMap<Node*, v8::Object*>& domMapImpl = store->domNodeMap().impl(); - HashMap<Node*, v8::Object*>::iterator it = domMapImpl.find(node); - if (it == domMapImpl.end() || it->second != *v8Object) - continue; - ASSERT(store->domData()->owningThread() == WTF::currentThread()); - v8Object.Dispose(); - domMapImpl.remove(it); - node->deref(); // Nobody overrides Node::deref so it's safe - break; // There might be at most one wrapper for the node in world's maps + if (store->domNodeMap().removeIfPresent(node, v8Object)) { + ASSERT(store->domData()->owningThread() == WTF::currentThread()); + node->deref(); // Nobody overrides Node::deref so it's safe + break; // There might be at most one wrapper for the node in world's maps + } } } +bool DOMDataStore::IntrusiveDOMWrapperMap::removeIfPresent(Node* obj, v8::Persistent<v8::Data> value) +{ + ASSERT(obj); + v8::Persistent<v8::Object>* entry = obj->wrapper(); + if (!entry) + return false; + if (*entry != value) + return false; + obj->clearWrapper(); + m_table.remove(entry); + value.Dispose(); + return true; +} + #if ENABLE(SVG) void DOMDataStore::weakSVGElementInstanceCallback(v8::Persistent<v8::Value> v8Object, void* domObject) { v8::HandleScope scope; ASSERT(v8Object->IsObject()); - DOMData::handleWeakObject(DOMDataStore::DOMSVGElementInstanceMap, v8::Handle<v8::Object>::Cast(v8Object), static_cast<SVGElementInstance*>(domObject)); + DOMData::handleWeakObject(DOMDataStore::DOMSVGElementInstanceMap, v8::Persistent<v8::Object>::Cast(v8Object), static_cast<SVGElementInstance*>(domObject)); } void DOMDataStore::weakSVGObjectWithContextCallback(v8::Persistent<v8::Value> v8Object, void* domObject) { v8::HandleScope scope; ASSERT(v8Object->IsObject()); - DOMData::handleWeakObject(DOMDataStore::DOMSVGObjectWithContextMap, v8::Handle<v8::Object>::Cast(v8Object), domObject); + DOMData::handleWeakObject(DOMDataStore::DOMSVGObjectWithContextMap, v8::Persistent<v8::Object>::Cast(v8Object), domObject); } #endif // ENABLE(SVG) diff --git a/WebCore/bindings/v8/DOMDataStore.h b/WebCore/bindings/v8/DOMDataStore.h index b127089..54a49e7 100644 --- a/WebCore/bindings/v8/DOMDataStore.h +++ b/WebCore/bindings/v8/DOMDataStore.h @@ -32,6 +32,7 @@ #define DOMDataStore_h #include "DOMObjectsInclude.h" +#include "V8Node.h" #include <v8.h> #include <wtf/HashMap.h> @@ -49,6 +50,95 @@ namespace WebCore { typedef WTF::Vector<DOMDataStore*> DOMDataList; + template <class T, int CHUNK_SIZE, class Traits> + class ChunkedTable { + public: + ChunkedTable() : m_chunks(0), m_current(0), m_last(0) { } + + T* add(T element) + { + if (m_current == m_last) { + m_chunks = new Chunk(m_chunks); + m_current = m_chunks->m_entries; + m_last = m_current + CHUNK_SIZE; + } + ASSERT((m_chunks->m_entries <= m_current) && (m_current < m_last)); + T* p = m_current++; + *p = element; + return p; + } + + void remove(T* element) + { + ASSERT(element); + ASSERT(m_current > m_chunks->m_entries); + m_current--; + if (element != m_current) + Traits::move(element, m_current); + if (m_current == m_chunks->m_entries) { + Chunk* toDelete = m_chunks; + m_chunks = toDelete->m_previous; + m_current = m_last = m_chunks ? m_chunks->m_entries + CHUNK_SIZE : 0; + delete toDelete; + } + ASSERT(!m_chunks || ((m_chunks->m_entries < m_current) && (m_current <= m_last))); + } + + void clear() + { + if (!m_chunks) + return; + + clearEntries(m_chunks->m_entries, m_current); + Chunk* last = m_chunks; + while (true) { + Chunk* previous = last->m_previous; + if (!previous) + break; + delete last; + clearEntries(previous->m_entries, previous->m_entries + CHUNK_SIZE); + last = previous; + } + + m_chunks = last; + m_current = m_chunks->m_entries; + m_last = m_current + CHUNK_SIZE; + } + + void visit(typename Traits::Visitor* visitor) + { + if (!m_chunks) + return; + + visitEntries(m_chunks->m_entries, m_current, visitor); + for (Chunk* chunk = m_chunks->m_previous; chunk; chunk = chunk->m_previous) + visitEntries(chunk->m_entries, chunk->m_entries + CHUNK_SIZE, visitor); + } + + private: + struct Chunk { + explicit Chunk(Chunk* previous) : m_previous(previous) { } + Chunk* const m_previous; + T m_entries[CHUNK_SIZE]; + }; + + static void clearEntries(T* first, T* last) + { + for (T* entry = first; entry < last; entry++) + Traits::clear(entry); + } + + static void visitEntries(T* first, T* last, typename Traits::Visitor* visitor) + { + for (T* entry = first; entry < last; entry++) + Traits::visit(entry, visitor); + } + + Chunk* m_chunks; + T* m_current; + T* m_last; + }; + // DOMDataStore // // DOMDataStore is the backing store that holds the maps between DOM objects @@ -82,12 +172,83 @@ namespace WebCore { forgetDelayedObject(m_domData, object); } - void forgetOnly(KeyType* object) { DOMWrapperMap<KeyType>::forget(object); } - private: DOMData* m_domData; }; + class IntrusiveDOMWrapperMap : public AbstractWeakReferenceMap<Node, v8::Object> { + public: + IntrusiveDOMWrapperMap(v8::WeakReferenceCallback callback) + : AbstractWeakReferenceMap<Node, v8::Object>(callback) { } + + virtual v8::Persistent<v8::Object> get(Node* obj) + { + v8::Persistent<v8::Object>* wrapper = obj->wrapper(); + return wrapper ? *wrapper : v8::Persistent<v8::Object>(); + } + + virtual void set(Node* obj, v8::Persistent<v8::Object> wrapper) + { + ASSERT(obj); + ASSERT(!obj->wrapper()); + v8::Persistent<v8::Object>* entry = m_table.add(wrapper); + obj->setWrapper(entry); + wrapper.MakeWeak(obj, weakReferenceCallback()); + } + + virtual bool contains(Node* obj) + { + return obj->wrapper(); + } + + virtual void visit(Visitor* visitor) + { + m_table.visit(visitor); + } + + virtual bool removeIfPresent(Node* key, v8::Persistent<v8::Data> value); + + virtual void clear() + { + m_table.clear(); + } + + private: + static int const numberOfEntries = (1 << 10) - 1; + + struct ChunkedTableTraits { + typedef IntrusiveDOMWrapperMap::Visitor Visitor; + + static void move(v8::Persistent<v8::Object>* target, v8::Persistent<v8::Object>* source) + { + *target = *source; + Node* node = V8Node::toNative(*target); + ASSERT(node); + node->setWrapper(target); + } + + static void clear(v8::Persistent<v8::Object>* entry) + { + Node* node = V8Node::toNative(*entry); + ASSERT(node->wrapper() == entry); + + node->clearWrapper(); + entry->Dispose(); + } + + static void visit(v8::Persistent<v8::Object>* entry, Visitor* visitor) + { + Node* node = V8Node::toNative(*entry); + ASSERT(node->wrapper() == entry); + + visitor->visitDOMWrapper(node, *entry); + } + }; + + typedef ChunkedTable<v8::Persistent<v8::Object>, numberOfEntries, ChunkedTableTraits> Table; + Table m_table; + }; + DOMDataStore(DOMData*); virtual ~DOMDataStore(); @@ -104,7 +265,7 @@ namespace WebCore { void* getDOMWrapperMap(DOMWrapperMapType); - InternalDOMWrapperMap<Node>& domNodeMap() { return *m_domNodeMap; } + DOMNodeMapping& domNodeMap() { return *m_domNodeMap; } InternalDOMWrapperMap<void>& domObjectMap() { return *m_domObjectMap; } InternalDOMWrapperMap<void>& activeDomObjectMap() { return *m_activeDomObjectMap; } #if ENABLE(SVG) @@ -124,7 +285,7 @@ namespace WebCore { static void weakSVGObjectWithContextCallback(v8::Persistent<v8::Value> v8Object, void* domObject); #endif - InternalDOMWrapperMap<Node>* m_domNodeMap; + DOMNodeMapping* m_domNodeMap; InternalDOMWrapperMap<void>* m_domObjectMap; InternalDOMWrapperMap<void>* m_activeDomObjectMap; #if ENABLE(SVG) diff --git a/WebCore/bindings/v8/DOMObjectsInclude.h b/WebCore/bindings/v8/DOMObjectsInclude.h index bded7f2..8f1b43d 100644 --- a/WebCore/bindings/v8/DOMObjectsInclude.h +++ b/WebCore/bindings/v8/DOMObjectsInclude.h @@ -34,6 +34,7 @@ #include "Attr.h" #include "BarInfo.h" #include "BeforeLoadEvent.h" +#include "Blob.h" #include "WebGLActiveInfo.h" #include "WebGLArray.h" #include "WebGLArrayBuffer.h" @@ -128,6 +129,7 @@ #include "PageTransitionEvent.h" #include "Plugin.h" #include "PluginArray.h" +#include "PopStateEvent.h" #include "ProcessingInstruction.h" #include "ProgressEvent.h" #include "Range.h" @@ -186,12 +188,23 @@ #include "StorageEvent.h" #endif // DOM_STORAGE +#if ENABLE(EVENTSOURCE) +#include "EventSource.h" +#endif // EVENTSOURCE + // GEOLOCATION #include "Coordinates.h" #include "Geolocation.h" #include "Geoposition.h" #include "PositionError.h" +#if ENABLE(INDEXED_DATABASE) +#include "IDBDatabaseError.h" +#include "IDBDatabaseException.h" +#include "IDBRequest.h" +#include "IndexedDatabaseRequest.h" +#endif // DATABASE + #if ENABLE(SVG) #include "SVGAngle.h" #include "SVGAnimatedPoints.h" diff --git a/WebCore/bindings/v8/custom/V8XMLSerializerConstructor.cpp b/WebCore/bindings/v8/DOMWrapperWorld.cpp index dd1c3ad..1e9429f 100644 --- a/WebCore/bindings/v8/custom/V8XMLSerializerConstructor.cpp +++ b/WebCore/bindings/v8/DOMWrapperWorld.cpp @@ -14,7 +14,7 @@ * * Neither the name of Google Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -29,17 +29,23 @@ */ #include "config.h" -#include "XMLSerializer.h" +#include "DOMWrapperWorld.h" -#include "V8Binding.h" -#include "V8Proxy.h" +#include <wtf/StdLibExtras.h> +#include <wtf/Threading.h> namespace WebCore { -CALLBACK_FUNC_DECL(XMLSerializerConstructor) +DOMWrapperWorld::DOMWrapperWorld() +{ + // This class is pretty boring, huh? +} + +DOMWrapperWorld* mainThreadNormalWorld() { - INC_STATS("DOM.XMLSerializer.Constructor"); - return V8Proxy::constructDOMObject<V8ClassIndex::XMLSERIALIZER, XMLSerializer>(args); + ASSERT(isMainThread()); + DEFINE_STATIC_LOCAL(RefPtr<DOMWrapperWorld>, cachedNormalWorld, (DOMWrapperWorld::create())); + return cachedNormalWorld.get(); } } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8ClientRectListCustom.cpp b/WebCore/bindings/v8/DOMWrapperWorld.h index 3c62e14..f54cd4e 100644 --- a/WebCore/bindings/v8/custom/V8ClientRectListCustom.cpp +++ b/WebCore/bindings/v8/DOMWrapperWorld.h @@ -28,28 +28,28 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "config.h" -#include "ClientRectList.h" - -#include "ClientRect.h" - -#include "V8Binding.h" -#include "V8CustomBinding.h" -#include "V8Proxy.h" +#ifndef DOMWrapperWorld_h +#define DOMWrapperWorld_h +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> #include <wtf/RefPtr.h> namespace WebCore { -INDEXED_PROPERTY_GETTER(ClientRectList) -{ - INC_STATS("DOM.ClientRectList.IndexedPropertyGetter"); - ClientRectList* imp = V8DOMWrapper::convertToNativeObject<ClientRectList>(V8ClassIndex::CLIENTRECTLIST, info.Holder()); - RefPtr<ClientRect> result = imp->item(index); - if (!result) - return notHandledByInterceptor(); +// This class represent a collection of DOM wrappers for a specific world. +// The base class is pretty boring because the wrappers are actually stored +// statically in V8DOMMap and garbage collected by V8 itself. +class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { +public: + static PassRefPtr<DOMWrapperWorld> create() { return adoptRef(new DOMWrapperWorld()); } - return V8DOMWrapper::convertToV8Object(V8ClassIndex::CLIENTRECT, result.release()); -} +protected: + DOMWrapperWorld(); +}; + +DOMWrapperWorld* mainThreadNormalWorld(); } // namespace WebCore + +#endif // DOMWrapperWorld_h diff --git a/WebCore/bindings/v8/DateExtension.cpp b/WebCore/bindings/v8/DateExtension.cpp index 7d8b9be..abf8967 100644 --- a/WebCore/bindings/v8/DateExtension.cpp +++ b/WebCore/bindings/v8/DateExtension.cpp @@ -116,7 +116,7 @@ v8::Handle<v8::Value> DateExtension::Setup(const v8::Arguments& args) v8::Handle<v8::Value> DateExtension::OnSleepDetected(const v8::Arguments&) { - v8::V8::TerminateExecution(); + V8Proxy::throwError(V8Proxy::GeneralError, "Too much time spent in unload handler."); return v8::Undefined(); } diff --git a/WebCore/bindings/v8/DerivedSourcesAllInOne.cpp b/WebCore/bindings/v8/DerivedSourcesAllInOne.cpp index bd2bb7b..9658b19 100644 --- a/WebCore/bindings/v8/DerivedSourcesAllInOne.cpp +++ b/WebCore/bindings/v8/DerivedSourcesAllInOne.cpp @@ -38,11 +38,13 @@ #include "bindings/V8Attr.cpp" #include "bindings/V8BarInfo.cpp" #include "bindings/V8BeforeLoadEvent.cpp" +#include "bindings/V8Blob.cpp" #include "bindings/V8WebGLActiveInfo.cpp" #include "bindings/V8WebGLArray.cpp" #include "bindings/V8WebGLArrayBuffer.cpp" #include "bindings/V8WebGLBuffer.cpp" #include "bindings/V8WebGLByteArray.cpp" +#include "bindings/V8WebGLContextAttributes.cpp" #include "bindings/V8WebGLFloatArray.cpp" #include "bindings/V8WebGLFramebuffer.cpp" #include "bindings/V8CanvasGradient.cpp" @@ -202,6 +204,7 @@ #include "bindings/V8PageTransitionEvent.cpp" #include "bindings/V8Plugin.cpp" #include "bindings/V8PluginArray.cpp" +#include "bindings/V8PopStateEvent.cpp" #include "bindings/V8PositionError.cpp" #include "bindings/V8ProcessingInstruction.cpp" #include "bindings/V8ProgressEvent.cpp" @@ -254,6 +257,13 @@ #include "bindings/V8SQLTransaction.cpp" #endif +#if ENABLE(INDEXED_DATABASE) +#include "bindings/V8IDBDatabaseError.cpp" +#include "bindings/V8IDBDatabaseException.cpp" +#include "bindings/V8IDBRequest.cpp" +#include "bindings/V8IndexedDatabaseRequest.cpp" +#endif + #if ENABLE(WORKERS) #include "bindings/V8AbstractWorker.cpp" #include "bindings/V8DedicatedWorkerContext.cpp" @@ -421,3 +431,7 @@ #include "bindings/V8InspectorBackend.cpp" #include "bindings/V8InspectorFrontendHost.cpp" #endif + +#if ENABLE(EVENTSOURCE) +#include "bindings/V8EventSource.cpp" +#endif diff --git a/WebCore/bindings/v8/custom/V8DOMParserConstructor.cpp b/WebCore/bindings/v8/IsolatedWorld.cpp index 4af5c6e..368683d 100644 --- a/WebCore/bindings/v8/custom/V8DOMParserConstructor.cpp +++ b/WebCore/bindings/v8/IsolatedWorld.cpp @@ -14,7 +14,7 @@ * * Neither the name of Google Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -29,17 +29,20 @@ */ #include "config.h" -#include "DOMParser.h" - -#include "V8Binding.h" -#include "V8Proxy.h" +#include "IsolatedWorld.h" namespace WebCore { -CALLBACK_FUNC_DECL(DOMParserConstructor) +int IsolatedWorld::isolatedWorldCount = 0; + +IsolatedWorld::IsolatedWorld() +{ + ++isolatedWorldCount; +} + +IsolatedWorld::~IsolatedWorld() { - INC_STATS("DOM.DOMParser.Contructor"); - return V8Proxy::constructDOMObject<V8ClassIndex::DOMPARSER, DOMParser>(args); + --isolatedWorldCount; } } // namespace WebCore diff --git a/WebCore/bindings/v8/IsolatedWorld.h b/WebCore/bindings/v8/IsolatedWorld.h new file mode 100644 index 0000000..3e86437 --- /dev/null +++ b/WebCore/bindings/v8/IsolatedWorld.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef IsolatedWorld_h +#define IsolatedWorld_h + +#include "DOMWrapperWorld.h" +#include "V8DOMMap.h" + +namespace WebCore { + +// An DOMWrapperWorld other than the thread's normal world. +class IsolatedWorld : public DOMWrapperWorld { +public: + static PassRefPtr<IsolatedWorld> create() { return adoptRef(new IsolatedWorld()); } + static int count() { return isolatedWorldCount; } + + DOMDataStore* domDataStore() const { return m_domDataStore.getStore(); } + +protected: + IsolatedWorld(); + ~IsolatedWorld(); + +private: + // The backing store for the isolated world's DOM wrappers. This class + // doesn't have visibility into the wrappers. This handle simply helps + // manage their lifetime. + DOMDataStoreHandle m_domDataStore; + + static int isolatedWorldCount; +}; + +} // namespace WebCore + +#endif // IsolatedWorld_h diff --git a/WebCore/bindings/v8/MainThreadDOMData.cpp b/WebCore/bindings/v8/MainThreadDOMData.cpp index b1b63bf..d9c865c 100644 --- a/WebCore/bindings/v8/MainThreadDOMData.cpp +++ b/WebCore/bindings/v8/MainThreadDOMData.cpp @@ -31,7 +31,7 @@ #include "config.h" #include "MainThreadDOMData.h" -#include "V8IsolatedWorld.h" +#include "V8IsolatedContext.h" namespace WebCore { @@ -53,9 +53,9 @@ DOMDataStore& MainThreadDOMData::getMainThreadStore() // so that it can be inlined by getCurrentMainThreadStore, which is // a hot spot in Dromaeo DOM tests. ASSERT(WTF::isMainThread()); - V8IsolatedWorld* world = V8IsolatedWorld::getEntered(); - if (UNLIKELY(world != 0)) - return *world->getDOMDataStore(); + V8IsolatedContext* context = V8IsolatedContext::getEntered(); + if (UNLIKELY(context != 0)) + return *context->world()->domDataStore(); return m_defaultStore; } diff --git a/WebCore/bindings/v8/NPV8Object.cpp b/WebCore/bindings/v8/NPV8Object.cpp index e222ecd..258f579 100644 --- a/WebCore/bindings/v8/NPV8Object.cpp +++ b/WebCore/bindings/v8/NPV8Object.cpp @@ -37,6 +37,7 @@ #include "V8CustomBinding.h" #include "V8GCController.h" #include "V8Helpers.h" +#include "V8Index.h" #include "V8NPUtils.h" #include "V8Proxy.h" #include "npruntime_impl.h" @@ -46,6 +47,7 @@ #include <v8.h> #include <wtf/StringExtras.h> +using WebCore::npObjectInternalFieldCount; using WebCore::toV8Context; using WebCore::toV8Proxy; using WebCore::V8ClassIndex; @@ -92,6 +94,11 @@ static v8::Local<v8::String> npIdentifierToV8Identifier(NPIdentifier name) return v8::String::New(buffer); } +NPObject* v8ObjectToNPObject(v8::Handle<v8::Object> object) +{ + return reinterpret_cast<NPObject*>(object->GetPointerFromInternalField(WebCore::v8DOMWrapperObjectIndex)); +} + static NPClass V8NPObjectClass = { NP_CLASS_STRUCT_VERSION, allocV8NPObject, freeV8NPObject, @@ -103,11 +110,11 @@ NPClass* npScriptObjectClass = &V8NPObjectClass; NPObject* npCreateV8ScriptObject(NPP npp, v8::Handle<v8::Object> object, WebCore::DOMWindow* root) { // Check to see if this object is already wrapped. - if (object->InternalFieldCount() == V8Custom::kNPObjectInternalFieldCount) { - v8::Local<v8::Value> typeIndex = object->GetInternalField(V8Custom::kDOMWrapperTypeIndex); + if (object->InternalFieldCount() == npObjectInternalFieldCount) { + v8::Local<v8::Value> typeIndex = object->GetInternalField(WebCore::v8DOMWrapperTypeIndex); if (typeIndex->IsNumber() && typeIndex->Uint32Value() == V8ClassIndex::NPOBJECT) { - NPObject* returnValue = V8DOMWrapper::convertToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, object); + NPObject* returnValue = v8ObjectToNPObject(object); _NPN_RetainObject(returnValue); return returnValue; } diff --git a/WebCore/bindings/v8/NPV8Object.h b/WebCore/bindings/v8/NPV8Object.h index 62b3ba4..911987a 100644 --- a/WebCore/bindings/v8/NPV8Object.h +++ b/WebCore/bindings/v8/NPV8Object.h @@ -30,6 +30,10 @@ #ifndef NPV8Object_h #define NPV8Object_h +<<<<<<< HEAD +======= +#include "V8Index.h" +>>>>>>> webkit.org at r54127 #if PLATFORM(CHROMIUM) // FIXME: Chromium uses a different npruntime.h, which is in // the Chromium source repository under third_party/npapi/bindings. @@ -43,6 +47,8 @@ namespace WebCore { class DOMWindow; + + static const int npObjectInternalFieldCount = v8DefaultWrapperInternalFieldCount + 0; } extern NPClass* npScriptObjectClass; @@ -65,4 +71,6 @@ struct PrivateIdentifier { NPObject* npCreateV8ScriptObject(NPP, v8::Handle<v8::Object>, WebCore::DOMWindow*); +NPObject* v8ObjectToNPObject(v8::Handle<v8::Object>); + #endif // NPV8Object_h diff --git a/WebCore/bindings/v8/RuntimeEnabledFeatures.cpp b/WebCore/bindings/v8/RuntimeEnabledFeatures.cpp index b750836..e542f53 100644 --- a/WebCore/bindings/v8/RuntimeEnabledFeatures.cpp +++ b/WebCore/bindings/v8/RuntimeEnabledFeatures.cpp @@ -33,6 +33,7 @@ namespace WebCore { +<<<<<<< HEAD #if PLATFORM(ANDROID) // This should default to true, to match the behavior with JSC bool RuntimeEnabledFeatures::isDatabaseEnabled = true; @@ -44,5 +45,13 @@ bool RuntimeEnabledFeatures::isSessionStorageEnabled = true; bool RuntimeEnabledFeatures::isNotificationsEnabled = true; bool RuntimeEnabledFeatures::isApplicationCacheEnabled = true; #endif +======= +bool RuntimeEnabledFeatures::isLocalStorageEnabled = true; +bool RuntimeEnabledFeatures::isSessionStorageEnabled = true; +bool RuntimeEnabledFeatures::isNotificationsEnabled = false; +bool RuntimeEnabledFeatures::isApplicationCacheEnabled = false; +bool RuntimeEnabledFeatures::isGeolocationEnabled = false; +bool RuntimeEnabledFeatures::isIndexedDatabaseEnabled = false; +>>>>>>> webkit.org at r54127 } // namespace WebCore diff --git a/WebCore/bindings/v8/RuntimeEnabledFeatures.h b/WebCore/bindings/v8/RuntimeEnabledFeatures.h index d8078c5..4428004 100644 --- a/WebCore/bindings/v8/RuntimeEnabledFeatures.h +++ b/WebCore/bindings/v8/RuntimeEnabledFeatures.h @@ -36,9 +36,6 @@ namespace WebCore { // A class that stores static enablers for all experimental features class RuntimeEnabledFeatures { public: - static void setDatabaseEnabled(bool isEnabled) { isDatabaseEnabled = isEnabled; } - static bool databaseEnabled() { return isDatabaseEnabled; } - static void setLocalStorageEnabled(bool isEnabled) { isLocalStorageEnabled = isEnabled; } static bool localStorageEnabled() { return isLocalStorageEnabled; } @@ -51,15 +48,22 @@ public: static void setApplicationCacheEnabled(bool isEnabled) { isApplicationCacheEnabled = isEnabled; } static bool applicationCacheEnabled() { return isApplicationCacheEnabled; } + static void setGeolocationEnabled(bool isEnabled) { isGeolocationEnabled = isEnabled; } + static bool geolocationEnabled() { return isGeolocationEnabled; } + + static void setIndexedDatabaseEnabled(bool isEnabled) { isIndexedDatabaseEnabled = isEnabled; } + static bool indexedDatabaseEnabled() { return isIndexedDatabaseEnabled; } + private: // Never instantiate. RuntimeEnabledFeatures() { } - static bool isDatabaseEnabled; static bool isLocalStorageEnabled; static bool isSessionStorageEnabled; static bool isNotificationsEnabled; static bool isApplicationCacheEnabled; + static bool isGeolocationEnabled; + static bool isIndexedDatabaseEnabled; }; } // namespace WebCore diff --git a/WebCore/bindings/v8/ScriptCallStack.cpp b/WebCore/bindings/v8/ScriptCallStack.cpp index d9b2fcf..21063ed 100644 --- a/WebCore/bindings/v8/ScriptCallStack.cpp +++ b/WebCore/bindings/v8/ScriptCallStack.cpp @@ -31,6 +31,8 @@ #include "config.h" #include "ScriptCallStack.h" +#include "ScriptController.h" + #include <v8.h> #include "V8Binding.h" @@ -53,7 +55,7 @@ ScriptCallStack* ScriptCallStack::create(const v8::Arguments& arguments, unsigne ScriptCallStack::ScriptCallStack(const v8::Arguments& arguments, unsigned skipArgumentCount, String sourceName, int sourceLineNumber) : m_lastCaller(String(), sourceName, sourceLineNumber, arguments, skipArgumentCount) - , m_scriptState(new ScriptState(V8Proxy::retrieveFrameForCurrentContext())) + , m_scriptState(ScriptState::current()) { } diff --git a/WebCore/bindings/v8/ScriptCallStack.h b/WebCore/bindings/v8/ScriptCallStack.h index f6a7e39..8ac394c 100644 --- a/WebCore/bindings/v8/ScriptCallStack.h +++ b/WebCore/bindings/v8/ScriptCallStack.h @@ -35,7 +35,6 @@ #include "ScriptState.h" #include "ScriptValue.h" #include <wtf/Noncopyable.h> -#include <wtf/OwnPtr.h> namespace v8 { class Arguments; @@ -52,13 +51,14 @@ namespace WebCore { // FIXME: implement retrieving and storing call stack trace unsigned size() const { return 1; } - ScriptState* state() const { return m_scriptState.get(); } + ScriptState* state() const { return m_scriptState; } + ScriptState* globalState() const { return m_scriptState; } private: ScriptCallStack(const v8::Arguments& arguments, unsigned skipArgumentCount, String sourceName, int sourceLineNumber); ScriptCallFrame m_lastCaller; - OwnPtr<ScriptState> m_scriptState; + ScriptState* m_scriptState; }; } // namespace WebCore diff --git a/WebCore/bindings/v8/ScriptController.cpp b/WebCore/bindings/v8/ScriptController.cpp index aa38ba0..8db55a1 100644 --- a/WebCore/bindings/v8/ScriptController.cpp +++ b/WebCore/bindings/v8/ScriptController.cpp @@ -47,9 +47,11 @@ #include "npruntime_priv.h" #include "NPV8Object.h" #include "ScriptSourceCode.h" -#include "ScriptState.h" #include "Settings.h" #include "V8Binding.h" +#include "V8BindingState.h" +#include "V8Event.h" +#include "V8IsolatedContext.h" #include "V8NPObject.h" #include "V8Proxy.h" #include "Widget.h" @@ -84,7 +86,7 @@ Frame* ScriptController::retrieveFrameForCurrentContext() bool ScriptController::isSafeScript(Frame* target) { - return V8Proxy::canAccessFrame(target, true); + return V8BindingSecurity::canAccessFrame(V8BindingState::Only(), target, true); } void ScriptController::gcProtectJSWrapper(void* domObject) @@ -138,7 +140,7 @@ void ScriptController::clearScriptObjects() void ScriptController::updateSecurityOrigin() { - m_proxy->updateSecurityOrigin(); + m_proxy->windowShell()->updateSecurityOrigin(); } void ScriptController::updatePlatformScriptObjects() @@ -167,7 +169,7 @@ bool ScriptController::processingUserGesture() const v8::Handle<v8::Object> global = v8Context->Global(); v8::Handle<v8::Value> jsEvent = global->Get(v8::String::NewSymbol("event")); - Event* event = V8DOMWrapper::convertToNativeEvent(jsEvent); + Event* event = V8DOMWrapper::isDOMEventWrapper(jsEvent) ? V8Event::toNative(v8::Handle<v8::Object>::Cast(jsEvent)) : 0; // Based on code from kjs_bindings.cpp. // Note: This is more liberal than Firefox's implementation. @@ -195,6 +197,12 @@ bool ScriptController::processingUserGesture() const return false; } +bool ScriptController::anyPageIsProcessingUserGesture() const +{ + // FIXME: is this right? + return processingUserGesture(); +} + void ScriptController::evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>& sources) { m_proxy->evaluateInIsolatedWorld(worldID, sources, 0); @@ -205,11 +213,6 @@ void ScriptController::evaluateInIsolatedWorld(unsigned worldID, const Vector<Sc m_proxy->evaluateInIsolatedWorld(worldID, sources, extensionGroup); } -void ScriptController::evaluateInNewContext(const Vector<ScriptSourceCode>& sources, int extensionGroup) -{ - m_proxy->evaluateInNewContext(sources, extensionGroup); -} - // Evaluate a script file in the environment of this proxy. ScriptValue ScriptController::evaluate(const ScriptSourceCode& sourceCode) { @@ -232,7 +235,7 @@ ScriptValue ScriptController::evaluate(const ScriptSourceCode& sourceCode) v8::Local<v8::Value> object = m_proxy->evaluate(sourceCode, 0); // Evaluating the JavaScript could cause the frame to be deallocated - // so we start the keep alive timer here. + // so we starot the keep alive timer here. m_frame->keepAlive(); if (object.IsEmpty() || object->IsUndefined()) @@ -288,13 +291,7 @@ void ScriptController::lowMemoryNotification() bool ScriptController::haveInterpreter() const { - return m_proxy->isContextInitialized(); -} - -bool ScriptController::isEnabled() const -{ - Settings* settings = m_proxy->frame()->settings(); - return m_proxy->frame()->loader()->client()->allowJavaScript(settings && settings->isJavaScriptEnabled() && !m_frame->loader()->isSandboxed(SandboxScripts)); + return m_proxy->windowShell()->isContextInitialized(); } PassScriptInstance ScriptController::createScriptInstanceForWidget(Widget* widget) @@ -356,13 +353,6 @@ void ScriptController::getAllWorlds(Vector<DOMWrapperWorld*>& worlds) worlds.append(mainThreadNormalWorld()); } -ScriptState* ScriptController::mainWorldScriptState() -{ - if (!m_mainWorldScriptState) - m_mainWorldScriptState.set(new ScriptState(m_frame, V8Proxy::mainWorldContext(m_frame))); - return m_mainWorldScriptState.get(); -} - static NPObject* createNoScriptObject() { notImplemented(); @@ -388,7 +378,7 @@ NPObject* ScriptController::windowScriptNPObject() if (m_windowScriptNPObject) return m_windowScriptNPObject; - if (isEnabled()) { + if (canExecuteScripts()) { // JavaScript is enabled, so there is a JavaScript window object. // Return an NPObject bound to the window object. m_windowScriptNPObject = createScriptObject(m_frame); @@ -405,7 +395,7 @@ NPObject* ScriptController::windowScriptNPObject() NPObject* ScriptController::createScriptObjectForPluginElement(HTMLPlugInElement* plugin) { // Can't create NPObjects when JavaScript is disabled. - if (!isEnabled()) + if (!canExecuteScripts()) return createNoScriptObject(); v8::HandleScope handleScope; @@ -438,7 +428,7 @@ void ScriptController::attachDebugger(void*) void ScriptController::updateDocument() { - m_proxy->updateDocument(); + m_proxy->windowShell()->updateDocument(); } } // namespace WebCore diff --git a/WebCore/bindings/v8/ScriptController.h b/WebCore/bindings/v8/ScriptController.h index fb7bbee..b45bdef 100644 --- a/WebCore/bindings/v8/ScriptController.h +++ b/WebCore/bindings/v8/ScriptController.h @@ -42,164 +42,155 @@ #include <wtf/RefCounted.h> #include <wtf/Vector.h> +struct NPObject; + namespace WebCore { - class DOMWrapperWorld; - class Event; - class Frame; - class HTMLPlugInElement; - class ScriptSourceCode; - class ScriptState; - class String; - class Widget; - class XSSAuditor; - class ScriptController { - public: - ScriptController(Frame*); - ~ScriptController(); +class DOMWrapperWorld; +class Event; +class Frame; +class HTMLPlugInElement; +class ScriptSourceCode; +class String; +class Widget; +class XSSAuditor; - // FIXME: V8Proxy should either be folded into ScriptController - // or this accessor should be made JSProxy* - V8Proxy* proxy() { return m_proxy.get(); } +class ScriptController { +public: + ScriptController(Frame*); + ~ScriptController(); - ScriptValue executeScript(const ScriptSourceCode&); - ScriptValue executeScript(const String& script, bool forceUserGesture = false); + // FIXME: V8Proxy should either be folded into ScriptController + // or this accessor should be made JSProxy* + V8Proxy* proxy() { return m_proxy.get(); } - // Returns true if argument is a JavaScript URL. - bool executeIfJavaScriptURL(const KURL&, bool userGesture = false, bool replaceDocument = true); + ScriptValue executeScript(const ScriptSourceCode&); + ScriptValue executeScript(const String& script, bool forceUserGesture = false); - // This function must be called from the main thread. It is safe to call it repeatedly. - static void initializeThreading(); + // Returns true if argument is a JavaScript URL. + bool executeIfJavaScriptURL(const KURL&, bool userGesture = false, bool replaceDocument = true); - // Evaluate a script file in the environment of this proxy. - // If succeeded, 'succ' is set to true and result is returned - // as a string. - ScriptValue evaluate(const ScriptSourceCode&); + // This function must be called from the main thread. It is safe to call it repeatedly. + static void initializeThreading(); - void evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>&); + // Evaluate a script file in the environment of this proxy. + // If succeeded, 'succ' is set to true and result is returned + // as a string. + ScriptValue evaluate(const ScriptSourceCode&); - // Executes JavaScript in an isolated world. The script gets its own global scope, - // its own prototypes for intrinsic JavaScript objects (String, Array, and so-on), - // and its own wrappers for all DOM nodes and DOM constructors. - // - // If an isolated world with the specified ID already exists, it is reused. - // Otherwise, a new world is created. - // - // If the worldID is 0, a new world is always created. - // - // FIXME: Get rid of extensionGroup here. - void evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>&, int extensionGroup); + void evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>&); - // Executes JavaScript in a new context associated with the web frame. The - // script gets its own global scope and its own prototypes for intrinsic - // JavaScript objects (String, Array, and so-on). It shares the wrappers for - // all DOM nodes and DOM constructors. - void evaluateInNewContext(const Vector<ScriptSourceCode>&, int extensionGroup); + // Executes JavaScript in an isolated world. The script gets its own global scope, + // its own prototypes for intrinsic JavaScript objects (String, Array, and so-on), + // and its own wrappers for all DOM nodes and DOM constructors. + // + // If an isolated world with the specified ID already exists, it is reused. + // Otherwise, a new world is created. + // + // If the worldID is 0, a new world is always created. + // + // FIXME: Get rid of extensionGroup here. + void evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>&, int extensionGroup); - // Masquerade 'this' as the windowShell. - // This is a bit of a hack, but provides reasonable compatibility - // with what JSC does as well. - ScriptController* windowShell(DOMWrapperWorld*) { return this; } - ScriptController* existingWindowShell(DOMWrapperWorld*) { return this; } + // Masquerade 'this' as the windowShell. + // This is a bit of a hack, but provides reasonable compatibility + // with what JSC does as well. + ScriptController* windowShell(DOMWrapperWorld*) { return this; } + ScriptController* existingWindowShell(DOMWrapperWorld*) { return this; } - XSSAuditor* xssAuditor() { return m_XSSAuditor.get(); } + XSSAuditor* xssAuditor() { return m_XSSAuditor.get(); } - void collectGarbage(); + void collectGarbage(); - // Notify V8 that the system is running low on memory. - void lowMemoryNotification(); + // Notify V8 that the system is running low on memory. + void lowMemoryNotification(); - // Creates a property of the global object of a frame. - void bindToWindowObject(Frame*, const String& key, NPObject*); + // Creates a property of the global object of a frame. + void bindToWindowObject(Frame*, const String& key, NPObject*); - PassScriptInstance createScriptInstanceForWidget(Widget*); + PassScriptInstance createScriptInstanceForWidget(Widget*); - // Check if the javascript engine has been initialized. - bool haveInterpreter() const; + // Check if the javascript engine has been initialized. + bool haveInterpreter() const; - bool isEnabled() const; + bool canExecuteScripts(); - // FIXME: void* is a compile hack. - void attachDebugger(void*); + // FIXME: void* is a compile hack. + void attachDebugger(void*); - // --- Static methods assume we are running VM in single thread, --- - // --- and there is only one VM instance. --- + // --- Static methods assume we are running VM in single thread, --- + // --- and there is only one VM instance. --- - // Returns the frame for the entered context. See comments in - // V8Proxy::retrieveFrameForEnteredContext() for more information. - static Frame* retrieveFrameForEnteredContext(); + // Returns the frame for the entered context. See comments in + // V8Proxy::retrieveFrameForEnteredContext() for more information. + static Frame* retrieveFrameForEnteredContext(); - // Returns the frame for the current context. See comments in - // V8Proxy::retrieveFrameForEnteredContext() for more information. - static Frame* retrieveFrameForCurrentContext(); + // Returns the frame for the current context. See comments in + // V8Proxy::retrieveFrameForEnteredContext() for more information. + static Frame* retrieveFrameForCurrentContext(); - // Check whether it is safe to access a frame in another domain. - static bool isSafeScript(Frame*); + // Check whether it is safe to access a frame in another domain. + static bool isSafeScript(Frame*); - // Pass command-line flags to the JS engine. - static void setFlags(const char* string, int length); + // Pass command-line flags to the JS engine. + static void setFlags(const char* string, int length); - // Protect and unprotect the JS wrapper from garbage collected. - static void gcProtectJSWrapper(void*); - static void gcUnprotectJSWrapper(void*); + // Protect and unprotect the JS wrapper from garbage collected. + static void gcProtectJSWrapper(void*); + static void gcUnprotectJSWrapper(void*); - void finishedWithEvent(Event*); - void setEventHandlerLineNumber(int lineNumber); + void finishedWithEvent(Event*); + void setEventHandlerLineNumber(int lineNumber); - void setProcessingTimerCallback(bool processingTimerCallback) { m_processingTimerCallback = processingTimerCallback; } - bool processingUserGesture() const; + void setProcessingTimerCallback(bool processingTimerCallback) { m_processingTimerCallback = processingTimerCallback; } + bool processingUserGesture() const; + bool anyPageIsProcessingUserGesture() const; - void setPaused(bool paused) { m_paused = paused; } - bool isPaused() const { return m_paused; } + void setPaused(bool paused) { m_paused = paused; } + bool isPaused() const { return m_paused; } - const String* sourceURL() const { return m_sourceURL; } // 0 if we are not evaluating any script. + const String* sourceURL() const { return m_sourceURL; } // 0 if we are not evaluating any script. - void clearWindowShell(); - void updateDocument(); + void clearWindowShell(); + void updateDocument(); - void updateSecurityOrigin(); - void clearScriptObjects(); - void updatePlatformScriptObjects(); - void cleanupScriptObjectsForPlugin(Widget*); + void updateSecurityOrigin(); + void clearScriptObjects(); + void updatePlatformScriptObjects(); + void cleanupScriptObjectsForPlugin(Widget*); #if ENABLE(NETSCAPE_PLUGIN_API) - NPObject* createScriptObjectForPluginElement(HTMLPlugInElement*); - NPObject* windowScriptNPObject(); + NPObject* createScriptObjectForPluginElement(HTMLPlugInElement*); + NPObject* windowScriptNPObject(); #endif - // Dummy method to avoid a bunch of ifdef's in WebCore. - void evaluateInWorld(const ScriptSourceCode&, DOMWrapperWorld*) { } - static void getAllWorlds(Vector<DOMWrapperWorld*>& worlds); - - // Script state for the main world context. - ScriptState* mainWorldScriptState(); + // Dummy method to avoid a bunch of ifdef's in WebCore. + void evaluateInWorld(const ScriptSourceCode&, DOMWrapperWorld*) { } + static void getAllWorlds(Vector<DOMWrapperWorld*>& worlds); - private: - Frame* m_frame; - const String* m_sourceURL; +private: + Frame* m_frame; + const String* m_sourceURL; - bool m_inExecuteScript; + bool m_inExecuteScript; - bool m_processingTimerCallback; - bool m_paused; + bool m_processingTimerCallback; + bool m_paused; - OwnPtr<V8Proxy> m_proxy; - typedef HashMap<Widget*, NPObject*> PluginObjectMap; + OwnPtr<V8Proxy> m_proxy; + typedef HashMap<Widget*, NPObject*> PluginObjectMap; - // A mapping between Widgets and their corresponding script object. - // This list is used so that when the plugin dies, we can immediately - // invalidate all sub-objects which are associated with that plugin. - // The frame keeps a NPObject reference for each item on the list. - PluginObjectMap m_pluginObjects; + // A mapping between Widgets and their corresponding script object. + // This list is used so that when the plugin dies, we can immediately + // invalidate all sub-objects which are associated with that plugin. + // The frame keeps a NPObject reference for each item on the list. + PluginObjectMap m_pluginObjects; #if ENABLE(NETSCAPE_PLUGIN_API) - NPObject* m_windowScriptNPObject; + NPObject* m_windowScriptNPObject; #endif - // The XSSAuditor associated with this ScriptController. - OwnPtr<XSSAuditor> m_XSSAuditor; - - // Script state for the main world context. - OwnPtr<ScriptState> m_mainWorldScriptState; - }; + // The XSSAuditor associated with this ScriptController. + OwnPtr<XSSAuditor> m_XSSAuditor; +}; } // namespace WebCore diff --git a/WebCore/bindings/v8/ScriptEventListener.cpp b/WebCore/bindings/v8/ScriptEventListener.cpp index 51d53ab..b318d2e 100644 --- a/WebCore/bindings/v8/ScriptEventListener.cpp +++ b/WebCore/bindings/v8/ScriptEventListener.cpp @@ -46,13 +46,17 @@ namespace WebCore { PassRefPtr<V8LazyEventListener> createAttributeEventListener(Node* node, Attribute* attr) { ASSERT(node); + ASSERT(attr); + if (attr->isNull()) + return 0; + int lineNumber = 1; int columnNumber = 0; String sourceURL; if (Frame* frame = node->document()->frame()) { ScriptController* scriptController = frame->script(); - if (!scriptController->isEnabled()) + if (!scriptController->canExecuteScripts()) return 0; if (!scriptController->xssAuditor()->canCreateInlineEventListener(attr->localName().string(), attr->value())) { @@ -76,12 +80,16 @@ PassRefPtr<V8LazyEventListener> createAttributeEventListener(Frame* frame, Attri if (!frame) return 0; + ASSERT(attr); + if (attr->isNull()) + return 0; + int lineNumber = 1; int columnNumber = 0; String sourceURL; ScriptController* scriptController = frame->script(); - if (!scriptController->isEnabled()) + if (!scriptController->canExecuteScripts()) return 0; if (!scriptController->xssAuditor()->canCreateInlineEventListener(attr->localName().string(), attr->value())) { diff --git a/WebCore/bindings/v8/ScriptObject.h b/WebCore/bindings/v8/ScriptObject.h index 630d3b9..a60f2a8 100644 --- a/WebCore/bindings/v8/ScriptObject.h +++ b/WebCore/bindings/v8/ScriptObject.h @@ -48,6 +48,7 @@ namespace WebCore { virtual ~ScriptObject() {} v8::Local<v8::Object> v8Object() const; + ScriptState* scriptState() const { return m_scriptState; } bool set(const String& name, const String&); bool set(const char* name, const ScriptObject&); diff --git a/WebCore/bindings/v8/ScriptScope.cpp b/WebCore/bindings/v8/ScriptScope.cpp index 727ab25..a1b13a1 100644 --- a/WebCore/bindings/v8/ScriptScope.cpp +++ b/WebCore/bindings/v8/ScriptScope.cpp @@ -33,10 +33,6 @@ #include "ScriptState.h" -#include "Document.h" -#include "Frame.h" -#include "V8Binding.h" - #include <v8.h> namespace WebCore { @@ -45,8 +41,8 @@ ScriptScope::ScriptScope(ScriptState* scriptState, bool reportExceptions) : m_context(scriptState->context()) , m_scope(m_context) , m_scriptState(scriptState) - , m_reportExceptions(reportExceptions) { + m_exceptionCatcher.SetVerbose(reportExceptions); ASSERT(!m_context.IsEmpty()); } @@ -54,11 +50,6 @@ bool ScriptScope::success() { if (!m_exceptionCatcher.HasCaught()) return true; - - v8::Local<v8::Message> message = m_exceptionCatcher.Message(); - if (m_reportExceptions) - m_scriptState->frame()->document()->reportException(toWebCoreString(message->Get()), message->GetLineNumber(), toWebCoreString(message->GetScriptResourceName())); - m_exceptionCatcher.Reset(); return false; } diff --git a/WebCore/bindings/v8/ScriptScope.h b/WebCore/bindings/v8/ScriptScope.h index 6fee458..3f9a332 100644 --- a/WebCore/bindings/v8/ScriptScope.h +++ b/WebCore/bindings/v8/ScriptScope.h @@ -49,7 +49,6 @@ namespace WebCore { v8::Context::Scope m_scope; v8::TryCatch m_exceptionCatcher; ScriptState* m_scriptState; - bool m_reportExceptions; }; } diff --git a/WebCore/bindings/v8/ScriptState.cpp b/WebCore/bindings/v8/ScriptState.cpp index 68593e7..fac1d26 100644 --- a/WebCore/bindings/v8/ScriptState.cpp +++ b/WebCore/bindings/v8/ScriptState.cpp @@ -35,22 +35,17 @@ #include "Node.h" #include "Page.h" #include "ScriptController.h" +#include "V8HiddenPropertyName.h" +#include <v8.h> #include <wtf/Assertions.h> -#include <wtf/StdLibExtras.h> namespace WebCore { -ScriptState::ScriptState(Frame* frame) - : m_frame(frame) - , m_context(v8::Persistent<v8::Context>::New(V8Proxy::mainWorldContext(frame))) -{ -} - -ScriptState::ScriptState(Frame* frame, v8::Handle<v8::Context> context) - : m_frame(frame) - , m_context(v8::Persistent<v8::Context>::New(context)) +ScriptState::ScriptState(v8::Handle<v8::Context> context) + : m_context(v8::Persistent<v8::Context>::New(context)) { + m_context.MakeWeak(this, &ScriptState::weakReferenceCallback); } ScriptState::~ScriptState() @@ -59,6 +54,49 @@ ScriptState::~ScriptState() m_context.Clear(); } +ScriptState* ScriptState::forContext(v8::Local<v8::Context> context) +{ + v8::Context::Scope contextScope(context); + + v8::Local<v8::Object> global = context->Global(); + // Skip proxy object. The proxy object will survive page navigation while we need + // an object whose lifetime consides with that of the inspected context. + global = v8::Local<v8::Object>::Cast(global->GetPrototype()); + + v8::Handle<v8::String> key = V8HiddenPropertyName::scriptState(); + v8::Local<v8::Value> val = global->GetHiddenValue(key); + if (!val.IsEmpty() && val->IsExternal()) + return static_cast<ScriptState*>(v8::External::Cast(*val)->Value()); + + ScriptState* state = new ScriptState(context); + global->SetHiddenValue(key, v8::External::New(state)); + return state; +} + +ScriptState* ScriptState::current() +{ + v8::HandleScope handleScope; + v8::Local<v8::Context> context = v8::Context::GetCurrent(); + if (context.IsEmpty()) { + ASSERT_NOT_REACHED(); + return 0; + } + return ScriptState::forContext(context); +} + +void ScriptState::weakReferenceCallback(v8::Persistent<v8::Value> object, void* parameter) +{ + ScriptState* scriptState = static_cast<ScriptState*>(parameter); + delete scriptState; +} + +ScriptState* mainWorldScriptState(Frame* frame) +{ + v8::HandleScope handleScope; + V8Proxy* proxy = frame->script()->proxy(); + return ScriptState::forContext(proxy->mainWorldContext()); +} + ScriptState* scriptStateFromNode(DOMWrapperWorld*, Node* node) { // This should be never reached with V8 bindings (WebKit only uses it @@ -70,14 +108,7 @@ ScriptState* scriptStateFromNode(DOMWrapperWorld*, Node* node) ScriptState* scriptStateFromPage(DOMWrapperWorld*, Page* page) { // This should be only reached with V8 bindings from single process layout tests. - return page->mainFrame()->script()->mainWorldScriptState(); -} - -// FIXME: Stub method so we compile. Currently called from FrameLoader.cpp. -DOMWrapperWorld* mainThreadNormalWorld() -{ - DEFINE_STATIC_LOCAL(DOMWrapperWorld, oneWorld, ()); - return &oneWorld; + return mainWorldScriptState(page->mainFrame()); } } diff --git a/WebCore/bindings/v8/ScriptState.h b/WebCore/bindings/v8/ScriptState.h index 12a1388..e71becb 100644 --- a/WebCore/bindings/v8/ScriptState.h +++ b/WebCore/bindings/v8/ScriptState.h @@ -31,6 +31,7 @@ #ifndef ScriptState_h #define ScriptState_h +#include "DOMWrapperWorld.h" #include <v8.h> #include <wtf/Noncopyable.h> #include <wtf/RefCounted.h> @@ -43,11 +44,6 @@ namespace WebCore { class ScriptState : public Noncopyable { public: - ScriptState() { } - ScriptState(Frame* frame); - ScriptState(Frame* frame, v8::Handle<v8::Context> context); - ~ScriptState(); - bool hadException() { return !m_exception.IsEmpty(); } void setException(v8::Local<v8::Value> exception) { @@ -55,29 +51,42 @@ namespace WebCore { } v8::Local<v8::Value> exception() { return m_exception; } - Frame* frame() const { return m_frame; } v8::Local<v8::Context> context() const { return v8::Local<v8::Context>::New(m_context); } + static ScriptState* forContext(v8::Local<v8::Context>); + static ScriptState* current(); + + protected: + ScriptState() { } + ~ScriptState(); + private: + friend ScriptState* mainWorldScriptState(Frame*); + explicit ScriptState(v8::Handle<v8::Context>); + + static void weakReferenceCallback(v8::Persistent<v8::Value> object, void* parameter); + v8::Local<v8::Value> m_exception; - Frame* m_frame; v8::Persistent<v8::Context> m_context; }; + class EmptyScriptState : public ScriptState { + public: + EmptyScriptState() : ScriptState() { } + ~EmptyScriptState() { } + }; + + ScriptState* mainWorldScriptState(Frame*); + ScriptState* scriptStateFromNode(DOMWrapperWorld*, Node*); ScriptState* scriptStateFromPage(DOMWrapperWorld*, Page*); - DOMWrapperWorld* mainThreadNormalWorld(); inline DOMWrapperWorld* debuggerWorld() { return mainThreadNormalWorld(); } inline DOMWrapperWorld* pluginWorld() { return mainThreadNormalWorld(); } - // Dummy class to avoid a bunch of ifdef's in WebCore. - class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { - }; - } #endif // ScriptState_h diff --git a/WebCore/bindings/v8/ScriptValue.h b/WebCore/bindings/v8/ScriptValue.h index c0ba8d5..6a70bd7 100644 --- a/WebCore/bindings/v8/ScriptValue.h +++ b/WebCore/bindings/v8/ScriptValue.h @@ -44,11 +44,6 @@ namespace WebCore { class ScriptValue { public: - static ScriptValue quarantineValue(ScriptState* scriptState, const ScriptValue& value) - { - return value; - } - ScriptValue() {} ScriptValue(v8::Handle<v8::Value> value) diff --git a/WebCore/bindings/v8/custom/V8FileListCustom.cpp b/WebCore/bindings/v8/ScriptWrappable.h index bc533cf..850994a 100644 --- a/WebCore/bindings/v8/custom/V8FileListCustom.cpp +++ b/WebCore/bindings/v8/ScriptWrappable.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Google Inc. All rights reserved. + * Copyright (C) 2010 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -14,7 +14,7 @@ * * Neither the name of Google Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -28,27 +28,34 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "config.h" -#include "FileList.h" - -#include "File.h" -#include "V8Binding.h" -#include "V8CustomBinding.h" -#include "V8Proxy.h" +#ifndef ScriptWrappable_h +#define ScriptWrappable_h -#include <wtf/RefPtr.h> +#include <v8.h> namespace WebCore { -INDEXED_PROPERTY_GETTER(FileList) -{ - INC_STATS("DOM.FileList.IndexedPropertyGetter"); - FileList* fileList = V8DOMWrapper::convertToNativeObject<FileList>(V8ClassIndex::FILELIST, info.Holder()); - RefPtr<File> file = fileList->item(index); - if (!file) - return notHandledByInterceptor(); +class ScriptWrappable { +public: + ScriptWrappable() : m_wrapper(0) { } + + v8::Persistent<v8::Object>* wrapper() const + { + return m_wrapper; + } - return V8DOMWrapper::convertToV8Object(V8ClassIndex::FILE, file.release()); -} + void setWrapper(v8::Persistent<v8::Object>* wrapper) + { + ASSERT(wrapper); + m_wrapper = wrapper; + } + + void clearWrapper() { m_wrapper = 0; } + +private: + v8::Persistent<v8::Object>* m_wrapper; +}; } // namespace WebCore + +#endif // ScriptWrappable_h diff --git a/WebCore/bindings/v8/SerializedScriptValue.cpp b/WebCore/bindings/v8/SerializedScriptValue.cpp new file mode 100644 index 0000000..bac7f20 --- /dev/null +++ b/WebCore/bindings/v8/SerializedScriptValue.cpp @@ -0,0 +1,699 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "SerializedScriptValue.h" + +#include "SharedBuffer.h" + +#include <v8.h> +#include <wtf/Assertions.h> +#include <wtf/RefCounted.h> +#include <wtf/Vector.h> + +// FIXME: +// - catch V8 exceptions +// - be ready to get empty handles +// - consider crashing in debug mode on deserialization errors + +namespace WebCore { + +namespace { + +typedef UChar BufferValueType; + +// Serialization format is a sequence of (tag, optional data) +// pairs. Tag always takes exactly one byte. +enum SerializationTag { + InvalidTag = '!', + PaddingTag = '\0', + UndefinedTag = '_', + NullTag = '0', + TrueTag = 'T', + FalseTag = 'F', + StringTag = 'S', + Int32Tag = 'I', + NumberTag = 'N', + ObjectTag = '{', + ArrayTag = '[', +}; + +// Helpers to do verbose handle casts. + +template <typename T, typename U> +static v8::Handle<T> handleCast(v8::Handle<U> handle) { return v8::Handle<T>::Cast(handle); } + +template <typename T, typename U> +static v8::Local<T> handleCast(v8::Local<U> handle) { return v8::Local<T>::Cast(handle); } + +static bool shouldCheckForCycles(int depth) +{ + ASSERT(depth >= 0); + // Since we are not required to spot the cycle as soon as it + // happens we can check for cycles only when the current depth + // is a power of two. + return !(depth & (depth - 1)); +} + +static const int maxDepth = 20000; + +// VarInt encoding constants. +static const int varIntShift = 7; +static const int varIntMask = (1 << varIntShift) - 1; + +// ZigZag encoding helps VarInt encoding stay small for negative +// numbers with small absolute values. +class ZigZag { +public: + static uint32_t encode(uint32_t value) + { + if (value & (1U << 31)) + value = ((~value) << 1) + 1; + else + value <<= 1; + return value; + } + + static uint32_t decode(uint32_t value) + { + if (value & 1) + value = ~(value >> 1); + else + value >>= 1; + return value; + } + +private: + ZigZag(); +}; + +// Writer is responsible for serializing primitive types and storing +// information used to reconstruct composite types. +class Writer : Noncopyable { +public: + Writer() : m_position(0) + { + } + + // Write functions for primitive types. + + void writeUndefined() { append(UndefinedTag); } + + void writeNull() { append(NullTag); } + + void writeTrue() { append(TrueTag); } + + void writeFalse() { append(FalseTag); } + + void writeString(const char* data, int length) + { + append(StringTag); + doWriteUint32(static_cast<uint32_t>(length)); + append(data, length); + } + + void writeInt32(int32_t value) + { + append(Int32Tag); + doWriteUint32(ZigZag::encode(static_cast<uint32_t>(value))); + } + + void writeNumber(double number) + { + append(NumberTag); + append(reinterpret_cast<char*>(&number), sizeof(number)); + } + + // Records that a composite object can be constructed by using + // |length| previously stored values. + void endComposite(SerializationTag tag, int32_t length) + { + ASSERT(tag == ObjectTag || tag == ArrayTag); + append(tag); + doWriteUint32(static_cast<uint32_t>(length)); + } + + Vector<BufferValueType>& data() + { + fillHole(); + return m_buffer; + } + +private: + void doWriteUint32(uint32_t value) + { + while (true) { + char b = (value & varIntMask); + value >>= varIntShift; + if (!value) { + append(b); + break; + } + append(b | (1 << varIntShift)); + } + } + + void append(SerializationTag tag) + { + append(static_cast<char>(tag)); + } + + void append(char b) + { + ensureSpace(1); + *charAt(m_position++) = b; + } + + void append(const char* data, int length) + { + ensureSpace(length); + memcpy(charAt(m_position), data, length); + m_position += length; + } + + void ensureSpace(int extra) + { + COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes); + m_buffer.grow((m_position + extra + 1) / 2); // "+ 1" to round up. + } + + void fillHole() + { + COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes); + // If the writer is at odd position in the buffer, then one of + // the bytes in the last UChar is not initialized. + if (m_position % 2) + *charAt(m_position) = static_cast<char>(PaddingTag); + } + + char* charAt(int position) { return reinterpret_cast<char*>(m_buffer.data()) + position; } + + Vector<BufferValueType> m_buffer; + unsigned m_position; +}; + +class Serializer { +public: + explicit Serializer(Writer& writer) + : m_writer(writer) + , m_state(0) + , m_depth(0) + { + } + + bool serialize(v8::Handle<v8::Value> value) + { + v8::HandleScope scope; + StackCleaner cleaner(&m_state); + if (!doSerialize(value)) + return false; + while (top()) { + int length; + while (!top()->isDone(&length)) { + // Note that doSerialize() can change current top(). + if (!doSerialize(top()->advance())) + return false; + } + m_writer.endComposite(top()->tag(), length); + pop(); + } + return true; + } + +private: + class StateBase : public Noncopyable { + public: + virtual ~StateBase() { } + + // Link to the next state to form a stack. + StateBase* nextState() { return m_next; } + void setNextState(StateBase* next) { m_next = next; } + + // Composite object we're processing in this state. + v8::Handle<v8::Value> composite() { return m_composite; } + + // Serialization tag for the current composite. + virtual SerializationTag tag() const = 0; + + // Returns whether iteration over subobjects of the current + // composite object is done. If yes, |*length| is set to the + // number of subobjects. + virtual bool isDone(int* length) = 0; + + // Advances to the next subobject. + // Requires: !this->isDone(). + virtual v8::Local<v8::Value> advance() = 0; + + protected: + StateBase(v8::Handle<v8::Value> composite) + : m_next(0) + , m_composite(composite) + { + } + + private: + StateBase* m_next; + v8::Handle<v8::Value> m_composite; + }; + + template <typename T, SerializationTag compositeTag> + class State : public StateBase { + public: + v8::Handle<T> composite() { return handleCast<T>(StateBase::composite()); } + + virtual SerializationTag tag() const { return compositeTag; } + + protected: + explicit State(v8::Handle<T> composite) : StateBase(composite) + { + } + }; + + // Helper to clean up the state stack in case of errors. + class StackCleaner : Noncopyable { + public: + explicit StackCleaner(StateBase** stack) : m_stack(stack) + { + } + + ~StackCleaner() + { + StateBase* state = *m_stack; + while (state) { + StateBase* tmp = state->nextState(); + delete state; + state = tmp; + } + *m_stack = 0; + } + + private: + StateBase** m_stack; + }; + + class ArrayState : public State<v8::Array, ArrayTag> { + public: + ArrayState(v8::Handle<v8::Array> array) + : State<v8::Array, ArrayTag>(array) + , m_index(0) + { + } + + virtual bool isDone(int* length) + { + *length = composite()->Length(); + return static_cast<int>(m_index) >= *length; + } + + virtual v8::Local<v8::Value> advance() + { + ASSERT(m_index < composite()->Length()); + v8::HandleScope scope; + return scope.Close(composite()->Get(v8::Integer::New(m_index++))); + } + + private: + unsigned m_index; + }; + + class ObjectState : public State<v8::Object, ObjectTag> { + public: + ObjectState(v8::Handle<v8::Object> object) + : State<v8::Object, ObjectTag>(object) + , m_propertyNames(object->GetPropertyNames()) + , m_index(-1) + , m_length(0) + { + nextProperty(); + } + + virtual bool isDone(int* length) + { + *length = m_length; + return m_index >= 2 * m_propertyNames->Length(); + } + + virtual v8::Local<v8::Value> advance() + { + ASSERT(m_index < 2 * m_propertyNames->Length()); + if (!(m_index % 2)) { + ++m_index; + return m_propertyName; + } + v8::Local<v8::Value> result = composite()->Get(m_propertyName); + nextProperty(); + return result; + } + + private: + void nextProperty() + { + v8::HandleScope scope; + ++m_index; + ASSERT(!(m_index % 2)); + for (; m_index < 2 * m_propertyNames->Length(); m_index += 2) { + v8::Local<v8::Value> propertyName = m_propertyNames->Get(v8::Integer::New(m_index / 2)); + if ((propertyName->IsString() && composite()->HasRealNamedProperty(handleCast<v8::String>(propertyName))) + || (propertyName->IsInt32() && composite()->HasRealIndexedProperty(propertyName->Uint32Value()))) { + m_propertyName = scope.Close(propertyName); + m_length += 2; + return; + } + } + } + + v8::Local<v8::Array> m_propertyNames; + v8::Local<v8::Value> m_propertyName; + unsigned m_index; + unsigned m_length; + }; + + bool doSerialize(v8::Handle<v8::Value> value) + { + if (value->IsUndefined()) + m_writer.writeUndefined(); + else if (value->IsNull()) + m_writer.writeNull(); + else if (value->IsTrue()) + m_writer.writeTrue(); + else if (value->IsFalse()) + m_writer.writeFalse(); + else if (value->IsInt32()) + m_writer.writeInt32(value->Int32Value()); + else if (value->IsNumber()) + m_writer.writeNumber(handleCast<v8::Number>(value)->Value()); + else if (value->IsString()) { + v8::String::Utf8Value stringValue(value); + m_writer.writeString(*stringValue, stringValue.length()); + } else if (value->IsArray()) { + if (!checkComposite(value)) + return false; + push(new ArrayState(handleCast<v8::Array>(value))); + } else if (value->IsObject()) { + if (!checkComposite(value)) + return false; + push(new ObjectState(handleCast<v8::Object>(value))); + // FIXME: + // - check not a wrapper + // - support File, ImageData, etc. + } + return true; + } + + void push(StateBase* state) + { + state->setNextState(m_state); + m_state = state; + ++m_depth; + } + + StateBase* top() { return m_state; } + + void pop() + { + if (!m_state) + return; + StateBase* top = m_state; + m_state = top->nextState(); + delete top; + --m_depth; + } + + bool checkComposite(v8::Handle<v8::Value> composite) + { + if (m_depth > maxDepth) + return false; + if (!shouldCheckForCycles(m_depth)) + return true; + for (StateBase* state = top(); state; state = state->nextState()) { + if (state->composite() == composite) + return false; + } + return true; + } + + Writer& m_writer; + StateBase* m_state; + int m_depth; +}; + +// Reader is responsible for deserializing primitive types and +// restoring information about saved objects of composite types. +class Reader { +public: + Reader(const char* buffer, int length) + : m_buffer(buffer) + , m_length(length) + , m_position(0) + { + ASSERT(length >= 0); + } + + bool isEof() const { return m_position >= m_length; } + + bool read(SerializationTag* tag, v8::Handle<v8::Value>* value, int* length) + { + uint32_t rawLength; + if (!readTag(tag)) + return false; + switch (*tag) { + case InvalidTag: + return false; + case PaddingTag: + break; + case UndefinedTag: + *value = v8::Undefined(); + break; + case NullTag: + *value = v8::Null(); + break; + case TrueTag: + *value = v8::True(); + break; + case FalseTag: + *value = v8::False(); + break; + case StringTag: + if (!readString(value)) + return false; + break; + case Int32Tag: + if (!readInt32(value)) + return false; + break; + case NumberTag: + if (!readNumber(value)) + return false; + break; + case ObjectTag: + case ArrayTag: + if (!doReadUint32(&rawLength)) + return false; + *length = rawLength; + break; + } + return true; + } + +private: + bool readTag(SerializationTag* tag) + { + if (m_position >= m_length) + return false; + *tag = static_cast<SerializationTag>(m_buffer[m_position++]); + return true; + } + + bool readString(v8::Handle<v8::Value>* value) + { + uint32_t length; + if (!doReadUint32(&length)) + return false; + if (m_position + length > m_length) + return false; + *value = v8::String::New(m_buffer + m_position, length); + m_position += length; + return true; + } + + bool readInt32(v8::Handle<v8::Value>* value) + { + uint32_t rawValue; + if (!doReadUint32(&rawValue)) + return false; + *value = v8::Integer::New(static_cast<int32_t>(ZigZag::decode(rawValue))); + return true; + } + + bool readNumber(v8::Handle<v8::Value>* value) + { + if (m_position + sizeof(double) > m_length) + return false; + double number; + char* numberAsByteArray = reinterpret_cast<char*>(&number); + for (unsigned i = 0; i < sizeof(double); ++i) + numberAsByteArray[i] = m_buffer[m_position++]; + *value = v8::Number::New(number); + return true; + } + + bool doReadUint32(uint32_t* value) + { + *value = 0; + char currentByte; + int shift = 0; + do { + if (m_position >= m_length) + return false; + currentByte = m_buffer[m_position++]; + *value |= ((currentByte & varIntMask) << shift); + shift += varIntShift; + } while (currentByte & (1 << varIntShift)); + return true; + } + + const char* m_buffer; + const unsigned m_length; + unsigned m_position; +}; + +class Deserializer { +public: + explicit Deserializer(Reader& reader) : m_reader(reader) + { + } + + v8::Local<v8::Value> deserialize() + { + v8::HandleScope scope; + while (!m_reader.isEof()) { + if (!doDeserialize()) + return v8::Local<v8::Value>(); + } + if (stackDepth() != 1) + return v8::Local<v8::Value>(); + return scope.Close(element(0)); + } + +private: + bool doDeserialize() + { + SerializationTag tag; + v8::Local<v8::Value> value; + int length = 0; + if (!m_reader.read(&tag, &value, &length)) + return false; + if (!value.IsEmpty()) { + push(value); + } else if (tag == ObjectTag) { + if (length > stackDepth()) + return false; + v8::Local<v8::Object> object = v8::Object::New(); + for (int i = stackDepth() - length; i < stackDepth(); i += 2) { + v8::Local<v8::Value> propertyName = element(i); + v8::Local<v8::Value> propertyValue = element(i + 1); + object->Set(propertyName, propertyValue); + } + pop(length); + push(object); + } else if (tag == ArrayTag) { + if (length > stackDepth()) + return false; + v8::Local<v8::Array> array = v8::Array::New(length); + const int depth = stackDepth() - length; + { + v8::HandleScope scope; + for (int i = 0; i < length; ++i) + array->Set(v8::Integer::New(i), element(depth + i)); + } + pop(length); + push(array); + } else if (tag != PaddingTag) + return false; + return true; + } + + void push(v8::Local<v8::Value> value) { m_stack.append(value); } + + void pop(unsigned length) + { + ASSERT(length <= m_stack.size()); + m_stack.shrink(m_stack.size() - length); + } + + int stackDepth() const { return m_stack.size(); } + + v8::Local<v8::Value> element(unsigned index) + { + ASSERT(index < m_stack.size()); + return m_stack[index]; + } + + Reader& m_reader; + Vector<v8::Local<v8::Value> > m_stack; +}; + +} // namespace + +SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value) +{ + Writer writer; + Serializer serializer(writer); + if (!serializer.serialize(value)) { + // FIXME: throw exception + return; + } + m_data = StringImpl::adopt(writer.data()); +} + +SerializedScriptValue::SerializedScriptValue(String data, StringDataMode mode) +{ + if (mode == WireData) + m_data = data; + else { + ASSERT(mode == StringValue); + RefPtr<SharedBuffer> buffer = utf8Buffer(data); + Writer writer; + writer.writeString(buffer->data(), buffer->size()); + m_data = StringImpl::adopt(writer.data()); + } +} + +v8::Local<v8::Value> SerializedScriptValue::deserialize() +{ + if (!m_data.impl()) + return v8::Local<v8::Value>(); + COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes); + Reader reader(reinterpret_cast<const char*>(m_data.impl()->characters()), 2 * m_data.length()); + Deserializer deserializer(reader); + return deserializer.deserialize(); +} + +} // namespace WebCore diff --git a/WebCore/bindings/v8/SerializedScriptValue.h b/WebCore/bindings/v8/SerializedScriptValue.h index 26a4199..7eb8935 100644 --- a/WebCore/bindings/v8/SerializedScriptValue.h +++ b/WebCore/bindings/v8/SerializedScriptValue.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Google Inc. All rights reserved. + * Copyright (C) 2009, 2010 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -40,11 +40,26 @@ namespace WebCore { class SerializedScriptValue : public RefCounted<SerializedScriptValue> { public: - static PassRefPtr<SerializedScriptValue> create(String string) + // Creates a serialized representation of the given V8 value. + static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value> value) { - return adoptRef(new SerializedScriptValue(string)); + return adoptRef(new SerializedScriptValue(value)); } + // Creates a serialized value with the given data obtained from a + // prior call to toWireString(). + static PassRefPtr<SerializedScriptValue> createFromWire(String data) + { + return adoptRef(new SerializedScriptValue(data, WireData)); + } + + // Creates a serialized representation of WebCore string. + static PassRefPtr<SerializedScriptValue> create(String data) + { + return adoptRef(new SerializedScriptValue(data, StringValue)); + } + + // Creates an empty serialized value. static PassRefPtr<SerializedScriptValue> create() { return adoptRef(new SerializedScriptValue()); @@ -52,23 +67,29 @@ public: PassRefPtr<SerializedScriptValue> release() { - RefPtr<SerializedScriptValue> result = adoptRef(new SerializedScriptValue(m_data)); + RefPtr<SerializedScriptValue> result = adoptRef(new SerializedScriptValue(m_data, WireData)); m_data = String(); return result.release(); } - String toString() - { - return m_data; - } + String toWireString() const { return m_data; } + + // Deserializes the value (in the current context). Returns an + // empty handle in case of failure. + v8::Local<v8::Value> deserialize(); private: - SerializedScriptValue(String string) - : m_data(string) - { - } + enum StringDataMode { + StringValue, + WireData + }; SerializedScriptValue() { } + + explicit SerializedScriptValue(v8::Handle<v8::Value>); + + SerializedScriptValue(String data, StringDataMode mode); + String m_data; }; diff --git a/WebCore/bindings/v8/StaticDOMDataStore.cpp b/WebCore/bindings/v8/StaticDOMDataStore.cpp index 3a02c0b..722051b 100644 --- a/WebCore/bindings/v8/StaticDOMDataStore.cpp +++ b/WebCore/bindings/v8/StaticDOMDataStore.cpp @@ -35,7 +35,7 @@ namespace WebCore { StaticDOMDataStore::StaticDOMDataStore(DOMData* domData) : DOMDataStore(domData) - , m_staticDomNodeMap(domData, &DOMDataStore::weakNodeCallback) + , m_staticDomNodeMap(&DOMDataStore::weakNodeCallback) , m_staticDomObjectMap(domData, &DOMDataStore::weakDOMObjectCallback) , m_staticActiveDomObjectMap(domData, &DOMDataStore::weakActiveDOMObjectCallback) #if ENABLE(SVG) diff --git a/WebCore/bindings/v8/StaticDOMDataStore.h b/WebCore/bindings/v8/StaticDOMDataStore.h index 4cd0515..64a90e0 100644 --- a/WebCore/bindings/v8/StaticDOMDataStore.h +++ b/WebCore/bindings/v8/StaticDOMDataStore.h @@ -48,7 +48,7 @@ public: StaticDOMDataStore(DOMData*); private: - InternalDOMWrapperMap<Node> m_staticDomNodeMap; + IntrusiveDOMWrapperMap m_staticDomNodeMap; InternalDOMWrapperMap<void> m_staticDomObjectMap; InternalDOMWrapperMap<void> m_staticActiveDomObjectMap; #if ENABLE(SVG) diff --git a/WebCore/bindings/v8/V8Binding.cpp b/WebCore/bindings/v8/V8Binding.cpp index 00286e5..4379230 100644 --- a/WebCore/bindings/v8/V8Binding.cpp +++ b/WebCore/bindings/v8/V8Binding.cpp @@ -41,6 +41,7 @@ #include "StringBuffer.h" #include "StringHash.h" #include "Threading.h" +#include "V8Element.h" #include "V8Proxy.h" #include <v8.h> @@ -126,16 +127,6 @@ private: #endif }; - -void* v8DOMWrapperToNative(v8::Handle<v8::Object> object) { - return object->GetPointerFromInternalField(V8Custom::kDOMWrapperObjectIndex); -} - -void* v8DOMWrapperToNative(const v8::AccessorInfo& info) { - return info.Holder()->GetPointerFromInternalField(V8Custom::kDOMWrapperObjectIndex); -} - - String v8ValueToWebCoreString(v8::Handle<v8::Value> value) { if (value->IsString()) @@ -239,6 +230,17 @@ v8::Handle<v8::Value> v8StringOrFalse(const String& str) return str.isNull() ? v8::Handle<v8::Value>(v8::False()) : v8::Handle<v8::Value>(v8String(str)); } +double toWebCoreDate(v8::Handle<v8::Value> object) +{ + return (object->IsDate() || object->IsNumber()) ? object->NumberValue() : std::numeric_limits<double>::quiet_NaN(); +} + +v8::Handle<v8::Value> v8DateOrNull(double value) +{ + if (isfinite(value)) + return v8::Date::New(value); + return v8::Null(); +} template <class S> struct StringTraits { @@ -407,7 +409,11 @@ v8::Local<v8::String> v8ExternalString(const String& string) StringCache& stringCache = getStringCache(); v8::String* cachedV8String = stringCache.get(stringImpl); if (cachedV8String) - return v8::Local<v8::String>::New(v8::Handle<v8::String>(cachedV8String)); + { + v8::Persistent<v8::String> handle(cachedV8String); + if (!handle.IsNearDeath() && !handle.IsEmpty()) + return v8::Local<v8::String>::New(handle); + } v8::Local<v8::String> newString = makeExternalString(string); if (newString.IsEmpty()) @@ -457,21 +463,42 @@ v8::Local<v8::Signature> configureTemplate(v8::Persistent<v8::FunctionTemplate>d return defaultSignature; } -void createCallback(v8::Local<v8::ObjectTemplate> proto, - const char *name, - v8::InvocationCallback callback, - v8::Handle<v8::Signature> signature, - v8::PropertyAttribute attribute) +v8::Persistent<v8::String> getToStringName() +{ + DEFINE_STATIC_LOCAL(v8::Persistent<v8::String>, value, ()); + if (value.IsEmpty()) + value = v8::Persistent<v8::String>::New(v8::String::New("toString")); + return value; +} + +static v8::Handle<v8::Value> constructorToString(const v8::Arguments& args) +{ + // The DOM constructors' toString functions grab the current toString + // for Functions by taking the toString function of itself and then + // calling it with the constructor as its receiver. This means that + // changes to the Function prototype chain or toString function are + // reflected when printing DOM constructors. The only wart is that + // changes to a DOM constructor's toString's toString will cause the + // toString of the DOM constructor itself to change. This is extremely + // obscure and unlikely to be a problem. + v8::Handle<v8::Value> value = args.Callee()->Get(getToStringName()); + if (!value->IsFunction()) + return v8::String::New(""); + return v8::Handle<v8::Function>::Cast(value)->Call(args.This(), 0, 0); +} + +v8::Persistent<v8::FunctionTemplate> getToStringTemplate() { - proto->Set(v8::String::New(name), - v8::FunctionTemplate::New(callback, v8::Handle<v8::Value>(), signature), - attribute); + DEFINE_STATIC_LOCAL(v8::Persistent<v8::FunctionTemplate>, toStringTemplate, ()); + if (toStringTemplate.IsEmpty()) + toStringTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(constructorToString)); + return toStringTemplate; } v8::Handle<v8::Value> getElementStringAttr(const v8::AccessorInfo& info, const QualifiedName& name) { - Element *imp = v8DOMWrapperToNode<Element>(info); + Element* imp = V8Element::toNative(info.Holder()); return v8ExternalString(imp->getAttribute(name)); } @@ -479,7 +506,7 @@ void setElementStringAttr(const v8::AccessorInfo& info, const QualifiedName& name, v8::Local<v8::Value> value) { - Element* imp = v8DOMWrapperToNode<Element>(info); + Element* imp = V8Element::toNative(info.Holder()); AtomicString v = toAtomicWebCoreStringWithNullCheck(value); imp->setAttribute(name, v); } diff --git a/WebCore/bindings/v8/V8Binding.h b/WebCore/bindings/v8/V8Binding.h index de5bb4c..439dfd7 100644 --- a/WebCore/bindings/v8/V8Binding.h +++ b/WebCore/bindings/v8/V8Binding.h @@ -32,6 +32,7 @@ #define V8Binding_h #include "AtomicString.h" +#include "BindingSecurity.h" #include "MathExtras.h" #include "PlatformString.h" #include "V8DOMWrapper.h" @@ -43,72 +44,15 @@ namespace WebCore { class EventListener; class EventTarget; - - // A helper function extract native object pointer from a DOM wrapper - // and cast to the specified type. - void* v8DOMWrapperToNative(v8::Handle<v8::Object>); - - template <class C> - C* v8DOMWrapperTo(v8::Handle<v8::Object> object) - { - ASSERT(V8DOMWrapper::maybeDOMWrapper(object)); - return reinterpret_cast<C*>(v8DOMWrapperToNative(object)); - } - template <class C> - C* v8DOMWrapperToNode(v8::Handle<v8::Object> object) - { - ASSERT(V8DOMWrapper::maybeDOMWrapper(object)); - ASSERT(V8DOMWrapper::domWrapperType(object) == V8ClassIndex::NODE); - return reinterpret_cast<C*>(v8DOMWrapperToNative(object)); - } - - void* v8DOMWrapperToNative(const v8::AccessorInfo&); - - template <class C> - C* v8DOMWrapperTo(const v8::AccessorInfo& info) { - ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder())); - return reinterpret_cast<C*>(v8DOMWrapperToNative(info)); - } - template <class C> - C* v8DOMWrapperToNode(const v8::AccessorInfo& info) { - ASSERT(V8DOMWrapper::domWrapperType(info.Holder()) == V8ClassIndex::NODE); - return reinterpret_cast<C*>(v8DOMWrapperToNative(info)); - } - - template <class C> - C* v8DOMWrapperTo(V8ClassIndex::V8WrapperType type, v8::Handle<v8::Object> object) - { - // Native event listener is per frame, it cannot be handled by this generic function. - ASSERT(type != V8ClassIndex::EVENTLISTENER); - ASSERT(type != V8ClassIndex::EVENTTARGET); - - ASSERT(V8DOMWrapper::maybeDOMWrapper(object)); - -#ifndef NDEBUG - const bool typeIsValid = -#define MAKE_CASE(TYPE, NAME) (type != V8ClassIndex::TYPE) && - DOM_NODE_TYPES(MAKE_CASE) -#if ENABLE(SVG) - SVG_NODE_TYPES(MAKE_CASE) -#endif -#undef MAKE_CASE - true; - ASSERT(typeIsValid); -#endif - - return v8DOMWrapperTo<C>(object); - } - - template <class C> - C* v8DOMWrapperTo(V8ClassIndex::V8WrapperType type, const v8::AccessorInfo& info) - { -#ifndef NDEBUG - return v8DOMWrapperTo<C>(type, info.Holder()); -#else - return reinterpret_cast<C*>(v8DOMWrapperToNative(info)); -#endif - } + class V8BindingDOMWindow; + // Instantiate binding template classes for V8. + class V8Binding { + public: + typedef v8::Handle<v8::Value> Value; + typedef V8BindingDOMWindow DOMWindow; + }; + typedef BindingSecurity<V8Binding> V8BindingSecurity; enum ExternalMode { Externalize, @@ -168,6 +112,11 @@ namespace WebCore { return static_cast<float>(value->NumberValue()); } + inline long long toInt64(v8::Local<v8::Value> value) + { + return static_cast<long long>(value->IntegerValue()); + } + // FIXME: Drop this in favor of the type specific v8ValueToWebCoreString when we rework the code generation. inline String toWebCoreString(v8::Handle<v8::Value> object) { @@ -200,6 +149,10 @@ namespace WebCore { v8::Handle<v8::Value> v8StringOrUndefined(const String& str); v8::Handle<v8::Value> v8StringOrFalse(const String& str); + + double toWebCoreDate(v8::Handle<v8::Value> object); + + v8::Handle<v8::Value> v8DateOrNull(double value); v8::Persistent<v8::FunctionTemplate> createRawTemplate(); @@ -215,20 +168,15 @@ namespace WebCore { const BatchedCallback*, size_t callbackCount); - void createCallback(v8::Local<v8::ObjectTemplate> proto, - const char *name, - v8::InvocationCallback, - v8::Handle<v8::Signature>, - v8::PropertyAttribute attributes = v8::DontDelete); - v8::Handle<v8::Value> getElementStringAttr(const v8::AccessorInfo&, const QualifiedName&); void setElementStringAttr(const v8::AccessorInfo&, const QualifiedName&, v8::Local<v8::Value>); - v8::Handle<v8::Value> getElementEventHandlerAttr(const v8::AccessorInfo&, - const AtomicString&); + + v8::Persistent<v8::String> getToStringName(); + v8::Persistent<v8::FunctionTemplate> getToStringTemplate(); // V8Parameter is an adapter class that converts V8 values to Strings // or AtomicStrings as appropriate, using multiple typecast operators. diff --git a/WebCore/bindings/v8/V8Collection.cpp b/WebCore/bindings/v8/V8Collection.cpp index c9fc9ac..2ff5c88 100644 --- a/WebCore/bindings/v8/V8Collection.cpp +++ b/WebCore/bindings/v8/V8Collection.cpp @@ -52,7 +52,7 @@ v8::Handle<v8::Value> toOptionsCollectionSetter(uint32_t index, v8::Handle<v8::V return value; } - HTMLOptionElement* element = V8DOMWrapper::convertDOMWrapperToNode<HTMLOptionElement>(v8::Handle<v8::Object>::Cast(value)); + HTMLOptionElement* element = V8HTMLOptionElement::toNative(v8::Handle<v8::Object>::Cast(value)); base->setOption(index, element, ec); V8Proxy::setDOMException(ec); diff --git a/WebCore/bindings/v8/V8Collection.h b/WebCore/bindings/v8/V8Collection.h index 0a4134e..84150d8 100644 --- a/WebCore/bindings/v8/V8Collection.h +++ b/WebCore/bindings/v8/V8Collection.h @@ -51,6 +51,11 @@ namespace WebCore { return V8DOMWrapper::convertToV8Object(type, implementation); } + template<class Collection> static Collection* toNativeCollection(v8::Local<v8::Object> object) + { + return reinterpret_cast<Collection*>(object->GetPointerFromInternalField(v8DOMWrapperObjectIndex)); + } + template<class T> static v8::Handle<v8::Value> getV8Object(PassRefPtr<T> implementation, v8::Local<v8::Value> implementationType) { return getV8Object(implementation.get(), implementationType); @@ -62,10 +67,9 @@ namespace WebCore { { // FIXME: assert object is a collection type ASSERT(V8DOMWrapper::maybeDOMWrapper(object)); - V8ClassIndex::V8WrapperType wrapperType = V8DOMWrapper::domWrapperType(object); - ASSERT(wrapperType != V8ClassIndex::NODE); - Collection* collection = V8DOMWrapper::convertToNativeObject<Collection>(wrapperType, object); - String propertyName = toWebCoreString(name); + ASSERT(V8DOMWrapper::domWrapperType(object) != V8ClassIndex::NODE); + Collection* collection = toNativeCollection<Collection>(object); + AtomicString propertyName = toAtomicWebCoreStringWithNullCheck(name); return getV8Object<ItemType>(collection->namedItem(propertyName), implementationType); } @@ -84,35 +88,14 @@ namespace WebCore { return getNamedPropertyOfCollection<Collection, ItemType>(name, info.Holder(), info.Data()); } - // A template of named property accessor of HTMLSelectElement and HTMLFormElement. - template<class Collection> static v8::Handle<v8::Value> nodeCollectionNamedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) - { - ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder())); - ASSERT(V8DOMWrapper::domWrapperType(info.Holder()) == V8ClassIndex::NODE); - v8::Handle<v8::Value> value = info.Holder()->GetRealNamedPropertyInPrototypeChain(name); - - if (!value.IsEmpty()) - return value; - - // Search local callback properties next to find IDL defined - // properties. - if (info.Holder()->HasRealNamedCallbackProperty(name)) - return notHandledByInterceptor(); - Collection* collection = V8DOMWrapper::convertDOMWrapperToNode<Collection>(info.Holder()); - String propertyName = toWebCoreString(name); - void* implementation = collection->namedItem(propertyName); - return getV8Object(implementation, info.Data()); - } - // Returns the property at the index of a collection. template<class Collection, class ItemType> static v8::Handle<v8::Value> getIndexedPropertyOfCollection(uint32_t index, v8::Local<v8::Object> object, v8::Local<v8::Value> implementationType) { // FIXME: Assert that object must be a collection type. ASSERT(V8DOMWrapper::maybeDOMWrapper(object)); - V8ClassIndex::V8WrapperType wrapperType = V8DOMWrapper::domWrapperType(object); - ASSERT(wrapperType != V8ClassIndex::NODE); - Collection* collection = V8DOMWrapper::convertToNativeObject<Collection>(wrapperType, object); + ASSERT(V8DOMWrapper::domWrapperType(object) != V8ClassIndex::NODE); + Collection* collection = toNativeCollection<Collection>(object); return getV8Object<ItemType>(collection->item(index), implementationType); } @@ -122,22 +105,12 @@ namespace WebCore { return getIndexedPropertyOfCollection<Collection, ItemType>(index, info.Holder(), info.Data()); } - // A template of index interceptor of HTMLSelectElement and HTMLFormElement. - template<class Collection> static v8::Handle<v8::Value> nodeCollectionIndexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info) - { - ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder())); - ASSERT(V8DOMWrapper::domWrapperType(info.Holder()) == V8ClassIndex::NODE); - Collection* collection = V8DOMWrapper::convertDOMWrapperToNode<Collection>(info.Holder()); - void* implementation = collection->item(index); - return getV8Object(implementation, info.Data()); - } - // Get an array containing the names of indexed properties of HTMLSelectElement and HTMLFormElement. template<class Collection> static v8::Handle<v8::Array> nodeCollectionIndexedPropertyEnumerator(const v8::AccessorInfo& info) { ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder())); ASSERT(V8DOMWrapper::domWrapperType(info.Holder()) == V8ClassIndex::NODE); - Collection* collection = V8DOMWrapper::convertDOMWrapperToNode<Collection>(info.Holder()); + Collection* collection = toNativeCollection<Collection>(info.Holder()); int length = collection->length(); v8::Handle<v8::Array> properties = v8::Array::New(length); for (int i = 0; i < length; ++i) { @@ -152,8 +125,7 @@ namespace WebCore { template<class Collection> static v8::Handle<v8::Array> collectionIndexedPropertyEnumerator(const v8::AccessorInfo& info) { ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder())); - V8ClassIndex::V8WrapperType wrapperType = V8DOMWrapper::domWrapperType(info.Holder()); - Collection* collection = V8DOMWrapper::convertToNativeObject<Collection>(wrapperType, info.Holder()); + Collection* collection = toNativeCollection<Collection>(info.Holder()); int length = collection->length(); v8::Handle<v8::Array> properties = v8::Array::New(length); for (int i = 0; i < length; ++i) { @@ -170,8 +142,7 @@ namespace WebCore { { // FIXME: assert that object must be a collection type ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder())); - V8ClassIndex::V8WrapperType wrapperType = V8DOMWrapper::domWrapperType(info.Holder()); - Collection* collection = V8DOMWrapper::convertToNativeObject<Collection>(wrapperType, info.Holder()); + Collection* collection = toNativeCollection<Collection>(info.Holder()); String result = collection->item(index); return v8StringOrNull(result); } @@ -182,8 +153,7 @@ namespace WebCore { { // FIXME: assert that object must be a collection type ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder())); - V8ClassIndex::V8WrapperType wrapperType = V8DOMWrapper::domWrapperType(info.Holder()); - Collection* collection = V8DOMWrapper::convertToNativeObject<Collection>(wrapperType, info.Holder()); + Collection* collection = toNativeCollection<Collection>(info.Holder()); String result = collection->item(index); return v8String(result); } @@ -203,17 +173,6 @@ namespace WebCore { desc->InstanceTemplate()->SetNamedPropertyHandler(collectionNamedPropertyGetter<Collection, ItemType>, 0, 0, 0, 0, v8::Integer::New(V8ClassIndex::ToInt(type))); } - - // Add named and indexed getters to the function template for a collection. - template<class Collection, class ItemType> static void setCollectionIndexedAndNamedGetters(v8::Handle<v8::FunctionTemplate> desc, V8ClassIndex::V8WrapperType type) - { - // If we interceptor before object, accessing 'length' can trigger a webkit assertion error (see fast/dom/HTMLDocument/document-special-properties.html). - desc->InstanceTemplate()->SetNamedPropertyHandler(collectionNamedPropertyGetter<Collection, ItemType>, 0, 0, 0, 0, v8::Integer::New(V8ClassIndex::ToInt(type))); - desc->InstanceTemplate()->SetIndexedPropertyHandler(collectionIndexedPropertyGetter<Collection, ItemType>, 0, 0, 0, collectionIndexedPropertyEnumerator<Collection>, - v8::Integer::New(V8ClassIndex::ToInt(type))); - } - - // Add indexed getter returning a string or null to a function template for a collection. template<class Collection> static void setCollectionStringOrNullIndexedGetter(v8::Handle<v8::FunctionTemplate> desc) { diff --git a/WebCore/bindings/v8/V8DOMMap.cpp b/WebCore/bindings/v8/V8DOMMap.cpp index acd88ec..fa2fba3 100644 --- a/WebCore/bindings/v8/V8DOMMap.cpp +++ b/WebCore/bindings/v8/V8DOMMap.cpp @@ -65,7 +65,7 @@ void enableFasterDOMStoreAccess() fasterDOMStoreAccess = true; } -DOMWrapperMap<Node>& getDOMNodeMap() +DOMNodeMapping& getDOMNodeMap() { return getDOMDataStore().domNodeMap(); } @@ -145,9 +145,7 @@ void visitDOMNodesInCurrentThread(DOMWrapperMap<Node>::Visitor* visitor) if (!store->domData()->owningThread() == WTF::currentThread()) continue; - HashMap<Node*, v8::Object*>& map = store->domNodeMap().impl(); - for (HashMap<Node*, v8::Object*>::iterator it = map.begin(); it != map.end(); ++it) - visitor->visitDOMWrapper(it->first, v8::Persistent<v8::Object>(it->second)); + store->domNodeMap().visit(visitor); } } @@ -162,9 +160,7 @@ void visitDOMObjectsInCurrentThread(DOMWrapperMap<void>::Visitor* visitor) if (!store->domData()->owningThread() == WTF::currentThread()) continue; - HashMap<void*, v8::Object*> & map = store->domObjectMap().impl(); - for (HashMap<void*, v8::Object*>::iterator it = map.begin(); it != map.end(); ++it) - visitor->visitDOMWrapper(it->first, v8::Persistent<v8::Object>(it->second)); + store->domObjectMap().visit(visitor); } } @@ -179,9 +175,7 @@ void visitActiveDOMObjectsInCurrentThread(DOMWrapperMap<void>::Visitor* visitor) if (!store->domData()->owningThread() == WTF::currentThread()) continue; - HashMap<void*, v8::Object*>& map = store->activeDomObjectMap().impl(); - for (HashMap<void*, v8::Object*>::iterator it = map.begin(); it != map.end(); ++it) - visitor->visitDOMWrapper(it->first, v8::Persistent<v8::Object>(it->second)); + store->activeDomObjectMap().visit(visitor); } } @@ -198,9 +192,7 @@ void visitDOMSVGElementInstancesInCurrentThread(DOMWrapperMap<SVGElementInstance if (!store->domData()->owningThread() == WTF::currentThread()) continue; - HashMap<SVGElementInstance*, v8::Object*> & map = store->domSvgElementInstanceMap().impl(); - for (HashMap<SVGElementInstance*, v8::Object*>::iterator it = map.begin(); it != map.end(); ++it) - visitor->visitDOMWrapper(it->first, v8::Persistent<v8::Object>(it->second)); + store->domSvgElementInstanceMap().visit(visitor); } } @@ -215,9 +207,7 @@ void visitSVGObjectsInCurrentThread(DOMWrapperMap<void>::Visitor* visitor) if (!store->domData()->owningThread() == WTF::currentThread()) continue; - HashMap<void*, v8::Object*>& map = store->domSvgObjectWithContextMap().impl(); - for (HashMap<void*, v8::Object*>::iterator it = map.begin(); it != map.end(); ++it) - visitor->visitDOMWrapper(it->first, v8::Persistent<v8::Object>(it->second)); + store->domSvgObjectWithContextMap().visit(visitor); } } diff --git a/WebCore/bindings/v8/V8DOMMap.h b/WebCore/bindings/v8/V8DOMMap.h index b6861d4..8f93127 100644 --- a/WebCore/bindings/v8/V8DOMMap.h +++ b/WebCore/bindings/v8/V8DOMMap.h @@ -41,12 +41,36 @@ namespace WebCore { class SVGElementInstance; #endif + template <class KeyType, class ValueType> class AbstractWeakReferenceMap { + public: + AbstractWeakReferenceMap(v8::WeakReferenceCallback callback) : m_weakReferenceCallback(callback) { } + + class Visitor { + public: + virtual void visitDOMWrapper(KeyType* key, v8::Persistent<ValueType> object) = 0; + }; + + virtual v8::Persistent<ValueType> get(KeyType* obj) = 0; + virtual void set(KeyType* obj, v8::Persistent<ValueType> wrapper) = 0; + virtual bool contains(KeyType* obj) = 0; + virtual void visit(Visitor* visitor) = 0; + virtual bool removeIfPresent(KeyType* key, v8::Persistent<v8::Data> value) = 0; + virtual void clear() = 0; + + v8::WeakReferenceCallback weakReferenceCallback() { return m_weakReferenceCallback; } + private: + v8::WeakReferenceCallback m_weakReferenceCallback; + }; + + typedef AbstractWeakReferenceMap<Node, v8::Object> DOMNodeMapping; + // A table of wrappers with weak pointers. // This table allows us to avoid track wrapped objects for debugging // and for ensuring that we don't double wrap the same object. - template<class KeyType, class ValueType> class WeakReferenceMap { + template<class KeyType, class ValueType> class WeakReferenceMap : public AbstractWeakReferenceMap<KeyType, ValueType> { public: - WeakReferenceMap(v8::WeakReferenceCallback callback) : m_weakReferenceCallback(callback) { } + typedef AbstractWeakReferenceMap<KeyType, ValueType> Parent; + WeakReferenceMap(v8::WeakReferenceCallback callback) : Parent(callback) { } virtual ~WeakReferenceMap() { #ifndef NDEBUG @@ -65,7 +89,7 @@ namespace WebCore { virtual void set(KeyType* obj, v8::Persistent<ValueType> wrapper) { ASSERT(!m_map.contains(obj)); - wrapper.MakeWeak(obj, m_weakReferenceCallback); + wrapper.MakeWeak(obj, Parent::weakReferenceCallback()); m_map.set(obj, *wrapper); } @@ -81,9 +105,30 @@ namespace WebCore { handle.Clear(); } + bool removeIfPresent(KeyType* key, v8::Persistent<v8::Data> value) + { + typename HashMap<KeyType*, ValueType*>::iterator it = m_map.find(key); + if (it == m_map.end() || it->second != *value) + return false; + + m_map.remove(it); + value.Dispose(); + return true; + } + + void clear() + { + m_map.clear(); + } + bool contains(KeyType* obj) { return m_map.contains(obj); } - HashMap<KeyType*, ValueType*>& impl() { return m_map; } + virtual void visit(typename Parent::Visitor* visitor) + { + typename HashMap<KeyType*, ValueType*>::iterator it = m_map.begin(); + for (; it != m_map.end(); ++it) + visitor->visitDOMWrapper(it->first, v8::Persistent<ValueType>(it->second)); + } protected: HashMap<KeyType*, ValueType*> m_map; @@ -93,12 +138,15 @@ namespace WebCore { template <class KeyType> class DOMWrapperMap : public WeakReferenceMap<KeyType, v8::Object> { public: DOMWrapperMap(v8::WeakReferenceCallback callback) : WeakReferenceMap<KeyType, v8::Object>(callback) { } +<<<<<<< HEAD class Visitor { public: virtual void visitDOMWrapper(KeyType* key, v8::Persistent<v8::Object> object) = 0; virtual ~Visitor() { } }; +======= +>>>>>>> webkit.org at r54127 }; // An opaque class that represents a set of DOM wrappers. @@ -117,7 +165,7 @@ namespace WebCore { }; // A map from DOM node to its JS wrapper. - DOMWrapperMap<Node>& getDOMNodeMap(); + DOMNodeMapping& getDOMNodeMap(); void visitDOMNodesInCurrentThread(DOMWrapperMap<Node>::Visitor*); // A map from a DOM object (non-node) to its JS wrapper. This map does not contain the DOM objects which can have pending activity (active dom objects). diff --git a/WebCore/bindings/v8/V8DOMWindowShell.cpp b/WebCore/bindings/v8/V8DOMWindowShell.cpp new file mode 100644 index 0000000..793547d --- /dev/null +++ b/WebCore/bindings/v8/V8DOMWindowShell.cpp @@ -0,0 +1,559 @@ +/* + * Copyright (C) 2008, 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "V8DOMWindowShell.h" + +#include "CString.h" +#include "PlatformBridge.h" +#include "CSSMutableStyleDeclaration.h" +#include "DateExtension.h" +#include "DocumentLoader.h" +#include "DOMObjectsInclude.h" +#include "Frame.h" +#include "FrameLoaderClient.h" +#include "InspectorTimelineAgent.h" +#include "Page.h" +#include "PageGroup.h" +#include "ScriptController.h" +#include "StorageNamespace.h" +#include "V8Binding.h" +#include "V8BindingState.h" +#include "V8Collection.h" +#include "V8ConsoleMessage.h" +#include "V8CustomBinding.h" +#include "V8DOMMap.h" +#include "V8DOMWindow.h" +#include "V8HiddenPropertyName.h" +#include "V8History.h" +#include "V8Index.h" +#include "V8Location.h" +#include "V8Proxy.h" +#include "WorkerContextExecutionProxy.h" + +#include <algorithm> +#include <stdio.h> +#include <utility> +#include <v8-debug.h> +#include <v8.h> +#include <wtf/Assertions.h> +#include <wtf/OwnArrayPtr.h> +#include <wtf/StdLibExtras.h> +#include <wtf/StringExtras.h> +#include <wtf/UnusedParam.h> + +namespace WebCore { + +static void handleFatalErrorInV8() +{ + // FIXME: We temporarily deal with V8 internal error situations + // such as out-of-memory by crashing the renderer. + CRASH(); +} + +static void reportFatalErrorInV8(const char* location, const char* message) +{ + // V8 is shutdown, we cannot use V8 api. + // The only thing we can do is to disable JavaScript. + // FIXME: clean up V8Proxy and disable JavaScript. + printf("V8 error: %s (%s)\n", message, location); + handleFatalErrorInV8(); +} + +// Returns the owner frame pointer of a DOM wrapper object. It only works for +// these DOM objects requiring cross-domain access check. +static Frame* getTargetFrame(v8::Local<v8::Object> host, v8::Local<v8::Value> data) +{ + Frame* target = 0; + switch (V8ClassIndex::FromInt(data->Int32Value())) { + case V8ClassIndex::DOMWINDOW: { + v8::Handle<v8::Object> window = V8DOMWrapper::lookupDOMWrapper(V8ClassIndex::DOMWINDOW, host); + if (window.IsEmpty()) + return target; + + DOMWindow* targetWindow = V8DOMWindow::toNative(window); + target = targetWindow->frame(); + break; + } + case V8ClassIndex::LOCATION: { + History* history = V8History::toNative(host); + target = history->frame(); + break; + } + case V8ClassIndex::HISTORY: { + Location* location = V8Location::toNative(host); + target = location->frame(); + break; + } + default: + break; + } + return target; +} + +static void reportUnsafeJavaScriptAccess(v8::Local<v8::Object> host, v8::AccessType type, v8::Local<v8::Value> data) +{ + Frame* target = getTargetFrame(host, data); + if (target) + V8Proxy::reportUnsafeAccessTo(target, V8Proxy::ReportLater); +} + +PassRefPtr<V8DOMWindowShell> V8DOMWindowShell::create(Frame* frame) +{ + return adoptRef(new V8DOMWindowShell(frame)); +} + +V8DOMWindowShell::V8DOMWindowShell(Frame* frame) + : m_frame(frame) +{ +} + +bool V8DOMWindowShell::isContextInitialized() +{ + // m_context, m_global, and m_wrapperBoilerplates should + // all be non-empty if if m_context is non-empty. + ASSERT(m_context.IsEmpty() || !m_global.IsEmpty()); + ASSERT(m_context.IsEmpty() || !m_wrapperBoilerplates.IsEmpty()); + return !m_context.IsEmpty(); +} + +void V8DOMWindowShell::disposeContextHandles() +{ + if (!m_context.IsEmpty()) { + m_frame->loader()->client()->didDestroyScriptContextForFrame(); + m_context.Dispose(); + m_context.Clear(); + } + + if (!m_wrapperBoilerplates.IsEmpty()) { +#ifndef NDEBUG + V8GCController::unregisterGlobalHandle(this, m_wrapperBoilerplates); +#endif + m_wrapperBoilerplates.Dispose(); + m_wrapperBoilerplates.Clear(); + } +} + +void V8DOMWindowShell::destroyGlobal() +{ + if (!m_global.IsEmpty()) { +#ifndef NDEBUG + V8GCController::unregisterGlobalHandle(this, m_global); +#endif + m_global.Dispose(); + m_global.Clear(); + } +} + +void V8DOMWindowShell::clearForClose() +{ + if (!m_context.IsEmpty()) { + v8::HandleScope handleScope; + + clearDocumentWrapper(); + disposeContextHandles(); + } +} + +void V8DOMWindowShell::clearForNavigation() +{ + if (!m_context.IsEmpty()) { + v8::HandleScope handle; + clearDocumentWrapper(); + + v8::Context::Scope contextScope(m_context); + + // Clear the document wrapper cache before turning on access checks on + // the old DOMWindow wrapper. This way, access to the document wrapper + // will be protected by the security checks on the DOMWindow wrapper. + clearDocumentWrapperCache(); + + // Turn on access check on the old DOMWindow wrapper. + v8::Handle<v8::Object> wrapper = V8DOMWrapper::lookupDOMWrapper(V8ClassIndex::DOMWINDOW, m_global); + ASSERT(!wrapper.IsEmpty()); + wrapper->TurnOnAccessCheck(); + + // Separate the context from its global object. + m_context->DetachGlobal(); + + disposeContextHandles(); + } +} + +// Create a new environment and setup the global object. +// +// The global object corresponds to a DOMWindow instance. However, to +// allow properties of the JS DOMWindow instance to be shadowed, we +// use a shadow object as the global object and use the JS DOMWindow +// instance as the prototype for that shadow object. The JS DOMWindow +// instance is undetectable from javascript code because the __proto__ +// accessors skip that object. +// +// The shadow object and the DOMWindow instance are seen as one object +// from javascript. The javascript object that corresponds to a +// DOMWindow instance is the shadow object. When mapping a DOMWindow +// instance to a V8 object, we return the shadow object. +// +// To implement split-window, see +// 1) https://bugs.webkit.org/show_bug.cgi?id=17249 +// 2) https://wiki.mozilla.org/Gecko:SplitWindow +// 3) https://bugzilla.mozilla.org/show_bug.cgi?id=296639 +// we need to split the shadow object further into two objects: +// an outer window and an inner window. The inner window is the hidden +// prototype of the outer window. The inner window is the default +// global object of the context. A variable declared in the global +// scope is a property of the inner window. +// +// The outer window sticks to a Frame, it is exposed to JavaScript +// via window.window, window.self, window.parent, etc. The outer window +// has a security token which is the domain. The outer window cannot +// have its own properties. window.foo = 'x' is delegated to the +// inner window. +// +// When a frame navigates to a new page, the inner window is cut off +// the outer window, and the outer window identify is preserved for +// the frame. However, a new inner window is created for the new page. +// If there are JS code holds a closure to the old inner window, +// it won't be able to reach the outer window via its global object. +void V8DOMWindowShell::initContextIfNeeded() +{ + // Bail out if the context has already been initialized. + if (!m_context.IsEmpty()) + return; + + // Create a handle scope for all local handles. + v8::HandleScope handleScope; + + // Setup the security handlers and message listener. This only has + // to be done once. + static bool isV8Initialized = false; + if (!isV8Initialized) { + // Tells V8 not to call the default OOM handler, binding code + // will handle it. + v8::V8::IgnoreOutOfMemoryException(); + v8::V8::SetFatalErrorHandler(reportFatalErrorInV8); + + v8::V8::SetGlobalGCPrologueCallback(&V8GCController::gcPrologue); + v8::V8::SetGlobalGCEpilogueCallback(&V8GCController::gcEpilogue); + + v8::V8::AddMessageListener(&V8ConsoleMessage::handler); + + v8::V8::SetFailedAccessCheckCallbackFunction(reportUnsafeJavaScriptAccess); + + isV8Initialized = true; + } + + + m_context = createNewContext(m_global, 0); + if (m_context.IsEmpty()) + return; + + v8::Local<v8::Context> v8Context = v8::Local<v8::Context>::New(m_context); + v8::Context::Scope contextScope(v8Context); + + // Store the first global object created so we can reuse it. + if (m_global.IsEmpty()) { + m_global = v8::Persistent<v8::Object>::New(v8Context->Global()); + // Bail out if allocation of the first global objects fails. + if (m_global.IsEmpty()) { + disposeContextHandles(); + return; + } +#ifndef NDEBUG + V8GCController::registerGlobalHandle(PROXY, this, m_global); +#endif + } + + installHiddenObjectPrototype(v8Context); + m_wrapperBoilerplates = v8::Persistent<v8::Array>::New(v8::Array::New(V8ClassIndex::WRAPPER_TYPE_COUNT)); + // Bail out if allocation failed. + if (m_wrapperBoilerplates.IsEmpty()) { + disposeContextHandles(); + return; + } +#ifndef NDEBUG + V8GCController::registerGlobalHandle(PROXY, this, m_wrapperBoilerplates); +#endif + + if (!installDOMWindow(v8Context, m_frame->domWindow())) + disposeContextHandles(); + + updateDocument(); + + setSecurityToken(); + + m_frame->loader()->client()->didCreateScriptContextForFrame(); + + // FIXME: This is wrong. We should actually do this for the proper world once + // we do isolated worlds the WebCore way. + m_frame->loader()->dispatchDidClearWindowObjectInWorld(0); +} + +v8::Persistent<v8::Context> V8DOMWindowShell::createNewContext(v8::Handle<v8::Object> global, int extensionGroup) +{ + v8::Persistent<v8::Context> result; + + // The activeDocumentLoader pointer could be 0 during frame shutdown. + if (!m_frame->loader()->activeDocumentLoader()) + return result; + + // Create a new environment using an empty template for the shadow + // object. Reuse the global object if one has been created earlier. + v8::Persistent<v8::ObjectTemplate> globalTemplate = V8DOMWindow::GetShadowObjectTemplate(); + if (globalTemplate.IsEmpty()) + return result; + + // Used to avoid sleep calls in unload handlers. + if (!V8Proxy::registeredExtensionWithV8(DateExtension::get())) + V8Proxy::registerExtension(DateExtension::get(), String()); + + // Dynamically tell v8 about our extensions now. + const V8Extensions& extensions = V8Proxy::extensions(); + OwnArrayPtr<const char*> extensionNames(new const char*[extensions.size()]); + int index = 0; + for (size_t i = 0; i < extensions.size(); ++i) { + if (extensions[i].group && extensions[i].group != extensionGroup) + continue; + + // Note: we check the loader URL here instead of the document URL + // because we might be currently loading an URL into a blank page. + // See http://code.google.com/p/chromium/issues/detail?id=10924 + if (extensions[i].scheme.length() > 0 && (extensions[i].scheme != m_frame->loader()->activeDocumentLoader()->url().protocol() || extensions[i].scheme != m_frame->page()->mainFrame()->loader()->activeDocumentLoader()->url().protocol())) + continue; + + extensionNames[index++] = extensions[i].extension->name(); + } + v8::ExtensionConfiguration extensionConfiguration(index, extensionNames.get()); + result = v8::Context::New(&extensionConfiguration, globalTemplate, global); + + return result; +} + +bool V8DOMWindowShell::installDOMWindow(v8::Handle<v8::Context> context, DOMWindow* window) +{ + v8::Handle<v8::String> implicitProtoString = v8::String::New("__proto__"); + if (implicitProtoString.IsEmpty()) + return false; + + // Create a new JS window object and use it as the prototype for the shadow global object. + v8::Handle<v8::Function> windowConstructor = V8DOMWrapper::getConstructor(V8ClassIndex::DOMWINDOW, getHiddenObjectPrototype(context)); + v8::Local<v8::Object> jsWindow = SafeAllocation::newInstance(windowConstructor); + // Bail out if allocation failed. + if (jsWindow.IsEmpty()) + return false; + + // Wrap the window. + V8DOMWrapper::setDOMWrapper(jsWindow, V8ClassIndex::ToInt(V8ClassIndex::DOMWINDOW), window); + V8DOMWrapper::setDOMWrapper(v8::Handle<v8::Object>::Cast(jsWindow->GetPrototype()), V8ClassIndex::ToInt(V8ClassIndex::DOMWINDOW), window); + + window->ref(); + V8DOMWrapper::setJSWrapperForDOMObject(window, v8::Persistent<v8::Object>::New(jsWindow)); + + // Insert the window instance as the prototype of the shadow object. + v8::Handle<v8::Object> v8Global = context->Global(); + V8DOMWrapper::setDOMWrapper(v8::Handle<v8::Object>::Cast(v8Global->GetPrototype()), V8ClassIndex::ToInt(V8ClassIndex::DOMWINDOW), window); + v8Global->Set(implicitProtoString, jsWindow); + return true; +} + +void V8DOMWindowShell::updateDocumentWrapper(v8::Handle<v8::Value> wrapper) +{ + clearDocumentWrapper(); + + ASSERT(m_document.IsEmpty()); + m_document = v8::Persistent<v8::Value>::New(wrapper); +#ifndef NDEBUG + V8GCController::registerGlobalHandle(PROXY, this, m_document); +#endif +} + +void V8DOMWindowShell::clearDocumentWrapper() +{ + if (!m_document.IsEmpty()) { +#ifndef NDEBUG + V8GCController::unregisterGlobalHandle(this, m_document); +#endif + m_document.Dispose(); + m_document.Clear(); + } +} + +void V8DOMWindowShell::updateDocumentWrapperCache() +{ + v8::HandleScope handleScope; + v8::Context::Scope contextScope(m_context); + + // If the document has no frame, NodeToV8Object might get the + // document wrapper for a document that is about to be deleted. + // If the ForceSet below causes a garbage collection, the document + // might get deleted and the global handle for the document + // wrapper cleared. Using the cleared global handle will lead to + // crashes. In this case we clear the cache and let the DOMWindow + // accessor handle access to the document. + if (!m_frame->document()->frame()) { + clearDocumentWrapperCache(); + return; + } + + v8::Handle<v8::Value> documentWrapper = V8DOMWrapper::convertNodeToV8Object(m_frame->document()); + + // If instantiation of the document wrapper fails, clear the cache + // and let the DOMWindow accessor handle access to the document. + if (documentWrapper.IsEmpty()) { + clearDocumentWrapperCache(); + return; + } + m_context->Global()->ForceSet(v8::String::New("document"), documentWrapper, static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); +} + +void V8DOMWindowShell::clearDocumentWrapperCache() +{ + ASSERT(!m_context.IsEmpty()); + m_context->Global()->ForceDelete(v8::String::New("document")); +} + +void V8DOMWindowShell::setSecurityToken() +{ + Document* document = m_frame->document(); + // Setup security origin and security token. + if (!document) { + m_context->UseDefaultSecurityToken(); + return; + } + + // Ask the document's SecurityOrigin to generate a security token. + // If two tokens are equal, then the SecurityOrigins canAccess each other. + // If two tokens are not equal, then we have to call canAccess. + // Note: we can't use the HTTPOrigin if it was set from the DOM. + SecurityOrigin* origin = document->securityOrigin(); + String token; + if (!origin->domainWasSetInDOM()) + token = document->securityOrigin()->toString(); + + // An empty or "null" token means we always have to call + // canAccess. The toString method on securityOrigins returns the + // string "null" for empty security origins and for security + // origins that should only allow access to themselves. In this + // case, we use the global object as the security token to avoid + // calling canAccess when a script accesses its own objects. + if (token.isEmpty() || token == "null") { + m_context->UseDefaultSecurityToken(); + return; + } + + CString utf8Token = token.utf8(); + // NOTE: V8 does identity comparison in fast path, must use a symbol + // as the security token. + m_context->SetSecurityToken(v8::String::NewSymbol(utf8Token.data(), utf8Token.length())); +} + +void V8DOMWindowShell::updateDocument() +{ + if (!m_frame->document()) + return; + + if (m_global.IsEmpty()) + return; + + // There is an existing JavaScript wrapper for the global object + // of this frame. JavaScript code in other frames might hold a + // reference to this wrapper. We eagerly initialize the JavaScript + // context for the new document to make property access on the + // global object wrapper succeed. + initContextIfNeeded(); + + // Bail out if context initialization failed. + if (m_context.IsEmpty()) + return; + + // We have a new document and we need to update the cache. + updateDocumentWrapperCache(); + + updateSecurityOrigin(); +} + +void V8DOMWindowShell::updateSecurityOrigin() +{ + v8::HandleScope scope; + setSecurityToken(); +} + +v8::Handle<v8::Value> V8DOMWindowShell::getHiddenObjectPrototype(v8::Handle<v8::Context> context) +{ + return context->Global()->GetHiddenValue(V8HiddenPropertyName::objectPrototype()); +} + +void V8DOMWindowShell::installHiddenObjectPrototype(v8::Handle<v8::Context> context) +{ + v8::Handle<v8::String> objectString = v8::String::New("Object"); + v8::Handle<v8::String> prototypeString = v8::String::New("prototype"); + v8::Handle<v8::String> hiddenObjectPrototypeString = V8HiddenPropertyName::objectPrototype(); + // Bail out if allocation failed. + if (objectString.IsEmpty() || prototypeString.IsEmpty() || hiddenObjectPrototypeString.IsEmpty()) + return; + + v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(context->Global()->Get(objectString)); + v8::Handle<v8::Value> objectPrototype = object->Get(prototypeString); + + context->Global()->SetHiddenValue(hiddenObjectPrototypeString, objectPrototype); +} + +v8::Local<v8::Object> V8DOMWindowShell::createWrapperFromCacheSlowCase(V8ClassIndex::V8WrapperType type) +{ + // Not in cache. + int classIndex = V8ClassIndex::ToInt(type); + initContextIfNeeded(); + v8::Context::Scope scope(m_context); + v8::Local<v8::Function> function = V8DOMWrapper::getConstructor(type, getHiddenObjectPrototype(m_context)); + v8::Local<v8::Object> instance = SafeAllocation::newInstance(function); + if (!instance.IsEmpty()) { + m_wrapperBoilerplates->Set(v8::Integer::New(classIndex), instance); + return instance->Clone(); + } + return notHandledByInterceptor(); +} + +void V8DOMWindowShell::setLocation(DOMWindow* window, const String& relativeURL) +{ + Frame* frame = window->frame(); + if (!frame) + return; + + KURL url = completeURL(relativeURL); + if (url.isNull()) + return; + + if (!shouldAllowNavigation(frame)) + return; + + navigateIfAllowed(frame, url, false, false); +} + +} // WebCore diff --git a/WebCore/bindings/v8/V8DOMWindowShell.h b/WebCore/bindings/v8/V8DOMWindowShell.h new file mode 100644 index 0000000..29dd517 --- /dev/null +++ b/WebCore/bindings/v8/V8DOMWindowShell.h @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef V8DOMWindowShell_h +#define V8DOMWindowShell_h + +#include "V8CustomBinding.h" +#include "V8Index.h" +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> +#include <wtf/RefPtr.h> + +namespace WebCore { + +class DOMWindow; +class Frame; +class String; + +// V8WindowShell represents all the per-global object state for a Frame that +// persist between navigations. +class V8DOMWindowShell : public RefCounted<V8DOMWindowShell> { +public: + static PassRefPtr<V8DOMWindowShell> create(Frame*); + + v8::Handle<v8::Context> context() const { return m_context; } + + // Update document object of the frame. + void updateDocument(); + + // Update the security origin of a document + // (e.g., after setting docoument.domain). + void updateSecurityOrigin(); + + bool isContextInitialized(); + + v8::Persistent<v8::Context> createNewContext(v8::Handle<v8::Object> global, int extensionGroup); + static bool installDOMWindow(v8::Handle<v8::Context> context, DOMWindow*); + + void initContextIfNeeded(); + void updateDocumentWrapper(v8::Handle<v8::Value> wrapper); + + void clearForNavigation(); + void clearForClose(); + + void destroyGlobal(); + + static v8::Handle<v8::Value> getHiddenObjectPrototype(v8::Handle<v8::Context>); + // WARNING: Call |installHiddenObjectPrototype| only on fresh contexts! + static void installHiddenObjectPrototype(v8::Handle<v8::Context>); + + // To create JS Wrapper objects, we create a cache of a 'boiler plate' + // object, and then simply Clone that object each time we need a new one. + // This is faster than going through the full object creation process. + v8::Local<v8::Object> createWrapperFromCache(V8ClassIndex::V8WrapperType type) + { + int classIndex = V8ClassIndex::ToInt(type); + v8::Local<v8::Object> clone(m_wrapperBoilerplates->CloneElementAt(classIndex)); + return clone.IsEmpty() ? createWrapperFromCacheSlowCase(type) : clone; + } + + static void setLocation(DOMWindow*, const String& relativeURL); + +private: + V8DOMWindowShell(Frame*); + + void disposeContextHandles(); + + void setSecurityToken(); + void clearDocumentWrapper(); + + // The JavaScript wrapper for the document object is cached on the global + // object for fast access. UpdateDocumentWrapperCache sets the wrapper + // for the current document on the global object. ClearDocumentWrapperCache + // deletes the document wrapper from the global object. + void updateDocumentWrapperCache(); + void clearDocumentWrapperCache(); + + v8::Local<v8::Object> createWrapperFromCacheSlowCase(V8ClassIndex::V8WrapperType); + + Frame* m_frame; + + // For each possible type of wrapper, we keep a boilerplate object. + // The boilerplate is used to create additional wrappers of the same + // type. We keep a single persistent handle to an array of the + // activated boilerplates. + v8::Persistent<v8::Array> m_wrapperBoilerplates; + + v8::Persistent<v8::Context> m_context; + v8::Persistent<v8::Object> m_global; + v8::Persistent<v8::Value> m_document; +}; + +} // namespace WebCore + +#endif // V8DOMWindowShell_h diff --git a/WebCore/bindings/v8/V8DOMWrapper.cpp b/WebCore/bindings/v8/V8DOMWrapper.cpp index 28b316a..da50af6 100644 --- a/WebCore/bindings/v8/V8DOMWrapper.cpp +++ b/WebCore/bindings/v8/V8DOMWrapper.cpp @@ -32,11 +32,16 @@ #include "V8DOMWrapper.h" #include "CSSMutableStyleDeclaration.h" +<<<<<<< HEAD +======= +#include "DOMDataStore.h" +>>>>>>> webkit.org at r54127 #include "DOMObjectsInclude.h" #include "DocumentLoader.h" #include "FrameLoaderClient.h" #include "Notification.h" #include "SVGElementInstance.h" +#include "SVGPathSeg.h" #include "ScriptController.h" #include "V8AbstractEventListener.h" #include "V8Binding.h" @@ -46,10 +51,18 @@ #include "V8DOMMap.h" #include "V8DOMWindow.h" #include "V8EventListenerList.h" +#include "V8HTMLCollection.h" +#include "V8HTMLDocument.h" #include "V8Index.h" -#include "V8IsolatedWorld.h" +#include "V8IsolatedContext.h" +#include "V8MessageChannel.h" +#include "V8Location.h" +#include "V8NamedNodeMap.h" +#include "V8NodeList.h" #include "V8Proxy.h" +#include "V8StyleSheet.h" #include "WebGLArray.h" +#include "WebGLContextAttributes.h" #include "WebGLUniformLocation.h" #include "WorkerContextExecutionProxy.h" @@ -67,32 +80,36 @@ namespace WebCore { typedef HashMap<Node*, v8::Object*> DOMNodeMap; typedef HashMap<void*, v8::Object*> DOMObjectMap; -// Get the string 'toString'. -static v8::Persistent<v8::String> GetToStringName() -{ - DEFINE_STATIC_LOCAL(v8::Persistent<v8::String>, value, ()); - if (value.IsEmpty()) - value = v8::Persistent<v8::String>::New(v8::String::New("toString")); - return value; -} +#if ENABLE(SVG) -static v8::Handle<v8::Value> ConstructorToString(const v8::Arguments& args) +static V8ClassIndex::V8WrapperType downcastSVGPathSeg(void* pathSeg) { - // The DOM constructors' toString functions grab the current toString - // for Functions by taking the toString function of itself and then - // calling it with the constructor as its receiver. This means that - // changes to the Function prototype chain or toString function are - // reflected when printing DOM constructors. The only wart is that - // changes to a DOM constructor's toString's toString will cause the - // toString of the DOM constructor itself to change. This is extremely - // obscure and unlikely to be a problem. - v8::Handle<v8::Value> value = args.Callee()->Get(GetToStringName()); - if (!value->IsFunction()) - return v8::String::New(""); - return v8::Handle<v8::Function>::Cast(value)->Call(args.This(), 0, 0); + SVGPathSeg* realPathSeg = reinterpret_cast<SVGPathSeg*>(pathSeg); + + switch (realPathSeg->pathSegType()) { + case SVGPathSeg::PATHSEG_CLOSEPATH: return V8ClassIndex::SVGPATHSEGCLOSEPATH; + case SVGPathSeg::PATHSEG_MOVETO_ABS: return V8ClassIndex::SVGPATHSEGMOVETOABS; + case SVGPathSeg::PATHSEG_MOVETO_REL: return V8ClassIndex::SVGPATHSEGMOVETOREL; + case SVGPathSeg::PATHSEG_LINETO_ABS: return V8ClassIndex::SVGPATHSEGLINETOABS; + case SVGPathSeg::PATHSEG_LINETO_REL: return V8ClassIndex::SVGPATHSEGLINETOREL; + case SVGPathSeg::PATHSEG_CURVETO_CUBIC_ABS: return V8ClassIndex::SVGPATHSEGCURVETOCUBICABS; + case SVGPathSeg::PATHSEG_CURVETO_CUBIC_REL: return V8ClassIndex::SVGPATHSEGCURVETOCUBICREL; + case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_ABS: return V8ClassIndex::SVGPATHSEGCURVETOQUADRATICABS; + case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_REL: return V8ClassIndex::SVGPATHSEGCURVETOQUADRATICREL; + case SVGPathSeg::PATHSEG_ARC_ABS: return V8ClassIndex::SVGPATHSEGARCABS; + case SVGPathSeg::PATHSEG_ARC_REL: return V8ClassIndex::SVGPATHSEGARCREL; + case SVGPathSeg::PATHSEG_LINETO_HORIZONTAL_ABS: return V8ClassIndex::SVGPATHSEGLINETOHORIZONTALABS; + case SVGPathSeg::PATHSEG_LINETO_HORIZONTAL_REL: return V8ClassIndex::SVGPATHSEGLINETOHORIZONTALREL; + case SVGPathSeg::PATHSEG_LINETO_VERTICAL_ABS: return V8ClassIndex::SVGPATHSEGLINETOVERTICALABS; + case SVGPathSeg::PATHSEG_LINETO_VERTICAL_REL: return V8ClassIndex::SVGPATHSEGLINETOVERTICALREL; + case SVGPathSeg::PATHSEG_CURVETO_CUBIC_SMOOTH_ABS: return V8ClassIndex::SVGPATHSEGCURVETOCUBICSMOOTHABS; + case SVGPathSeg::PATHSEG_CURVETO_CUBIC_SMOOTH_REL: return V8ClassIndex::SVGPATHSEGCURVETOCUBICSMOOTHREL; + case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS: return V8ClassIndex::SVGPATHSEGCURVETOQUADRATICSMOOTHABS; + case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL: return V8ClassIndex::SVGPATHSEGCURVETOQUADRATICSMOOTHREL; + default: return V8ClassIndex::INVALID_CLASS_INDEX; + } } -#if ENABLE(SVG) v8::Handle<v8::Value> V8DOMWrapper::convertSVGElementInstanceToV8Object(SVGElementInstance* instance) { if (!instance) @@ -124,7 +141,7 @@ v8::Handle<v8::Value> V8DOMWrapper::convertSVGObjectWithContextToV8Object(V8Clas // Special case: SVGPathSegs need to be downcast to their real type if (type == V8ClassIndex::SVGPATHSEG) - type = V8Custom::DowncastSVGPathSeg(object); + type = downcastSVGPathSeg(object); v8::Local<v8::Object> v8Object = instantiateV8Object(type, type, object); if (!v8Object.IsEmpty()) { @@ -148,7 +165,7 @@ v8::Handle<v8::Value> V8DOMWrapper::convertSVGObjectWithContextToV8Object(V8Clas return result; } -#endif +#endif // ENABLE(SVG) #if ENABLE(3D_CANVAS) void V8DOMWrapper::setIndexedPropertiesToExternalArray(v8::Handle<v8::Object> wrapper, @@ -189,25 +206,6 @@ void V8DOMWrapper::setIndexedPropertiesToExternalArray(v8::Handle<v8::Object> wr } #endif -bool V8DOMWrapper::domObjectHasJSWrapper(void* object) -{ - return getDOMObjectMap().contains(object) || getActiveDOMObjectMap().contains(object); -} - -v8::Persistent<v8::Object> V8DOMWrapper::jsWrapperForDOMObject(void* object) -{ - v8::Persistent<v8::Object> wrapper = getDOMObjectMap().get(object); - ASSERT(!wrapper.IsEmpty()); - return wrapper; -} - -v8::Persistent<v8::Object> V8DOMWrapper::jsWrapperForActiveDOMObject(void* object) -{ - v8::Persistent<v8::Object> wrapper = getActiveDOMObjectMap().get(object); - ASSERT(!wrapper.IsEmpty()); - return wrapper; -} - // The caller must have increased obj's ref count. void V8DOMWrapper::setJSWrapperForDOMObject(void* object, v8::Persistent<v8::Object> wrapper) { @@ -259,6 +257,7 @@ v8::Persistent<v8::FunctionTemplate> V8DOMWrapper::getTemplate(V8ClassIndex::V8W // Not in the cache. FunctionTemplateFactory factory = V8ClassIndex::GetFactory(type); v8::Persistent<v8::FunctionTemplate> descriptor = factory(); +<<<<<<< HEAD // DOM constructors are functions and should print themselves as such. // However, we will later replace their prototypes with Object // prototypes so we need to explicitly override toString on the @@ -618,6 +617,8 @@ v8::Persistent<v8::FunctionTemplate> V8DOMWrapper::getTemplate(V8ClassIndex::V8W default: break; } +======= +>>>>>>> webkit.org at r54127 *cacheCell = descriptor; return descriptor; @@ -652,7 +653,7 @@ v8::Local<v8::Function> V8DOMWrapper::getConstructorForContext(V8ClassIndex::V8W // Enter the scope for this context to get the correct constructor. v8::Context::Scope scope(context); - return getConstructor(type, V8Proxy::getHiddenObjectPrototype(context)); + return getConstructor(type, V8DOMWindowShell::getHiddenObjectPrototype(context)); } v8::Local<v8::Function> V8DOMWrapper::getConstructor(V8ClassIndex::V8WrapperType type, DOMWindow* window) @@ -813,44 +814,44 @@ v8::Handle<v8::Value> V8DOMWrapper::convertToV8Object(V8ClassIndex::V8WrapperTyp // reused by a new page. switch (type) { case V8ClassIndex::CONSOLE: - setHiddenWindowReference(static_cast<Console*>(impl)->frame(), V8Custom::kDOMWindowConsoleIndex, result); + setHiddenWindowReference(static_cast<Console*>(impl)->frame(), V8DOMWindow::consoleIndex, result); break; case V8ClassIndex::HISTORY: - setHiddenWindowReference(static_cast<History*>(impl)->frame(), V8Custom::kDOMWindowHistoryIndex, result); + setHiddenWindowReference(static_cast<History*>(impl)->frame(), V8DOMWindow::historyIndex, result); break; case V8ClassIndex::NAVIGATOR: - setHiddenWindowReference(static_cast<Navigator*>(impl)->frame(), V8Custom::kDOMWindowNavigatorIndex, result); + setHiddenWindowReference(static_cast<Navigator*>(impl)->frame(), V8DOMWindow::navigatorIndex, result); break; case V8ClassIndex::SCREEN: - setHiddenWindowReference(static_cast<Screen*>(impl)->frame(), V8Custom::kDOMWindowScreenIndex, result); + setHiddenWindowReference(static_cast<Screen*>(impl)->frame(), V8DOMWindow::screenIndex, result); break; case V8ClassIndex::LOCATION: - setHiddenWindowReference(static_cast<Location*>(impl)->frame(), V8Custom::kDOMWindowLocationIndex, result); + setHiddenWindowReference(static_cast<Location*>(impl)->frame(), V8DOMWindow::locationIndex, result); break; case V8ClassIndex::DOMSELECTION: - setHiddenWindowReference(static_cast<DOMSelection*>(impl)->frame(), V8Custom::kDOMWindowDOMSelectionIndex, result); + setHiddenWindowReference(static_cast<DOMSelection*>(impl)->frame(), V8DOMWindow::domSelectionIndex, result); break; case V8ClassIndex::BARINFO: { BarInfo* barInfo = static_cast<BarInfo*>(impl); Frame* frame = barInfo->frame(); switch (barInfo->type()) { case BarInfo::Locationbar: - setHiddenWindowReference(frame, V8Custom::kDOMWindowLocationbarIndex, result); + setHiddenWindowReference(frame, V8DOMWindow::locationbarIndex, result); break; case BarInfo::Menubar: - setHiddenWindowReference(frame, V8Custom::kDOMWindowMenubarIndex, result); + setHiddenWindowReference(frame, V8DOMWindow::menubarIndex, result); break; case BarInfo::Personalbar: - setHiddenWindowReference(frame, V8Custom::kDOMWindowPersonalbarIndex, result); + setHiddenWindowReference(frame, V8DOMWindow::personalbarIndex, result); break; case BarInfo::Scrollbars: - setHiddenWindowReference(frame, V8Custom::kDOMWindowScrollbarsIndex, result); + setHiddenWindowReference(frame, V8DOMWindow::scrollbarsIndex, result); break; case BarInfo::Statusbar: - setHiddenWindowReference(frame, V8Custom::kDOMWindowStatusbarIndex, result); + setHiddenWindowReference(frame, V8DOMWindow::statusbarIndex, result); break; case BarInfo::Toolbar: - setHiddenWindowReference(frame, V8Custom::kDOMWindowToolbarIndex, result); + setHiddenWindowReference(frame, V8DOMWindow::toolbarIndex, result); break; } break; @@ -872,7 +873,7 @@ void V8DOMWrapper::setHiddenWindowReference(Frame* frame, const int internalInde if (context.IsEmpty()) return; - ASSERT(internalIndex < V8Custom::kDOMWindowInternalFieldCount); + ASSERT(internalIndex < V8DOMWindow::internalFieldCount); v8::Handle<v8::Object> global = context->Global(); // Look for real DOM wrapper. @@ -885,15 +886,10 @@ void V8DOMWrapper::setHiddenWindowReference(Frame* frame, const int internalInde V8ClassIndex::V8WrapperType V8DOMWrapper::domWrapperType(v8::Handle<v8::Object> object) { ASSERT(V8DOMWrapper::maybeDOMWrapper(object)); - v8::Handle<v8::Value> type = object->GetInternalField(V8Custom::kDOMWrapperTypeIndex); + v8::Handle<v8::Value> type = object->GetInternalField(v8DOMWrapperTypeIndex); return V8ClassIndex::FromInt(type->Int32Value()); } -void* V8DOMWrapper::convertToSVGPODTypeImpl(V8ClassIndex::V8WrapperType type, v8::Handle<v8::Value> object) -{ - return isWrapperOfType(object, type) ? convertDOMWrapperToNative<void>(v8::Handle<v8::Object>::Cast(object)) : 0; -} - PassRefPtr<NodeFilter> V8DOMWrapper::wrapNativeNodeFilter(v8::Handle<v8::Value> filter) { // A NodeFilter is used when walking through a DOM tree or iterating tree @@ -917,17 +913,19 @@ v8::Local<v8::Object> V8DOMWrapper::instantiateV8Object(V8Proxy* proxy, V8ClassI if (descriptorType == V8ClassIndex::HTMLCOLLECTION && static_cast<HTMLCollection*>(impl)->type() == DocAll) descriptorType = V8ClassIndex::HTMLALLCOLLECTION; - if (V8IsolatedWorld::getEntered()) { + if (V8IsolatedContext::getEntered()) { // This effectively disables the wrapper cache for isolated worlds. proxy = 0; // FIXME: Do we need a wrapper cache for the isolated world? We should - // see if the performance gains are worth while. + // see if the performance gains are worth while. + // We'll get one once we give the isolated context a proper window shell. } else if (!proxy) proxy = V8Proxy::retrieve(); v8::Local<v8::Object> instance; if (proxy) - instance = proxy->createWrapperFromCache(descriptorType); + // FIXME: Fix this to work properly with isolated worlds (see above). + instance = proxy->windowShell()->createWrapperFromCache(descriptorType); else { v8::Local<v8::Function> function = getTemplate(descriptorType)->GetFunction(); instance = SafeAllocation::newInstance(function); @@ -949,13 +947,13 @@ bool V8DOMWrapper::maybeDOMWrapper(v8::Handle<v8::Value> value) if (!object->InternalFieldCount()) return false; - ASSERT(object->InternalFieldCount() >= V8Custom::kDefaultWrapperInternalFieldCount); + ASSERT(object->InternalFieldCount() >= v8DefaultWrapperInternalFieldCount); - v8::Handle<v8::Value> type = object->GetInternalField(V8Custom::kDOMWrapperTypeIndex); + v8::Handle<v8::Value> type = object->GetInternalField(v8DOMWrapperTypeIndex); ASSERT(type->IsInt32()); ASSERT(V8ClassIndex::INVALID_CLASS_INDEX < type->Int32Value() && type->Int32Value() < V8ClassIndex::CLASSINDEX_END); - v8::Handle<v8::Value> wrapper = object->GetInternalField(V8Custom::kDOMWrapperObjectIndex); + v8::Handle<v8::Value> wrapper = object->GetInternalField(v8DOMWrapperObjectIndex); ASSERT(wrapper->IsNumber() || wrapper->IsExternal()); return true; @@ -978,12 +976,12 @@ bool V8DOMWrapper::isWrapperOfType(v8::Handle<v8::Value> value, V8ClassIndex::V8 if (!object->InternalFieldCount()) return false; - ASSERT(object->InternalFieldCount() >= V8Custom::kDefaultWrapperInternalFieldCount); + ASSERT(object->InternalFieldCount() >= v8DefaultWrapperInternalFieldCount); - v8::Handle<v8::Value> wrapper = object->GetInternalField(V8Custom::kDOMWrapperObjectIndex); + v8::Handle<v8::Value> wrapper = object->GetInternalField(v8DOMWrapperObjectIndex); ASSERT(wrapper->IsNumber() || wrapper->IsExternal()); - v8::Handle<v8::Value> type = object->GetInternalField(V8Custom::kDOMWrapperTypeIndex); + v8::Handle<v8::Value> type = object->GetInternalField(v8DOMWrapperTypeIndex); ASSERT(type->IsInt32()); ASSERT(V8ClassIndex::INVALID_CLASS_INDEX < type->Int32Value() && type->Int32Value() < V8ClassIndex::CLASSINDEX_END); @@ -1135,6 +1133,7 @@ V8ClassIndex::V8WrapperType V8DOMWrapper::htmlElementType(HTMLElement* element) macro(feImage, FEIMAGE) \ macro(feMerge, FEMERGE) \ macro(feMergeNode, FEMERGENODE) \ + macro(feMorphology, FEMORPHOLOGY) \ macro(feOffset, FEOFFSET) \ macro(fePointLight, FEPOINTLIGHT) \ macro(feSpecularLighting, FESPECULARLIGHTING) \ @@ -1274,6 +1273,8 @@ v8::Handle<v8::Value> V8DOMWrapper::convertEventToV8Object(Event* event) type = V8ClassIndex::MESSAGEEVENT; else if (event->isPageTransitionEvent()) type = V8ClassIndex::PAGETRANSITIONEVENT; + else if (event->isPopStateEvent()) + type = V8ClassIndex::POPSTATEEVENT; else if (event->isProgressEvent()) { if (event->isXMLHttpRequestProgressEvent()) type = V8ClassIndex::XMLHTTPREQUESTPROGRESSEVENT; @@ -1335,9 +1336,9 @@ v8::Handle<v8::Value> V8DOMWrapper::convertDocumentToV8Object(Document* document // checking if the node already has a wrapper. V8Proxy* proxy = V8Proxy::retrieve(document->frame()); if (proxy) - proxy->initContextIfNeeded(); + proxy->windowShell()->initContextIfNeeded(); - DOMWrapperMap<Node>& domNodeMap = getDOMNodeMap(); + DOMNodeMapping& domNodeMap = getDOMNodeMap(); v8::Handle<v8::Object> wrapper = domNodeMap.get(document); if (wrapper.IsEmpty()) return convertNewNodeToV8Object(document, proxy, domNodeMap); @@ -1345,25 +1346,39 @@ v8::Handle<v8::Value> V8DOMWrapper::convertDocumentToV8Object(Document* document return wrapper; } +static v8::Handle<v8::Value> getWrapper(Node* node) +{ + ASSERT(WTF::isMainThread()); + V8IsolatedContext* context = V8IsolatedContext::getEntered(); + if (LIKELY(!context)) { + v8::Persistent<v8::Object>* wrapper = node->wrapper(); + if (!wrapper) + return v8::Handle<v8::Value>(); + return *wrapper; + } + + DOMNodeMapping& domNodeMap = context->world()->domDataStore()->domNodeMap(); + return domNodeMap.get(node); +} + v8::Handle<v8::Value> V8DOMWrapper::convertNodeToV8Object(Node* node) { if (!node) return v8::Null(); + v8::Handle<v8::Value> wrapper = getWrapper(node); + if (!wrapper.IsEmpty()) + return wrapper; + Document* document = node->document(); if (node == document) return convertDocumentToV8Object(document); - - DOMWrapperMap<Node>& domNodeMap = getDOMNodeMap(); - v8::Handle<v8::Object> wrapper = domNodeMap.get(node); - if (wrapper.IsEmpty()) - return convertNewNodeToV8Object(node, 0, domNodeMap); - - return wrapper; + + return convertNewNodeToV8Object(node, 0, getDOMNodeMap()); } // Caller checks node is not null. -v8::Handle<v8::Value> V8DOMWrapper::convertNewNodeToV8Object(Node* node, V8Proxy* proxy, DOMWrapperMap<Node>& domNodeMap) +v8::Handle<v8::Value> V8DOMWrapper::convertNewNodeToV8Object(Node* node, V8Proxy* proxy, DOMNodeMapping& domNodeMap) { if (!proxy && node->document()) proxy = V8Proxy::retrieve(node->document()->frame()); @@ -1425,16 +1440,16 @@ v8::Handle<v8::Value> V8DOMWrapper::convertNewNodeToV8Object(Node* node, V8Proxy if (isDocument) { if (proxy) - proxy->updateDocumentWrapper(result); + proxy->windowShell()->updateDocumentWrapper(result); if (type == V8ClassIndex::HTMLDOCUMENT) { // Create marker object and insert it in two internal fields. // This is used to implement temporary shadowing of // document.all. - ASSERT(result->InternalFieldCount() == V8Custom::kHTMLDocumentInternalFieldCount); + ASSERT(result->InternalFieldCount() == V8HTMLDocument::internalFieldCount); v8::Local<v8::Object> marker = v8::Object::New(); - result->SetInternalField(V8Custom::kHTMLDocumentMarkerIndex, marker); - result->SetInternalField(V8Custom::kHTMLDocumentShadowIndex, marker); + result->SetInternalField(V8HTMLDocument::markerIndex, marker); + result->SetInternalField(V8HTMLDocument::shadowIndex, marker); } } @@ -1514,6 +1529,12 @@ v8::Handle<v8::Value> V8DOMWrapper::convertEventTargetToV8Object(EventTarget* ta return convertToV8Object(V8ClassIndex::DOMAPPLICATIONCACHE, domAppCache); #endif +#if ENABLE(EVENTSOURCE) + EventSource* eventSource = target->toEventSource(); + if (eventSource) + return convertToV8Object(V8ClassIndex::EVENTSOURCE, eventSource); +#endif + ASSERT(0); return notHandledByInterceptor(); } @@ -1578,6 +1599,22 @@ PassRefPtr<EventListener> V8DOMWrapper::getEventListener(XMLHttpRequestUpload* u return getEventListener(upload->associatedXMLHttpRequest(), value, isAttribute, lookup); } +#if ENABLE(EVENTSOURCE) +PassRefPtr<EventListener> V8DOMWrapper::getEventListener(EventSource* eventSource, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup) +{ + if (V8Proxy::retrieve(eventSource->scriptExecutionContext())) + return (lookup == ListenerFindOnly) ? V8EventListenerList::findWrapper(value, isAttribute) : V8EventListenerList::findOrCreateWrapper<V8EventListener>(value, isAttribute); + +#if ENABLE(WORKERS) + WorkerContextExecutionProxy* workerContextProxy = WorkerContextExecutionProxy::retrieve(); + if (workerContextProxy) + return workerContextProxy->findOrCreateEventListener(value, isAttribute, lookup == ListenerFindOnly); +#endif + + return 0; +} +#endif + PassRefPtr<EventListener> V8DOMWrapper::getEventListener(EventTarget* eventTarget, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup) { if (V8Proxy::retrieve(eventTarget->scriptExecutionContext())) @@ -1632,7 +1669,7 @@ v8::Handle<v8::Value> V8DOMWrapper::convertStyleSheetToV8Object(StyleSheet* shee Node* ownerNode = sheet->ownerNode(); if (ownerNode) { v8::Handle<v8::Object> owner = v8::Handle<v8::Object>::Cast(convertNodeToV8Object(ownerNode)); - result->SetInternalField(V8Custom::kStyleSheetOwnerNodeIndex, owner); + result->SetInternalField(V8StyleSheet::ownerNodeIndex, owner); } return result; @@ -1737,7 +1774,7 @@ v8::Handle<v8::Value> V8DOMWrapper::convertWindowToV8Object(DOMWindow* window) if (!frame) return v8::Handle<v8::Object>(); - // Special case: Because of evaluateInNewContext() one DOMWindow can have + // Special case: Because of evaluateInIsolatedWorld() one DOMWindow can have // multiple contexts and multiple global objects associated with it. When // code running in one of those contexts accesses the window object, we // want to return the global object associated with that context, not @@ -1746,7 +1783,7 @@ v8::Handle<v8::Value> V8DOMWrapper::convertWindowToV8Object(DOMWindow* window) v8::Handle<v8::Object> currentGlobal = currentContext->Global(); v8::Handle<v8::Object> windowWrapper = V8DOMWrapper::lookupDOMWrapper(V8ClassIndex::DOMWINDOW, currentGlobal); if (!windowWrapper.IsEmpty()) { - if (convertDOMWrapperToNative<DOMWindow>(windowWrapper) == window) + if (V8DOMWindow::toNative(windowWrapper) == window) return currentGlobal; } @@ -1780,7 +1817,7 @@ v8::Handle<v8::Value> V8DOMWrapper::convertNamedNodeMapToV8Object(NamedNodeMap* // Add a hidden reference from named node map to its owner node. if (Element* element = map->element()) { v8::Handle<v8::Object> owner = v8::Handle<v8::Object>::Cast(convertNodeToV8Object(element)); - result->SetInternalField(V8Custom::kNamedNodeMapOwnerNodeIndex, owner); + result->SetInternalField(V8NamedNodeMap::ownerNodeIndex, owner); } return result; diff --git a/WebCore/bindings/v8/V8DOMWrapper.h b/WebCore/bindings/v8/V8DOMWrapper.h index b00915e..3cff691 100644 --- a/WebCore/bindings/v8/V8DOMWrapper.h +++ b/WebCore/bindings/v8/V8DOMWrapper.h @@ -39,6 +39,7 @@ #include "V8CustomBinding.h" #include "V8CustomXPathNSResolver.h" #include "V8DOMMap.h" +#include "V8Event.h" #include "V8Index.h" #include "V8Utilities.h" #include "V8XPathNSResolver.h" @@ -91,6 +92,7 @@ namespace WebCore { class StyleSheetList; class V8EventListener; class V8ObjectEventListener; + class V8Proxy; #if ENABLE(WEB_SOCKETS) class WebSocket; #endif @@ -112,8 +114,8 @@ namespace WebCore { static void setDOMWrapper(v8::Handle<v8::Object> object, int type, void* cptr) { ASSERT(object->InternalFieldCount() >= 2); - object->SetPointerInInternalField(V8Custom::kDOMWrapperObjectIndex, cptr); - object->SetInternalField(V8Custom::kDOMWrapperTypeIndex, v8::Integer::New(type)); + object->SetPointerInInternalField(v8DOMWrapperObjectIndex, cptr); + object->SetInternalField(v8DOMWrapperTypeIndex, v8::Integer::New(type)); } static v8::Handle<v8::Object> lookupDOMWrapper(V8ClassIndex::V8WrapperType type, v8::Handle<v8::Object> object) @@ -121,23 +123,6 @@ namespace WebCore { return object.IsEmpty() ? object : object->FindInstanceInPrototypeChain(getTemplate(type)); } - // A helper function extract native object pointer from a DOM wrapper - // and cast to the specified type. - template <class C> - static C* convertDOMWrapperToNative(v8::Handle<v8::Object> object) - { - ASSERT(maybeDOMWrapper(object)); - return reinterpret_cast<C*>(object->GetPointerFromInternalField(V8Custom::kDOMWrapperObjectIndex)); - } - - template <class C> - static C* convertDOMWrapperToNode(v8::Handle<v8::Object> object) - { - ASSERT(maybeDOMWrapper(object)); - ASSERT(domWrapperType(object) == V8ClassIndex::NODE); - return convertDOMWrapperToNative<C>(object); - } - template<typename T> static v8::Handle<v8::Value> convertToV8Object(V8ClassIndex::V8WrapperType type, PassRefPtr<T> imp) { @@ -166,31 +151,7 @@ namespace WebCore { return convertNewNodeToV8Object(node, 0, getDOMNodeMap()); } - static v8::Handle<v8::Value> convertNewNodeToV8Object(Node*, V8Proxy*, DOMWrapperMap<Node>&); - - template <class C> - static C* convertToNativeObject(V8ClassIndex::V8WrapperType type, v8::Handle<v8::Object> object) - { - // Native event listener is per frame, it cannot be handled by this generic function. - ASSERT(type != V8ClassIndex::EVENTLISTENER); - ASSERT(type != V8ClassIndex::EVENTTARGET); - - ASSERT(maybeDOMWrapper(object)); - -#ifndef NDEBUG - const bool typeIsValid = -#define MAKE_CASE(TYPE, NAME) (type != V8ClassIndex::TYPE) && - DOM_NODE_TYPES(MAKE_CASE) -#if ENABLE(SVG) - SVG_NODE_TYPES(MAKE_CASE) -#endif -#undef MAKE_CASE - true; - ASSERT(typeIsValid); -#endif - - return convertDOMWrapperToNative<C>(object); - } + static v8::Handle<v8::Value> convertNewNodeToV8Object(Node*, V8Proxy*, DOMNodeMapping&); static V8ClassIndex::V8WrapperType domWrapperType(v8::Handle<v8::Object>); @@ -201,13 +162,6 @@ namespace WebCore { static v8::Handle<v8::Value> convertEventToV8Object(Event*); - static Event* convertToNativeEvent(v8::Handle<v8::Value> jsEvent) - { - if (!isDOMEventWrapper(jsEvent)) - return 0; - return convertDOMWrapperToNative<Event>(v8::Handle<v8::Object>::Cast(jsEvent)); - } - static v8::Handle<v8::Value> convertEventTargetToV8Object(PassRefPtr<EventTarget> eventTarget) { return convertEventTargetToV8Object(eventTarget.get()); @@ -237,6 +191,10 @@ namespace WebCore { static PassRefPtr<EventListener> getEventListener(XMLHttpRequestUpload* upload, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup); +#if ENABLE(EVENTSOURCE) + static PassRefPtr<EventListener> getEventListener(EventSource* eventTarget, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup); +#endif + static PassRefPtr<EventListener> getEventListener(EventTarget* eventTarget, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup); static PassRefPtr<EventListener> getEventListener(V8Proxy* proxy, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup); @@ -247,7 +205,7 @@ namespace WebCore { { RefPtr<XPathNSResolver> resolver; if (V8XPathNSResolver::HasInstance(value)) - resolver = convertToNativeObject<XPathNSResolver>(V8ClassIndex::XPATHNSRESOLVER, v8::Handle<v8::Object>::Cast(value)); + resolver = V8XPathNSResolver::toNative(v8::Handle<v8::Object>::Cast(value)); else if (value->IsObject()) resolver = V8CustomXPathNSResolver::create(proxy, value->ToObject()); return resolver; @@ -267,12 +225,6 @@ namespace WebCore { static v8::Local<v8::Function> getConstructor(V8ClassIndex::V8WrapperType, DOMWindow*); static v8::Local<v8::Function> getConstructor(V8ClassIndex::V8WrapperType, WorkerContext*); - // Checks whether a DOM object has a JS wrapper. - static bool domObjectHasJSWrapper(void*); - // Get JS wrapper of an existing DOM object, assuming that the wrapper - // exists. - static v8::Persistent<v8::Object> jsWrapperForDOMObject(void*); - static v8::Persistent<v8::Object> jsWrapperForActiveDOMObject(void*); // Set JS wrapper of a DOM object, the caller in charge of increase ref. static void setJSWrapperForDOMObject(void*, v8::Persistent<v8::Object>); static void setJSWrapperForActiveDOMObject(void*, v8::Persistent<v8::Object>); @@ -281,8 +233,6 @@ namespace WebCore { // Check whether a V8 value is a wrapper of type |classType|. static bool isWrapperOfType(v8::Handle<v8::Value>, V8ClassIndex::V8WrapperType); - static void* convertToSVGPODTypeImpl(V8ClassIndex::V8WrapperType, v8::Handle<v8::Value>); - // Check whether a V8 value is a DOM Event wrapper. static bool isDOMEventWrapper(v8::Handle<v8::Value>); diff --git a/WebCore/bindings/v8/V8HiddenPropertyName.h b/WebCore/bindings/v8/V8HiddenPropertyName.h index bb1ca4c..0bfadd9 100644 --- a/WebCore/bindings/v8/V8HiddenPropertyName.h +++ b/WebCore/bindings/v8/V8HiddenPropertyName.h @@ -39,6 +39,7 @@ namespace WebCore { V(objectPrototype) \ V(listener) \ V(attributeListener) \ + V(scriptState) \ V(sleepFunction) \ V(toStringString) diff --git a/WebCore/bindings/v8/V8Index.cpp b/WebCore/bindings/v8/V8Index.cpp index ea13d2f..b87e060 100644 --- a/WebCore/bindings/v8/V8Index.cpp +++ b/WebCore/bindings/v8/V8Index.cpp @@ -34,6 +34,7 @@ #include "V8Attr.h" #include "V8BarInfo.h" #include "V8BeforeLoadEvent.h" +#include "V8Blob.h" #include "V8WebGLActiveInfo.h" #include "V8CanvasRenderingContext.h" #include "V8CanvasRenderingContext2D.h" @@ -154,6 +155,7 @@ #include "V8NodeList.h" #include "V8NodeFilter.h" #include "V8Notation.h" +#include "V8PopStateEvent.h" #include "V8ProcessingInstruction.h" #include "V8ProgressEvent.h" #include "V8StyleSheet.h" @@ -249,11 +251,13 @@ #endif #if ENABLE(SVG_FONTS) +#include "V8SVGFontElement.h" #include "V8SVGFontFaceElement.h" #include "V8SVGFontFaceFormatElement.h" #include "V8SVGFontFaceNameElement.h" #include "V8SVGFontFaceSrcElement.h" #include "V8SVGFontFaceUriElement.h" +#include "V8SVGMissingGlyphElement.h" #endif #if ENABLE(SVG_FOREIGN_OBJECT) @@ -400,6 +404,7 @@ #include "V8WebGLArray.h" #include "V8WebGLByteArray.h" #include "V8WebGLBuffer.h" +#include "V8WebGLContextAttributes.h" #include "V8WebGLFloatArray.h" #include "V8WebGLFramebuffer.h" #include "V8WebGLIntArray.h" @@ -422,6 +427,13 @@ #include "V8SQLTransaction.h" #endif +#if ENABLE(INDEXED_DATABASE) +#include "V8IDBDatabaseError.h" +#include "V8IDBDatabaseException.h" +#include "V8IDBRequest.h" +#include "V8IndexedDatabaseRequest.h" +#endif + #if ENABLE(XPATH) #include "V8XPathResult.h" #include "V8XPathException.h" @@ -440,6 +452,10 @@ #include "V8InspectorFrontendHost.h" #endif +#if ENABLE(EVENTSOURCE) +#include "V8EventSource.h" +#endif + // Geolocation #include "V8Coordinates.h" #include "V8Geolocation.h" diff --git a/WebCore/bindings/v8/V8Index.h b/WebCore/bindings/v8/V8Index.h index a3aebdf..f7582f7 100644 --- a/WebCore/bindings/v8/V8Index.h +++ b/WebCore/bindings/v8/V8Index.h @@ -32,10 +32,13 @@ #define V8Index_h #include <v8.h> -#include "PlatformString.h" // for WebCore::String namespace WebCore { +static const int v8DOMWrapperTypeIndex = 0; +static const int v8DOMWrapperObjectIndex = 1; +static const int v8DefaultWrapperInternalFieldCount = 2; + typedef v8::Persistent<v8::FunctionTemplate> (*FunctionTemplateFactory)(); #if ENABLE(DATAGRID) @@ -82,6 +85,13 @@ typedef v8::Persistent<v8::FunctionTemplate> (*FunctionTemplateFactory)(); #define WORKER_NONNODE_WRAPPER_TYPES(V) #endif +#if ENABLE(EVENTSOURCE) +#define EVENTSOURCE_ACTIVE_OBJECT_WRAPPER_TYPES(V) \ + V(EVENTSOURCE, EventSource) +#else +#define EVENTSOURCE_ACTIVE_OBJECT_WRAPPER_TYPES(V) +#endif + #if ENABLE(OFFLINE_WEB_APPLICATIONS) #define APPLICATIONCACHE_NONNODE_WRAPPER_TYPES(V) \ V(DOMAPPLICATIONCACHE, DOMApplicationCache) @@ -230,11 +240,13 @@ typedef v8::Persistent<v8::FunctionTemplate> (*FunctionTemplateFactory)(); #if ENABLE(SVG_FONTS) #define SVG_FONTS_ELEMENT_TYPES(V) \ + V(SVGFONTELEMENT, SVGFontElement) \ V(SVGFONTFACEELEMENT, SVGFontFaceElement) \ V(SVGFONTFACEFORMATELEMENT, SVGFontFaceFormatElement) \ V(SVGFONTFACENAMEELEMENT, SVGFontFaceNameElement) \ V(SVGFONTFACESRCELEMENT, SVGFontFaceSrcElement) \ - V(SVGFONTFACEURIELEMENT, SVGFontFaceUriElement) + V(SVGFONTFACEURIELEMENT, SVGFontFaceUriElement) \ + V(SVGMISSINGGLYPHELEMENT, SVGMissingGlyphElement) #else #define SVG_FONTS_ELEMENT_TYPES(V) #endif @@ -316,7 +328,8 @@ typedef v8::Persistent<v8::FunctionTemplate> (*FunctionTemplateFactory)(); V(XMLHTTPREQUEST, XMLHttpRequest) \ WORKER_ACTIVE_OBJECT_WRAPPER_TYPES(V) \ SHARED_WORKER_ACTIVE_OBJECT_WRAPPER_TYPES(V) \ - WEBSOCKET_ACTIVE_OBJECT_WRAPPER_TYPES(V) + WEBSOCKET_ACTIVE_OBJECT_WRAPPER_TYPES(V) \ + EVENTSOURCE_ACTIVE_OBJECT_WRAPPER_TYPES(V) // NOTE: DOM_OBJECT_TYPES is split into two halves because // Visual Studio's Intellinonsense crashes when macros get @@ -325,6 +338,7 @@ typedef v8::Persistent<v8::FunctionTemplate> (*FunctionTemplateFactory)(); #define DOM_OBJECT_TYPES_1(V) \ V(BARINFO, BarInfo) \ V(BEFORELOADEVENT, BeforeLoadEvent) \ + V(BLOB, Blob) \ V(CANVASGRADIENT, CanvasGradient) \ V(CANVASPATTERN, CanvasPattern) \ V(CANVASRENDERINGCONTEXT, CanvasRenderingContext) \ @@ -386,6 +400,7 @@ typedef v8::Persistent<v8::FunctionTemplate> (*FunctionTemplateFactory)(); V(PAGETRANSITIONEVENT, PageTransitionEvent) \ V(PLUGIN, Plugin) \ V(PLUGINARRAY, PluginArray) \ + V(POPSTATEEVENT, PopStateEvent) \ V(PROGRESSEVENT, ProgressEvent) \ V(RANGE, Range) \ V(RANGEEXCEPTION, RangeException) \ @@ -438,6 +453,16 @@ typedef v8::Persistent<v8::FunctionTemplate> (*FunctionTemplateFactory)(); #define DOM_OBJECT_STORAGE_TYPES(V) #endif +#if ENABLE(INDEXED_DATABASE) +#define DOM_OBJECT_INDEXED_DATABASE_TYPES(V) \ + V(IDBDATABASEERROR, IDBDatabaseError) \ + V(IDBDATABASEEXCEPTION, IDBDatabaseException) \ + V(IDBREQUEST, IDBRequest) \ + V(INDEXEDDATABASEREQUEST, IndexedDatabaseRequest) +#else +#define DOM_OBJECT_INDEXED_DATABASE_TYPES(V) +#endif + #if ENABLE(WORKERS) #define DOM_OBJECT_WORKERS_TYPES(V) \ V(ERROREVENT, ErrorEvent) @@ -452,6 +477,7 @@ typedef v8::Persistent<v8::FunctionTemplate> (*FunctionTemplateFactory)(); V(WEBGLARRAYBUFFER, WebGLArrayBuffer) \ V(WEBGLBUFFER, WebGLBuffer) \ V(WEBGLBYTEARRAY, WebGLByteArray) \ + V(WEBGLCONTEXTATTRIBUTES, WebGLContextAttributes) \ V(WEBGLFLOATARRAY, WebGLFloatArray) \ V(WEBGLFRAMEBUFFER, WebGLFramebuffer) \ V(WEBGLINTARRAY, WebGLIntArray) \ @@ -530,6 +556,7 @@ typedef v8::Persistent<v8::FunctionTemplate> (*FunctionTemplateFactory)(); DOM_OBJECT_TYPES_2(V) \ DOM_OBJECT_DATABASE_TYPES(V) \ DOM_OBJECT_STORAGE_TYPES(V) \ + DOM_OBJECT_INDEXED_DATABASE_TYPES(V) \ DOM_OBJECT_WORKERS_TYPES(V) \ DOM_OBJECT_3D_CANVAS_TYPES(V) \ DOM_OBJECT_XPATH_TYPES(V) \ @@ -544,7 +571,6 @@ typedef v8::Persistent<v8::FunctionTemplate> (*FunctionTemplateFactory)(); #if ENABLE(SVG) // SVG_OBJECT_TYPES are svg non-node, non-pod types. #define SVG_OBJECT_TYPES(V) \ - V(SVGANGLE, SVGAngle) \ V(SVGANIMATEDANGLE, SVGAnimatedAngle) \ V(SVGANIMATEDBOOLEAN, SVGAnimatedBoolean) \ V(SVGANIMATEDENUMERATION, SVGAnimatedEnumeration) \ @@ -586,7 +612,6 @@ typedef v8::Persistent<v8::FunctionTemplate> (*FunctionTemplateFactory)(); V(SVGPATHSEGMOVETOABS, SVGPathSegMovetoAbs) \ V(SVGPATHSEGMOVETOREL, SVGPathSegMovetoRel) \ V(SVGPOINTLIST, SVGPointList) \ - V(SVGPRESERVEASPECTRATIO, SVGPreserveAspectRatio) \ V(SVGRENDERINGINTENT, SVGRenderingIntent) \ V(SVGSTRINGLIST, SVGStringList) \ V(SVGTRANSFORMLIST, SVGTransformList) \ @@ -595,7 +620,9 @@ typedef v8::Persistent<v8::FunctionTemplate> (*FunctionTemplateFactory)(); // SVG POD types should list all types whose IDL has PODType declaration. #define SVG_POD_TYPES(V) \ + V(SVGANGLE, SVGAngle) \ V(SVGLENGTH, SVGLength) \ + V(SVGPRESERVEASPECTRATIO, SVGPreserveAspectRatio) \ V(SVGTRANSFORM, SVGTransform) \ V(SVGMATRIX, SVGMatrix) \ V(SVGNUMBER, SVGNumber) \ @@ -604,7 +631,9 @@ typedef v8::Persistent<v8::FunctionTemplate> (*FunctionTemplateFactory)(); // POD types can have different implementation names, see CodeGenerateV8.pm. #define SVG_POD_NATIVE_TYPES(V) \ + V(SVGANGLE, SVGAngle) \ V(SVGLENGTH, SVGLength) \ + V(SVGPRESERVEASPECTRATIO, SVGPreserveAspectRatio) \ V(SVGTRANSFORM, SVGTransform) \ V(SVGMATRIX, TransformationMatrix) \ V(SVGNUMBER, float) \ diff --git a/WebCore/bindings/v8/V8IsolatedWorld.cpp b/WebCore/bindings/v8/V8IsolatedContext.cpp index cb65097..3237ede 100644 --- a/WebCore/bindings/v8/V8IsolatedWorld.cpp +++ b/WebCore/bindings/v8/V8IsolatedContext.cpp @@ -30,9 +30,7 @@ #include "config.h" -#include "V8IsolatedWorld.h" - -#include <v8.h> +#include "V8IsolatedContext.h" #include "Frame.h" #include "FrameLoaderClient.h" @@ -40,34 +38,35 @@ #include "ScriptController.h" #include "V8DOMWindow.h" #include "V8HiddenPropertyName.h" +#include <v8.h> namespace WebCore { -int V8IsolatedWorld::isolatedWorldCount = 0; -void V8IsolatedWorld::contextWeakReferenceCallback(v8::Persistent<v8::Value> object, void* isolated_world) +void V8IsolatedContext::contextWeakReferenceCallback(v8::Persistent<v8::Value> object, void* isolatedContext) { // Our context is going away. Time to clean up the world. - V8IsolatedWorld* world = static_cast<V8IsolatedWorld*>(isolated_world); - delete world; + V8IsolatedContext* context = static_cast<V8IsolatedContext*>(isolatedContext); + delete context; } -V8IsolatedWorld::V8IsolatedWorld(V8Proxy* proxy, int extensionGroup) +V8IsolatedContext::V8IsolatedContext(V8Proxy* proxy, int extensionGroup) + : m_world(IsolatedWorld::create()) { - ++isolatedWorldCount; - v8::HandleScope scope; - m_context = SharedPersistent<v8::Context>::create(proxy->createNewContext(v8::Handle<v8::Object>(), extensionGroup)); + // FIXME: We should be creating a new V8DOMWindowShell here instead of riping out the context. + m_context = SharedPersistent<v8::Context>::create(proxy->windowShell()->createNewContext(v8::Handle<v8::Object>(), extensionGroup)); if (m_context->get().IsEmpty()) return; // Run code in the new context. - v8::Context::Scope context_scope(m_context->get()); + v8::Context::Scope contextScope(m_context->get()); - getGlobalObject(m_context->get())->SetPointerInInternalField(V8Custom::kDOMWindowEnteredIsolatedWorldIndex, this); + getGlobalObject(m_context->get())->SetPointerInInternalField(V8DOMWindow::enteredIsolatedWorldIndex, this); - V8Proxy::installHiddenObjectPrototype(m_context->get()); - proxy->installDOMWindow(m_context->get(), proxy->frame()->domWindow()); + V8DOMWindowShell::installHiddenObjectPrototype(m_context->get()); + // FIXME: This will go away once we have a windowShell for the isolated world. + proxy->windowShell()->installDOMWindow(m_context->get(), proxy->frame()->domWindow()); // Using the default security token means that the canAccess is always // called, which is slow. @@ -80,14 +79,13 @@ V8IsolatedWorld::V8IsolatedWorld(V8Proxy* proxy, int extensionGroup) proxy->frame()->loader()->client()->didCreateIsolatedScriptContext(); } -void V8IsolatedWorld::destroy() +void V8IsolatedContext::destroy() { m_context->get().MakeWeak(this, &contextWeakReferenceCallback); } -V8IsolatedWorld::~V8IsolatedWorld() +V8IsolatedContext::~V8IsolatedContext() { - --isolatedWorldCount; m_context->disposeHandle(); } diff --git a/WebCore/bindings/v8/V8IsolatedContext.h b/WebCore/bindings/v8/V8IsolatedContext.h new file mode 100644 index 0000000..70ca270 --- /dev/null +++ b/WebCore/bindings/v8/V8IsolatedContext.h @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef V8IsolatedContext_h +#define V8IsolatedContext_h + +#include "IsolatedWorld.h" +#include "ScriptSourceCode.h" // for WebCore::ScriptSourceCode +#include "V8DOMWindow.h" +#include "V8Index.h" +#include "V8Proxy.h" +#include "V8Utilities.h" +#include <v8.h> + +namespace WebCore { + +class V8Proxy; + +// V8IsolatedContext +// +// V8IsolatedContext represents a isolated execution environment for +// JavaScript. Each isolated world executes in parallel with the main +// JavaScript world. An isolated world has access to the same DOM data +// structures as the main world but none of the JavaScript pointers. +// +// It is an error to ever share a JavaScript pointer between two isolated +// worlds or between an isolated world and the main world. Because +// isolated worlds have access to the DOM, they need their own DOM wrappers +// to avoid having pointers to the main world's DOM wrappers (which are +// JavaScript objects). +class V8IsolatedContext { +public: + // Creates an isolated world. To destroy it, call destroy(). + // This will delete the isolated world when the context it owns is GC'd. + V8IsolatedContext(V8Proxy* proxy, int extensionGroup); + ~V8IsolatedContext(); + + // Call this to destroy the isolated world. It will be deleted sometime + // after this call, once all script references to the world's context + // have been dropped. + void destroy(); + + // Returns the isolated world associated with + // v8::Context::GetEntered(). Because worlds are isolated, the entire + // JavaScript call stack should be from the same isolated world. + // Returns 0 if the entered context is from the main world. + // + // FIXME: Consider edge cases with DOM mutation events that might + // violate this invariant. + // + static V8IsolatedContext* getEntered() + { + // This is a temporary performance optimization. Essentially, + // GetHiddenValue is too slow for this code path. We need to get the + // V8 team to add a real property to v8::Context for isolated worlds. + // Until then, we optimize the common case of not having any isolated + // worlds at all. + if (!IsolatedWorld::count()) + return 0; + if (!v8::Context::InContext()) + return 0; + return reinterpret_cast<V8IsolatedContext*>(getGlobalObject(v8::Context::GetEntered())->GetPointerFromInternalField(V8DOMWindow::enteredIsolatedWorldIndex)); + } + + v8::Handle<v8::Context> context() { return m_context->get(); } + PassRefPtr<SharedPersistent<v8::Context> > sharedContext() { return m_context; } + + IsolatedWorld* world() const { return m_world.get(); } + +private: + static v8::Handle<v8::Object> getGlobalObject(v8::Handle<v8::Context> context) + { + return v8::Handle<v8::Object>::Cast(context->Global()->GetPrototype()); + } + + // Called by the garbage collector when our JavaScript context is about + // to be destroyed. + static void contextWeakReferenceCallback(v8::Persistent<v8::Value> object, void* isolatedContext); + + // The underlying v8::Context. This object is keep on the heap as + // long as |m_context| has not been garbage collected. + RefPtr<SharedPersistent<v8::Context> > m_context; + + RefPtr<IsolatedWorld> m_world; +}; + +} // namespace WebCore + +#endif // V8IsolatedContext_h diff --git a/WebCore/bindings/v8/V8IsolatedWorld.h b/WebCore/bindings/v8/V8IsolatedWorld.h deleted file mode 100644 index 6313da8..0000000 --- a/WebCore/bindings/v8/V8IsolatedWorld.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef V8IsolatedWorld_h -#define V8IsolatedWorld_h - -#include <v8.h> - -#include "V8DOMMap.h" -#include "V8Index.h" -#include "V8Proxy.h" -#include "V8Utilities.h" -#include "ScriptSourceCode.h" // for WebCore::ScriptSourceCode - -namespace WebCore { - - class V8Proxy; - - // V8IsolatedWorld - // - // V8IsolatedWorld represents a isolated execution environment for - // JavaScript. Each isolated world executes in parallel with the main - // JavaScript world. An isolated world has access to the same DOM data - // structures as the main world but none of the JavaScript pointers. - // - // It is an error to ever share a JavaScript pointer between two isolated - // worlds or between an isolated world and the main world. Because - // isolated worlds have access to the DOM, they need their own DOM wrappers - // to avoid having pointers to the main world's DOM wrappers (which are - // JavaScript objects). - // - class V8IsolatedWorld { - public: - // Creates an isolated world. To destroy it, call destroy(). - // This will delete the isolated world when the context it owns is GC'd. - V8IsolatedWorld(V8Proxy* proxy, int extensionGroup); - ~V8IsolatedWorld(); - - // Call this to destroy the isolated world. It will be deleted sometime - // after this call, once all script references to the world's context - // have been dropped. - void destroy(); - - // Returns the isolated world associated with - // v8::Context::GetEntered(). Because worlds are isolated, the entire - // JavaScript call stack should be from the same isolated world. - // Returns NULL if the entered context is from the main world. - // - // FIXME: Consider edge cases with DOM mutation events that might - // violate this invariant. - // - static V8IsolatedWorld* getEntered() - { - // This is a temporary performance optimization. Essentially, - // GetHiddenValue is too slow for this code path. We need to get the - // V8 team to add a real property to v8::Context for isolated worlds. - // Until then, we optimize the common case of not having any isolated - // worlds at all. - if (!isolatedWorldCount) - return 0; - if (!v8::Context::InContext()) - return 0; - return reinterpret_cast<V8IsolatedWorld*>(getGlobalObject(v8::Context::GetEntered())->GetPointerFromInternalField(V8Custom::kDOMWindowEnteredIsolatedWorldIndex)); - } - - v8::Handle<v8::Context> context() { return m_context->get(); } - PassRefPtr<SharedPersistent<v8::Context> > sharedContext() { return m_context; } - - DOMDataStore* getDOMDataStore() const { return m_domDataStore.getStore(); } - - private: - static v8::Handle<v8::Object> getGlobalObject(v8::Handle<v8::Context> context) - { - return v8::Handle<v8::Object>::Cast(context->Global()->GetPrototype()); - } - - // Called by the garbage collector when our JavaScript context is about - // to be destroyed. - static void contextWeakReferenceCallback(v8::Persistent<v8::Value> object, void* isolated_world); - - // The v8::Context for the isolated world. This object is keep on the - // heap as long as |m_context| has not been garbage collected. - RefPtr<SharedPersistent<v8::Context> > m_context; - - // The backing store for the isolated world's DOM wrappers. This class - // doesn't have visibility into the wrappers. This handle simply helps - // manage their lifetime. - DOMDataStoreHandle m_domDataStore; - - static int isolatedWorldCount; - }; - -} // namespace WebCore - -#endif // V8IsolatedWorld_h diff --git a/WebCore/bindings/v8/V8LazyEventListener.cpp b/WebCore/bindings/v8/V8LazyEventListener.cpp index 16b21d6..7f13c5a 100644 --- a/WebCore/bindings/v8/V8LazyEventListener.cpp +++ b/WebCore/bindings/v8/V8LazyEventListener.cpp @@ -54,7 +54,11 @@ V8LazyEventListener::V8LazyEventListener(const String& functionName, bool isSVGE v8::Local<v8::Value> V8LazyEventListener::callListenerFunction(ScriptExecutionContext* context, v8::Handle<v8::Value> jsEvent, Event* event) { - v8::Local<v8::Function> handlerFunction = v8::Local<v8::Function>::Cast(getListenerObject(context)); + v8::Local<v8::Object> listenerObject = getListenerObject(context); + if (listenerObject.IsEmpty()) + return v8::Local<v8::Value>(); + + v8::Local<v8::Function> handlerFunction = v8::Local<v8::Function>::Cast(listenerObject); v8::Local<v8::Object> receiver = getReceiverObject(event); if (handlerFunction.IsEmpty() || receiver.IsEmpty()) return v8::Local<v8::Value>(); diff --git a/WebCore/bindings/v8/V8NPObject.cpp b/WebCore/bindings/v8/V8NPObject.cpp index bab3688..196972e 100644 --- a/WebCore/bindings/v8/V8NPObject.cpp +++ b/WebCore/bindings/v8/V8NPObject.cpp @@ -65,19 +65,25 @@ static v8::Handle<v8::Value> npObjectInvokeImpl(const v8::Arguments& args, Invok if (V8HTMLAppletElement::HasInstance(args.Holder()) || V8HTMLEmbedElement::HasInstance(args.Holder()) || V8HTMLObjectElement::HasInstance(args.Holder())) { // The holder object is a subtype of HTMLPlugInElement. - HTMLPlugInElement* element = V8DOMWrapper::convertDOMWrapperToNode<HTMLPlugInElement>(args.Holder()); + HTMLPlugInElement* element; + if (V8HTMLAppletElement::HasInstance(args.Holder())) + element = V8HTMLAppletElement::toNative(args.Holder()); + else if (V8HTMLEmbedElement::HasInstance(args.Holder())) + element = V8HTMLEmbedElement::toNative(args.Holder()); + else + element = V8HTMLObjectElement::toNative(args.Holder()); ScriptInstance scriptInstance = element->getInstance(); if (scriptInstance) - npObject = V8DOMWrapper::convertToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, scriptInstance->instance()); + npObject = v8ObjectToNPObject(scriptInstance->instance()); else npObject = 0; } else { // The holder object is not a subtype of HTMLPlugInElement, it must be an NPObject which has three // internal fields. - if (args.Holder()->InternalFieldCount() != V8Custom::kNPObjectInternalFieldCount) + if (args.Holder()->InternalFieldCount() != npObjectInternalFieldCount) return throwError("NPMethod called on non-NPObject", V8Proxy::ReferenceError); - npObject = V8DOMWrapper::convertToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, args.Holder()); + npObject = v8ObjectToNPObject(args.Holder()); } // Verify that our wrapper wasn't using a NPObject which has already been deleted. @@ -161,7 +167,7 @@ static void weakTemplateCallback(v8::Persistent<v8::Value> object, void* paramet static v8::Handle<v8::Value> npObjectGetProperty(v8::Local<v8::Object> self, NPIdentifier identifier, v8::Local<v8::Value> key) { - NPObject* npObject = V8DOMWrapper::convertToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, self); + NPObject* npObject = v8ObjectToNPObject(self); // Verify that our wrapper wasn't using a NPObject which // has already been deleted. @@ -230,7 +236,7 @@ v8::Handle<v8::Value> npObjectGetIndexedProperty(v8::Local<v8::Object> self, uin static v8::Handle<v8::Value> npObjectSetProperty(v8::Local<v8::Object> self, NPIdentifier identifier, v8::Local<v8::Value> value) { - NPObject* npObject = V8DOMWrapper::convertToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, self); + NPObject* npObject = v8ObjectToNPObject(self); // Verify that our wrapper wasn't using a NPObject which has already been deleted. if (!npObject || !_NPN_IsAlive(npObject)) { @@ -280,7 +286,7 @@ v8::Handle<v8::Value> npObjectSetIndexedProperty(v8::Local<v8::Object> self, uin v8::Handle<v8::Array> npObjectPropertyEnumerator(const v8::AccessorInfo& info, bool namedProperty) { - NPObject* npObject = V8DOMWrapper::convertToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, info.Holder()); + NPObject* npObject = v8ObjectToNPObject(info.Holder()); // Verify that our wrapper wasn't using a NPObject which // has already been deleted. @@ -357,7 +363,7 @@ v8::Local<v8::Object> createV8ObjectForNPObject(NPObject* object, NPObject* root // can be used by DOM bindings. if (npObjectDesc.IsEmpty()) { npObjectDesc = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New()); - npObjectDesc->InstanceTemplate()->SetInternalFieldCount(V8Custom::kNPObjectInternalFieldCount); + npObjectDesc->InstanceTemplate()->SetInternalFieldCount(npObjectInternalFieldCount); npObjectDesc->InstanceTemplate()->SetNamedPropertyHandler(npObjectNamedPropertyGetter, npObjectNamedPropertySetter, 0, 0, npObjectNamedPropertyEnumerator); npObjectDesc->InstanceTemplate()->SetIndexedPropertyHandler(npObjectIndexedPropertyGetter, npObjectIndexedPropertySetter, 0, 0, npObjectIndexedPropertyEnumerator); npObjectDesc->InstanceTemplate()->SetCallAsFunctionHandler(npObjectInvokeDefaultHandler); diff --git a/WebCore/bindings/v8/V8Proxy.cpp b/WebCore/bindings/v8/V8Proxy.cpp index 5da73d5..a5cc433 100644 --- a/WebCore/bindings/v8/V8Proxy.cpp +++ b/WebCore/bindings/v8/V8Proxy.cpp @@ -42,6 +42,7 @@ #include "ScriptController.h" #include "StorageNamespace.h" #include "V8Binding.h" +#include "V8BindingState.h" #include "V8Collection.h" #include "V8ConsoleMessage.h" #include "V8CustomBinding.h" @@ -49,7 +50,7 @@ #include "V8DOMWindow.h" #include "V8HiddenPropertyName.h" #include "V8Index.h" -#include "V8IsolatedWorld.h" +#include "V8IsolatedContext.h" #include "WorkerContextExecutionProxy.h" #include <algorithm> @@ -174,7 +175,7 @@ enum DelayReporting { ReportNow }; -static void reportUnsafeAccessTo(Frame* target, DelayReporting delay) +void V8Proxy::reportUnsafeAccessTo(Frame* target, DelayReporting delay) { ASSERT(target); Document* targetDocument = target->document(); @@ -214,13 +215,6 @@ static void reportUnsafeAccessTo(Frame* target, DelayReporting delay) } } -static void reportUnsafeJavaScriptAccess(v8::Local<v8::Object> host, v8::AccessType type, v8::Local<v8::Value> data) -{ - Frame* target = V8Custom::GetTargetFrame(host, data); - if (target) - reportUnsafeAccessTo(target, ReportLater); -} - static void handleFatalErrorInV8() { // FIXME: We temporarily deal with V8 internal error situations @@ -228,17 +222,9 @@ static void handleFatalErrorInV8() CRASH(); } -static void reportFatalErrorInV8(const char* location, const char* message) -{ - // V8 is shutdown, we cannot use V8 api. - // The only thing we can do is to disable JavaScript. - // FIXME: clean up V8Proxy and disable JavaScript. - printf("V8 error: %s (%s)\n", message, location); - handleFatalErrorInV8(); -} - V8Proxy::V8Proxy(Frame* frame) : m_frame(frame) + , m_windowShell(V8DOMWindowShell::create(frame)) , m_inlineCode(false) , m_timerCallback(false) , m_recursion(0) @@ -248,18 +234,7 @@ V8Proxy::V8Proxy(Frame* frame) V8Proxy::~V8Proxy() { clearForClose(); - destroyGlobal(); -} - -void V8Proxy::destroyGlobal() -{ - if (!m_global.IsEmpty()) { -#ifndef NDEBUG - V8GCController::unregisterGlobalHandle(this, m_global); -#endif - m_global.Dispose(); - m_global.Clear(); - } + windowShell()->destroyGlobal(); } v8::Handle<v8::Script> V8Proxy::compileScript(v8::Handle<v8::String> code, const String& fileName, int baseLine) @@ -297,7 +272,7 @@ bool V8Proxy::handleOutOfMemory() // Clean m_context, and event handlers. proxy->clearForClose(); - proxy->destroyGlobal(); + proxy->windowShell()->destroyGlobal(); } #if PLATFORM(CHROMIUM) @@ -315,104 +290,58 @@ bool V8Proxy::handleOutOfMemory() void V8Proxy::evaluateInIsolatedWorld(int worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup) { - initContextIfNeeded(); + // FIXME: This will need to get reorganized once we have a windowShell for the isolated world. + windowShell()->initContextIfNeeded(); v8::HandleScope handleScope; - V8IsolatedWorld* world = 0; + V8IsolatedContext* isolatedContext = 0; if (worldID > 0) { IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(worldID); if (iter != m_isolatedWorlds.end()) { - world = iter->second; + isolatedContext = iter->second; } else { - world = new V8IsolatedWorld(this, extensionGroup); - if (world->context().IsEmpty()) { - delete world; + isolatedContext = new V8IsolatedContext(this, extensionGroup); + if (isolatedContext->context().IsEmpty()) { + delete isolatedContext; return; } - m_isolatedWorlds.set(worldID, world); + // FIXME: We should change this to using window shells to match JSC. + m_isolatedWorlds.set(worldID, isolatedContext); // Setup context id for JS debugger. - if (!setInjectedScriptContextDebugId(world->context())) { + if (!setInjectedScriptContextDebugId(isolatedContext->context())) { m_isolatedWorlds.take(worldID); - delete world; + delete isolatedContext; return; } } } else { - world = new V8IsolatedWorld(this, extensionGroup); - if (world->context().IsEmpty()) { - delete world; + isolatedContext = new V8IsolatedContext(this, extensionGroup); + if (isolatedContext->context().IsEmpty()) { + delete isolatedContext; return; } } - v8::Local<v8::Context> context = v8::Local<v8::Context>::New(world->context()); + v8::Local<v8::Context> context = v8::Local<v8::Context>::New(isolatedContext->context()); v8::Context::Scope context_scope(context); for (size_t i = 0; i < sources.size(); ++i) evaluate(sources[i], 0); if (worldID == 0) - world->destroy(); -} - -void V8Proxy::evaluateInNewContext(const Vector<ScriptSourceCode>& sources, int extensionGroup) -{ - initContextIfNeeded(); - - v8::HandleScope handleScope; - - // Set up the DOM window as the prototype of the new global object. - v8::Handle<v8::Context> windowContext = m_context; - v8::Handle<v8::Object> windowGlobal = windowContext->Global(); - v8::Handle<v8::Object> windowWrapper = V8DOMWrapper::lookupDOMWrapper(V8ClassIndex::DOMWINDOW, windowGlobal); - - ASSERT(V8DOMWrapper::convertDOMWrapperToNative<DOMWindow>(windowWrapper) == m_frame->domWindow()); - - v8::Persistent<v8::Context> context = createNewContext(v8::Handle<v8::Object>(), extensionGroup); - if (context.IsEmpty()) - return; - - v8::Context::Scope contextScope(context); - - // Setup context id for JS debugger. - if (!setInjectedScriptContextDebugId(context)) { - context.Dispose(); - return; - } - - v8::Handle<v8::Object> global = context->Global(); - - v8::Handle<v8::String> implicitProtoString = v8::String::New("__proto__"); - global->Set(implicitProtoString, windowWrapper); - - // Give the code running in the new context a way to get access to the - // original context. - global->Set(v8::String::New("contentWindow"), windowGlobal); - - m_frame->loader()->client()->didCreateIsolatedScriptContext(); - - // Run code in the new context. - for (size_t i = 0; i < sources.size(); ++i) - evaluate(sources[i], 0); - - // Using the default security token means that the canAccess is always - // called, which is slow. - // FIXME: Use tokens where possible. This will mean keeping track of all - // created contexts so that they can all be updated when the document domain - // changes. - context->UseDefaultSecurityToken(); - context.Dispose(); + isolatedContext->destroy(); } bool V8Proxy::setInjectedScriptContextDebugId(v8::Handle<v8::Context> targetContext) { // Setup context id for JS debugger. v8::Context::Scope contextScope(targetContext); - if (m_context.IsEmpty()) + v8::Handle<v8::Context> context = windowShell()->context(); + if (context.IsEmpty()) return false; - int debugId = contextDebugId(m_context); + int debugId = contextDebugId(context); char buffer[32]; if (debugId == -1) @@ -611,37 +540,13 @@ v8::Local<v8::Value> V8Proxy::newInstance(v8::Handle<v8::Function> constructor, return result; } -v8::Local<v8::Object> V8Proxy::createWrapperFromCacheSlowCase(V8ClassIndex::V8WrapperType type) -{ - // Not in cache. - int classIndex = V8ClassIndex::ToInt(type); - initContextIfNeeded(); - v8::Context::Scope scope(m_context); - v8::Local<v8::Function> function = V8DOMWrapper::getConstructor(type, getHiddenObjectPrototype(m_context)); - v8::Local<v8::Object> instance = SafeAllocation::newInstance(function); - if (!instance.IsEmpty()) { - m_wrapperBoilerplates->Set(v8::Integer::New(classIndex), instance); - return instance->Clone(); - } - return notHandledByInterceptor(); -} - -bool V8Proxy::isContextInitialized() -{ - // m_context, m_global, and m_wrapperBoilerplates should - // all be non-empty if if m_context is non-empty. - ASSERT(m_context.IsEmpty() || !m_global.IsEmpty()); - ASSERT(m_context.IsEmpty() || !m_wrapperBoilerplates.IsEmpty()); - return !m_context.IsEmpty(); -} - DOMWindow* V8Proxy::retrieveWindow(v8::Handle<v8::Context> context) { v8::Handle<v8::Object> global = context->Global(); ASSERT(!global.IsEmpty()); global = V8DOMWrapper::lookupDOMWrapper(V8ClassIndex::DOMWINDOW, global); ASSERT(!global.IsEmpty()); - return V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, global); + return V8DOMWindow::toNative(global); } Frame* V8Proxy::retrieveFrame(v8::Handle<v8::Context> context) @@ -691,12 +596,12 @@ V8Proxy* V8Proxy::retrieve(Frame* frame) { if (!frame) return 0; - return frame->script()->isEnabled() ? frame->script()->proxy() : 0; + return frame->script()->canExecuteScripts() ? frame->script()->proxy() : 0; } V8Proxy* V8Proxy::retrieve(ScriptExecutionContext* context) { - if (!context->isDocument()) + if (!context || !context->isDocument()) return 0; return retrieve(static_cast<Document*>(context)->frame()); } @@ -705,79 +610,6 @@ void V8Proxy::disconnectFrame() { } -void V8Proxy::updateDocumentWrapper(v8::Handle<v8::Value> wrapper) -{ - clearDocumentWrapper(); - - ASSERT(m_document.IsEmpty()); - m_document = v8::Persistent<v8::Value>::New(wrapper); -#ifndef NDEBUG - V8GCController::registerGlobalHandle(PROXY, this, m_document); -#endif -} - -void V8Proxy::clearDocumentWrapper() -{ - if (!m_document.IsEmpty()) { -#ifndef NDEBUG - V8GCController::unregisterGlobalHandle(this, m_document); -#endif - m_document.Dispose(); - m_document.Clear(); - } -} - -void V8Proxy::updateDocumentWrapperCache() -{ - v8::HandleScope handleScope; - v8::Context::Scope contextScope(m_context); - - // If the document has no frame, NodeToV8Object might get the - // document wrapper for a document that is about to be deleted. - // If the ForceSet below causes a garbage collection, the document - // might get deleted and the global handle for the document - // wrapper cleared. Using the cleared global handle will lead to - // crashes. In this case we clear the cache and let the DOMWindow - // accessor handle access to the document. - if (!m_frame->document()->frame()) { - clearDocumentWrapperCache(); - return; - } - - v8::Handle<v8::Value> documentWrapper = V8DOMWrapper::convertNodeToV8Object(m_frame->document()); - - // If instantiation of the document wrapper fails, clear the cache - // and let the DOMWindow accessor handle access to the document. - if (documentWrapper.IsEmpty()) { - clearDocumentWrapperCache(); - return; - } - m_context->Global()->ForceSet(v8::String::New("document"), documentWrapper, static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); -} - -void V8Proxy::clearDocumentWrapperCache() -{ - ASSERT(!m_context.IsEmpty()); - m_context->Global()->ForceDelete(v8::String::New("document")); -} - -void V8Proxy::disposeContextHandles() -{ - if (!m_context.IsEmpty()) { - m_frame->loader()->client()->didDestroyScriptContextForFrame(); - m_context.Dispose(); - m_context.Clear(); - } - - if (!m_wrapperBoilerplates.IsEmpty()) { -#ifndef NDEBUG - V8GCController::unregisterGlobalHandle(this, m_wrapperBoilerplates); -#endif - m_wrapperBoilerplates.Dispose(); - m_wrapperBoilerplates.Clear(); - } -} - void V8Proxy::releaseStorageMutex() { // If we've just left a top level script context and local storage has been @@ -804,18 +636,13 @@ void V8Proxy::resetIsolatedWorlds() void V8Proxy::clearForClose() { resetIsolatedWorlds(); - - if (!m_context.IsEmpty()) { - v8::HandleScope handleScope; - - clearDocumentWrapper(); - disposeContextHandles(); - } + windowShell()->clearForClose(); } void V8Proxy::clearForNavigation() { resetIsolatedWorlds(); +<<<<<<< HEAD if (!m_context.IsEmpty()) { v8::HandleScope handle; @@ -1181,6 +1008,9 @@ void V8Proxy::initContextIfNeeded() #ifdef ANDROID_INSTRUMENT android::TimeCounter::record(android::TimeCounter::JavaScriptInitTimeCounter, __FUNCTION__); #endif +======= + windowShell()->clearForNavigation(); +>>>>>>> webkit.org at r54127 } void V8Proxy::setDOMException(int exceptionCode) @@ -1246,8 +1076,8 @@ v8::Local<v8::Context> V8Proxy::context(Frame* frame) if (context.IsEmpty()) return v8::Local<v8::Context>(); - if (V8IsolatedWorld* world = V8IsolatedWorld::getEntered()) { - context = v8::Local<v8::Context>::New(world->context()); + if (V8IsolatedContext* isolatedContext = V8IsolatedContext::getEntered()) { + context = v8::Local<v8::Context>::New(isolatedContext->context()); if (frame != V8Proxy::retrieveFrame(context)) return v8::Local<v8::Context>(); } @@ -1257,8 +1087,8 @@ v8::Local<v8::Context> V8Proxy::context(Frame* frame) v8::Local<v8::Context> V8Proxy::context() { - if (V8IsolatedWorld* world = V8IsolatedWorld::getEntered()) { - RefPtr<SharedPersistent<v8::Context> > context = world->sharedContext(); + if (V8IsolatedContext* isolatedContext = V8IsolatedContext::getEntered()) { + RefPtr<SharedPersistent<v8::Context> > context = isolatedContext->sharedContext(); if (m_frame != V8Proxy::retrieveFrame(context->get())) return v8::Local<v8::Context>(); return v8::Local<v8::Context>::New(context->get()); @@ -1268,8 +1098,8 @@ v8::Local<v8::Context> V8Proxy::context() v8::Local<v8::Context> V8Proxy::mainWorldContext() { - initContextIfNeeded(); - return v8::Local<v8::Context>::New(m_context); + windowShell()->initContextIfNeeded(); + return v8::Local<v8::Context>::New(windowShell()->context()); } v8::Local<v8::Context> V8Proxy::mainWorldContext(Frame* frame) @@ -1427,17 +1257,18 @@ void V8Proxy::registerExtension(v8::Extension* extension, int extensionGroup) bool V8Proxy::setContextDebugId(int debugId) { ASSERT(debugId > 0); - if (m_context.IsEmpty()) - return false; v8::HandleScope scope; - if (!m_context->GetData()->IsUndefined()) + v8::Handle<v8::Context> context = windowShell()->context(); + if (context.IsEmpty()) + return false; + if (!context->GetData()->IsUndefined()) return false; - v8::Context::Scope contextScope(m_context); + v8::Context::Scope contextScope(context); char buffer[32]; snprintf(buffer, sizeof(buffer), "page,%d", debugId); - m_context->SetData(v8::String::New(buffer)); + context->SetData(v8::String::New(buffer)); return true; } @@ -1454,26 +1285,6 @@ int V8Proxy::contextDebugId(v8::Handle<v8::Context> context) return atoi(comma + 1); } -v8::Handle<v8::Value> V8Proxy::getHiddenObjectPrototype(v8::Handle<v8::Context> context) -{ - return context->Global()->GetHiddenValue(V8HiddenPropertyName::objectPrototype()); -} - -void V8Proxy::installHiddenObjectPrototype(v8::Handle<v8::Context> context) -{ - v8::Handle<v8::String> objectString = v8::String::New("Object"); - v8::Handle<v8::String> prototypeString = v8::String::New("prototype"); - v8::Handle<v8::String> hiddenObjectPrototypeString = V8HiddenPropertyName::objectPrototype(); - // Bail out if allocation failed. - if (objectString.IsEmpty() || prototypeString.IsEmpty() || hiddenObjectPrototypeString.IsEmpty()) - return; - - v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(context->Global()->Get(objectString)); - v8::Handle<v8::Value> objectPrototype = object->Get(prototypeString); - - context->Global()->SetHiddenValue(hiddenObjectPrototypeString, objectPrototype); -} - v8::Local<v8::Context> toV8Context(ScriptExecutionContext* context, const WorldContextHandle& worldContext) { if (context->isDocument()) { diff --git a/WebCore/bindings/v8/V8Proxy.h b/WebCore/bindings/v8/V8Proxy.h index 900ee18..6f6470e 100644 --- a/WebCore/bindings/v8/V8Proxy.h +++ b/WebCore/bindings/v8/V8Proxy.h @@ -35,6 +35,7 @@ #include "SecurityOrigin.h" // for WebCore::SecurityOrigin #include "SharedPersistent.h" #include "V8AbstractEventListener.h" +#include "V8DOMWindowShell.h" #include "V8DOMWrapper.h" #include "V8GCController.h" #include "V8Index.h" @@ -58,7 +59,7 @@ namespace WebCore { class ScriptExecutionContext; class String; class V8EventListener; - class V8IsolatedWorld; + class V8IsolatedContext; class WorldContextHandle; // FIXME: use standard logging facilities in WebCore. @@ -139,28 +140,21 @@ namespace WebCore { GeneralError }; + // When to report errors. + enum DelayReporting { + ReportLater, + ReportNow + }; + explicit V8Proxy(Frame*); ~V8Proxy(); Frame* frame() { return m_frame; } - // Clear page-specific data, but keep the global object identify. void clearForNavigation(); - - // Clear page-specific data before shutting down the proxy object. void clearForClose(); - // Update document object of the frame. - void updateDocument(); - - // Update the security origin of a document - // (e.g., after setting docoument.domain). - void updateSecurityOrigin(); - - // Destroy the global object. - void destroyGlobal(); - // FIXME: Need comment. User Gesture related. bool inlineCode() const { return m_inlineCode; } void setInlineCode(bool value) { m_inlineCode = value; } @@ -168,9 +162,6 @@ namespace WebCore { bool timerCallback() const { return m_timerCallback; } void setTimerCallback(bool value) { m_timerCallback = value; } - // Has the context for this proxy been initialized? - bool isContextInitialized(); - // Disconnects the proxy from its owner frame, // and clears all timeouts on the DOM window. void disconnectFrame(); @@ -216,11 +207,6 @@ namespace WebCore { // constructors. void evaluateInIsolatedWorld(int worldId, const Vector<ScriptSourceCode>& sources, int extensionGroup); - // Evaluate JavaScript in a new context. The script gets its own global scope - // and its own prototypes for intrinsic JavaScript objects (String, Array, - // and so-on). It shares the wrappers for all DOM nodes and DOM constructors. - void evaluateInNewContext(const Vector<ScriptSourceCode>&, int extensionGroup); - // Evaluate a script file in the current execution environment. // The caller must hold an execution context. // If cannot evalute the script, it returns an error. @@ -239,16 +225,6 @@ namespace WebCore { // Call the function as constructor with the given arguments. v8::Local<v8::Value> newInstance(v8::Handle<v8::Function>, int argc, v8::Handle<v8::Value> argv[]); - // To create JS Wrapper objects, we create a cache of a 'boiler plate' - // object, and then simply Clone that object each time we need a new one. - // This is faster than going through the full object creation process. - v8::Local<v8::Object> createWrapperFromCache(V8ClassIndex::V8WrapperType type) - { - int classIndex = V8ClassIndex::ToInt(type); - v8::Local<v8::Object> clone(m_wrapperBoilerplates->CloneElementAt(classIndex)); - return clone.IsEmpty() ? createWrapperFromCacheSlowCase(type) : clone; - } - // Returns the window object associated with a context. static DOMWindow* retrieveWindow(v8::Handle<v8::Context>); // Returns V8Proxy object of the currently executing context. @@ -305,13 +281,6 @@ namespace WebCore { // is disabled and it returns true. static bool handleOutOfMemory(); - // Check if the active execution context can access the target frame. - static bool canAccessFrame(Frame*, bool reportError); - - // Check if it is safe to access the given node from the - // current security context. - static bool checkNodeSecurity(Node*); - static v8::Handle<v8::Value> checkNewLegal(const v8::Arguments&); static v8::Handle<v8::Script> compileScript(v8::Handle<v8::String> code, const String& fileName, int baseLine); @@ -350,13 +319,12 @@ namespace WebCore { v8::Local<v8::Context> context(); v8::Local<v8::Context> mainWorldContext(); + // FIXME: This should eventually take DOMWrapperWorld argument! + V8DOMWindowShell* windowShell() const { return m_windowShell.get(); } + bool setContextDebugId(int id); static int contextDebugId(v8::Handle<v8::Context>); - static v8::Handle<v8::Value> getHiddenObjectPrototype(v8::Handle<v8::Context>); - // WARNING: Call |installHiddenObjectPrototype| only on fresh contexts! - static void installHiddenObjectPrototype(v8::Handle<v8::Context>); - // Registers a v8 extension to be available on webpages. The two forms // offer various restrictions on what types of contexts the extension is // loaded into. If a scheme is provided, only pages whose URL has the given @@ -367,27 +335,15 @@ namespace WebCore { static void registerExtension(v8::Extension*, const String& schemeRestriction); static void registerExtension(v8::Extension*, int extensionGroup); - // FIXME: Separate these concerns from V8Proxy? - v8::Persistent<v8::Context> createNewContext(v8::Handle<v8::Object> global, int extensionGroup); - static bool installDOMWindow(v8::Handle<v8::Context> context, DOMWindow* window); - - void initContextIfNeeded(); - void updateDocumentWrapper(v8::Handle<v8::Value> wrapper); - - private: - void setSecurityToken(); - void clearDocumentWrapper(); + static void registerExtensionWithV8(v8::Extension*); + static bool registeredExtensionWithV8(v8::Extension*); - // The JavaScript wrapper for the document object is cached on the global - // object for fast access. UpdateDocumentWrapperCache sets the wrapper - // for the current document on the global object. ClearDocumentWrapperCache - // deletes the document wrapper from the global object. - void updateDocumentWrapperCache(); - void clearDocumentWrapperCache(); + static const V8Extensions& extensions() { return m_extensions; } - // Dispose global handles of m_contexts and friends. - void disposeContextHandles(); + // Report an unsafe attempt to access the given frame on the console. + static void reportUnsafeAccessTo(Frame* target, DelayReporting delay); + private: // If m_recursionCount is 0, let LocalStorage know so we can release // the storage mutex. void releaseStorageMutex(); @@ -397,8 +353,6 @@ namespace WebCore { // Returns false when we're out of memory in V8. bool setInjectedScriptContextDebugId(v8::Handle<v8::Context> targetContext); - static bool canAccessPrivate(DOMWindow*); - static const char* rangeExceptionName(int exceptionCode); static const char* eventExceptionName(int exceptionCode); static const char* xmlHttpRequestExceptionName(int exceptionCode); @@ -422,24 +376,11 @@ namespace WebCore { return v8::Local<v8::Context>::New(m_utilityContext); } - v8::Local<v8::Object> createWrapperFromCacheSlowCase(V8ClassIndex::V8WrapperType); - - static void registerExtensionWithV8(v8::Extension*); - static bool registeredExtensionWithV8(v8::Extension*); - Frame* m_frame; - v8::Persistent<v8::Context> m_context; - - // For each possible type of wrapper, we keep a boilerplate object. - // The boilerplate is used to create additional wrappers of the same - // type. We keep a single persistent handle to an array of the - // activated boilerplates. - v8::Persistent<v8::Array> m_wrapperBoilerplates; - - v8::Persistent<v8::Object> m_global; - v8::Persistent<v8::Value> m_document; - + // For the moment, we have one of these. Soon we will have one per DOMWrapperWorld. + RefPtr<V8DOMWindowShell> m_windowShell; + // Utility context holding JavaScript functions used internally. static v8::Persistent<v8::Context> m_utilityContext; @@ -468,7 +409,10 @@ namespace WebCore { // Note: although the pointer is raw, the instance is kept alive by a strong // reference to the v8 context it contains, which is not made weak until we // call world->destroy(). - typedef HashMap<int, V8IsolatedWorld*> IsolatedWorldMap; + // + // FIXME: We want to eventually be holding window shells instead of the + // IsolatedContext directly. + typedef HashMap<int, V8IsolatedContext*> IsolatedWorldMap; IsolatedWorldMap m_isolatedWorlds; }; diff --git a/WebCore/bindings/v8/V8SVGPODTypeWrapper.h b/WebCore/bindings/v8/V8SVGPODTypeWrapper.h index b6e47af..d4cdcf8 100644 --- a/WebCore/bindings/v8/V8SVGPODTypeWrapper.h +++ b/WebCore/bindings/v8/V8SVGPODTypeWrapper.h @@ -51,6 +51,11 @@ public: virtual ~V8SVGPODTypeWrapper() { } virtual operator PODType() = 0; virtual void commitChange(PODType, SVGElement*) = 0; + + static V8SVGPODTypeWrapper<PODType>* toNative(v8::Handle<v8::Object> object) + { + return reinterpret_cast<V8SVGPODTypeWrapper<PODType>*>(object->GetPointerFromInternalField(v8DOMWrapperObjectIndex)); + } }; template<typename PODType> @@ -59,7 +64,7 @@ public: typedef SVGPODListItem<PODType> PODListItemPtrType; typedef PODType (SVGPODListItem<PODType>::*GetterMethod)() const; - typedef void (SVGPODListItem<PODType>::*SetterMethod)(PODType); + typedef void (SVGPODListItem<PODType>::*SetterMethod)(const PODType&); static PassRefPtr<V8SVGPODTypeWrapperCreatorForList> create(PassRefPtr<PODListItemPtrType> creator, const QualifiedName& attributeName) { @@ -197,7 +202,7 @@ template<typename PODType, typename PODTypeCreator> class V8SVGDynamicPODTypeWrapper : public V8SVGPODTypeWrapper<PODType> { public: typedef PODType (PODTypeCreator::*GetterMethod)() const; - typedef void (PODTypeCreator::*SetterMethod)(PODType); + typedef void (PODTypeCreator::*SetterMethod)(const PODType&); typedef void (*CacheRemovalCallback)(V8SVGPODTypeWrapper<PODType>*); static PassRefPtr<V8SVGDynamicPODTypeWrapper> create(PassRefPtr<PODTypeCreator> creator, GetterMethod getter, SetterMethod setter, CacheRemovalCallback cacheRemovalCallback) @@ -247,7 +252,7 @@ private: template<typename PODType, typename PODTypeCreator> struct PODTypeWrapperCacheInfo { typedef PODType (PODTypeCreator::*GetterMethod)() const; - typedef void (PODTypeCreator::*SetterMethod)(PODType); + typedef void (PODTypeCreator::*SetterMethod)(const PODType&); // Empty value PODTypeWrapperCacheInfo() @@ -338,7 +343,7 @@ template<typename PODType, typename PODTypeCreator> class V8SVGDynamicPODTypeWrapperCache { public: typedef PODType (PODTypeCreator::*GetterMethod)() const; - typedef void (PODTypeCreator::*SetterMethod)(PODType); + typedef void (PODTypeCreator::*SetterMethod)(const PODType&); typedef PODTypeWrapperCacheInfo<PODType, PODTypeCreator> CacheInfo; typedef PODTypeWrapperCacheInfoHash<PODType, PODTypeCreator> CacheInfoHash; @@ -397,14 +402,12 @@ public: template <class P> P V8SVGPODTypeUtil::toSVGPODType(V8ClassIndex::V8WrapperType type, v8::Handle<v8::Value> object, bool& ok) { - void *wrapper = V8DOMWrapper::convertToSVGPODTypeImpl(type, object); - if (wrapper == NULL) { + if (!V8DOMWrapper::isWrapperOfType(object, type)) { ok = false; return P(); - } else { - ok = true; - return *static_cast<V8SVGPODTypeWrapper<P>*>(wrapper); } + ok = true; + return *V8SVGPODTypeWrapper<P>::toNative(v8::Handle<v8::Object>::Cast(object)); } } // namespace WebCore diff --git a/WebCore/bindings/v8/V8Utilities.cpp b/WebCore/bindings/v8/V8Utilities.cpp index c547cc7..fb1ecaa 100644 --- a/WebCore/bindings/v8/V8Utilities.cpp +++ b/WebCore/bindings/v8/V8Utilities.cpp @@ -134,13 +134,15 @@ ScriptExecutionContext* getScriptExecutionContext(ScriptState* scriptState) return proxy->workerContext()->scriptExecutionContext(); #endif - if (scriptState) - return scriptState->frame()->document()->scriptExecutionContext(); - else { - Frame* frame = V8Proxy::retrieveFrameForCurrentContext(); - if (frame) - return frame->document()->scriptExecutionContext(); - } + Frame* frame; + if (scriptState) { + v8::HandleScope handleScope; + frame = V8Proxy::retrieveFrame(scriptState->context()); + } else + frame = V8Proxy::retrieveFrameForCurrentContext(); + + if (frame) + return frame->document()->scriptExecutionContext(); return 0; } @@ -170,7 +172,7 @@ void reportException(ScriptState* scriptState, v8::TryCatch& exceptionCatcher) ScriptExecutionContext* context = getScriptExecutionContext(scriptState); // During the frame teardown, there may not be a valid context. if (context && !context->isDocument()) - context->reportException(errorMessage, lineNumber, sourceURL); + context->reportException(errorMessage, lineNumber, sourceURL); exceptionCatcher.Reset(); } diff --git a/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp b/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp index 412fde0..ac677a2 100644 --- a/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp +++ b/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp @@ -38,6 +38,7 @@ #include "DOMCoreException.h" #include "DedicatedWorkerContext.h" #include "Event.h" +#include "EventSource.h" #include "Notification.h" #include "NotificationCenter.h" #include "EventException.h" @@ -49,6 +50,7 @@ #include "V8DOMMap.h" #include "V8Index.h" #include "V8Proxy.h" +#include "V8WorkerContext.h" #include "V8WorkerContextEventListener.h" #if ENABLE(WEB_SOCKETS) #include "WebSocket.h" @@ -109,7 +111,7 @@ WorkerContextExecutionProxy* WorkerContextExecutionProxy::retrieve() // Return 0 if the current executing context is not the worker context. if (global.IsEmpty()) return 0; - WorkerContext* workerContext = V8DOMWrapper::convertToNativeObject<WorkerContext>(V8ClassIndex::WORKERCONTEXT, global); + WorkerContext* workerContext = V8WorkerContext::toNative(global); return workerContext->script()->proxy(); } @@ -319,6 +321,18 @@ v8::Handle<v8::Value> WorkerContextExecutionProxy::convertEventTargetToV8Object( if (mp) return convertToV8Object(V8ClassIndex::MESSAGEPORT, mp); +#if ENABLE(WEB_SOCKETS) + WebSocket* webSocket = target->toWebSocket(); + if (webSocket) + return convertToV8Object(V8ClassIndex::WEBSOCKET, webSocket); +#endif + +#if ENABLE(EVENTSOURCE) + EventSource* eventSource = target->toEventSource(); + if (eventSource) + return convertToV8Object(V8ClassIndex::EVENTSOURCE, eventSource); +#endif + ASSERT_NOT_REACHED(); return v8::Handle<v8::Value>(); } diff --git a/WebCore/bindings/v8/WorldContextHandle.cpp b/WebCore/bindings/v8/WorldContextHandle.cpp index eb83586..7ba76d3 100644 --- a/WebCore/bindings/v8/WorldContextHandle.cpp +++ b/WebCore/bindings/v8/WorldContextHandle.cpp @@ -31,7 +31,7 @@ #include "config.h" #include "WorldContextHandle.h" -#include "V8IsolatedWorld.h" +#include "V8IsolatedContext.h" namespace WebCore { @@ -41,8 +41,8 @@ WorldContextHandle::WorldContextHandle(WorldToUse worldToUse) if (worldToUse == UseMainWorld) return; - if (V8IsolatedWorld* world = V8IsolatedWorld::getEntered()) - m_context = world->sharedContext(); + if (V8IsolatedContext* context = V8IsolatedContext::getEntered()) + m_context = context->sharedContext(); } v8::Local<v8::Context> WorldContextHandle::adjustedContext(V8Proxy* proxy) const diff --git a/WebCore/bindings/v8/custom/V8AbstractWorkerCustom.cpp b/WebCore/bindings/v8/custom/V8AbstractWorkerCustom.cpp index 0240895..6b8f195 100644 --- a/WebCore/bindings/v8/custom/V8AbstractWorkerCustom.cpp +++ b/WebCore/bindings/v8/custom/V8AbstractWorkerCustom.cpp @@ -31,9 +31,9 @@ #include "config.h" #if ENABLE(WORKERS) +#include "V8AbstractWorker.h" #include "AbstractWorker.h" - #include "ExceptionCode.h" #include "ScriptExecutionContext.h" #include "V8Binding.h" @@ -44,10 +44,10 @@ namespace WebCore { -CALLBACK_FUNC_DECL(AbstractWorkerAddEventListener) +v8::Handle<v8::Value> V8AbstractWorker::addEventListenerCallback(const v8::Arguments& args) { INC_STATS(L"DOM.AbstractWorker.addEventListener()"); - AbstractWorker* worker = V8DOMWrapper::convertToNativeObject<AbstractWorker>(V8ClassIndex::ABSTRACTWORKER, args.Holder()); + AbstractWorker* worker = V8AbstractWorker::toNative(args.Holder()); RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(worker, args[1], false, ListenerFindOrCreate); if (listener) { @@ -55,15 +55,15 @@ CALLBACK_FUNC_DECL(AbstractWorkerAddEventListener) bool useCapture = args[2]->BooleanValue(); worker->addEventListener(type, listener, useCapture); - createHiddenDependency(args.Holder(), args[1], V8Custom::kAbstractWorkerRequestCacheIndex); + createHiddenDependency(args.Holder(), args[1], cacheIndex); } return v8::Undefined(); } -CALLBACK_FUNC_DECL(AbstractWorkerRemoveEventListener) +v8::Handle<v8::Value> V8AbstractWorker::removeEventListenerCallback(const v8::Arguments& args) { INC_STATS(L"DOM.AbstractWorker.removeEventListener()"); - AbstractWorker* worker = V8DOMWrapper::convertToNativeObject<AbstractWorker>(V8ClassIndex::ABSTRACTWORKER, args.Holder()); + AbstractWorker* worker = V8AbstractWorker::toNative(args.Holder()); RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(worker, args[1], false, ListenerFindOnly); if (listener) { @@ -71,7 +71,7 @@ CALLBACK_FUNC_DECL(AbstractWorkerRemoveEventListener) bool useCapture = args[2]->BooleanValue(); worker->removeEventListener(type, listener.get(), useCapture); - removeHiddenDependency(args.Holder(), args[1], V8Custom::kAbstractWorkerRequestCacheIndex); + removeHiddenDependency(args.Holder(), args[1], cacheIndex); } return v8::Undefined(); diff --git a/WebCore/bindings/v8/custom/V8AttrCustom.cpp b/WebCore/bindings/v8/custom/V8AttrCustom.cpp index 81f1586..7bec619 100644 --- a/WebCore/bindings/v8/custom/V8AttrCustom.cpp +++ b/WebCore/bindings/v8/custom/V8AttrCustom.cpp @@ -29,24 +29,25 @@ */ #include "config.h" -#include "Attr.h" +#include "V8Attr.h" +#include "Attr.h" #include "Element.h" #include "ExceptionCode.h" - #include "V8Binding.h" +#include "V8BindingState.h" #include "V8CustomBinding.h" #include "V8Proxy.h" namespace WebCore { -ACCESSOR_SETTER(AttrValue) +void V8Attr::valueAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { - Attr* imp = V8DOMWrapper::convertDOMWrapperToNode<Attr>(info.Holder()); + Attr* imp = V8Attr::toNative(info.Holder()); String attrValue = toWebCoreStringWithNullCheck(value); Element* ownerElement = imp->ownerElement(); - if (ownerElement && !allowSettingSrcToJavascriptURL(ownerElement, imp->name(), attrValue)) + if (ownerElement && !V8BindingSecurity::allowSettingSrcToJavascriptURL(V8BindingState::Only(), ownerElement, imp->name(), attrValue)) return; ExceptionCode ec = 0; diff --git a/WebCore/bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp b/WebCore/bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp index 6bd0035..25d141a 100644 --- a/WebCore/bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp +++ b/WebCore/bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp @@ -29,9 +29,10 @@ */ #include "config.h" -#include "CSSStyleDeclaration.h" +#include "V8CSSStyleDeclaration.h" #include "CSSParser.h" +#include "CSSStyleDeclaration.h" #include "CSSValue.h" #include "CSSPrimitiveValue.h" #include "EventTarget.h" @@ -152,7 +153,7 @@ static CSSPropertyInfo* cssPropertyInfo(v8::Handle<v8::String>v8PropertyName) return propInfo; } -NAMED_PROPERTY_GETTER(CSSStyleDeclaration) +v8::Handle<v8::Value> V8CSSStyleDeclaration::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.CSSStyleDeclaration.NamedPropertyGetter"); // First look for API defined attributes on the style declaration object. @@ -160,8 +161,7 @@ NAMED_PROPERTY_GETTER(CSSStyleDeclaration) return notHandledByInterceptor(); // Search the style declaration. - CSSStyleDeclaration* imp = - V8DOMWrapper::convertToNativeObject<CSSStyleDeclaration>(V8ClassIndex::CSSSTYLEDECLARATION, info.Holder()); + CSSStyleDeclaration* imp = V8CSSStyleDeclaration::toNative(info.Holder()); CSSPropertyInfo* propInfo = cssPropertyInfo(name); // Do not handle non-property names. @@ -191,12 +191,10 @@ NAMED_PROPERTY_GETTER(CSSStyleDeclaration) return v8String(result); } -NAMED_PROPERTY_SETTER(CSSStyleDeclaration) +v8::Handle<v8::Value> V8CSSStyleDeclaration::namedPropertySetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.CSSStyleDeclaration.NamedPropertySetter"); - CSSStyleDeclaration* imp = - V8DOMWrapper::convertToNativeObject<CSSStyleDeclaration>( - V8ClassIndex::CSSSTYLEDECLARATION, info.Holder()); + CSSStyleDeclaration* imp = V8CSSStyleDeclaration::toNative(info.Holder()); CSSPropertyInfo* propInfo = cssPropertyInfo(name); if (!propInfo) return notHandledByInterceptor(); diff --git a/WebCore/bindings/v8/custom/V8CanvasRenderingContext2DCustom.cpp b/WebCore/bindings/v8/custom/V8CanvasRenderingContext2DCustom.cpp index 676610c..b45ef35 100644 --- a/WebCore/bindings/v8/custom/V8CanvasRenderingContext2DCustom.cpp +++ b/WebCore/bindings/v8/custom/V8CanvasRenderingContext2DCustom.cpp @@ -29,9 +29,10 @@ */ #include "config.h" -#include "CanvasRenderingContext2D.h" +#include "V8CanvasRenderingContext2D.h" #include "CanvasGradient.h" +#include "CanvasRenderingContext2D.h" #include "CanvasPattern.h" #include "CanvasStyle.h" #include "ExceptionCode.h" @@ -44,6 +45,7 @@ #include "V8HTMLCanvasElement.h" #include "V8HTMLImageElement.h" #include "V8HTMLVideoElement.h" +#include "V8ImageData.h" #include "V8Proxy.h" namespace WebCore { @@ -65,44 +67,44 @@ static PassRefPtr<CanvasStyle> toCanvasStyle(v8::Handle<v8::Value> value) return CanvasStyle::create(toWebCoreString(value)); if (V8CanvasGradient::HasInstance(value)) - return CanvasStyle::create(V8DOMWrapper::convertDOMWrapperToNative<CanvasGradient>(v8::Handle<v8::Object>::Cast(value))); + return CanvasStyle::create(V8CanvasGradient::toNative(v8::Handle<v8::Object>::Cast(value))); if (V8CanvasPattern::HasInstance(value)) - return CanvasStyle::create(V8DOMWrapper::convertDOMWrapperToNative<CanvasPattern>(v8::Handle<v8::Object>::Cast(value))); + return CanvasStyle::create(V8CanvasPattern::toNative(v8::Handle<v8::Object>::Cast(value))); return 0; } -ACCESSOR_GETTER(CanvasRenderingContext2DStrokeStyle) +v8::Handle<v8::Value> V8CanvasRenderingContext2D::strokeStyleAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { - CanvasRenderingContext2D* impl = V8DOMWrapper::convertDOMWrapperToNative<CanvasRenderingContext2D>(info.Holder()); + CanvasRenderingContext2D* impl = V8CanvasRenderingContext2D::toNative(info.Holder()); return toV8(impl->strokeStyle()); } -ACCESSOR_SETTER(CanvasRenderingContext2DStrokeStyle) +void V8CanvasRenderingContext2D::strokeStyleAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { - CanvasRenderingContext2D* impl = V8DOMWrapper::convertDOMWrapperToNative<CanvasRenderingContext2D>(info.Holder()); + CanvasRenderingContext2D* impl = V8CanvasRenderingContext2D::toNative(info.Holder()); impl->setStrokeStyle(toCanvasStyle(value)); } -ACCESSOR_GETTER(CanvasRenderingContext2DFillStyle) +v8::Handle<v8::Value> V8CanvasRenderingContext2D::fillStyleAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { - CanvasRenderingContext2D* impl = V8DOMWrapper::convertDOMWrapperToNative<CanvasRenderingContext2D>(info.Holder()); + CanvasRenderingContext2D* impl = V8CanvasRenderingContext2D::toNative(info.Holder()); return toV8(impl->fillStyle()); } -ACCESSOR_SETTER(CanvasRenderingContext2DFillStyle) +void V8CanvasRenderingContext2D::fillStyleAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { - CanvasRenderingContext2D* impl = V8DOMWrapper::convertDOMWrapperToNative<CanvasRenderingContext2D>(info.Holder()); + CanvasRenderingContext2D* impl = V8CanvasRenderingContext2D::toNative(info.Holder()); impl->setFillStyle(toCanvasStyle(value)); } // TODO: SetStrokeColor and SetFillColor are similar except function names, // consolidate them into one. -CALLBACK_FUNC_DECL(CanvasRenderingContext2DSetStrokeColor) +v8::Handle<v8::Value> V8CanvasRenderingContext2D::setStrokeColorCallback(const v8::Arguments& args) { INC_STATS("DOM.CanvasRenderingContext2D.setStrokeColor()"); - CanvasRenderingContext2D* context = V8DOMWrapper::convertToNativeObject<CanvasRenderingContext2D>(V8ClassIndex::CANVASRENDERINGCONTEXT2D, args.Holder()); + CanvasRenderingContext2D* context = V8CanvasRenderingContext2D::toNative(args.Holder()); switch (args.Length()) { case 1: if (args[0]->IsString()) @@ -129,10 +131,10 @@ CALLBACK_FUNC_DECL(CanvasRenderingContext2DSetStrokeColor) return v8::Undefined(); } -CALLBACK_FUNC_DECL(CanvasRenderingContext2DSetFillColor) +v8::Handle<v8::Value> V8CanvasRenderingContext2D::setFillColorCallback(const v8::Arguments& args) { INC_STATS("DOM.CanvasRenderingContext2D.setFillColor()"); - CanvasRenderingContext2D* context = V8DOMWrapper::convertToNativeObject<CanvasRenderingContext2D>(V8ClassIndex::CANVASRENDERINGCONTEXT2D, args.Holder()); + CanvasRenderingContext2D* context = V8CanvasRenderingContext2D::toNative(args.Holder()); switch (args.Length()) { case 1: if (args[0]->IsString()) @@ -159,10 +161,10 @@ CALLBACK_FUNC_DECL(CanvasRenderingContext2DSetFillColor) return v8::Undefined(); } -CALLBACK_FUNC_DECL(CanvasRenderingContext2DStrokeRect) +v8::Handle<v8::Value> V8CanvasRenderingContext2D::strokeRectCallback(const v8::Arguments& args) { INC_STATS("DOM.CanvasRenderingContext2D.strokeRect()"); - CanvasRenderingContext2D* context = V8DOMWrapper::convertToNativeObject<CanvasRenderingContext2D>(V8ClassIndex::CANVASRENDERINGCONTEXT2D, args.Holder()); + CanvasRenderingContext2D* context = V8CanvasRenderingContext2D::toNative(args.Holder()); if (args.Length() == 5) context->strokeRect(toFloat(args[0]), toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4])); else if (args.Length() == 4) @@ -174,10 +176,10 @@ CALLBACK_FUNC_DECL(CanvasRenderingContext2DStrokeRect) return v8::Undefined(); } -CALLBACK_FUNC_DECL(CanvasRenderingContext2DSetShadow) +v8::Handle<v8::Value> V8CanvasRenderingContext2D::setShadowCallback(const v8::Arguments& args) { INC_STATS("DOM.CanvasRenderingContext2D.setShadow()"); - CanvasRenderingContext2D* context = V8DOMWrapper::convertToNativeObject<CanvasRenderingContext2D>(V8ClassIndex::CANVASRENDERINGCONTEXT2D, args.Holder()); + CanvasRenderingContext2D* context = V8CanvasRenderingContext2D::toNative(args.Holder()); switch (args.Length()) { case 3: @@ -209,29 +211,29 @@ CALLBACK_FUNC_DECL(CanvasRenderingContext2DSetShadow) return v8::Undefined(); } -CALLBACK_FUNC_DECL(CanvasRenderingContext2DDrawImage) +v8::Handle<v8::Value> V8CanvasRenderingContext2D::drawImageCallback(const v8::Arguments& args) { INC_STATS("DOM.CanvasRenderingContext2D.drawImage()"); - CanvasRenderingContext2D* context = V8DOMWrapper::convertToNativeObject<CanvasRenderingContext2D>(V8ClassIndex::CANVASRENDERINGCONTEXT2D, args.Holder()); + CanvasRenderingContext2D* context = V8CanvasRenderingContext2D::toNative(args.Holder()); v8::Handle<v8::Value> arg = args[0]; if (V8HTMLImageElement::HasInstance(arg)) { ExceptionCode ec = 0; - HTMLImageElement* image_element = V8DOMWrapper::convertDOMWrapperToNode<HTMLImageElement>(v8::Handle<v8::Object>::Cast(arg)); + HTMLImageElement* imageElement = V8HTMLImageElement::toNative(v8::Handle<v8::Object>::Cast(arg)); switch (args.Length()) { case 3: - context->drawImage(image_element, toFloat(args[1]), toFloat(args[2])); + context->drawImage(imageElement, toFloat(args[1]), toFloat(args[2])); break; case 5: - context->drawImage(image_element, toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4]), ec); + context->drawImage(imageElement, toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4]), ec); if (ec != 0) { V8Proxy::setDOMException(ec); return notHandledByInterceptor(); } break; case 9: - context->drawImage(image_element, + context->drawImage(imageElement, FloatRect(toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4])), FloatRect(toFloat(args[5]), toFloat(args[6]), toFloat(args[7]), toFloat(args[8])), ec); @@ -249,20 +251,20 @@ CALLBACK_FUNC_DECL(CanvasRenderingContext2DDrawImage) // HTMLCanvasElement if (V8HTMLCanvasElement::HasInstance(arg)) { ExceptionCode ec = 0; - HTMLCanvasElement* canvas_element = V8DOMWrapper::convertDOMWrapperToNode<HTMLCanvasElement>(v8::Handle<v8::Object>::Cast(arg)); + HTMLCanvasElement* canvasElement = V8HTMLCanvasElement::toNative(v8::Handle<v8::Object>::Cast(arg)); switch (args.Length()) { case 3: - context->drawImage(canvas_element, toFloat(args[1]), toFloat(args[2])); + context->drawImage(canvasElement, toFloat(args[1]), toFloat(args[2])); break; case 5: - context->drawImage(canvas_element, toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4]), ec); + context->drawImage(canvasElement, toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4]), ec); if (ec != 0) { V8Proxy::setDOMException(ec); return notHandledByInterceptor(); } break; case 9: - context->drawImage(canvas_element, + context->drawImage(canvasElement, FloatRect(toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4])), FloatRect(toFloat(args[5]), toFloat(args[6]), toFloat(args[7]), toFloat(args[8])), ec); @@ -281,20 +283,20 @@ CALLBACK_FUNC_DECL(CanvasRenderingContext2DDrawImage) // HTMLVideoElement if (V8HTMLVideoElement::HasInstance(arg)) { ExceptionCode ec = 0; - HTMLVideoElement* video_element = V8DOMWrapper::convertDOMWrapperToNode<HTMLVideoElement>(v8::Handle<v8::Object>::Cast(arg)); + HTMLVideoElement* videoElement = V8HTMLVideoElement::toNative(v8::Handle<v8::Object>::Cast(arg)); switch (args.Length()) { case 3: - context->drawImage(video_element, toFloat(args[1]), toFloat(args[2])); + context->drawImage(videoElement, toFloat(args[1]), toFloat(args[2])); break; case 5: - context->drawImage(video_element, toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4]), ec); + context->drawImage(videoElement, toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4]), ec); if (ec != 0) { V8Proxy::setDOMException(ec); return notHandledByInterceptor(); } break; case 9: - context->drawImage(video_element, + context->drawImage(videoElement, FloatRect(toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4])), FloatRect(toFloat(args[5]), toFloat(args[6]), toFloat(args[7]), toFloat(args[8])), ec); @@ -314,33 +316,34 @@ CALLBACK_FUNC_DECL(CanvasRenderingContext2DDrawImage) return notHandledByInterceptor(); } -CALLBACK_FUNC_DECL(CanvasRenderingContext2DDrawImageFromRect) + +v8::Handle<v8::Value> V8CanvasRenderingContext2D::drawImageFromRectCallback(const v8::Arguments& args) { INC_STATS("DOM.CanvasRenderingContext2D.drawImageFromRect()"); - CanvasRenderingContext2D* context = V8DOMWrapper::convertToNativeObject<CanvasRenderingContext2D>(V8ClassIndex::CANVASRENDERINGCONTEXT2D, args.Holder()); + CanvasRenderingContext2D* context = V8CanvasRenderingContext2D::toNative(args.Holder()); v8::Handle<v8::Value> arg = args[0]; if (V8HTMLImageElement::HasInstance(arg)) { - HTMLImageElement* image_element = V8DOMWrapper::convertDOMWrapperToNode<HTMLImageElement>(v8::Handle<v8::Object>::Cast(arg)); - context->drawImageFromRect(image_element, toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4]), toFloat(args[5]), toFloat(args[6]), toFloat(args[7]), toFloat(args[8]), toWebCoreString(args[9])); + HTMLImageElement* imageElement = V8HTMLImageElement::toNative(v8::Handle<v8::Object>::Cast(arg)); + context->drawImageFromRect(imageElement, toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4]), toFloat(args[5]), toFloat(args[6]), toFloat(args[7]), toFloat(args[8]), toWebCoreString(args[9])); } else V8Proxy::throwError(V8Proxy::TypeError, "drawImageFromRect: Invalid type of arguments"); return v8::Undefined(); } -CALLBACK_FUNC_DECL(CanvasRenderingContext2DCreatePattern) +v8::Handle<v8::Value> V8CanvasRenderingContext2D::createPatternCallback(const v8::Arguments& args) { INC_STATS("DOM.CanvasRenderingContext2D.createPattern()"); - CanvasRenderingContext2D* context = V8DOMWrapper::convertToNativeObject<CanvasRenderingContext2D>(V8ClassIndex::CANVASRENDERINGCONTEXT2D, args.Holder()); + CanvasRenderingContext2D* context = V8CanvasRenderingContext2D::toNative(args.Holder()); v8::Handle<v8::Value> arg = args[0]; if (V8HTMLImageElement::HasInstance(arg)) { - HTMLImageElement* image_element = V8DOMWrapper::convertDOMWrapperToNode<HTMLImageElement>(v8::Handle<v8::Object>::Cast(arg)); + HTMLImageElement* imageElement = V8HTMLImageElement::toNative(v8::Handle<v8::Object>::Cast(arg)); ExceptionCode ec = 0; - RefPtr<CanvasPattern> pattern = context->createPattern(image_element, toWebCoreStringWithNullCheck(args[1]), ec); + RefPtr<CanvasPattern> pattern = context->createPattern(imageElement, toWebCoreStringWithNullCheck(args[1]), ec); if (ec != 0) { V8Proxy::setDOMException(ec); return notHandledByInterceptor(); @@ -349,9 +352,9 @@ CALLBACK_FUNC_DECL(CanvasRenderingContext2DCreatePattern) } if (V8HTMLCanvasElement::HasInstance(arg)) { - HTMLCanvasElement* canvas_element = V8DOMWrapper::convertDOMWrapperToNode<HTMLCanvasElement>(v8::Handle<v8::Object>::Cast(arg)); + HTMLCanvasElement* canvasElement = V8HTMLCanvasElement::toNative(v8::Handle<v8::Object>::Cast(arg)); ExceptionCode ec = 0; - RefPtr<CanvasPattern> pattern = context->createPattern(canvas_element, toWebCoreStringWithNullCheck(args[1]), ec); + RefPtr<CanvasPattern> pattern = context->createPattern(canvasElement, toWebCoreStringWithNullCheck(args[1]), ec); if (ec != 0) { V8Proxy::setDOMException(ec); return notHandledByInterceptor(); @@ -363,11 +366,11 @@ CALLBACK_FUNC_DECL(CanvasRenderingContext2DCreatePattern) return notHandledByInterceptor(); } -CALLBACK_FUNC_DECL(CanvasRenderingContext2DFillText) +v8::Handle<v8::Value> V8CanvasRenderingContext2D::fillTextCallback(const v8::Arguments& args) { INC_STATS("DOM.CanvasRenderingContext2D.fillText()"); - CanvasRenderingContext2D* context = V8DOMWrapper::convertToNativeObject<CanvasRenderingContext2D>(V8ClassIndex::CANVASRENDERINGCONTEXT2D, args.Holder()); + CanvasRenderingContext2D* context = V8CanvasRenderingContext2D::toNative(args.Holder()); // Two forms: // * fillText(text, x, y) @@ -390,10 +393,10 @@ CALLBACK_FUNC_DECL(CanvasRenderingContext2DFillText) return v8::Undefined(); } -CALLBACK_FUNC_DECL(CanvasRenderingContext2DStrokeText) +v8::Handle<v8::Value> V8CanvasRenderingContext2D::strokeTextCallback(const v8::Arguments& args) { INC_STATS("DOM.CanvasRenderingContext2D.strokeText()"); - CanvasRenderingContext2D* context = V8DOMWrapper::convertToNativeObject<CanvasRenderingContext2D>(V8ClassIndex::CANVASRENDERINGCONTEXT2D, args.Holder()); + CanvasRenderingContext2D* context = V8CanvasRenderingContext2D::toNative(args.Holder()); // Two forms: // * strokeText(text, x, y) @@ -416,7 +419,7 @@ CALLBACK_FUNC_DECL(CanvasRenderingContext2DStrokeText) return v8::Undefined(); } -CALLBACK_FUNC_DECL(CanvasRenderingContext2DPutImageData) +v8::Handle<v8::Value> V8CanvasRenderingContext2D::putImageDataCallback(const v8::Arguments& args) { INC_STATS("DOM.CanvasRenderingContext2D.putImageData()"); @@ -428,16 +431,16 @@ CALLBACK_FUNC_DECL(CanvasRenderingContext2DPutImageData) return notHandledByInterceptor(); } - CanvasRenderingContext2D* context = V8DOMWrapper::convertToNativeObject<CanvasRenderingContext2D>(V8ClassIndex::CANVASRENDERINGCONTEXT2D, args.Holder()); + CanvasRenderingContext2D* context = V8CanvasRenderingContext2D::toNative(args.Holder()); ImageData* imageData = 0; // Need to check that the argument is of the correct type, since - // convertToNativeObject() expects it to be correct. If the argument was incorrect + // toNative() expects it to be correct. If the argument was incorrect // we leave it null, and putImageData() will throw the correct exception // (TYPE_MISMATCH_ERR). if (V8DOMWrapper::isWrapperOfType(args[0], V8ClassIndex::IMAGEDATA)) - imageData = V8DOMWrapper::convertToNativeObject<ImageData>(V8ClassIndex::IMAGEDATA, v8::Handle<v8::Object>::Cast(args[0])); + imageData = V8ImageData::toNative(v8::Handle<v8::Object>::Cast(args[0])); ExceptionCode ec = 0; diff --git a/WebCore/bindings/v8/custom/V8ClipboardCustom.cpp b/WebCore/bindings/v8/custom/V8ClipboardCustom.cpp index 4526304..5f0b4e3 100644 --- a/WebCore/bindings/v8/custom/V8ClipboardCustom.cpp +++ b/WebCore/bindings/v8/custom/V8ClipboardCustom.cpp @@ -29,8 +29,9 @@ */ #include "config.h" -#include "Clipboard.h" +#include "V8Clipboard.h" +#include "Clipboard.h" #include "HTMLImageElement.h" #include "HTMLNames.h" #include "IntPoint.h" @@ -44,10 +45,10 @@ namespace WebCore { -ACCESSOR_GETTER(ClipboardTypes) +v8::Handle<v8::Value> V8Clipboard::typesAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.Clipboard.types()"); - Clipboard* clipboard = V8DOMWrapper::convertToNativeObject<Clipboard>(V8ClassIndex::CLIPBOARD, info.Holder()); + Clipboard* clipboard = V8Clipboard::toNative(info.Holder()); HashSet<String> types = clipboard->types(); if (types.isEmpty()) @@ -62,10 +63,10 @@ ACCESSOR_GETTER(ClipboardTypes) return result; } -CALLBACK_FUNC_DECL(ClipboardClearData) +v8::Handle<v8::Value> V8Clipboard::clearDataCallback(const v8::Arguments& args) { INC_STATS("DOM.Clipboard.clearData()"); - Clipboard* clipboard = V8DOMWrapper::convertToNativeObject<Clipboard>(V8ClassIndex::CLIPBOARD, args.Holder()); + Clipboard* clipboard = V8Clipboard::toNative(args.Holder()); if (!args.Length()) { clipboard->clearAllData(); @@ -80,10 +81,10 @@ CALLBACK_FUNC_DECL(ClipboardClearData) return v8::Undefined(); } -CALLBACK_FUNC_DECL(ClipboardGetData) +v8::Handle<v8::Value> V8Clipboard::getDataCallback(const v8::Arguments& args) { INC_STATS("DOM.Clipboard.getData()"); - Clipboard* clipboard = V8DOMWrapper::convertToNativeObject<Clipboard>(V8ClassIndex::CLIPBOARD, args.Holder()); + Clipboard* clipboard = V8Clipboard::toNative(args.Holder()); if (args.Length() != 1) return throwError("getData: Invalid number of arguments", V8Proxy::SyntaxError); @@ -96,10 +97,10 @@ CALLBACK_FUNC_DECL(ClipboardGetData) return v8::Undefined(); } -CALLBACK_FUNC_DECL(ClipboardSetData) +v8::Handle<v8::Value> V8Clipboard::setDataCallback(const v8::Arguments& args) { INC_STATS("DOM.Clipboard.setData()"); - Clipboard* clipboard = V8DOMWrapper::convertToNativeObject<Clipboard>(V8ClassIndex::CLIPBOARD, args.Holder()); + Clipboard* clipboard = V8Clipboard::toNative(args.Holder()); if (args.Length() != 2) return throwError("setData: Invalid number of arguments", V8Proxy::SyntaxError); @@ -109,10 +110,10 @@ CALLBACK_FUNC_DECL(ClipboardSetData) return v8Boolean(clipboard->setData(type, data)); } -CALLBACK_FUNC_DECL(ClipboardSetDragImage) +v8::Handle<v8::Value> V8Clipboard::setDragImageCallback(const v8::Arguments& args) { INC_STATS("DOM.Clipboard.setDragImage()"); - Clipboard* clipboard = V8DOMWrapper::convertToNativeObject<Clipboard>(V8ClassIndex::CLIPBOARD, args.Holder()); + Clipboard* clipboard = V8Clipboard::toNative(args.Holder()); if (!clipboard->isForDragging()) return v8::Undefined(); @@ -125,7 +126,7 @@ CALLBACK_FUNC_DECL(ClipboardSetDragImage) Node* node = 0; if (V8Node::HasInstance(args[0])) - node = V8DOMWrapper::convertDOMWrapperToNode<Node>(v8::Handle<v8::Object>::Cast(args[0])); + node = V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])); if (!node || !node->isElementNode()) return throwError("setDragImageFromElement: Invalid first argument"); diff --git a/WebCore/bindings/v8/custom/V8ConsoleCustom.cpp b/WebCore/bindings/v8/custom/V8ConsoleCustom.cpp index b44e074..0dbdcd7 100644 --- a/WebCore/bindings/v8/custom/V8ConsoleCustom.cpp +++ b/WebCore/bindings/v8/custom/V8ConsoleCustom.cpp @@ -29,6 +29,7 @@ */ #include "config.h" +#include "V8Console.h" #include "V8Binding.h" #include "V8CustomBinding.h" @@ -37,7 +38,7 @@ namespace WebCore { -CALLBACK_FUNC_DECL(ConsoleProfile) +v8::Handle<v8::Value> V8Console::profileCallback(const v8::Arguments& args) { INC_STATS("console.profile()"); v8::HandleScope scope; @@ -46,7 +47,7 @@ CALLBACK_FUNC_DECL(ConsoleProfile) return v8::Undefined(); } -CALLBACK_FUNC_DECL(ConsoleProfileEnd) +v8::Handle<v8::Value> V8Console::profileEndCallback(const v8::Arguments& args) { INC_STATS("console.profileEnd()"); v8::V8::PauseProfiler(); diff --git a/WebCore/bindings/v8/custom/V8CoordinatesCustom.cpp b/WebCore/bindings/v8/custom/V8CoordinatesCustom.cpp index 1c07f29..a5197f5 100644 --- a/WebCore/bindings/v8/custom/V8CoordinatesCustom.cpp +++ b/WebCore/bindings/v8/custom/V8CoordinatesCustom.cpp @@ -24,49 +24,50 @@ */ #include "config.h" -#include "Coordinates.h" +#include "V8Coordinates.h" +#include "Coordinates.h" #include "V8Binding.h" #include "V8CustomBinding.h" #include "V8Proxy.h" namespace WebCore { -ACCESSOR_GETTER(CoordinatesAltitude) +v8::Handle<v8::Value> V8Coordinates::altitudeAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.Coordinates.altitude._get"); v8::Handle<v8::Object> holder = info.Holder(); - Coordinates* imp = V8DOMWrapper::convertToNativeObject<Coordinates>(V8ClassIndex::COORDINATES, holder); + Coordinates* imp = V8Coordinates::toNative(holder); if (!imp->canProvideAltitude()) return v8::Null(); return v8::Number::New(imp->altitude()); } -ACCESSOR_GETTER(CoordinatesAltitudeAccuracy) +v8::Handle<v8::Value> V8Coordinates::altitudeAccuracyAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.Coordinates.altitudeAccuracy._get"); v8::Handle<v8::Object> holder = info.Holder(); - Coordinates* imp = V8DOMWrapper::convertToNativeObject<Coordinates>(V8ClassIndex::COORDINATES, holder); + Coordinates* imp = V8Coordinates::toNative(holder); if (!imp->canProvideAltitudeAccuracy()) return v8::Null(); return v8::Number::New(imp->altitudeAccuracy()); } -ACCESSOR_GETTER(CoordinatesHeading) +v8::Handle<v8::Value> V8Coordinates::headingAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.Coordinates.heading._get"); v8::Handle<v8::Object> holder = info.Holder(); - Coordinates* imp = V8DOMWrapper::convertToNativeObject<Coordinates>(V8ClassIndex::COORDINATES, holder); + Coordinates* imp = V8Coordinates::toNative(holder); if (!imp->canProvideHeading()) return v8::Null(); return v8::Number::New(imp->heading()); } -ACCESSOR_GETTER(CoordinatesSpeed) +v8::Handle<v8::Value> V8Coordinates::speedAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.Coordinates.speed._get"); v8::Handle<v8::Object> holder = info.Holder(); - Coordinates* imp = V8DOMWrapper::convertToNativeObject<Coordinates>(V8ClassIndex::COORDINATES, holder); + Coordinates* imp = V8Coordinates::toNative(holder); if (!imp->canProvideSpeed()) return v8::Null(); return v8::Number::New(imp->speed()); diff --git a/WebCore/bindings/v8/custom/V8CustomBinding.cpp b/WebCore/bindings/v8/custom/V8CustomBinding.cpp deleted file mode 100644 index 510aded..0000000 --- a/WebCore/bindings/v8/custom/V8CustomBinding.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (C) 2007-2009 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "V8CustomBinding.h" - -#include "CSSHelper.h" -#include "Element.h" -#include "Document.h" -#include "DOMWindow.h" -#include "History.h" -#include "HTMLNames.h" -#include "HTMLFrameElementBase.h" -#include "Location.h" -#include "V8Proxy.h" - -#if ENABLE(SVG) -#include "SVGPathSeg.h" -#endif - -namespace WebCore { - -bool allowSettingFrameSrcToJavascriptUrl(HTMLFrameElementBase* frame, String value) -{ - if (protocolIs(deprecatedParseURL(value), "javascript")) { - Node* contentDoc = frame->contentDocument(); - if (contentDoc && !V8Proxy::checkNodeSecurity(contentDoc)) - return false; - } - return true; -} - -bool allowSettingSrcToJavascriptURL(Element* element, String name, String value) -{ - if ((element->hasTagName(HTMLNames::iframeTag) || element->hasTagName(HTMLNames::frameTag)) && equalIgnoringCase(name, "src")) - return allowSettingFrameSrcToJavascriptUrl(static_cast<HTMLFrameElementBase*>(element), value); - return true; -} - -// DOMImplementation is a singleton in WebCore. If we use our normal -// mapping from DOM objects to V8 wrappers, the same wrapper will be -// shared for all frames in the same process. This is a major -// security problem. Therefore, we generate a DOMImplementation -// wrapper per document and store it in an internal field of the -// document. Since the DOMImplementation object is a singleton, we do -// not have to do anything to keep the DOMImplementation object alive -// for the lifetime of the wrapper. -ACCESSOR_GETTER(DocumentImplementation) -{ - ASSERT(info.Holder()->InternalFieldCount() >= kDocumentMinimumInternalFieldCount); - - // Check if the internal field already contains a wrapper. - v8::Local<v8::Value> implementation = info.Holder()->GetInternalField(kDocumentImplementationIndex); - if (!implementation->IsUndefined()) - return implementation; - - // Generate a wrapper. - Document* document = V8DOMWrapper::convertDOMWrapperToNative<Document>(info.Holder()); - v8::Handle<v8::Value> wrapper = V8DOMWrapper::convertDOMImplementationToV8Object(document->implementation()); - - // Store the wrapper in the internal field. - info.Holder()->SetInternalField(kDocumentImplementationIndex, wrapper); - - return wrapper; -} - -// --------------- Security Checks ------------------------- -INDEXED_ACCESS_CHECK(History) -{ - ASSERT(V8ClassIndex::FromInt(data->Int32Value()) == V8ClassIndex::HISTORY); - // Only allow same origin access. - History* history = V8DOMWrapper::convertToNativeObject<History>(V8ClassIndex::HISTORY, host); - return V8Proxy::canAccessFrame(history->frame(), false); -} - -NAMED_ACCESS_CHECK(History) -{ - ASSERT(V8ClassIndex::FromInt(data->Int32Value()) == V8ClassIndex::HISTORY); - // Only allow same origin access. - History* history = V8DOMWrapper::convertToNativeObject<History>(V8ClassIndex::HISTORY, host); - return V8Proxy::canAccessFrame(history->frame(), false); -} - -#undef INDEXED_ACCESS_CHECK -#undef NAMED_ACCESS_CHECK -#undef NAMED_PROPERTY_GETTER -#undef NAMED_PROPERTY_SETTER - -Frame* V8Custom::GetTargetFrame(v8::Local<v8::Object> host, v8::Local<v8::Value> data) -{ - Frame* target = 0; - switch (V8ClassIndex::FromInt(data->Int32Value())) { - case V8ClassIndex::DOMWINDOW: { - v8::Handle<v8::Object> window = V8DOMWrapper::lookupDOMWrapper(V8ClassIndex::DOMWINDOW, host); - if (window.IsEmpty()) - return target; - - DOMWindow* targetWindow = V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, window); - target = targetWindow->frame(); - break; - } - case V8ClassIndex::LOCATION: { - History* history = V8DOMWrapper::convertToNativeObject<History>(V8ClassIndex::HISTORY, host); - target = history->frame(); - break; - } - case V8ClassIndex::HISTORY: { - Location* location = V8DOMWrapper::convertToNativeObject<Location>(V8ClassIndex::LOCATION, host); - target = location->frame(); - break; - } - default: - break; - } - return target; -} - -#if ENABLE(SVG) -V8ClassIndex::V8WrapperType V8Custom::DowncastSVGPathSeg(void* pathSeg) -{ - WebCore::SVGPathSeg* realPathSeg = reinterpret_cast<WebCore::SVGPathSeg*>(pathSeg); - - switch (realPathSeg->pathSegType()) { -#define MAKE_CASE(svgValue, v8Value) case WebCore::SVGPathSeg::svgValue: return V8ClassIndex::v8Value - - MAKE_CASE(PATHSEG_CLOSEPATH, SVGPATHSEGCLOSEPATH); - MAKE_CASE(PATHSEG_MOVETO_ABS, SVGPATHSEGMOVETOABS); - MAKE_CASE(PATHSEG_MOVETO_REL, SVGPATHSEGMOVETOREL); - MAKE_CASE(PATHSEG_LINETO_ABS, SVGPATHSEGLINETOABS); - MAKE_CASE(PATHSEG_LINETO_REL, SVGPATHSEGLINETOREL); - MAKE_CASE(PATHSEG_CURVETO_CUBIC_ABS, SVGPATHSEGCURVETOCUBICABS); - MAKE_CASE(PATHSEG_CURVETO_CUBIC_REL, SVGPATHSEGCURVETOCUBICREL); - MAKE_CASE(PATHSEG_CURVETO_QUADRATIC_ABS, SVGPATHSEGCURVETOQUADRATICABS); - MAKE_CASE(PATHSEG_CURVETO_QUADRATIC_REL, SVGPATHSEGCURVETOQUADRATICREL); - MAKE_CASE(PATHSEG_ARC_ABS, SVGPATHSEGARCABS); - MAKE_CASE(PATHSEG_ARC_REL, SVGPATHSEGARCREL); - MAKE_CASE(PATHSEG_LINETO_HORIZONTAL_ABS, SVGPATHSEGLINETOHORIZONTALABS); - MAKE_CASE(PATHSEG_LINETO_HORIZONTAL_REL, SVGPATHSEGLINETOHORIZONTALREL); - MAKE_CASE(PATHSEG_LINETO_VERTICAL_ABS, SVGPATHSEGLINETOVERTICALABS); - MAKE_CASE(PATHSEG_LINETO_VERTICAL_REL, SVGPATHSEGLINETOVERTICALREL); - MAKE_CASE(PATHSEG_CURVETO_CUBIC_SMOOTH_ABS, SVGPATHSEGCURVETOCUBICSMOOTHABS); - MAKE_CASE(PATHSEG_CURVETO_CUBIC_SMOOTH_REL, SVGPATHSEGCURVETOCUBICSMOOTHREL); - MAKE_CASE(PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS, SVGPATHSEGCURVETOQUADRATICSMOOTHABS); - MAKE_CASE(PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL, SVGPATHSEGCURVETOQUADRATICSMOOTHREL); - -#undef MAKE_CASE - - default: - return V8ClassIndex::INVALID_CLASS_INDEX; - } -} - -#endif // ENABLE(SVG) - -} // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8CustomBinding.h b/WebCore/bindings/v8/custom/V8CustomBinding.h index e7670b7..25f4507 100644 --- a/WebCore/bindings/v8/custom/V8CustomBinding.h +++ b/WebCore/bindings/v8/custom/V8CustomBinding.h @@ -34,308 +34,16 @@ #include "V8Index.h" #include <v8.h> -struct NPObject; - -#define CALLBACK_FUNC_DECL(NAME) v8::Handle<v8::Value> V8Custom::v8##NAME##Callback(const v8::Arguments& args) - -#define ACCESSOR_GETTER(NAME) \ - v8::Handle<v8::Value> V8Custom::v8##NAME##AccessorGetter( \ - v8::Local<v8::String> name, const v8::AccessorInfo& info) - -#define ACCESSOR_SETTER(NAME) \ - void V8Custom::v8##NAME##AccessorSetter(v8::Local<v8::String> name, \ - v8::Local<v8::Value> value, const v8::AccessorInfo& info) - -#define INDEXED_PROPERTY_GETTER(NAME) \ - v8::Handle<v8::Value> V8Custom::v8##NAME##IndexedPropertyGetter( \ - uint32_t index, const v8::AccessorInfo& info) - -#define INDEXED_PROPERTY_SETTER(NAME) \ - v8::Handle<v8::Value> V8Custom::v8##NAME##IndexedPropertySetter( \ - uint32_t index, v8::Local<v8::Value> value, const v8::AccessorInfo& info) - -#define INDEXED_PROPERTY_DELETER(NAME) \ - v8::Handle<v8::Boolean> V8Custom::v8##NAME##IndexedPropertyDeleter( \ - uint32_t index, const v8::AccessorInfo& info) - -#define NAMED_PROPERTY_GETTER(NAME) \ - v8::Handle<v8::Value> V8Custom::v8##NAME##NamedPropertyGetter( \ - v8::Local<v8::String> name, const v8::AccessorInfo& info) - -#define NAMED_PROPERTY_SETTER(NAME) \ - v8::Handle<v8::Value> V8Custom::v8##NAME##NamedPropertySetter( \ - v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) - -#define NAMED_PROPERTY_DELETER(NAME) \ - v8::Handle<v8::Boolean> V8Custom::v8##NAME##NamedPropertyDeleter( \ - v8::Local<v8::String> name, const v8::AccessorInfo& info) - -#define NAMED_ACCESS_CHECK(NAME) \ - bool V8Custom::v8##NAME##NamedSecurityCheck(v8::Local<v8::Object> host, \ - v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value> data) - -#define INDEXED_ACCESS_CHECK(NAME) \ - bool V8Custom::v8##NAME##IndexedSecurityCheck(v8::Local<v8::Object> host, \ - uint32_t index, v8::AccessType type, v8::Local<v8::Value> data) - -#define ACCESSOR_RUNTIME_ENABLER(NAME) bool V8Custom::v8##NAME##Enabled() - namespace WebCore { - - class DOMWindow; - class Element; - class Frame; - class HTMLCollection; - class HTMLFrameElementBase; - class String; - class V8Proxy; - - bool allowSettingFrameSrcToJavascriptUrl(HTMLFrameElementBase*, String value); - bool allowSettingSrcToJavascriptURL(Element*, String name, String value); - class V8Custom { public: - // Constants. - static const int kDOMWrapperTypeIndex = 0; - static const int kDOMWrapperObjectIndex = 1; - static const int kDefaultWrapperInternalFieldCount = 2; - - static const int kNPObjectInternalFieldCount = kDefaultWrapperInternalFieldCount + 0; - - static const int kNodeEventListenerCacheIndex = kDefaultWrapperInternalFieldCount + 0; - static const int kNodeMinimumInternalFieldCount = kDefaultWrapperInternalFieldCount + 1; - - static const int kDocumentImplementationIndex = kNodeMinimumInternalFieldCount + 0; - static const int kDocumentMinimumInternalFieldCount = kNodeMinimumInternalFieldCount + 1; - - static const int kHTMLDocumentMarkerIndex = kDocumentMinimumInternalFieldCount + 0; - static const int kHTMLDocumentShadowIndex = kDocumentMinimumInternalFieldCount + 1; - static const int kHTMLDocumentInternalFieldCount = kDocumentMinimumInternalFieldCount + 2; - - static const int kXMLHttpRequestCacheIndex = kDefaultWrapperInternalFieldCount + 0; - static const int kXMLHttpRequestInternalFieldCount = kDefaultWrapperInternalFieldCount + 1; - - static const int kMessageChannelPort1Index = kDefaultWrapperInternalFieldCount + 0; - static const int kMessageChannelPort2Index = kDefaultWrapperInternalFieldCount + 1; - static const int kMessageChannelInternalFieldCount = kDefaultWrapperInternalFieldCount + 2; - - static const int kMessagePortRequestCacheIndex = kDefaultWrapperInternalFieldCount + 0; - static const int kMessagePortInternalFieldCount = kDefaultWrapperInternalFieldCount + 1; - -#if ENABLE(WORKERS) - static const int kAbstractWorkerRequestCacheIndex = kDefaultWrapperInternalFieldCount + 0; - static const int kAbstractWorkerInternalFieldCount = kDefaultWrapperInternalFieldCount + 1; - - static const int kWorkerRequestCacheIndex = kAbstractWorkerInternalFieldCount + 0; - static const int kWorkerInternalFieldCount = kAbstractWorkerInternalFieldCount + 1; - - static const int kWorkerContextRequestCacheIndex = kDefaultWrapperInternalFieldCount + 0; - static const int kWorkerContextMinimumInternalFieldCount = kDefaultWrapperInternalFieldCount + 1; - - static const int kDedicatedWorkerContextRequestCacheIndex = kWorkerContextMinimumInternalFieldCount + 0; - static const int kDedicatedWorkerContextInternalFieldCount = kWorkerContextMinimumInternalFieldCount + 1; -#endif - -#if ENABLE(SHARED_WORKERS) - static const int kSharedWorkerRequestCacheIndex = kAbstractWorkerInternalFieldCount + 0; - static const int kSharedWorkerInternalFieldCount = kAbstractWorkerInternalFieldCount + 1; - - static const int kSharedWorkerContextRequestCacheIndex = kWorkerContextMinimumInternalFieldCount + 0; - static const int kSharedWorkerContextInternalFieldCount = kWorkerContextMinimumInternalFieldCount + 1; -#endif - -#if ENABLE(NOTIFICATIONS) - static const int kNotificationRequestCacheIndex = kDefaultWrapperInternalFieldCount + 0; - static const int kNotificationInternalFieldCount = kDefaultWrapperInternalFieldCount + 1; -#endif - -#if ENABLE(SVG) - static const int kSVGElementInstanceEventListenerCacheIndex = kDefaultWrapperInternalFieldCount + 0; - static const int kSVGElementInstanceInternalFieldCount = kDefaultWrapperInternalFieldCount + 1; -#endif - - static const int kDOMWindowConsoleIndex = kDefaultWrapperInternalFieldCount + 0; - static const int kDOMWindowHistoryIndex = kDefaultWrapperInternalFieldCount + 1; - static const int kDOMWindowLocationbarIndex = kDefaultWrapperInternalFieldCount + 2; - static const int kDOMWindowMenubarIndex = kDefaultWrapperInternalFieldCount + 3; - static const int kDOMWindowNavigatorIndex = kDefaultWrapperInternalFieldCount + 4; - static const int kDOMWindowPersonalbarIndex = kDefaultWrapperInternalFieldCount + 5; - static const int kDOMWindowScreenIndex = kDefaultWrapperInternalFieldCount + 6; - static const int kDOMWindowScrollbarsIndex = kDefaultWrapperInternalFieldCount + 7; - static const int kDOMWindowSelectionIndex = kDefaultWrapperInternalFieldCount + 8; - static const int kDOMWindowStatusbarIndex = kDefaultWrapperInternalFieldCount + 9; - static const int kDOMWindowToolbarIndex = kDefaultWrapperInternalFieldCount + 10; - static const int kDOMWindowLocationIndex = kDefaultWrapperInternalFieldCount + 11; - static const int kDOMWindowDOMSelectionIndex = kDefaultWrapperInternalFieldCount + 12; - static const int kDOMWindowEventListenerCacheIndex = kDefaultWrapperInternalFieldCount + 13; - static const int kDOMWindowEnteredIsolatedWorldIndex = kDefaultWrapperInternalFieldCount + 14; - static const int kDOMWindowInternalFieldCount = kDefaultWrapperInternalFieldCount + 15; - - static const int kStyleSheetOwnerNodeIndex = kDefaultWrapperInternalFieldCount + 0; - static const int kStyleSheetInternalFieldCount = kDefaultWrapperInternalFieldCount + 1; - static const int kNamedNodeMapOwnerNodeIndex = kDefaultWrapperInternalFieldCount + 0; - static const int kNamedNodeMapInternalFieldCount = kDefaultWrapperInternalFieldCount + 1; - -#if ENABLE(OFFLINE_WEB_APPLICATIONS) - static const int kDOMApplicationCacheCacheIndex = kDefaultWrapperInternalFieldCount + 0; - static const int kDOMApplicationCacheFieldCount = kDefaultWrapperInternalFieldCount + 1; -#endif - -#if ENABLE(WEB_SOCKETS) - static const int kWebSocketCacheIndex = kDefaultWrapperInternalFieldCount + 0; - static const int kWebSocketInternalFieldCount = kDefaultWrapperInternalFieldCount + 1; -#endif - -#define DECLARE_PROPERTY_ACCESSOR_GETTER(NAME) \ - static v8::Handle<v8::Value> v8##NAME##AccessorGetter( \ - v8::Local<v8::String> name, const v8::AccessorInfo& info) - -#define DECLARE_PROPERTY_ACCESSOR_SETTER(NAME) \ - static void v8##NAME##AccessorSetter(v8::Local<v8::String> name, \ - v8::Local<v8::Value> value, const v8::AccessorInfo& info) - -#define DECLARE_PROPERTY_ACCESSOR(NAME) DECLARE_PROPERTY_ACCESSOR_GETTER(NAME); DECLARE_PROPERTY_ACCESSOR_SETTER(NAME) - -#define DECLARE_NAMED_PROPERTY_GETTER(NAME) \ - static v8::Handle<v8::Value> v8##NAME##NamedPropertyGetter( \ - v8::Local<v8::String> name, const v8::AccessorInfo& info) - -#define DECLARE_NAMED_PROPERTY_SETTER(NAME) \ - static v8::Handle<v8::Value> v8##NAME##NamedPropertySetter( \ - v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) - -#define DECLARE_NAMED_PROPERTY_DELETER(NAME) \ - static v8::Handle<v8::Boolean> v8##NAME##NamedPropertyDeleter( \ - v8::Local<v8::String> name, const v8::AccessorInfo& info) - -#define USE_NAMED_PROPERTY_GETTER(NAME) V8Custom::v8##NAME##NamedPropertyGetter - -#define USE_NAMED_PROPERTY_SETTER(NAME) V8Custom::v8##NAME##NamedPropertySetter - -#define USE_NAMED_PROPERTY_DELETER(NAME) V8Custom::v8##NAME##NamedPropertyDeleter - -#define DECLARE_INDEXED_PROPERTY_GETTER(NAME) \ - static v8::Handle<v8::Value> v8##NAME##IndexedPropertyGetter( \ - uint32_t index, const v8::AccessorInfo& info) - -#define DECLARE_INDEXED_PROPERTY_SETTER(NAME) \ - static v8::Handle<v8::Value> v8##NAME##IndexedPropertySetter( \ - uint32_t index, v8::Local<v8::Value> value, const v8::AccessorInfo& info) - -#define DECLARE_INDEXED_PROPERTY_DELETER(NAME) \ - static v8::Handle<v8::Boolean> v8##NAME##IndexedPropertyDeleter( \ - uint32_t index, const v8::AccessorInfo& info) - -#define USE_INDEXED_PROPERTY_GETTER(NAME) V8Custom::v8##NAME##IndexedPropertyGetter - -#define USE_INDEXED_PROPERTY_SETTER(NAME) V8Custom::v8##NAME##IndexedPropertySetter - -#define USE_INDEXED_PROPERTY_DELETER(NAME) V8Custom::v8##NAME##IndexedPropertyDeleter - #define DECLARE_CALLBACK(NAME) static v8::Handle<v8::Value> v8##NAME##Callback(const v8::Arguments& args) - #define USE_CALLBACK(NAME) V8Custom::v8##NAME##Callback -#define DECLARE_NAMED_ACCESS_CHECK(NAME) \ - static bool v8##NAME##NamedSecurityCheck(v8::Local<v8::Object> host, \ - v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value> data) - -#define DECLARE_INDEXED_ACCESS_CHECK(NAME) \ - static bool v8##NAME##IndexedSecurityCheck(v8::Local<v8::Object> host, \ - uint32_t index, v8::AccessType type, v8::Local<v8::Value> data) - -#define DECLARE_ACCESSOR_RUNTIME_ENABLER(NAME) static bool v8##NAME##Enabled() - - DECLARE_PROPERTY_ACCESSOR(CanvasRenderingContext2DStrokeStyle); - DECLARE_PROPERTY_ACCESSOR(CanvasRenderingContext2DFillStyle); - DECLARE_PROPERTY_ACCESSOR(DOMWindowEvent); - DECLARE_PROPERTY_ACCESSOR_GETTER(DOMWindowCrypto); - DECLARE_PROPERTY_ACCESSOR_SETTER(DOMWindowLocation); - DECLARE_PROPERTY_ACCESSOR_SETTER(DOMWindowOpener); - -#if ENABLE(VIDEO) - DECLARE_PROPERTY_ACCESSOR_GETTER(DOMWindowAudio); - DECLARE_ACCESSOR_RUNTIME_ENABLER(DOMWindowAudio); - DECLARE_ACCESSOR_RUNTIME_ENABLER(DOMWindowHTMLMediaElement); - DECLARE_ACCESSOR_RUNTIME_ENABLER(DOMWindowHTMLAudioElement); - DECLARE_ACCESSOR_RUNTIME_ENABLER(DOMWindowHTMLVideoElement); - DECLARE_ACCESSOR_RUNTIME_ENABLER(DOMWindowMediaError); -#endif - - DECLARE_PROPERTY_ACCESSOR_GETTER(DOMWindowImage); - DECLARE_PROPERTY_ACCESSOR_GETTER(DOMWindowOption); - - DECLARE_PROPERTY_ACCESSOR(DocumentLocation); - DECLARE_PROPERTY_ACCESSOR(DocumentImplementation); - DECLARE_PROPERTY_ACCESSOR_GETTER(EventSrcElement); - DECLARE_PROPERTY_ACCESSOR(EventReturnValue); - DECLARE_PROPERTY_ACCESSOR_GETTER(EventDataTransfer); - DECLARE_PROPERTY_ACCESSOR_GETTER(EventClipboardData); - - DECLARE_PROPERTY_ACCESSOR(DOMWindowEventHandler); - - DECLARE_CALLBACK(HTMLCanvasElementGetContext); - - DECLARE_PROPERTY_ACCESSOR_SETTER(HTMLFrameElementSrc); - DECLARE_PROPERTY_ACCESSOR_SETTER(HTMLFrameElementLocation); - DECLARE_PROPERTY_ACCESSOR_SETTER(HTMLIFrameElementSrc); - - DECLARE_PROPERTY_ACCESSOR_SETTER(AttrValue); - - DECLARE_PROPERTY_ACCESSOR(HTMLOptionsCollectionLength); - - DECLARE_CALLBACK(HTMLInputElementSetSelectionRange); - - DECLARE_PROPERTY_ACCESSOR(HTMLInputElementSelectionStart); - DECLARE_PROPERTY_ACCESSOR(HTMLInputElementSelectionEnd); - - DECLARE_NAMED_ACCESS_CHECK(Location); - DECLARE_INDEXED_ACCESS_CHECK(History); - - DECLARE_NAMED_ACCESS_CHECK(History); - DECLARE_INDEXED_ACCESS_CHECK(Location); - - DECLARE_CALLBACK(HTMLCollectionItem); - DECLARE_CALLBACK(HTMLCollectionNamedItem); - DECLARE_CALLBACK(HTMLCollectionCallAsFunction); - - DECLARE_CALLBACK(HTMLAllCollectionItem); - DECLARE_CALLBACK(HTMLAllCollectionNamedItem); - DECLARE_CALLBACK(HTMLAllCollectionCallAsFunction); - - DECLARE_CALLBACK(HTMLSelectElementRemove); - - DECLARE_CALLBACK(HTMLOptionsCollectionRemove); - DECLARE_CALLBACK(HTMLOptionsCollectionAdd); - - DECLARE_CALLBACK(HTMLDocumentWrite); - DECLARE_CALLBACK(HTMLDocumentWriteln); - DECLARE_CALLBACK(HTMLDocumentOpen); - DECLARE_PROPERTY_ACCESSOR(HTMLDocumentAll); - DECLARE_NAMED_PROPERTY_GETTER(HTMLDocument); - DECLARE_NAMED_PROPERTY_DELETER(HTMLDocument); - - DECLARE_CALLBACK(DocumentEvaluate); - DECLARE_CALLBACK(DocumentGetCSSCanvasContext); - - DECLARE_CALLBACK(DOMWindowAddEventListener); - DECLARE_CALLBACK(DOMWindowRemoveEventListener); - DECLARE_CALLBACK(DOMWindowPostMessage); - DECLARE_CALLBACK(DOMWindowSetTimeout); - DECLARE_CALLBACK(DOMWindowSetInterval); - DECLARE_CALLBACK(DOMWindowAtob); - DECLARE_CALLBACK(DOMWindowBtoa); - DECLARE_CALLBACK(DOMWindowNOP); - DECLARE_CALLBACK(DOMWindowToString); - DECLARE_CALLBACK(DOMWindowShowModalDialog); - DECLARE_CALLBACK(DOMWindowOpen); - DECLARE_CALLBACK(DOMWindowClearTimeout); - DECLARE_CALLBACK(DOMWindowClearInterval); - - DECLARE_CALLBACK(DOMParserConstructor); DECLARE_CALLBACK(HTMLAudioElementConstructor); DECLARE_CALLBACK(HTMLImageElementConstructor); DECLARE_CALLBACK(HTMLOptionElementConstructor); +<<<<<<< HEAD DECLARE_CALLBACK(MessageChannelConstructor); DECLARE_CALLBACK(WebKitCSSMatrixConstructor); DECLARE_CALLBACK(WebKitPointConstructor); @@ -714,27 +422,11 @@ namespace WebCore { #undef DECLARE_INDEXED_PROPERTY_GETTER #undef DECLARE_INDEXED_PROPERTY_SETTER #undef DECLARE_INDEXED_PROPERTY_DELETER +======= +>>>>>>> webkit.org at r54127 #undef DECLARE_CALLBACK - - // Returns the NPObject corresponding to an HTMLElement object. - static NPObject* GetHTMLPlugInElementNPObject(v8::Handle<v8::Object>); - - // Returns the owner frame pointer of a DOM wrapper object. It only works for - // these DOM objects requiring cross-domain access check. - static Frame* GetTargetFrame(v8::Local<v8::Object> host, v8::Local<v8::Value> data); - - // Special case for downcasting SVG path segments. -#if ENABLE(SVG) - static V8ClassIndex::V8WrapperType DowncastSVGPathSeg(void* pathSeg); -#endif - - private: - static v8::Handle<v8::Value> WindowSetTimeoutImpl(const v8::Arguments&, bool singleShot); - static void ClearTimeoutImpl(const v8::Arguments&); - static void WindowSetLocation(DOMWindow*, const String&); }; - } // namespace WebCore #endif // V8CustomBinding_h diff --git a/WebCore/bindings/v8/custom/V8DOMApplicationCacheCustom.cpp b/WebCore/bindings/v8/custom/V8DOMApplicationCacheCustom.cpp index 134de95..a439432 100644 --- a/WebCore/bindings/v8/custom/V8DOMApplicationCacheCustom.cpp +++ b/WebCore/bindings/v8/custom/V8DOMApplicationCacheCustom.cpp @@ -29,11 +29,12 @@ */ #include "config.h" -#include "DOMApplicationCache.h" +#include "V8DOMApplicationCache.h" #if ENABLE(OFFLINE_WEB_APPLICATIONS) #include "ApplicationCacheHost.h" +#include "DOMApplicationCache.h" #include "V8Binding.h" #include "V8CustomBinding.h" #include "V8Document.h" @@ -44,14 +45,14 @@ namespace WebCore { // Handles appcache.addEventListner(name, func, capture) method calls -CALLBACK_FUNC_DECL(DOMApplicationCacheAddEventListener) +v8::Handle<v8::Value> V8DOMApplicationCache::addEventListenerCallback(const v8::Arguments& args) { INC_STATS("DOMApplicationCache.addEventListener()"); - DOMApplicationCache* appcache = V8DOMWrapper::convertToNativeObject<DOMApplicationCache>(V8ClassIndex::DOMAPPLICATIONCACHE, args.Holder()); + DOMApplicationCache* appcache = V8DOMApplicationCache::toNative(args.Holder()); RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(appcache, args[1], false, ListenerFindOrCreate); if (listener) { - createHiddenDependency(args.Holder(), args[1], V8Custom::kDOMApplicationCacheCacheIndex); + createHiddenDependency(args.Holder(), args[1], cacheIndex); String eventType = toWebCoreString(args[0]); bool useCapture = args[2]->BooleanValue(); appcache->addEventListener(eventType, listener, useCapture); @@ -60,14 +61,14 @@ CALLBACK_FUNC_DECL(DOMApplicationCacheAddEventListener) } // Handles appcache.removeEventListner(name, func, capture) method calls -CALLBACK_FUNC_DECL(DOMApplicationCacheRemoveEventListener) +v8::Handle<v8::Value> V8DOMApplicationCache::removeEventListenerCallback(const v8::Arguments& args) { INC_STATS("DOMApplicationCache.removeEventListener()"); - DOMApplicationCache* appcache = V8DOMWrapper::convertToNativeObject<DOMApplicationCache>(V8ClassIndex::DOMAPPLICATIONCACHE, args.Holder()); + DOMApplicationCache* appcache = V8DOMApplicationCache::toNative(args.Holder()); RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(appcache, args[1], false, ListenerFindOnly); if (listener) { - removeHiddenDependency(args.Holder(), args[1], V8Custom::kDOMApplicationCacheCacheIndex); + removeHiddenDependency(args.Holder(), args[1], cacheIndex); String eventType = toWebCoreString(args[0]); bool useCapture = args[2]->BooleanValue(); appcache->removeEventListener(eventType, listener.get(), useCapture); diff --git a/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp b/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp index 46c33b9..2933b4d 100644 --- a/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp +++ b/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp @@ -29,22 +29,19 @@ */ #include "config.h" -#include "DOMWindow.h" - -#include "V8Binding.h" -#include "V8CustomBinding.h" -#include "V8CustomEventListener.h" -#include "V8MessagePortCustom.h" -#include "V8Proxy.h" -#include "V8Utilities.h" +#include "V8DOMWindow.h" #include "Base64.h" -#include "ExceptionCode.h" +#include "Chrome.h" +#include "Database.h" #include "DOMTimer.h" +#include "DOMWindow.h" +#include "ExceptionCode.h" #include "Frame.h" #include "FrameLoadRequest.h" #include "FrameView.h" #include "HTMLCollection.h" +#include "HTMLDocument.h" #include "MediaPlayer.h" #include "Page.h" #include "PlatformScreen.h" @@ -55,6 +52,14 @@ #include "Settings.h" #include "SharedWorkerRepository.h" #include "Storage.h" +#include "V8Binding.h" +#include "V8BindingDOMWindow.h" +#include "V8BindingState.h" +#include "V8CustomBinding.h" +#include "V8CustomEventListener.h" +#include "V8MessagePortCustom.h" +#include "V8Proxy.h" +#include "V8Utilities.h" #if ENABLE(WEB_SOCKETS) #include "WebSocket.h" #endif @@ -66,7 +71,7 @@ static const int popupTilePixels = 10; namespace WebCore { -v8::Handle<v8::Value> V8Custom::WindowSetTimeoutImpl(const v8::Arguments& args, bool singleShot) +v8::Handle<v8::Value> WindowSetTimeoutImpl(const v8::Arguments& args, bool singleShot) { int argumentCount = args.Length(); @@ -99,9 +104,9 @@ v8::Handle<v8::Value> V8Custom::WindowSetTimeoutImpl(const v8::Arguments& args, if (argumentCount >= 2) timeout = args[1]->Int32Value(); - DOMWindow* imp = V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, args.Holder()); + DOMWindow* imp = V8DOMWindow::toNative(args.Holder()); - if (!V8Proxy::canAccessFrame(imp->frame(), true)) + if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), true)) return v8::Undefined(); ScriptExecutionContext* scriptContext = static_cast<ScriptExecutionContext*>(imp->document()); @@ -164,14 +169,14 @@ static v8::Handle<v8::Value> convertBase64(const String& str, bool encode) return v8String(String(outputCharacters.data(), outputCharacters.size())); } -ACCESSOR_GETTER(DOMWindowEvent) +v8::Handle<v8::Value> V8DOMWindow::eventAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { v8::Handle<v8::Object> holder = V8DOMWrapper::lookupDOMWrapper(V8ClassIndex::DOMWINDOW, info.This()); if (holder.IsEmpty()) return v8::Undefined(); - Frame* frame = V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, holder)->frame(); - if (!V8Proxy::canAccessFrame(frame, true)) + Frame* frame = V8DOMWindow::toNative(holder)->frame(); + if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), frame, true)) return v8::Undefined(); v8::Local<v8::Context> context = V8Proxy::context(frame); @@ -185,14 +190,14 @@ ACCESSOR_GETTER(DOMWindowEvent) return jsEvent; } -ACCESSOR_SETTER(DOMWindowEvent) +void V8DOMWindow::eventAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { v8::Handle<v8::Object> holder = V8DOMWrapper::lookupDOMWrapper(V8ClassIndex::DOMWINDOW, info.This()); if (holder.IsEmpty()) return; - Frame* frame = V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, holder)->frame(); - if (!V8Proxy::canAccessFrame(frame, true)) + Frame* frame = V8DOMWindow::toNative(holder)->frame(); + if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), frame, true)) return; v8::Local<v8::Context> context = V8Proxy::context(frame); @@ -203,24 +208,24 @@ ACCESSOR_SETTER(DOMWindowEvent) context->Global()->SetHiddenValue(eventSymbol, value); } -ACCESSOR_GETTER(DOMWindowCrypto) +v8::Handle<v8::Value> V8DOMWindow::cryptoAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { // FIXME: Implement me. return v8::Undefined(); } -ACCESSOR_SETTER(DOMWindowLocation) +void V8DOMWindow::locationAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { - DOMWindow* imp = V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, info.Holder()); - WindowSetLocation(imp, toWebCoreString(value)); + DOMWindow* imp = V8DOMWindow::toNative(info.Holder()); + V8DOMWindowShell::setLocation(imp, toWebCoreString(value)); } -ACCESSOR_SETTER(DOMWindowOpener) +void V8DOMWindow::openerAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { - DOMWindow* imp = V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, info.Holder()); + DOMWindow* imp = V8DOMWindow::toNative(info.Holder()); - if (!V8Proxy::canAccessFrame(imp->frame(), true)) + if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), true)) return; // Opener can be shadowed if it is in the same domain. @@ -242,33 +247,33 @@ ACCESSOR_SETTER(DOMWindowOpener) #if ENABLE(VIDEO) -ACCESSOR_GETTER(DOMWindowAudio) +v8::Handle<v8::Value> V8DOMWindow::AudioAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { - DOMWindow* window = V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, info.Holder()); + DOMWindow* window = V8DOMWindow::toNative(info.Holder()); return V8DOMWrapper::getConstructor(V8ClassIndex::AUDIO, window); } -ACCESSOR_RUNTIME_ENABLER(DOMWindowAudio) +bool V8DOMWindow::AudioEnabled() { return MediaPlayer::isAvailable(); } -ACCESSOR_RUNTIME_ENABLER(DOMWindowHTMLMediaElement) +bool V8DOMWindow::HTMLMediaElementEnabled() { return MediaPlayer::isAvailable(); } -ACCESSOR_RUNTIME_ENABLER(DOMWindowHTMLAudioElement) +bool V8DOMWindow::HTMLAudioElementEnabled() { return MediaPlayer::isAvailable(); } -ACCESSOR_RUNTIME_ENABLER(DOMWindowHTMLVideoElement) +bool V8DOMWindow::HTMLVideoElementEnabled() { return MediaPlayer::isAvailable(); } -ACCESSOR_RUNTIME_ENABLER(DOMWindowMediaError) +bool V8DOMWindow::MediaErrorEnabled() { return MediaPlayer::isAvailable(); } @@ -276,74 +281,81 @@ ACCESSOR_RUNTIME_ENABLER(DOMWindowMediaError) #endif #if ENABLE(SHARED_WORKERS) -ACCESSOR_RUNTIME_ENABLER(DOMWindowSharedWorker) +bool V8DOMWindow::SharedWorkerEnabled() { return SharedWorkerRepository::isAvailable(); } #endif #if ENABLE(WEB_SOCKETS) -ACCESSOR_RUNTIME_ENABLER(DOMWindowWebSocket) +bool V8DOMWindow::WebSocketEnabled() { return WebSocket::isAvailable(); } #endif #if ENABLE(DATABASE) -ACCESSOR_RUNTIME_ENABLER(DOMWindowOpenDatabase) +bool V8DOMWindow::OpenDatabaseEnabled() +{ + return Database::isAvailable(); +} +#endif + +#if ENABLE(INDEXED_DATABASE) +bool V8DOMWindow::IndexedDBEnabled() { - return WebCore::RuntimeEnabledFeatures::databaseEnabled(); + return RuntimeEnabledFeatures::indexedDatabaseEnabled(); } #endif #if ENABLE(DOM_STORAGE) -ACCESSOR_RUNTIME_ENABLER(DOMWindowLocalStorage) +bool V8DOMWindow::LocalStorageEnabled() { return RuntimeEnabledFeatures::localStorageEnabled(); } -ACCESSOR_RUNTIME_ENABLER(DOMWindowSessionStorage) +bool V8DOMWindow::SessionStorageEnabled() { return RuntimeEnabledFeatures::sessionStorageEnabled(); } #endif #if ENABLE(NOTIFICATIONS) -ACCESSOR_RUNTIME_ENABLER(DOMWindowWebkitNotifications) +bool V8DOMWindow::WebkitNotificationsEnabled() { return RuntimeEnabledFeatures::notificationsEnabled(); } #endif #if ENABLE(OFFLINE_WEB_APPLICATIONS) -ACCESSOR_RUNTIME_ENABLER(DOMWindowApplicationCache) +bool V8DOMWindow::ApplicationCacheEnabled() { return RuntimeEnabledFeatures::applicationCacheEnabled(); } #endif -ACCESSOR_GETTER(DOMWindowImage) +v8::Handle<v8::Value> V8DOMWindow::ImageAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { - DOMWindow* window = V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, info.Holder()); + DOMWindow* window = V8DOMWindow::toNative(info.Holder()); return V8DOMWrapper::getConstructor(V8ClassIndex::IMAGE, window); } -ACCESSOR_GETTER(DOMWindowOption) +v8::Handle<v8::Value> V8DOMWindow::OptionAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { - DOMWindow* window = V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, info.Holder()); + DOMWindow* window = V8DOMWindow::toNative(info.Holder()); return V8DOMWrapper::getConstructor(V8ClassIndex::OPTION, window); } -CALLBACK_FUNC_DECL(DOMWindowAddEventListener) +v8::Handle<v8::Value> V8DOMWindow::addEventListenerCallback(const v8::Arguments& args) { INC_STATS("DOM.DOMWindow.addEventListener()"); String eventType = toWebCoreString(args[0]); bool useCapture = args[2]->BooleanValue(); - DOMWindow* imp = V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, args.Holder()); + DOMWindow* imp = V8DOMWindow::toNative(args.Holder()); - if (!V8Proxy::canAccessFrame(imp->frame(), true)) + if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), true)) return v8::Undefined(); Document* doc = imp->document(); @@ -360,23 +372,23 @@ CALLBACK_FUNC_DECL(DOMWindowAddEventListener) if (listener) { imp->addEventListener(eventType, listener, useCapture); - createHiddenDependency(args.Holder(), args[1], V8Custom::kDOMWindowEventListenerCacheIndex); + createHiddenDependency(args.Holder(), args[1], cacheIndex); } return v8::Undefined(); } -CALLBACK_FUNC_DECL(DOMWindowRemoveEventListener) +v8::Handle<v8::Value> V8DOMWindow::removeEventListenerCallback(const v8::Arguments& args) { INC_STATS("DOM.DOMWindow.removeEventListener()"); String eventType = toWebCoreString(args[0]); bool useCapture = args[2]->BooleanValue(); - DOMWindow* imp = V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, args.Holder()); + DOMWindow* imp = V8DOMWindow::toNative(args.Holder()); - if (!V8Proxy::canAccessFrame(imp->frame(), true)) + if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), true)) return v8::Undefined(); Document* doc = imp->document(); @@ -392,22 +404,22 @@ CALLBACK_FUNC_DECL(DOMWindowRemoveEventListener) if (listener) { imp->removeEventListener(eventType, listener.get(), useCapture); - removeHiddenDependency(args.Holder(), args[1], V8Custom::kDOMWindowEventListenerCacheIndex); + removeHiddenDependency(args.Holder(), args[1], cacheIndex); } return v8::Undefined(); } -CALLBACK_FUNC_DECL(DOMWindowPostMessage) +v8::Handle<v8::Value> V8DOMWindow::postMessageCallback(const v8::Arguments& args) { INC_STATS("DOM.DOMWindow.postMessage()"); - DOMWindow* window = V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, args.Holder()); + DOMWindow* window = V8DOMWindow::toNative(args.Holder()); DOMWindow* source = V8Proxy::retrieveFrameForCallingContext()->domWindow(); ASSERT(source->frame()); v8::TryCatch tryCatch; - RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(toWebCoreString(args[0])); + RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0]); MessagePortArray portArray; String targetOrigin; @@ -431,7 +443,7 @@ CALLBACK_FUNC_DECL(DOMWindowPostMessage) return throwError(ec); } -CALLBACK_FUNC_DECL(DOMWindowAtob) +v8::Handle<v8::Value> V8DOMWindow::atobCallback(const v8::Arguments& args) { INC_STATS("DOM.DOMWindow.atob()"); @@ -439,9 +451,9 @@ CALLBACK_FUNC_DECL(DOMWindowAtob) return v8String(""); String str = toWebCoreString(args[0]); - DOMWindow* imp = V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, args.Holder()); + DOMWindow* imp = V8DOMWindow::toNative(args.Holder()); - if (!V8Proxy::canAccessFrame(imp->frame(), true)) + if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), true)) return v8::Undefined(); if (args.Length() < 1) @@ -450,7 +462,7 @@ CALLBACK_FUNC_DECL(DOMWindowAtob) return convertBase64(str, false); } -CALLBACK_FUNC_DECL(DOMWindowBtoa) +v8::Handle<v8::Value> V8DOMWindow::btoaCallback(const v8::Arguments& args) { INC_STATS("DOM.DOMWindow.btoa()"); @@ -458,9 +470,9 @@ CALLBACK_FUNC_DECL(DOMWindowBtoa) return v8String(""); String str = toWebCoreString(args[0]); - DOMWindow* imp = V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, args.Holder()); + DOMWindow* imp = V8DOMWindow::toNative(args.Holder()); - if (!V8Proxy::canAccessFrame(imp->frame(), true)) + if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), true)) return v8::Undefined(); if (args.Length() < 1) @@ -473,7 +485,7 @@ CALLBACK_FUNC_DECL(DOMWindowBtoa) // fix this by calling toString function on the receiver. // However, V8 implements toString in JavaScript, which requires // switching context of receiver. I consider it is dangerous. -CALLBACK_FUNC_DECL(DOMWindowToString) +v8::Handle<v8::Value> V8DOMWindow::toStringCallback(const v8::Arguments& args) { INC_STATS("DOM.DOMWindow.toString()"); v8::Handle<v8::Object> domWrapper = V8DOMWrapper::lookupDOMWrapper(V8ClassIndex::DOMWINDOW, args.This()); @@ -482,7 +494,13 @@ CALLBACK_FUNC_DECL(DOMWindowToString) return domWrapper->ObjectProtoToString(); } -CALLBACK_FUNC_DECL(DOMWindowNOP) +v8::Handle<v8::Value> V8DOMWindow::releaseEventsCallback(const v8::Arguments& args) +{ + INC_STATS("DOM.DOMWindow.nop()"); + return v8::Undefined(); +} + +v8::Handle<v8::Value> V8DOMWindow::captureEventsCallback(const v8::Arguments& args) { INC_STATS("DOM.DOMWindow.nop()"); return v8::Undefined(); @@ -538,78 +556,7 @@ static HashMap<String, String> parseModalDialogFeatures(const String& featuresAr return map; } - -static Frame* createWindow(Frame* callingFrame, - Frame* enteredFrame, - Frame* openerFrame, - const String& url, - const String& frameName, - const WindowFeatures& windowFeatures, - v8::Local<v8::Value> dialogArgs) -{ - ASSERT(callingFrame); - ASSERT(enteredFrame); - - // Sandboxed iframes cannot open new auxiliary browsing contexts. - if (callingFrame && callingFrame->loader()->isSandboxed(SandboxNavigation)) - return 0; - - ResourceRequest request; - - // For whatever reason, Firefox uses the entered frame to determine - // the outgoingReferrer. We replicate that behavior here. - String referrer = enteredFrame->loader()->outgoingReferrer(); - request.setHTTPReferrer(referrer); - FrameLoader::addHTTPOriginIfNeeded(request, enteredFrame->loader()->outgoingOrigin()); - FrameLoadRequest frameRequest(request, frameName); - - // FIXME: It's much better for client API if a new window starts with a URL, - // here where we know what URL we are going to open. Unfortunately, this - // code passes the empty string for the URL, but there's a reason for that. - // Before loading we have to set up the opener, openedByDOM, - // and dialogArguments values. Also, to decide whether to use the URL - // we currently do an allowsAccessFrom call using the window we create, - // which can't be done before creating it. We'd have to resolve all those - // issues to pass the URL instead of "". - - bool created; - // We pass in the opener frame here so it can be used for looking up the - // frame name, in case the active frame is different from the opener frame, - // and the name references a frame relative to the opener frame, for example - // "_self" or "_parent". - Frame* newFrame = callingFrame->loader()->createWindow(openerFrame->loader(), frameRequest, windowFeatures, created); - if (!newFrame) - return 0; - - newFrame->loader()->setOpener(openerFrame); - newFrame->page()->setOpenedByDOM(); - - // Set dialog arguments on the global object of the new frame. - if (!dialogArgs.IsEmpty()) { - v8::Local<v8::Context> context = V8Proxy::context(newFrame); - if (!context.IsEmpty()) { - v8::Context::Scope scope(context); - context->Global()->Set(v8::String::New("dialogArguments"), dialogArgs); - } - } - - if (protocolIsJavaScript(url) || ScriptController::isSafeScript(newFrame)) { - KURL completedUrl = - url.isEmpty() ? KURL(ParsedURLString, "") : completeURL(url); - bool userGesture = processingUserGesture(); - - if (created) - newFrame->loader()->changeLocation(completedUrl, referrer, false, false, userGesture); - else if (!url.isEmpty()) - newFrame->redirectScheduler()->scheduleLocationChange(completedUrl.string(), referrer, false, userGesture); - } - - return newFrame; -} - - - -CALLBACK_FUNC_DECL(DOMWindowShowModalDialog) +v8::Handle<v8::Value> V8DOMWindow::showModalDialogCallback(const v8::Arguments& args) { INC_STATS("DOM.DOMWindow.showModalDialog()"); @@ -617,11 +564,10 @@ CALLBACK_FUNC_DECL(DOMWindowShowModalDialog) v8::Local<v8::Value> dialogArgs = args[1]; String featureArgs = toWebCoreStringWithNullOrUndefinedCheck(args[2]); - DOMWindow* window = V8DOMWrapper::convertToNativeObject<DOMWindow>( - V8ClassIndex::DOMWINDOW, args.Holder()); + DOMWindow* window = V8DOMWindow::toNative(args.Holder()); Frame* frame = window->frame(); - if (!V8Proxy::canAccessFrame(frame, true)) + if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), frame, true)) return v8::Undefined(); Frame* callingFrame = V8Proxy::retrieveFrameForCallingContext(); @@ -674,7 +620,7 @@ CALLBACK_FUNC_DECL(DOMWindowShowModalDialog) windowFeatures.locationBarVisible = false; windowFeatures.fullscreen = false; - Frame* dialogFrame = createWindow(callingFrame, enteredFrame, frame, url, "", windowFeatures, dialogArgs); + Frame* dialogFrame = V8BindingDOMWindow::createWindow(V8BindingState::Only(), callingFrame, enteredFrame, frame, url, "", windowFeatures, dialogArgs); if (!dialogFrame) return v8::Undefined(); @@ -699,17 +645,17 @@ CALLBACK_FUNC_DECL(DOMWindowShowModalDialog) } -CALLBACK_FUNC_DECL(DOMWindowOpen) +v8::Handle<v8::Value> V8DOMWindow::openCallback(const v8::Arguments& args) { INC_STATS("DOM.DOMWindow.open()"); String urlString = toWebCoreStringWithNullOrUndefinedCheck(args[0]); AtomicString frameName = (args[1]->IsUndefined() || args[1]->IsNull()) ? "_blank" : AtomicString(toWebCoreString(args[1])); - DOMWindow* parent = V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, args.Holder()); + DOMWindow* parent = V8DOMWindow::toNative(args.Holder()); Frame* frame = parent->frame(); - if (!V8Proxy::canAccessFrame(frame, true)) + if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), frame, true)) return v8::Undefined(); Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext(); @@ -817,7 +763,7 @@ CALLBACK_FUNC_DECL(DOMWindowOpen) windowFeatures.ySet = false; } - frame = createWindow(callingFrame, enteredFrame, frame, urlString, frameName, windowFeatures, v8::Local<v8::Value>()); + frame = V8BindingDOMWindow::createWindow(V8BindingState::Only(), callingFrame, enteredFrame, frame, urlString, frameName, windowFeatures, v8::Local<v8::Value>()); if (!frame) return v8::Undefined(); @@ -826,11 +772,11 @@ CALLBACK_FUNC_DECL(DOMWindowOpen) } -INDEXED_PROPERTY_GETTER(DOMWindow) +v8::Handle<v8::Value> V8DOMWindow::indexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info) { INC_STATS("DOM.DOMWindow.IndexedPropertyGetter"); - DOMWindow* window = V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, info.Holder()); + DOMWindow* window = V8DOMWindow::toNative(info.Holder()); if (!window) return notHandledByInterceptor(); @@ -846,12 +792,11 @@ INDEXED_PROPERTY_GETTER(DOMWindow) } -NAMED_PROPERTY_GETTER(DOMWindow) +v8::Handle<v8::Value> V8DOMWindow::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.DOMWindow.NamedPropertyGetter"); - // TODO(antonm): investigate what convertToNativeObject does for the case of DOMWINDOW. - DOMWindow* window = V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, info.Holder()); + DOMWindow* window = V8DOMWindow::toNative(info.Holder()); if (!window) return notHandledByInterceptor(); @@ -874,13 +819,14 @@ NAMED_PROPERTY_GETTER(DOMWindow) // Search named items in the document. Document* doc = frame->document(); - if (doc) { - RefPtr<HTMLCollection> items = doc->windowNamedItems(propName); - if (items->length() >= 1) { - if (items->length() == 1) - return V8DOMWrapper::convertNodeToV8Object(items->firstItem()); - else + if (doc && doc->isHTMLDocument()) { + if (static_cast<HTMLDocument*>(doc)->hasNamedItem(propName.impl()) || doc->hasElementWithId(propName.impl())) { + RefPtr<HTMLCollection> items = doc->windowNamedItems(propName); + if (items->length() >= 1) { + if (items->length() == 1) + return V8DOMWrapper::convertNodeToV8Object(items->firstItem()); return V8DOMWrapper::convertToV8Object(V8ClassIndex::HTMLCOLLECTION, items.release()); + } } } @@ -888,44 +834,27 @@ NAMED_PROPERTY_GETTER(DOMWindow) } -void V8Custom::WindowSetLocation(DOMWindow* window, const String& relativeURL) -{ - Frame* frame = window->frame(); - if (!frame) - return; - - KURL url = completeURL(relativeURL); - if (url.isNull()) - return; - - if (!shouldAllowNavigation(frame)) - return; - - navigateIfAllowed(frame, url, false, false); -} - - -CALLBACK_FUNC_DECL(DOMWindowSetTimeout) +v8::Handle<v8::Value> V8DOMWindow::setTimeoutCallback(const v8::Arguments& args) { INC_STATS("DOM.DOMWindow.setTimeout()"); return WindowSetTimeoutImpl(args, true); } -CALLBACK_FUNC_DECL(DOMWindowSetInterval) +v8::Handle<v8::Value> V8DOMWindow::setIntervalCallback(const v8::Arguments& args) { INC_STATS("DOM.DOMWindow.setInterval()"); return WindowSetTimeoutImpl(args, false); } -void V8Custom::ClearTimeoutImpl(const v8::Arguments& args) +void ClearTimeoutImpl(const v8::Arguments& args) { int handle = toInt32(args[0]); v8::Handle<v8::Object> holder = args.Holder(); - DOMWindow* imp = V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, holder); - if (!V8Proxy::canAccessFrame(imp->frame(), true)) + DOMWindow* imp = V8DOMWindow::toNative(holder); + if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), true)) return; ScriptExecutionContext* context = static_cast<ScriptExecutionContext*>(imp->document()); if (!context) @@ -934,28 +863,28 @@ void V8Custom::ClearTimeoutImpl(const v8::Arguments& args) } -CALLBACK_FUNC_DECL(DOMWindowClearTimeout) +v8::Handle<v8::Value> V8DOMWindow::clearTimeoutCallback(const v8::Arguments& args) { INC_STATS("DOM.DOMWindow.clearTimeout"); ClearTimeoutImpl(args); return v8::Undefined(); } -CALLBACK_FUNC_DECL(DOMWindowClearInterval) +v8::Handle<v8::Value> V8DOMWindow::clearIntervalCallback(const v8::Arguments& args) { INC_STATS("DOM.DOMWindow.clearInterval"); ClearTimeoutImpl(args); return v8::Undefined(); } -NAMED_ACCESS_CHECK(DOMWindow) +bool V8DOMWindow::namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value> data) { ASSERT(V8ClassIndex::FromInt(data->Int32Value()) == V8ClassIndex::DOMWINDOW); v8::Handle<v8::Object> window = V8DOMWrapper::lookupDOMWrapper(V8ClassIndex::DOMWINDOW, host); if (window.IsEmpty()) return false; // the frame is gone. - DOMWindow* targetWindow = V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, window); + DOMWindow* targetWindow = V8DOMWindow::toNative(window); ASSERT(targetWindow); @@ -971,17 +900,17 @@ NAMED_ACCESS_CHECK(DOMWindow) return true; } - return V8Proxy::canAccessFrame(target, false); + return V8BindingSecurity::canAccessFrame(V8BindingState::Only(), target, false); } -INDEXED_ACCESS_CHECK(DOMWindow) +bool V8DOMWindow::indexedSecurityCheck(v8::Local<v8::Object> host, uint32_t index, v8::AccessType type, v8::Local<v8::Value> data) { ASSERT(V8ClassIndex::FromInt(data->Int32Value()) == V8ClassIndex::DOMWINDOW); v8::Handle<v8::Object> window = V8DOMWrapper::lookupDOMWrapper(V8ClassIndex::DOMWINDOW, host); if (window.IsEmpty()) return false; - DOMWindow* targetWindow = V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, window); + DOMWindow* targetWindow = V8DOMWindow::toNative(window); ASSERT(targetWindow); @@ -993,7 +922,7 @@ INDEXED_ACCESS_CHECK(DOMWindow) if ((type == v8::ACCESS_GET || type == v8::ACCESS_HAS) && target->tree()->child(index)) return true; - return V8Proxy::canAccessFrame(target, false); + return V8BindingSecurity::canAccessFrame(V8BindingState::Only(), target, false); } } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8DataGridColumnListCustom.cpp b/WebCore/bindings/v8/custom/V8DataGridColumnListCustom.cpp index 1dde996..8980cfe 100644 --- a/WebCore/bindings/v8/custom/V8DataGridColumnListCustom.cpp +++ b/WebCore/bindings/v8/custom/V8DataGridColumnListCustom.cpp @@ -40,16 +40,6 @@ namespace WebCore { -INDEXED_PROPERTY_GETTER(DataGridColumnList) -{ - INC_STATS("DataGridColumnList.IndexedPropertyGetter"); - DataGridColumnList* imp = V8DOMWrapper::convertToNativeObject<DataGridColumnList>(V8ClassIndex::DATAGRIDCOLUMNLIST, info.Holder()); - DataGridColumn* result = imp->item(index); - if (!result) - return notHandledByInterceptor(); - return V8DOMWrapper::convertToV8Object(V8ClassIndex::DATAGRIDCOLUMN, result); -} - NAMED_PROPERTY_GETTER(DataGridColumnList) { INC_STATS("DataGridColumnList.NamedPropertyGetter"); @@ -63,7 +53,7 @@ NAMED_PROPERTY_GETTER(DataGridColumnList) return notHandledByInterceptor(); // Finally, look up a column by name. - DataGridColumnList* imp = V8DOMWrapper::convertToNativeObject<DataGridColumnList>(V8ClassIndex::DATAGRIDCOLUMNLIST, info.Holder()); + DataGridColumnList* imp = V8DataGridColumnList::toNative(info.Holder()); DataGridColumn* result = imp->itemWithName(toWebCoreString(name)); if (!result) return notHandledByInterceptor(); diff --git a/WebCore/bindings/v8/custom/V8DatabaseCustom.cpp b/WebCore/bindings/v8/custom/V8DatabaseCustom.cpp index 9ddd620..c83e1cc 100644 --- a/WebCore/bindings/v8/custom/V8DatabaseCustom.cpp +++ b/WebCore/bindings/v8/custom/V8DatabaseCustom.cpp @@ -31,6 +31,7 @@ #include "config.h" #if ENABLE(DATABASE) +#include "V8Database.h" #include "Database.h" #include "V8Binding.h" @@ -42,7 +43,7 @@ namespace WebCore { -CALLBACK_FUNC_DECL(DatabaseChangeVersion) +v8::Handle<v8::Value> V8Database::changeVersionCallback(const v8::Arguments& args) { INC_STATS("DOM.Database.changeVersion()"); @@ -52,7 +53,7 @@ CALLBACK_FUNC_DECL(DatabaseChangeVersion) if (!(args[0]->IsString() && args[1]->IsString())) return throwError("The old and new versions must be strings."); - Database* database = V8DOMWrapper::convertToNativeObject<Database>(V8ClassIndex::DATABASE, args.Holder()); + Database* database = V8Database::toNative(args.Holder()); Frame* frame = V8Proxy::retrieveFrameForCurrentContext(); if (!frame) @@ -95,7 +96,7 @@ static v8::Handle<v8::Value> createTransaction(const v8::Arguments& args, bool r if (!args[0]->IsObject()) return throwError("Transaction callback must be of valid type."); - Database* database = V8DOMWrapper::convertToNativeObject<Database>(V8ClassIndex::DATABASE, args.Holder()); + Database* database = V8Database::toNative(args.Holder()); Frame* frame = V8Proxy::retrieveFrameForCurrentContext(); if (!frame) @@ -123,13 +124,13 @@ static v8::Handle<v8::Value> createTransaction(const v8::Arguments& args, bool r return v8::Undefined(); } -CALLBACK_FUNC_DECL(DatabaseTransaction) +v8::Handle<v8::Value> V8Database::transactionCallback(const v8::Arguments& args) { INC_STATS("DOM.Database.transaction()"); return createTransaction(args, false); } -CALLBACK_FUNC_DECL(DatabaseReadTransaction) +v8::Handle<v8::Value> V8Database::readTransactionCallback(const v8::Arguments& args) { INC_STATS("DOM.Database.readTransaction()"); return createTransaction(args, true); diff --git a/WebCore/bindings/v8/custom/V8DedicatedWorkerContextCustom.cpp b/WebCore/bindings/v8/custom/V8DedicatedWorkerContextCustom.cpp index 263c005..4486dbe 100644 --- a/WebCore/bindings/v8/custom/V8DedicatedWorkerContextCustom.cpp +++ b/WebCore/bindings/v8/custom/V8DedicatedWorkerContextCustom.cpp @@ -31,10 +31,10 @@ #include "config.h" #if ENABLE(WORKERS) - -#include "WorkerContextExecutionProxy.h" +#include "V8DedicatedWorkerContext.h" #include "DedicatedWorkerContext.h" +#include "WorkerContextExecutionProxy.h" #include "V8Binding.h" #include "V8MessagePortCustom.h" #include "V8Proxy.h" @@ -42,11 +42,11 @@ namespace WebCore { -CALLBACK_FUNC_DECL(DedicatedWorkerContextPostMessage) +v8::Handle<v8::Value> V8DedicatedWorkerContext::postMessageCallback(const v8::Arguments& args) { INC_STATS(L"DOM.DedicatedWorkerContext.postMessage"); - DedicatedWorkerContext* workerContext = V8DOMWrapper::convertToNativeObject<DedicatedWorkerContext>(V8ClassIndex::DEDICATEDWORKERCONTEXT, args.Holder()); - RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(v8ValueToWebCoreString(args[0])); + DedicatedWorkerContext* workerContext = V8DedicatedWorkerContext::toNative(args.Holder()); + RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0]); MessagePortArray portArray; if (args.Length() > 1) { if (!getMessagePortArray(args[1], portArray)) diff --git a/WebCore/bindings/v8/custom/V8DocumentCustom.cpp b/WebCore/bindings/v8/custom/V8DocumentCustom.cpp index ee68293..4aedde5 100644 --- a/WebCore/bindings/v8/custom/V8DocumentCustom.cpp +++ b/WebCore/bindings/v8/custom/V8DocumentCustom.cpp @@ -29,9 +29,10 @@ */ #include "config.h" -#include "Document.h" +#include "V8Document.h" #include "CanvasRenderingContext.h" +#include "Document.h" #include "ExceptionCode.h" #include "Node.h" #include "XPathNSResolver.h" @@ -53,16 +54,21 @@ namespace WebCore { -CALLBACK_FUNC_DECL(DocumentEvaluate) +v8::Handle<v8::Value> V8Document::evaluateCallback(const v8::Arguments& args) { INC_STATS("DOM.Document.evaluate()"); +<<<<<<< HEAD #if ENABLE(XPATH) RefPtr<Document> document = V8DOMWrapper::convertDOMWrapperToNode<Document>(args.Holder()); +======= + + RefPtr<Document> document = V8Document::toNative(args.Holder()); +>>>>>>> webkit.org at r54127 ExceptionCode ec = 0; String expression = toWebCoreString(args[0]); RefPtr<Node> contextNode; if (V8Node::HasInstance(args[1])) - contextNode = V8DOMWrapper::convertDOMWrapperToNode<Node>(v8::Handle<v8::Object>::Cast(args[1])); + contextNode = V8Node::toNative(v8::Handle<v8::Object>::Cast(args[1])); RefPtr<XPathNSResolver> resolver = V8DOMWrapper::getXPathNSResolver(args[2], V8Proxy::retrieve(V8Proxy::retrieveFrameForCallingContext())); if (!resolver && !args[2]->IsNull() && !args[2]->IsUndefined()) @@ -71,7 +77,7 @@ CALLBACK_FUNC_DECL(DocumentEvaluate) int type = toInt32(args[3]); RefPtr<XPathResult> inResult; if (V8XPathResult::HasInstance(args[4])) - inResult = V8DOMWrapper::convertToNativeObject<XPathResult>(V8ClassIndex::XPATHRESULT, v8::Handle<v8::Object>::Cast(args[4])); + inResult = V8XPathResult::toNative(v8::Handle<v8::Object>::Cast(args[4])); v8::TryCatch exceptionCatcher; RefPtr<XPathResult> result = document->evaluate(expression, contextNode.get(), resolver.get(), type, inResult.get(), ec); @@ -88,11 +94,11 @@ CALLBACK_FUNC_DECL(DocumentEvaluate) } -CALLBACK_FUNC_DECL(DocumentGetCSSCanvasContext) +v8::Handle<v8::Value> V8Document::getCSSCanvasContextCallback(const v8::Arguments& args) { INC_STATS("DOM.Document.getCSSCanvasContext"); v8::Handle<v8::Object> holder = args.Holder(); - Document* imp = V8DOMWrapper::convertDOMWrapperToNode<Document>(holder); + Document* imp = V8Document::toNative(holder); String contextId = toWebCoreString(args[0]); String name = toWebCoreString(args[1]); int width = toInt32(args[2]); @@ -110,4 +116,32 @@ CALLBACK_FUNC_DECL(DocumentGetCSSCanvasContext) return v8::Undefined(); } + +// DOMImplementation is a singleton in WebCore. If we use our normal +// mapping from DOM objects to V8 wrappers, the same wrapper will be +// shared for all frames in the same process. This is a major +// security problem. Therefore, we generate a DOMImplementation +// wrapper per document and store it in an internal field of the +// document. Since the DOMImplementation object is a singleton, we do +// not have to do anything to keep the DOMImplementation object alive +// for the lifetime of the wrapper. +v8::Handle<v8::Value> V8Document::implementationAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + ASSERT(info.Holder()->InternalFieldCount() >= internalFieldCount); + + // Check if the internal field already contains a wrapper. + v8::Local<v8::Value> implementation = info.Holder()->GetInternalField(V8Document::implementationIndex); + if (!implementation->IsUndefined()) + return implementation; + + // Generate a wrapper. + Document* document = V8Document::toNative(info.Holder()); + v8::Handle<v8::Value> wrapper = V8DOMWrapper::convertDOMImplementationToV8Object(document->implementation()); + + // Store the wrapper in the internal field. + info.Holder()->SetInternalField(implementationIndex, wrapper); + + return wrapper; +} + } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8DocumentLocationCustom.cpp b/WebCore/bindings/v8/custom/V8DocumentLocationCustom.cpp index 440bbdc..8dc4672 100644 --- a/WebCore/bindings/v8/custom/V8DocumentLocationCustom.cpp +++ b/WebCore/bindings/v8/custom/V8DocumentLocationCustom.cpp @@ -22,19 +22,20 @@ */ #include "config.h" -#include "V8CustomBinding.h" +#include "V8Document.h" #include "DOMWindow.h" #include "Frame.h" #include "V8Binding.h" +#include "V8CustomBinding.h" #include "V8Document.h" #include "V8Proxy.h" namespace WebCore { -ACCESSOR_GETTER(DocumentLocation) +v8::Handle<v8::Value> V8Document::locationAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { - Document* document = V8DOMWrapper::convertDOMWrapperToNative<Document>(info.Holder()); + Document* document = V8Document::toNative(info.Holder()); if (!document->frame()) return v8::Null(); @@ -42,15 +43,15 @@ ACCESSOR_GETTER(DocumentLocation) return V8DOMWrapper::convertToV8Object(V8ClassIndex::LOCATION, window->location()); } -ACCESSOR_SETTER(DocumentLocation) +void V8Document::locationAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { - Document* document = V8DOMWrapper::convertDOMWrapperToNative<Document>(info.Holder()); + Document* document = V8Document::toNative(info.Holder()); if (!document->frame()) return; DOMWindow* window = document->frame()->domWindow(); - // WindowSetLocation does security checks. // XXXMB- verify! - WindowSetLocation(window, toWebCoreString(value)); + // setLocation does security checks. // XXXMB- verify! + V8DOMWindowShell::setLocation(window, toWebCoreString(value)); } } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8ElementCustom.cpp b/WebCore/bindings/v8/custom/V8ElementCustom.cpp index e17e0a9..0f13f9d 100644 --- a/WebCore/bindings/v8/custom/V8ElementCustom.cpp +++ b/WebCore/bindings/v8/custom/V8ElementCustom.cpp @@ -29,11 +29,12 @@ */ #include "config.h" -#include "Element.h" +#include "V8Element.h" #include "Attr.h" #include "CSSHelper.h" #include "Document.h" +#include "Element.h" #include "ExceptionCode.h" #include "HTMLFrameElementBase.h" #include "HTMLNames.h" @@ -41,6 +42,7 @@ #include "V8Attr.h" #include "V8Binding.h" +#include "V8BindingState.h" #include "V8CustomBinding.h" #include "V8Proxy.h" @@ -48,14 +50,14 @@ namespace WebCore { -CALLBACK_FUNC_DECL(ElementSetAttribute) +v8::Handle<v8::Value> V8Element::setAttributeCallback(const v8::Arguments& args) { INC_STATS("DOM.Element.setAttribute()"); - Element* element = V8DOMWrapper::convertDOMWrapperToNode<Element>(args.Holder()); + Element* element = V8Element::toNative(args.Holder()); String name = toWebCoreString(args[0]); String value = toWebCoreString(args[1]); - if (!allowSettingSrcToJavascriptURL(element, name, value)) + if (!V8BindingSecurity::allowSettingSrcToJavascriptURL(V8BindingState::Only(), element, name, value)) return v8::Undefined(); ExceptionCode ec = 0; @@ -66,16 +68,16 @@ CALLBACK_FUNC_DECL(ElementSetAttribute) return v8::Undefined(); } -CALLBACK_FUNC_DECL(ElementSetAttributeNode) +v8::Handle<v8::Value> V8Element::setAttributeNodeCallback(const v8::Arguments& args) { INC_STATS("DOM.Element.setAttributeNode()"); if (!V8Attr::HasInstance(args[0])) return throwError(TYPE_MISMATCH_ERR); - Attr* newAttr = V8DOMWrapper::convertDOMWrapperToNode<Attr>(v8::Handle<v8::Object>::Cast(args[0])); - Element* element = V8DOMWrapper::convertDOMWrapperToNode<Element>(args.Holder()); + Attr* newAttr = V8Attr::toNative(v8::Handle<v8::Object>::Cast(args[0])); + Element* element = V8Element::toNative(args.Holder()); - if (!allowSettingSrcToJavascriptURL(element, newAttr->name(), newAttr->value())) + if (!V8BindingSecurity::allowSettingSrcToJavascriptURL(V8BindingState::Only(), element, newAttr->name(), newAttr->value())) return v8::Undefined(); ExceptionCode ec = 0; @@ -86,15 +88,15 @@ CALLBACK_FUNC_DECL(ElementSetAttributeNode) return V8DOMWrapper::convertNodeToV8Object(result.release()); } -CALLBACK_FUNC_DECL(ElementSetAttributeNS) +v8::Handle<v8::Value> V8Element::setAttributeNSCallback(const v8::Arguments& args) { INC_STATS("DOM.Element.setAttributeNS()"); - Element* element = V8DOMWrapper::convertDOMWrapperToNode<Element>(args.Holder()); + Element* element = V8Element::toNative(args.Holder()); String namespaceURI = toWebCoreStringWithNullCheck(args[0]); String qualifiedName = toWebCoreString(args[1]); String value = toWebCoreString(args[2]); - if (!allowSettingSrcToJavascriptURL(element, qualifiedName, value)) + if (!V8BindingSecurity::allowSettingSrcToJavascriptURL(V8BindingState::Only(), element, qualifiedName, value)) return v8::Undefined(); ExceptionCode ec = 0; @@ -105,16 +107,16 @@ CALLBACK_FUNC_DECL(ElementSetAttributeNS) return v8::Undefined(); } -CALLBACK_FUNC_DECL(ElementSetAttributeNodeNS) +v8::Handle<v8::Value> V8Element::setAttributeNodeNSCallback(const v8::Arguments& args) { INC_STATS("DOM.Element.setAttributeNodeNS()"); if (!V8Attr::HasInstance(args[0])) return throwError(TYPE_MISMATCH_ERR); - Attr* newAttr = V8DOMWrapper::convertDOMWrapperToNode<Attr>(v8::Handle<v8::Object>::Cast(args[0])); - Element* element = V8DOMWrapper::convertDOMWrapperToNode<Element>(args.Holder()); + Attr* newAttr = V8Attr::toNative(v8::Handle<v8::Object>::Cast(args[0])); + Element* element = V8Element::toNative(args.Holder()); - if (!allowSettingSrcToJavascriptURL(element, newAttr->name(), newAttr->value())) + if (!V8BindingSecurity::allowSettingSrcToJavascriptURL(V8BindingState::Only(), element, newAttr->name(), newAttr->value())) return v8::Undefined(); ExceptionCode ec = 0; diff --git a/WebCore/bindings/v8/custom/V8EventCustom.cpp b/WebCore/bindings/v8/custom/V8EventCustom.cpp index 8bac40f..65cd41e 100644 --- a/WebCore/bindings/v8/custom/V8EventCustom.cpp +++ b/WebCore/bindings/v8/custom/V8EventCustom.cpp @@ -29,27 +29,27 @@ */ #include "config.h" -#include "Event.h" +#include "V8Event.h" #include "Clipboard.h" #include "ClipboardEvent.h" +#include "Event.h" #include "MouseEvent.h" - #include "V8Binding.h" #include "V8CustomBinding.h" #include "V8Proxy.h" namespace WebCore { -ACCESSOR_SETTER(EventReturnValue) +void V8Event::valueAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { - Event* event = V8DOMWrapper::convertDOMWrapperToNative<Event>(info.Holder()); + Event* event = V8Event::toNative(info.Holder()); event->setDefaultPrevented(!value->BooleanValue()); } -ACCESSOR_GETTER(EventDataTransfer) +v8::Handle<v8::Value> V8Event::dataTransferAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { - Event* event = V8DOMWrapper::convertDOMWrapperToNative<Event>(info.Holder()); + Event* event = V8Event::toNative(info.Holder()); if (event->isDragEvent()) return V8DOMWrapper::convertToV8Object(V8ClassIndex::CLIPBOARD, static_cast<MouseEvent*>(event)->clipboard()); @@ -57,9 +57,9 @@ ACCESSOR_GETTER(EventDataTransfer) return v8::Undefined(); } -ACCESSOR_GETTER(EventClipboardData) +v8::Handle<v8::Value> V8Event::clipboardDataAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { - Event* event = V8DOMWrapper::convertDOMWrapperToNative<Event>(info.Holder()); + Event* event = V8Event::toNative(info.Holder()); if (event->isClipboardEvent()) return V8DOMWrapper::convertToV8Object(V8ClassIndex::CLIPBOARD, static_cast<ClipboardEvent*>(event)->clipboard()); @@ -67,16 +67,4 @@ ACCESSOR_GETTER(EventClipboardData) return v8::Undefined(); } -ACCESSOR_GETTER(EventSrcElement) -{ - Event* event = V8DOMWrapper::convertDOMWrapperToNative<Event>(info.Holder()); - return V8DOMWrapper::convertEventTargetToV8Object(event->target()); -} - -ACCESSOR_GETTER(EventReturnValue) -{ - Event* event = V8DOMWrapper::convertDOMWrapperToNative<Event>(info.Holder()); - return event->defaultPrevented() ? v8::False() : v8::True(); -} - } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8HTMLSelectElementCollectionCustom.cpp b/WebCore/bindings/v8/custom/V8EventSourceConstructor.cpp index 0dfa515..458c35d 100644 --- a/WebCore/bindings/v8/custom/V8HTMLSelectElementCollectionCustom.cpp +++ b/WebCore/bindings/v8/custom/V8EventSourceConstructor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Google Inc. All rights reserved. + * Copyright (C) 2010 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -29,50 +29,52 @@ */ #include "config.h" -#include "HTMLSelectElement.h" -#include "HTMLOptionsCollection.h" +#if ENABLE(EVENTSOURCE) +#include "V8EventSource.h" + +#include "EventSource.h" +#include "Frame.h" #include "V8Binding.h" -#include "V8Collection.h" #include "V8CustomBinding.h" -#include "V8NamedNodesCollection.h" #include "V8Proxy.h" +#include "V8Utilities.h" +#include "WorkerContext.h" +#include "WorkerContextExecutionProxy.h" namespace WebCore { -NAMED_PROPERTY_GETTER(HTMLSelectElementCollection) +v8::Handle<v8::Value> V8EventSource::constructorCallback(const v8::Arguments& args) { - INC_STATS("DOM.HTMLSelectElementCollection.NamedPropertySetter"); - HTMLSelectElement* select = V8DOMWrapper::convertDOMWrapperToNode<HTMLSelectElement>(info.Holder()); - v8::Handle<v8::Value> value = info.Holder()->GetRealNamedPropertyInPrototypeChain(name); - - if (!value.IsEmpty()) - return value; - - // Search local callback properties next to find IDL defined properties. - if (info.Holder()->HasRealNamedCallbackProperty(name)) - return notHandledByInterceptor(); + INC_STATS("DOM.EventSource.Constructor"); - PassRefPtr<HTMLOptionsCollection> collection = select->options(); + if (!args.IsConstructCall()) + return throwError("DOM object constructor cannot be called as a function.", V8Proxy::TypeError); - Vector<RefPtr<Node> > items; - collection->namedItems(v8StringToAtomicWebCoreString(name), items); + // Expect one parameter. + // Allocate an EventSource object as its internal field. + ScriptExecutionContext* context = getScriptExecutionContext(); + if (!context) + return throwError("EventSource constructor's associated context is not available", V8Proxy::ReferenceError); + if (args.Length() != 1) + return throwError("EventSource constructor wrong number of parameters", V8Proxy::TypeError); - if (!items.size()) - return notHandledByInterceptor(); + ExceptionCode ec = 0; + String url = toWebCoreString(args[0]); - if (items.size() == 1) - return V8DOMWrapper::convertNodeToV8Object(items.at(0).release()); + RefPtr<EventSource> eventSource = EventSource::create(url, context, ec); + + if (ec) + return throwError(ec); - NodeList* list = new V8NamedNodesCollection(items); - return V8DOMWrapper::convertToV8Object(V8ClassIndex::NODELIST, list); -} + V8DOMWrapper::setDOMWrapper(args.Holder(), V8ClassIndex::ToInt(V8ClassIndex::EVENTSOURCE), eventSource.get()); -INDEXED_PROPERTY_SETTER(HTMLSelectElementCollection) -{ - INC_STATS("DOM.HTMLSelectElementCollection.IndexedPropertySetter"); - HTMLSelectElement* select = V8DOMWrapper::convertDOMWrapperToNode<HTMLSelectElement>(info.Holder()); - return toOptionsCollectionSetter(index, value, select); + // Add object to the wrapper map. + eventSource->ref(); + V8DOMWrapper::setJSWrapperForActiveDOMObject(eventSource.get(), v8::Persistent<v8::Object>::New(args.Holder())); + return args.Holder(); } } // namespace WebCore + +#endif // ENABLE(EVENTSOURCE) diff --git a/WebCore/bindings/v8/custom/V8EventSourceCustom.cpp b/WebCore/bindings/v8/custom/V8EventSourceCustom.cpp new file mode 100644 index 0000000..e603549 --- /dev/null +++ b/WebCore/bindings/v8/custom/V8EventSourceCustom.cpp @@ -0,0 +1,74 @@ +/* + * Copyright 2010, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(EVENTSOURCE) +#include "V8EventSource.h" + +#include "EventSource.h" + +#include "V8Binding.h" +#include "V8CustomBinding.h" +#include "V8Proxy.h" + +namespace WebCore { + +v8::Handle<v8::Value> V8EventSource::addEventListenerCallback(const v8::Arguments& args) +{ + INC_STATS("DOM.EventSource.addEventListener()"); + EventSource* eventSource = V8EventSource::toNative(args.Holder()); + + RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(eventSource, args[1], false, ListenerFindOrCreate); + if (listener) { + String type = toWebCoreString(args[0]); + bool useCapture = args[2]->BooleanValue(); + eventSource->addEventListener(type, listener, useCapture); + + createHiddenDependency(args.Holder(), args[1], cacheIndex); + } + return v8::Undefined(); +} + +v8::Handle<v8::Value> V8EventSource::removeEventListenerCallback(const v8::Arguments& args) +{ + INC_STATS("DOM.EventSource.removeEventListener()"); + EventSource* eventSource = V8EventSource::toNative(args.Holder()); + + RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(eventSource, args[1], false, ListenerFindOnly); + if (listener) { + String type = toWebCoreString(args[0]); + bool useCapture = args[2]->BooleanValue(); + eventSource->removeEventListener(type, listener.get(), useCapture); + + removeHiddenDependency(args.Holder(), args[1], cacheIndex); + } + + return v8::Undefined(); +} + +} // namespace WebCore + +#endif // ENABLE(EVENTSOURCE) diff --git a/WebCore/bindings/v8/custom/V8GeolocationCustom.cpp b/WebCore/bindings/v8/custom/V8GeolocationCustom.cpp index 011beff..6bd9ff2 100644 --- a/WebCore/bindings/v8/custom/V8GeolocationCustom.cpp +++ b/WebCore/bindings/v8/custom/V8GeolocationCustom.cpp @@ -24,6 +24,8 @@ */ #include "config.h" +#include "V8Geolocation.h" + #include "Geolocation.h" #include "V8Binding.h" @@ -165,7 +167,7 @@ static PassRefPtr<PositionOptions> createPositionOptions(v8::Local<v8::Value> va return options.release(); } -CALLBACK_FUNC_DECL(GeolocationGetCurrentPosition) +v8::Handle<v8::Value> V8Geolocation::getCurrentPositionCallback(const v8::Arguments& args) { INC_STATS("DOM.Geolocation.getCurrentPosition()"); @@ -185,12 +187,12 @@ CALLBACK_FUNC_DECL(GeolocationGetCurrentPosition) return v8::Undefined(); ASSERT(positionOptions); - Geolocation* geolocation = V8DOMWrapper::convertToNativeObject<Geolocation>(V8ClassIndex::GEOLOCATION, args.Holder()); + Geolocation* geolocation = V8Geolocation::toNative(args.Holder()); geolocation->getCurrentPosition(positionCallback.release(), positionErrorCallback.release(), positionOptions.release()); return v8::Undefined(); } -CALLBACK_FUNC_DECL(GeolocationWatchPosition) +v8::Handle<v8::Value> V8Geolocation::watchPositionCallback(const v8::Arguments& args) { INC_STATS("DOM.Geolocation.watchPosition()"); @@ -210,7 +212,7 @@ CALLBACK_FUNC_DECL(GeolocationWatchPosition) return v8::Undefined(); ASSERT(positionOptions); - Geolocation* geolocation = V8DOMWrapper::convertToNativeObject<Geolocation>(V8ClassIndex::GEOLOCATION, args.Holder()); + Geolocation* geolocation = V8Geolocation::toNative(args.Holder()); int watchId = geolocation->watchPosition(positionCallback.release(), positionErrorCallback.release(), positionOptions.release()); return v8::Number::New(watchId); } diff --git a/WebCore/bindings/v8/custom/V8HTMLAllCollectionCustom.cpp b/WebCore/bindings/v8/custom/V8HTMLAllCollectionCustom.cpp index 419f374..c34d9e7 100644 --- a/WebCore/bindings/v8/custom/V8HTMLAllCollectionCustom.cpp +++ b/WebCore/bindings/v8/custom/V8HTMLAllCollectionCustom.cpp @@ -29,6 +29,8 @@ */ #include "config.h" +#include "V8HTMLAllCollection.h" + #include "HTMLAllCollection.h" #include "V8Binding.h" @@ -69,7 +71,7 @@ static v8::Handle<v8::Value> getItem(HTMLAllCollection* collection, v8::Handle<v return V8DOMWrapper::convertNodeToV8Object(result.release()); } -NAMED_PROPERTY_GETTER(HTMLAllCollection) +v8::Handle<v8::Value> V8HTMLAllCollection::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLAllCollection.NamedPropertyGetter"); // Search the prototype chain first. @@ -84,21 +86,21 @@ NAMED_PROPERTY_GETTER(HTMLAllCollection) return v8::Handle<v8::Value>(); // Finally, search the DOM structure. - HTMLAllCollection* imp = V8DOMWrapper::convertToNativeObject<HTMLAllCollection>(V8ClassIndex::HTMLALLCOLLECTION, info.Holder()); + HTMLAllCollection* imp = V8HTMLAllCollection::toNative(info.Holder()); return getNamedItems(imp, v8StringToAtomicWebCoreString(name)); } -CALLBACK_FUNC_DECL(HTMLAllCollectionItem) +v8::Handle<v8::Value> V8HTMLAllCollection::itemCallback(const v8::Arguments& args) { INC_STATS("DOM.HTMLAllCollection.item()"); - HTMLAllCollection* imp = V8DOMWrapper::convertToNativeObject<HTMLAllCollection>(V8ClassIndex::HTMLALLCOLLECTION, args.Holder()); + HTMLAllCollection* imp = V8HTMLAllCollection::toNative(args.Holder()); return getItem(imp, args[0]); } -CALLBACK_FUNC_DECL(HTMLAllCollectionNamedItem) +v8::Handle<v8::Value> V8HTMLAllCollection::namedItemCallback(const v8::Arguments& args) { INC_STATS("DOM.HTMLAllCollection.namedItem()"); - HTMLAllCollection* imp = V8DOMWrapper::convertToNativeObject<HTMLAllCollection>(V8ClassIndex::HTMLALLCOLLECTION, args.Holder()); + HTMLAllCollection* imp = V8HTMLAllCollection::toNative(args.Holder()); v8::Handle<v8::Value> result = getNamedItems(imp, toWebCoreString(args[0])); if (result.IsEmpty()) @@ -107,13 +109,13 @@ CALLBACK_FUNC_DECL(HTMLAllCollectionNamedItem) return result; } -CALLBACK_FUNC_DECL(HTMLAllCollectionCallAsFunction) +v8::Handle<v8::Value> V8HTMLAllCollection::callAsFunctionCallback(const v8::Arguments& args) { INC_STATS("DOM.HTMLAllCollection.callAsFunction()"); if (args.Length() < 1) return v8::Undefined(); - HTMLAllCollection* imp = V8DOMWrapper::convertToNativeObject<HTMLAllCollection>(V8ClassIndex::HTMLALLCOLLECTION, args.Holder()); + HTMLAllCollection* imp = V8HTMLAllCollection::toNative(args.Holder()); if (args.Length() == 1) return getItem(imp, args[0]); diff --git a/WebCore/bindings/v8/custom/V8HTMLAudioElementConstructor.cpp b/WebCore/bindings/v8/custom/V8HTMLAudioElementConstructor.cpp index c82d88a..e634003 100644 --- a/WebCore/bindings/v8/custom/V8HTMLAudioElementConstructor.cpp +++ b/WebCore/bindings/v8/custom/V8HTMLAudioElementConstructor.cpp @@ -35,8 +35,8 @@ #include "Document.h" #include "Frame.h" #include "HTMLNames.h" - #include "V8Binding.h" +#include "V8HTMLAudioElement.h" #include "V8Proxy.h" #include <wtf/RefPtr.h> @@ -53,7 +53,7 @@ v8::Persistent<v8::FunctionTemplate> V8HTMLAudioElementConstructor::GetTemplate( v8::Local<v8::FunctionTemplate> result = v8::FunctionTemplate::New(USE_CALLBACK(HTMLAudioElementConstructor)); v8::Local<v8::ObjectTemplate> instance = result->InstanceTemplate(); - instance->SetInternalFieldCount(V8Custom::kNodeMinimumInternalFieldCount); + instance->SetInternalFieldCount(V8HTMLAudioElement::internalFieldCount); result->SetClassName(v8::String::New("HTMLAudioElement")); result->Inherit(V8DOMWrapper::getTemplate(V8ClassIndex::HTMLAUDIOELEMENT)); @@ -61,7 +61,7 @@ v8::Persistent<v8::FunctionTemplate> V8HTMLAudioElementConstructor::GetTemplate( return cachedTemplate; } -CALLBACK_FUNC_DECL(HTMLAudioElementConstructor) +v8::Handle<v8::Value> V8Custom::v8HTMLAudioElementConstructorCallback(const v8::Arguments& args) { INC_STATS("DOM.HTMLAudioElement.Contructor"); diff --git a/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp b/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp index e51437e..0d1ff44 100644 --- a/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp +++ b/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp @@ -29,10 +29,12 @@ */ #include "config.h" -#include "HTMLCanvasElement.h" -#include "CanvasRenderingContext.h" +#include "V8HTMLCanvasElement.h" +#include "CanvasContextAttributes.h" #include "CanvasRenderingContext.h" +#include "HTMLCanvasElement.h" +#include "WebGLContextAttributes.h" #include "V8Binding.h" #include "V8CustomBinding.h" #include "V8Node.h" @@ -40,13 +42,38 @@ namespace WebCore { -CALLBACK_FUNC_DECL(HTMLCanvasElementGetContext) +v8::Handle<v8::Value> V8HTMLCanvasElement::getContextCallback(const v8::Arguments& args) { INC_STATS("DOM.HTMLCanvasElement.context"); v8::Handle<v8::Object> holder = args.Holder(); - HTMLCanvasElement* imp = V8DOMWrapper::convertDOMWrapperToNode<HTMLCanvasElement>(holder); + HTMLCanvasElement* imp = V8HTMLCanvasElement::toNative(holder); String contextId = toWebCoreString(args[0]); - CanvasRenderingContext* result = imp->getContext(contextId); + RefPtr<CanvasContextAttributes> attrs; +#if ENABLE(3D_CANVAS) + if (contextId == "experimental-webgl" || contextId == "webkit-3d") { + attrs = WebGLContextAttributes::create(); + WebGLContextAttributes* webGLAttrs = static_cast<WebGLContextAttributes*>(attrs.get()); + if (args.Length() > 1 && args[0]->IsObject()) { + v8::Handle<v8::Object> jsAttrs = args[1]->ToObject(); + v8::Handle<v8::String> alpha = v8::String::New("alpha"); + if (jsAttrs->Has(alpha)) + webGLAttrs->setAlpha(jsAttrs->Get(alpha)->BooleanValue()); + v8::Handle<v8::String> depth = v8::String::New("depth"); + if (jsAttrs->Has(depth)) + webGLAttrs->setDepth(jsAttrs->Get(depth)->BooleanValue()); + v8::Handle<v8::String> stencil = v8::String::New("stencil"); + if (jsAttrs->Has(stencil)) + webGLAttrs->setStencil(jsAttrs->Get(stencil)->BooleanValue()); + v8::Handle<v8::String> antialias = v8::String::New("antialias"); + if (jsAttrs->Has(antialias)) + webGLAttrs->setAntialias(jsAttrs->Get(antialias)->BooleanValue()); + v8::Handle<v8::String> premultipliedAlpha = v8::String::New("premultipliedAlpha"); + if (jsAttrs->Has(premultipliedAlpha)) + webGLAttrs->setPremultipliedAlpha(jsAttrs->Get(premultipliedAlpha)->BooleanValue()); + } + } +#endif + CanvasRenderingContext* result = imp->getContext(contextId, attrs.get()); if (!result) return v8::Undefined(); if (result->is2d()) @@ -60,4 +87,3 @@ CALLBACK_FUNC_DECL(HTMLCanvasElementGetContext) } } // namespace WebCore - diff --git a/WebCore/bindings/v8/custom/V8HTMLCollectionCustom.cpp b/WebCore/bindings/v8/custom/V8HTMLCollectionCustom.cpp index 7c9b40f..8bb3c3a 100644 --- a/WebCore/bindings/v8/custom/V8HTMLCollectionCustom.cpp +++ b/WebCore/bindings/v8/custom/V8HTMLCollectionCustom.cpp @@ -29,8 +29,9 @@ */ #include "config.h" -#include "HTMLCollection.h" +#include "V8HTMLCollection.h" +#include "HTMLCollection.h" #include "V8Binding.h" #include "V8CustomBinding.h" #include "V8NamedNodesCollection.h" @@ -69,7 +70,7 @@ static v8::Handle<v8::Value> getItem(HTMLCollection* collection, v8::Handle<v8:: return V8DOMWrapper::convertNodeToV8Object(result.release()); } -NAMED_PROPERTY_GETTER(HTMLCollection) +v8::Handle<v8::Value> V8HTMLCollection::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLCollection.NamedPropertyGetter"); // Search the prototype chain first. @@ -84,21 +85,21 @@ NAMED_PROPERTY_GETTER(HTMLCollection) return v8::Handle<v8::Value>(); // Finally, search the DOM structure. - HTMLCollection* imp = V8DOMWrapper::convertToNativeObject<HTMLCollection>(V8ClassIndex::HTMLCOLLECTION, info.Holder()); + HTMLCollection* imp = V8HTMLCollection::toNative(info.Holder()); return getNamedItems(imp, v8StringToAtomicWebCoreString(name)); } -CALLBACK_FUNC_DECL(HTMLCollectionItem) +v8::Handle<v8::Value> V8HTMLCollection::itemCallback(const v8::Arguments& args) { INC_STATS("DOM.HTMLCollection.item()"); - HTMLCollection* imp = V8DOMWrapper::convertToNativeObject<HTMLCollection>(V8ClassIndex::HTMLCOLLECTION, args.Holder()); + HTMLCollection* imp = V8HTMLCollection::toNative(args.Holder()); return getItem(imp, args[0]); } -CALLBACK_FUNC_DECL(HTMLCollectionNamedItem) +v8::Handle<v8::Value> V8HTMLCollection::namedItemCallback(const v8::Arguments& args) { INC_STATS("DOM.HTMLCollection.namedItem()"); - HTMLCollection* imp = V8DOMWrapper::convertToNativeObject<HTMLCollection>(V8ClassIndex::HTMLCOLLECTION, args.Holder()); + HTMLCollection* imp = V8HTMLCollection::toNative(args.Holder()); v8::Handle<v8::Value> result = getNamedItems(imp, toWebCoreString(args[0])); if (result.IsEmpty()) @@ -107,13 +108,13 @@ CALLBACK_FUNC_DECL(HTMLCollectionNamedItem) return result; } -CALLBACK_FUNC_DECL(HTMLCollectionCallAsFunction) +v8::Handle<v8::Value> V8HTMLCollection::callAsFunctionCallback(const v8::Arguments& args) { INC_STATS("DOM.HTMLCollection.callAsFunction()"); if (args.Length() < 1) return v8::Undefined(); - HTMLCollection* imp = V8DOMWrapper::convertToNativeObject<HTMLCollection>(V8ClassIndex::HTMLCOLLECTION, args.Holder()); + HTMLCollection* imp = V8HTMLCollection::toNative(args.Holder()); if (args.Length() == 1) return getItem(imp, args[0]); diff --git a/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp b/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp index 9cf2f3d..13243ef 100644 --- a/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp +++ b/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp @@ -29,24 +29,22 @@ */ #include "config.h" -#include "HTMLDocument.h" +#include "V8HTMLDocument.h" #include "Frame.h" #include "HTMLAllCollection.h" +#include "HTMLDocument.h" #include "HTMLCollection.h" #include "HTMLIFrameElement.h" #include "HTMLNames.h" - #include "V8Binding.h" -#include "V8CustomBinding.h" #include "V8Proxy.h" - #include <wtf/RefPtr.h> #include <wtf/StdLibExtras.h> namespace WebCore { -NAMED_PROPERTY_DELETER(HTMLDocument) +v8::Handle<v8::Boolean> V8HTMLDocument::namedPropertyDeleter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { // Only handle document.all. Insert the marker object into the // shadow internal field to signal that document.all is no longer @@ -56,13 +54,13 @@ NAMED_PROPERTY_DELETER(HTMLDocument) if (key != all) return deletionNotHandledByInterceptor(); - ASSERT(info.Holder()->InternalFieldCount() == kHTMLDocumentInternalFieldCount); - v8::Local<v8::Value> marker = info.Holder()->GetInternalField(kHTMLDocumentMarkerIndex); - info.Holder()->SetInternalField(kHTMLDocumentShadowIndex, marker); + ASSERT(info.Holder()->InternalFieldCount() == V8HTMLDocument::internalFieldCount); + v8::Local<v8::Value> marker = info.Holder()->GetInternalField(V8HTMLDocument::markerIndex); + info.Holder()->SetInternalField(V8HTMLDocument::shadowIndex, marker); return v8::True(); } -NAMED_PROPERTY_GETTER(HTMLDocument) +v8::Handle<v8::Value> V8HTMLDocument::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLDocument.NamedPropertyGetter"); AtomicString key = v8StringToAtomicWebCoreString(name); @@ -72,14 +70,14 @@ NAMED_PROPERTY_GETTER(HTMLDocument) // been temporarily shadowed and we return the value. DEFINE_STATIC_LOCAL(const AtomicString, all, ("all")); if (key == all) { - ASSERT(info.Holder()->InternalFieldCount() == kHTMLDocumentInternalFieldCount); - v8::Local<v8::Value> marker = info.Holder()->GetInternalField(kHTMLDocumentMarkerIndex); - v8::Local<v8::Value> value = info.Holder()->GetInternalField(kHTMLDocumentShadowIndex); + ASSERT(info.Holder()->InternalFieldCount() == V8HTMLDocument::internalFieldCount); + v8::Local<v8::Value> marker = info.Holder()->GetInternalField(V8HTMLDocument::markerIndex); + v8::Local<v8::Value> value = info.Holder()->GetInternalField(V8HTMLDocument::shadowIndex); if (marker != value) return value; } - HTMLDocument* htmlDocument = V8DOMWrapper::convertDOMWrapperToNode<HTMLDocument>(info.Holder()); + HTMLDocument* htmlDocument = V8HTMLDocument::toNative(info.Holder()); // Fast case for named elements that are not there. if (!htmlDocument->hasNamedItem(key.impl()) && !htmlDocument->hasExtraNamedItem(key.impl())) @@ -101,6 +99,13 @@ NAMED_PROPERTY_GETTER(HTMLDocument) return V8DOMWrapper::convertToV8Object(V8ClassIndex::HTMLCOLLECTION, items.release()); } +v8::Handle<v8::Value> V8HTMLDocument::indexedPropertyGetter(uint32_t index, const v8::AccessorInfo &info) +{ + INC_STATS("DOM.HTMLDocument.IndexedPropertyGetter"); + v8::Local<v8::Integer> indexV8 = v8::Integer::NewFromUnsigned(index); + return namedPropertyGetter(indexV8->ToString(), info); +} + // HTMLDocument ---------------------------------------------------------------- // Concatenates "args" to a string. If args is empty, returns empty string. @@ -115,28 +120,28 @@ static String writeHelperGetString(const v8::Arguments& args) return str; } -CALLBACK_FUNC_DECL(HTMLDocumentWrite) +v8::Handle<v8::Value> V8HTMLDocument::writeCallback(const v8::Arguments& args) { INC_STATS("DOM.HTMLDocument.write()"); - HTMLDocument* htmlDocument = V8DOMWrapper::convertDOMWrapperToNode<HTMLDocument>(args.Holder()); + HTMLDocument* htmlDocument = V8HTMLDocument::toNative(args.Holder()); Frame* frame = V8Proxy::retrieveFrameForCallingContext(); htmlDocument->write(writeHelperGetString(args), frame ? frame->document() : NULL); return v8::Undefined(); } -CALLBACK_FUNC_DECL(HTMLDocumentWriteln) +v8::Handle<v8::Value> V8HTMLDocument::writelnCallback(const v8::Arguments& args) { INC_STATS("DOM.HTMLDocument.writeln()"); - HTMLDocument* htmlDocument = V8DOMWrapper::convertDOMWrapperToNode<HTMLDocument>(args.Holder()); + HTMLDocument* htmlDocument = V8HTMLDocument::toNative(args.Holder()); Frame* frame = V8Proxy::retrieveFrameForCallingContext(); htmlDocument->writeln(writeHelperGetString(args), frame ? frame->document() : NULL); return v8::Undefined(); } -CALLBACK_FUNC_DECL(HTMLDocumentOpen) +v8::Handle<v8::Value> V8HTMLDocument::openCallback(const v8::Arguments& args) { INC_STATS("DOM.HTMLDocument.open()"); - HTMLDocument* htmlDocument = V8DOMWrapper::convertDOMWrapperToNode<HTMLDocument>(args.Holder()); + HTMLDocument* htmlDocument = V8HTMLDocument::toNative(args.Holder()); if (args.Length() > 2) { if (Frame* frame = htmlDocument->frame()) { @@ -173,21 +178,21 @@ CALLBACK_FUNC_DECL(HTMLDocumentOpen) return args.Holder(); } -ACCESSOR_GETTER(HTMLDocumentAll) +v8::Handle<v8::Value> V8HTMLDocument::allAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLDocument.all._get"); v8::HandleScope scope; v8::Handle<v8::Object> holder = info.Holder(); - HTMLDocument* htmlDocument = V8DOMWrapper::convertDOMWrapperToNode<HTMLDocument>(holder); + HTMLDocument* htmlDocument = V8HTMLDocument::toNative(holder); return V8DOMWrapper::convertToV8Object(V8ClassIndex::HTMLCOLLECTION, htmlDocument->all()); } -ACCESSOR_SETTER(HTMLDocumentAll) +void V8HTMLDocument::allAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLDocument.all._set"); v8::Handle<v8::Object> holder = info.Holder(); - ASSERT(info.Holder()->InternalFieldCount() == kHTMLDocumentInternalFieldCount); - info.Holder()->SetInternalField(kHTMLDocumentShadowIndex, value); + ASSERT(info.Holder()->InternalFieldCount() == V8HTMLDocument::internalFieldCount); + info.Holder()->SetInternalField(V8HTMLDocument::shadowIndex, value); } } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8HTMLFormElementCustom.cpp b/WebCore/bindings/v8/custom/V8HTMLFormElementCustom.cpp index 1ec09f7..d819e9b 100644 --- a/WebCore/bindings/v8/custom/V8HTMLFormElementCustom.cpp +++ b/WebCore/bindings/v8/custom/V8HTMLFormElementCustom.cpp @@ -29,9 +29,10 @@ */ #include "config.h" -#include "HTMLFormElement.h" +#include "V8HTMLFormElement.h" #include "HTMLCollection.h" +#include "HTMLFormElement.h" #include "V8Binding.h" #include "V8CustomBinding.h" #include "V8NamedNodesCollection.h" @@ -39,10 +40,10 @@ namespace WebCore { -INDEXED_PROPERTY_GETTER(HTMLFormElement) +v8::Handle<v8::Value> V8HTMLFormElement::indexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLFormElement.IndexedPropertyGetter"); - HTMLFormElement* form = V8DOMWrapper::convertDOMWrapperToNode<HTMLFormElement>(info.Holder()); + HTMLFormElement* form = V8HTMLFormElement::toNative(info.Holder()); RefPtr<Node> formElement = form->elements()->item(index); if (!formElement) @@ -50,11 +51,10 @@ INDEXED_PROPERTY_GETTER(HTMLFormElement) return V8DOMWrapper::convertNodeToV8Object(formElement.release()); } - -NAMED_PROPERTY_GETTER(HTMLFormElement) +v8::Handle<v8::Value> V8HTMLFormElement::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLFormElement.NamedPropertyGetter"); - HTMLFormElement* imp = V8DOMWrapper::convertDOMWrapperToNode<HTMLFormElement>(info.Holder()); + HTMLFormElement* imp = V8HTMLFormElement::toNative(info.Holder()); AtomicString v = v8StringToAtomicWebCoreString(name); // Call getNamedElements twice, first time check if it has a value @@ -80,10 +80,15 @@ NAMED_PROPERTY_GETTER(HTMLFormElement) return V8DOMWrapper::convertToV8Object(V8ClassIndex::NODELIST, collection); } -CALLBACK_FUNC_DECL(HTMLFormElementSubmit) { +v8::Handle<v8::Value> V8HTMLFormElement::submitCallback(const v8::Arguments& args) +{ INC_STATS("DOM.HTMLFormElement.submit()"); - HTMLFormElement* form = V8DOMWrapper::convertDOMWrapperToNative<HTMLFormElement>(args.Holder()); - form->submit(0, false, false); + HTMLFormElement* form = V8HTMLFormElement::toNative(args.Holder()); + Frame* frame = V8Proxy::retrieveFrameForEnteredContext(); + if (!frame) + return v8::Undefined(); + + form->submit(frame); return v8::Undefined(); } diff --git a/WebCore/bindings/v8/custom/V8HTMLFrameElementCustom.cpp b/WebCore/bindings/v8/custom/V8HTMLFrameElementCustom.cpp index 2f55758..fd831bf 100644 --- a/WebCore/bindings/v8/custom/V8HTMLFrameElementCustom.cpp +++ b/WebCore/bindings/v8/custom/V8HTMLFrameElementCustom.cpp @@ -29,10 +29,12 @@ */ #include "config.h" +#include "V8HTMLFrameElement.h" + #include "HTMLFrameElement.h" #include "HTMLNames.h" - #include "V8Binding.h" +#include "V8BindingState.h" #include "V8CustomBinding.h" #include "V8Proxy.h" @@ -40,23 +42,23 @@ namespace WebCore { using namespace HTMLNames; -ACCESSOR_SETTER(HTMLFrameElementSrc) +void V8HTMLFrameElement::srcAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { - HTMLFrameElement* frame = V8DOMWrapper::convertDOMWrapperToNode<HTMLFrameElement>(info.Holder()); + HTMLFrameElement* frame = V8HTMLFrameElement::toNative(info.Holder()); String srcValue = toWebCoreStringWithNullCheck(value); - if (!allowSettingFrameSrcToJavascriptUrl(frame, srcValue)) + if (!V8BindingSecurity::allowSettingFrameSrcToJavascriptUrl(V8BindingState::Only(), frame, srcValue)) return; frame->setAttribute(srcAttr, srcValue); } -ACCESSOR_SETTER(HTMLFrameElementLocation) +void V8HTMLFrameElement::locationAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { - HTMLFrameElement* frame = V8DOMWrapper::convertDOMWrapperToNode<HTMLFrameElement>(info.Holder()); + HTMLFrameElement* frame = V8HTMLFrameElement::toNative(info.Holder()); String locationValue = toWebCoreStringWithNullCheck(value); - if (!allowSettingFrameSrcToJavascriptUrl(frame, locationValue)) + if (!V8BindingSecurity::allowSettingFrameSrcToJavascriptUrl(V8BindingState::Only(), frame, locationValue)) return; frame->setLocation(locationValue); diff --git a/WebCore/bindings/v8/custom/V8HTMLFrameSetElementCustom.cpp b/WebCore/bindings/v8/custom/V8HTMLFrameSetElementCustom.cpp index e8e2e72..214b11e 100644 --- a/WebCore/bindings/v8/custom/V8HTMLFrameSetElementCustom.cpp +++ b/WebCore/bindings/v8/custom/V8HTMLFrameSetElementCustom.cpp @@ -29,12 +29,13 @@ */ #include "config.h" -#include "HTMLFrameSetElement.h" +#include "V8HTMLFrameSetElement.h" #include "Document.h" #include "Frame.h" #include "HTMLCollection.h" #include "HTMLFrameElement.h" +#include "HTMLFrameSetElement.h" #include "HTMLNames.h" #include "Node.h" @@ -44,10 +45,10 @@ namespace WebCore { -NAMED_PROPERTY_GETTER(HTMLFrameSetElement) +v8::Handle<v8::Value> V8HTMLFrameSetElement::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLFrameSetElement.NamedPropertyGetter"); - HTMLFrameSetElement* imp = V8DOMWrapper::convertDOMWrapperToNode<HTMLFrameSetElement>(info.Holder()); + HTMLFrameSetElement* imp = V8HTMLFrameSetElement::toNative(info.Holder()); Node* frameNode = imp->children()->namedItem(v8StringToAtomicWebCoreString(name)); if (frameNode && frameNode->hasTagName(HTMLNames::frameTag)) { Document* doc = static_cast<HTMLFrameElement*>(frameNode)->contentDocument(); diff --git a/WebCore/bindings/v8/custom/V8HTMLIFrameElementCustom.cpp b/WebCore/bindings/v8/custom/V8HTMLIFrameElementCustom.cpp index a4863e8..1949632 100644 --- a/WebCore/bindings/v8/custom/V8HTMLIFrameElementCustom.cpp +++ b/WebCore/bindings/v8/custom/V8HTMLIFrameElementCustom.cpp @@ -29,10 +29,12 @@ */ #include "config.h" +#include "V8HTMLIFrameElement.h" + #include "HTMLIFrameElement.h" #include "HTMLNames.h" - #include "V8Binding.h" +#include "V8BindingState.h" #include "V8CustomBinding.h" #include "V8Proxy.h" @@ -40,12 +42,12 @@ namespace WebCore { using namespace HTMLNames; -ACCESSOR_SETTER(HTMLIFrameElementSrc) +void V8HTMLIFrameElement::srcAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { - HTMLIFrameElement* iframe = V8DOMWrapper::convertDOMWrapperToNode<HTMLIFrameElement>(info.Holder()); + HTMLIFrameElement* iframe = V8HTMLIFrameElement::toNative(info.Holder()); String v = toWebCoreStringWithNullCheck(value); - if (!allowSettingFrameSrcToJavascriptUrl(iframe, v)) + if (!V8BindingSecurity::allowSettingFrameSrcToJavascriptUrl(V8BindingState::Only(), iframe, v)) return; iframe->setAttribute(srcAttr, v); diff --git a/WebCore/bindings/v8/custom/V8HTMLImageElementConstructor.cpp b/WebCore/bindings/v8/custom/V8HTMLImageElementConstructor.cpp index 71c99cf..57efa34 100644 --- a/WebCore/bindings/v8/custom/V8HTMLImageElementConstructor.cpp +++ b/WebCore/bindings/v8/custom/V8HTMLImageElementConstructor.cpp @@ -35,8 +35,8 @@ #include "Document.h" #include "Frame.h" #include "HTMLNames.h" - #include "V8Binding.h" +#include "V8HTMLImageElement.h" #include "V8Proxy.h" #include <wtf/RefPtr.h> @@ -53,7 +53,7 @@ v8::Persistent<v8::FunctionTemplate> V8HTMLImageElementConstructor::GetTemplate( v8::Local<v8::FunctionTemplate> result = v8::FunctionTemplate::New(USE_CALLBACK(HTMLImageElementConstructor)); v8::Local<v8::ObjectTemplate> instance = result->InstanceTemplate(); - instance->SetInternalFieldCount(V8Custom::kNodeMinimumInternalFieldCount); + instance->SetInternalFieldCount(V8HTMLImageElement::internalFieldCount); result->SetClassName(v8::String::New("HTMLImageElement")); result->Inherit(V8DOMWrapper::getTemplate(V8ClassIndex::HTMLIMAGEELEMENT)); @@ -61,7 +61,7 @@ v8::Persistent<v8::FunctionTemplate> V8HTMLImageElementConstructor::GetTemplate( return cachedTemplate; } -CALLBACK_FUNC_DECL(HTMLImageElementConstructor) +v8::Handle<v8::Value> V8Custom::v8HTMLImageElementConstructorCallback(const v8::Arguments& args) { INC_STATS("DOM.HTMLImageElement.Contructor"); diff --git a/WebCore/bindings/v8/custom/V8HTMLInputElementCustom.cpp b/WebCore/bindings/v8/custom/V8HTMLInputElementCustom.cpp index 63fbcec..78486b3 100644 --- a/WebCore/bindings/v8/custom/V8HTMLInputElementCustom.cpp +++ b/WebCore/bindings/v8/custom/V8HTMLInputElementCustom.cpp @@ -29,6 +29,8 @@ */ #include "config.h" +#include "V8HTMLInputElement.h" + #include "HTMLInputElement.h" #include "V8Binding.h" @@ -37,11 +39,11 @@ namespace WebCore { -ACCESSOR_GETTER(HTMLInputElementSelectionStart) +v8::Handle<v8::Value> V8HTMLInputElement::selectionStartAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLInputElement.selectionStart._get"); v8::Handle<v8::Object> holder = info.Holder(); - HTMLInputElement* imp = V8DOMWrapper::convertDOMWrapperToNode<HTMLInputElement>(holder); + HTMLInputElement* imp = V8HTMLInputElement::toNative(holder); if (!imp->canHaveSelection()) return throwError("Accessing selectionStart on an input element that cannot have a selection."); @@ -50,11 +52,11 @@ ACCESSOR_GETTER(HTMLInputElementSelectionStart) return v8::Integer::New(v); } -ACCESSOR_SETTER(HTMLInputElementSelectionStart) +void V8HTMLInputElement::selectionStartAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLInputElement.selectionStart._set"); v8::Handle<v8::Object> holder = info.Holder(); - HTMLInputElement* imp = V8DOMWrapper::convertDOMWrapperToNode<HTMLInputElement>(holder); + HTMLInputElement* imp = V8HTMLInputElement::toNative(holder); if (!imp->canHaveSelection()) { throwError("Accessing selectionStart on an input element that cannot have a selection."); @@ -63,11 +65,11 @@ ACCESSOR_SETTER(HTMLInputElementSelectionStart) imp->setSelectionStart(value->Int32Value()); } -ACCESSOR_GETTER(HTMLInputElementSelectionEnd) +v8::Handle<v8::Value> V8HTMLInputElement::selectionEndAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLInputElement.selectionEnd._get"); v8::Handle<v8::Object> holder = info.Holder(); - HTMLInputElement* imp = V8DOMWrapper::convertDOMWrapperToNode<HTMLInputElement>(holder); + HTMLInputElement* imp = V8HTMLInputElement::toNative(holder); if (!imp->canHaveSelection()) return throwError("Accessing selectionEnd on an input element that cannot have a selection."); @@ -76,11 +78,11 @@ ACCESSOR_GETTER(HTMLInputElementSelectionEnd) return v8::Integer::New(v); } -ACCESSOR_SETTER(HTMLInputElementSelectionEnd) +void V8HTMLInputElement::selectionEndAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLInputElement.selectionEnd._set"); v8::Handle<v8::Object> holder = info.Holder(); - HTMLInputElement* imp = V8DOMWrapper::convertDOMWrapperToNode<HTMLInputElement>(holder); + HTMLInputElement* imp = V8HTMLInputElement::toNative(holder); if (!imp->canHaveSelection()) { throwError("Accessing selectionEnd on an input element that cannot have a selection."); @@ -90,11 +92,11 @@ ACCESSOR_SETTER(HTMLInputElementSelectionEnd) imp->setSelectionEnd(value->Int32Value()); } -CALLBACK_FUNC_DECL(HTMLInputElementSetSelectionRange) +v8::Handle<v8::Value> V8HTMLInputElement::setSelectionRangeCallback(const v8::Arguments& args) { INC_STATS("DOM.HTMLInputElement.setSelectionRange"); v8::Handle<v8::Object> holder = args.Holder(); - HTMLInputElement* imp = V8DOMWrapper::convertDOMWrapperToNode<HTMLInputElement>(holder); + HTMLInputElement* imp = V8HTMLInputElement::toNative(holder); if (!imp->canHaveSelection()) return throwError("Calling setSelectionRange on an input element that cannot have a selection."); diff --git a/WebCore/bindings/v8/custom/V8HTMLOptionElementConstructor.cpp b/WebCore/bindings/v8/custom/V8HTMLOptionElementConstructor.cpp index f9c9cb4..5325933 100644 --- a/WebCore/bindings/v8/custom/V8HTMLOptionElementConstructor.cpp +++ b/WebCore/bindings/v8/custom/V8HTMLOptionElementConstructor.cpp @@ -36,8 +36,8 @@ #include "Frame.h" #include "HTMLNames.h" #include "Text.h" - #include "V8Binding.h" +#include "V8HTMLOptionElement.h" #include "V8Proxy.h" #include <wtf/RefPtr.h> @@ -54,7 +54,7 @@ v8::Persistent<v8::FunctionTemplate> V8HTMLOptionElementConstructor::GetTemplate v8::Local<v8::FunctionTemplate> result = v8::FunctionTemplate::New(USE_CALLBACK(HTMLOptionElementConstructor)); v8::Local<v8::ObjectTemplate> instance = result->InstanceTemplate(); - instance->SetInternalFieldCount(V8Custom::kNodeMinimumInternalFieldCount); + instance->SetInternalFieldCount(V8HTMLOptionElement::internalFieldCount); result->SetClassName(v8::String::New("HTMLOptionElement")); result->Inherit(V8DOMWrapper::getTemplate(V8ClassIndex::HTMLOPTIONELEMENT)); @@ -62,7 +62,7 @@ v8::Persistent<v8::FunctionTemplate> V8HTMLOptionElementConstructor::GetTemplate return cachedTemplate; } -CALLBACK_FUNC_DECL(HTMLOptionElementConstructor) +v8::Handle<v8::Value> V8Custom::v8HTMLOptionElementConstructorCallback(const v8::Arguments& args) { INC_STATS("DOM.HTMLOptionElement.Contructor"); diff --git a/WebCore/bindings/v8/custom/V8HTMLOptionsCollectionCustom.cpp b/WebCore/bindings/v8/custom/V8HTMLOptionsCollectionCustom.cpp index 02c3499..c060df7 100644 --- a/WebCore/bindings/v8/custom/V8HTMLOptionsCollectionCustom.cpp +++ b/WebCore/bindings/v8/custom/V8HTMLOptionsCollectionCustom.cpp @@ -29,8 +29,9 @@ */ #include "config.h" -#include "HTMLOptionsCollection.h" +#include "V8HTMLOptionsCollection.h" +#include "HTMLOptionsCollection.h" #include "HTMLOptionElement.h" #include "ExceptionCode.h" @@ -43,23 +44,23 @@ namespace WebCore { -CALLBACK_FUNC_DECL(HTMLOptionsCollectionRemove) +v8::Handle<v8::Value> V8HTMLOptionsCollection::removeCallback(const v8::Arguments& args) { INC_STATS("DOM.HTMLOptionsCollection.remove()"); - HTMLOptionsCollection* imp = V8DOMWrapper::convertToNativeObject<HTMLOptionsCollection>(V8ClassIndex::HTMLOPTIONSCOLLECTION, args.Holder()); + HTMLOptionsCollection* imp = V8HTMLOptionsCollection::toNative(args.Holder()); HTMLSelectElement* base = static_cast<HTMLSelectElement*>(imp->base()); return removeElement(base, args); } -CALLBACK_FUNC_DECL(HTMLOptionsCollectionAdd) +v8::Handle<v8::Value> V8HTMLOptionsCollection::addCallback(const v8::Arguments& args) { INC_STATS("DOM.HTMLOptionsCollection.add()"); if (!V8HTMLOptionElement::HasInstance(args[0])) { V8Proxy::setDOMException(TYPE_MISMATCH_ERR); return v8::Undefined(); } - HTMLOptionsCollection* imp = V8DOMWrapper::convertToNativeObject<HTMLOptionsCollection>(V8ClassIndex::HTMLOPTIONSCOLLECTION, args.Holder()); - HTMLOptionElement* option = V8DOMWrapper::convertDOMWrapperToNode<HTMLOptionElement>(v8::Handle<v8::Object>(v8::Handle<v8::Object>::Cast(args[0]))); + HTMLOptionsCollection* imp = V8HTMLOptionsCollection::toNative(args.Holder()); + HTMLOptionElement* option = V8HTMLOptionElement::toNative(v8::Handle<v8::Object>(v8::Handle<v8::Object>::Cast(args[0]))); ExceptionCode ec = 0; if (args.Length() < 2) @@ -84,18 +85,18 @@ CALLBACK_FUNC_DECL(HTMLOptionsCollectionAdd) return v8::Undefined(); } -ACCESSOR_GETTER(HTMLOptionsCollectionLength) +v8::Handle<v8::Value> V8HTMLOptionsCollection::lengthAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLOptionsCollection.length._get"); - HTMLOptionsCollection* imp = V8DOMWrapper::convertToNativeObject<HTMLOptionsCollection>(V8ClassIndex::HTMLOPTIONSCOLLECTION, info.Holder()); + HTMLOptionsCollection* imp = V8HTMLOptionsCollection::toNative(info.Holder()); int v = imp->length(); return v8::Integer::New(v); } -ACCESSOR_SETTER(HTMLOptionsCollectionLength) +void V8HTMLOptionsCollection::lengthAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLOptionsCollection.length._set"); - HTMLOptionsCollection* imp = V8DOMWrapper::convertToNativeObject<HTMLOptionsCollection>(V8ClassIndex::HTMLOPTIONSCOLLECTION, info.Holder()); + HTMLOptionsCollection* imp = V8HTMLOptionsCollection::toNative(info.Holder()); double v = value->NumberValue(); unsigned newLength = 0; ExceptionCode ec = 0; @@ -113,10 +114,10 @@ ACCESSOR_SETTER(HTMLOptionsCollectionLength) V8Proxy::setDOMException(ec); } -INDEXED_PROPERTY_GETTER(HTMLOptionsCollection) +v8::Handle<v8::Value> V8HTMLOptionsCollection::indexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLOptionsCollection.IndexedPropertyGetter"); - HTMLOptionsCollection* collection = V8DOMWrapper::convertToNativeObject<HTMLOptionsCollection>(V8ClassIndex::HTMLOPTIONSCOLLECTION, info.Holder()); + HTMLOptionsCollection* collection = V8HTMLOptionsCollection::toNative(info.Holder()); RefPtr<Node> result = collection->item(index); if (!result) @@ -125,10 +126,10 @@ INDEXED_PROPERTY_GETTER(HTMLOptionsCollection) return V8DOMWrapper::convertNodeToV8Object(result.release()); } -INDEXED_PROPERTY_SETTER(HTMLOptionsCollection) +v8::Handle<v8::Value> V8HTMLOptionsCollection::indexedPropertySetter(uint32_t index, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLOptionsCollection.IndexedPropertySetter"); - HTMLOptionsCollection* collection = V8DOMWrapper::convertToNativeObject<HTMLOptionsCollection>(V8ClassIndex::HTMLOPTIONSCOLLECTION, info.Holder()); + HTMLOptionsCollection* collection = V8HTMLOptionsCollection::toNative(info.Holder()); HTMLSelectElement* base = static_cast<HTMLSelectElement*>(collection->base()); return toOptionsCollectionSetter(index, value, base); } diff --git a/WebCore/bindings/v8/custom/V8HTMLPlugInElementCustom.cpp b/WebCore/bindings/v8/custom/V8HTMLPlugInElementCustom.cpp index 13c82f3..261b5a8 100644 --- a/WebCore/bindings/v8/custom/V8HTMLPlugInElementCustom.cpp +++ b/WebCore/bindings/v8/custom/V8HTMLPlugInElementCustom.cpp @@ -32,18 +32,23 @@ #include "HTMLPlugInElement.h" #include "ScriptInstance.h" - #include "V8Binding.h" #include "V8CustomBinding.h" +#include "V8HTMLAppletElement.h" +#include "V8HTMLEmbedElement.h" +#include "V8HTMLObjectElement.h" #include "V8NPObject.h" #include "V8Proxy.h" namespace WebCore { -NAMED_PROPERTY_GETTER(HTMLPlugInElement) +// FIXME: Consider moving getter/setter helpers to V8NPObject and renaming this file to V8PluginElementFunctions +// to match JSC bindings naming convention. + +template <class C> +static v8::Handle<v8::Value> npObjectNamedGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { - INC_STATS("DOM.HTMLPlugInElement.NamedPropertyGetter"); - HTMLPlugInElement* imp = V8DOMWrapper::convertDOMWrapperToNode<HTMLPlugInElement>(info.Holder()); + HTMLPlugInElement* imp = C::toNative(info.Holder()); ScriptInstance scriptInstance = imp->getInstance(); if (!scriptInstance) return notHandledByInterceptor(); @@ -55,10 +60,10 @@ NAMED_PROPERTY_GETTER(HTMLPlugInElement) return npObjectGetNamedProperty(instance, name); } -NAMED_PROPERTY_SETTER(HTMLPlugInElement) +template <class C> +static v8::Handle<v8::Value> npObjectNamedSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { - INC_STATS("DOM.HTMLPlugInElement.NamedPropertySetter"); - HTMLPlugInElement* imp = V8DOMWrapper::convertDOMWrapperToNode<HTMLPlugInElement>(info.Holder()); + HTMLPlugInElement* imp = C::toNative(info.Holder()); ScriptInstance scriptInstance = imp->getInstance(); if (!scriptInstance) return notHandledByInterceptor(); @@ -70,16 +75,65 @@ NAMED_PROPERTY_SETTER(HTMLPlugInElement) return npObjectSetNamedProperty(instance, name, value); } -CALLBACK_FUNC_DECL(HTMLPlugInElement) +v8::Handle<v8::Value> V8HTMLAppletElement::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.HTMLAppletElement.NamedPropertyGetter"); + return npObjectNamedGetter<V8HTMLAppletElement>(name, info); +} + +v8::Handle<v8::Value> V8HTMLEmbedElement::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.HTMLEmbedElement.NamedPropertyGetter"); + return npObjectNamedGetter<V8HTMLEmbedElement>(name, info); +} + +v8::Handle<v8::Value> V8HTMLObjectElement::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.HTMLObjectElement.NamedPropertyGetter"); + return npObjectNamedGetter<V8HTMLObjectElement>(name, info); +} + +v8::Handle<v8::Value> V8HTMLAppletElement::namedPropertySetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.HTMLAppletElement.NamedPropertySetter"); + return npObjectNamedSetter<V8HTMLAppletElement>(name, value, info); +} + +v8::Handle<v8::Value> V8HTMLEmbedElement::namedPropertySetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.HTMLEmbedElement.NamedPropertySetter"); + return npObjectNamedSetter<V8HTMLEmbedElement>(name, value, info); +} + +v8::Handle<v8::Value> V8HTMLObjectElement::namedPropertySetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.HTMLObjectElement.NamedPropertySetter"); + return npObjectNamedSetter<V8HTMLObjectElement>(name, value, info); +} + +v8::Handle<v8::Value> V8HTMLAppletElement::callAsFunctionCallback(const v8::Arguments& args) +{ + INC_STATS("DOM.HTMLAppletElement()"); + return npObjectInvokeDefaultHandler(args); +} + +v8::Handle<v8::Value> V8HTMLEmbedElement::callAsFunctionCallback(const v8::Arguments& args) +{ + INC_STATS("DOM.HTMLEmbedElement()"); + return npObjectInvokeDefaultHandler(args); +} + +v8::Handle<v8::Value> V8HTMLObjectElement::callAsFunctionCallback(const v8::Arguments& args) { - INC_STATS("DOM.HTMLPluginElement()"); + INC_STATS("DOM.HTMLObjectElement()"); return npObjectInvokeDefaultHandler(args); } -INDEXED_PROPERTY_GETTER(HTMLPlugInElement) +template <class C> +v8::Handle<v8::Value> npObjectIndexedGetter(uint32_t index, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLPlugInElement.IndexedPropertyGetter"); - HTMLPlugInElement* imp = V8DOMWrapper::convertDOMWrapperToNode<HTMLPlugInElement>(info.Holder()); + HTMLPlugInElement* imp = C::toNative(info.Holder()); ScriptInstance scriptInstance = imp->getInstance(); if (!scriptInstance) return notHandledByInterceptor(); @@ -91,10 +145,11 @@ INDEXED_PROPERTY_GETTER(HTMLPlugInElement) return npObjectGetIndexedProperty(instance, index); } -INDEXED_PROPERTY_SETTER(HTMLPlugInElement) +template <class C> +v8::Handle<v8::Value> npObjectIndexedSetter(uint32_t index, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLPlugInElement.IndexedPropertySetter"); - HTMLPlugInElement* imp = V8DOMWrapper::convertDOMWrapperToNode<HTMLPlugInElement>(info.Holder()); + HTMLPlugInElement* imp = C::toNative(info.Holder()); ScriptInstance scriptInstance = imp->getInstance(); if (!scriptInstance) return notHandledByInterceptor(); @@ -106,4 +161,40 @@ INDEXED_PROPERTY_SETTER(HTMLPlugInElement) return npObjectSetIndexedProperty(instance, index, value); } +v8::Handle<v8::Value> V8HTMLAppletElement::indexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.HTMLAppletElement.IndexedPropertyGetter"); + return npObjectIndexedGetter<V8HTMLAppletElement>(index, info); +} + +v8::Handle<v8::Value> V8HTMLEmbedElement::indexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.HTMLEmbedElement.IndexedPropertyGetter"); + return npObjectIndexedGetter<V8HTMLEmbedElement>(index, info); +} + +v8::Handle<v8::Value> V8HTMLObjectElement::indexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.HTMLObjectElement.IndexedPropertyGetter"); + return npObjectIndexedGetter<V8HTMLObjectElement>(index, info); +} + +v8::Handle<v8::Value> V8HTMLAppletElement::indexedPropertySetter(uint32_t index, v8::Local<v8::Value> value, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.HTMLAppletElement.IndexedPropertySetter"); + return npObjectIndexedSetter<V8HTMLAppletElement>(index, value, info); +} + +v8::Handle<v8::Value> V8HTMLEmbedElement::indexedPropertySetter(uint32_t index, v8::Local<v8::Value> value, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.HTMLEmbedElement.IndexedPropertySetter"); + return npObjectIndexedSetter<V8HTMLEmbedElement>(index, value, info); +} + +v8::Handle<v8::Value> V8HTMLObjectElement::indexedPropertySetter(uint32_t index, v8::Local<v8::Value> value, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.HTMLObjectElement.IndexedPropertySetter"); + return npObjectIndexedSetter<V8HTMLObjectElement>(index, value, info); +} + } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8HTMLSelectElementCustom.cpp b/WebCore/bindings/v8/custom/V8HTMLSelectElementCustom.cpp index 661ffa2..0904b3e 100644 --- a/WebCore/bindings/v8/custom/V8HTMLSelectElementCustom.cpp +++ b/WebCore/bindings/v8/custom/V8HTMLSelectElementCustom.cpp @@ -33,25 +33,75 @@ #include "HTMLSelectElement.h" #include "HTMLOptionElement.h" +#include "HTMLOptionsCollection.h" #include "V8Binding.h" +#include "V8Collection.h" #include "V8CustomBinding.h" #include "V8HTMLOptionElement.h" +#include "V8HTMLSelectElement.h" +#include "V8NamedNodesCollection.h" #include "V8Proxy.h" namespace WebCore { -CALLBACK_FUNC_DECL(HTMLSelectElementRemove) +v8::Handle<v8::Value> V8HTMLSelectElement::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.HTMLSelectElement.NamedPropertyGetter"); + HTMLSelectElement* select = V8HTMLSelectElement::toNative(info.Holder()); + v8::Handle<v8::Value> value = info.Holder()->GetRealNamedPropertyInPrototypeChain(name); + + if (!value.IsEmpty()) + return value; + + // Search local callback properties next to find IDL defined properties. + if (info.Holder()->HasRealNamedCallbackProperty(name)) + return notHandledByInterceptor(); + + PassRefPtr<HTMLOptionsCollection> collection = select->options(); + + Vector<RefPtr<Node> > items; + collection->namedItems(v8StringToAtomicWebCoreString(name), items); + + if (!items.size()) + return notHandledByInterceptor(); + + if (items.size() == 1) + return V8DOMWrapper::convertNodeToV8Object(items.at(0).release()); + + NodeList* list = new V8NamedNodesCollection(items); + return V8DOMWrapper::convertToV8Object(V8ClassIndex::NODELIST, list); +} + +v8::Handle<v8::Value> V8HTMLSelectElement::indexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info) +{ + ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder())); + ASSERT(V8DOMWrapper::domWrapperType(info.Holder()) == V8ClassIndex::NODE); + RefPtr<Node> result = V8HTMLSelectElement::toNative(info.Holder())->item(index); + if (!result) + return notHandledByInterceptor(); + + return V8DOMWrapper::convertNodeToV8Object(result.release()); +} + +v8::Handle<v8::Value> V8HTMLSelectElement::indexedPropertySetter(uint32_t index, v8::Local<v8::Value> value, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.HTMLSelectElement.IndexedPropertySetter"); + HTMLSelectElement* select = V8HTMLSelectElement::toNative(info.Holder()); + return toOptionsCollectionSetter(index, value, select); +} + +v8::Handle<v8::Value> V8HTMLSelectElement::removeCallback(const v8::Arguments& args) { INC_STATS("DOM.HTMLSelectElement.remove"); - HTMLSelectElement* imp = V8DOMWrapper::convertDOMWrapperToNode<HTMLSelectElement>(args.Holder()); + HTMLSelectElement* imp = V8HTMLSelectElement::toNative(args.Holder()); return removeElement(imp, args); } v8::Handle<v8::Value> removeElement(HTMLSelectElement* imp, const v8::Arguments& args) { if (V8HTMLOptionElement::HasInstance(args[0])) { - HTMLOptionElement* element = V8DOMWrapper::convertDOMWrapperToNode<HTMLOptionElement>(v8::Handle<v8::Object>::Cast(args[0])); + HTMLOptionElement* element = V8HTMLOptionElement::toNative(v8::Handle<v8::Object>::Cast(args[0])); imp->remove(element->index()); return v8::Undefined(); } diff --git a/WebCore/bindings/v8/custom/V8HistoryCustom.cpp b/WebCore/bindings/v8/custom/V8HistoryCustom.cpp index c884d15..b857d6e 100644 --- a/WebCore/bindings/v8/custom/V8HistoryCustom.cpp +++ b/WebCore/bindings/v8/custom/V8HistoryCustom.cpp @@ -29,18 +29,21 @@ */ #include "config.h" -#include "History.h" +#include "V8History.h" #include "ExceptionCode.h" +#include "History.h" #include "SerializedScriptValue.h" #include "V8Binding.h" +#include "V8BindingState.h" #include "V8CustomBinding.h" #include "V8Proxy.h" namespace WebCore { -CALLBACK_FUNC_DECL(HistoryPushState) + +v8::Handle<v8::Value> V8History::pushStateCallback(const v8::Arguments& args) { - RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(toWebCoreString(args[0])); + RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(args[0]); v8::TryCatch tryCatch; String title = toWebCoreStringWithNullOrUndefinedCheck(args[1]); @@ -54,14 +57,14 @@ CALLBACK_FUNC_DECL(HistoryPushState) } ExceptionCode ec = 0; - History* history = V8DOMWrapper::convertToNativeObject<History>(V8ClassIndex::HISTORY, args.Holder()); + History* history = V8History::toNative(args.Holder()); history->stateObjectAdded(historyState.release(), title, url, History::StateObjectPush, ec); return throwError(ec); } -CALLBACK_FUNC_DECL(HistoryReplaceState) +v8::Handle<v8::Value> V8History::replaceStateCallback(const v8::Arguments& args) { - RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(toWebCoreString(args[0])); + RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(args[0]); v8::TryCatch tryCatch; String title = toWebCoreStringWithNullOrUndefinedCheck(args[1]); @@ -75,9 +78,25 @@ CALLBACK_FUNC_DECL(HistoryReplaceState) } ExceptionCode ec = 0; - History* history = V8DOMWrapper::convertToNativeObject<History>(V8ClassIndex::HISTORY, args.Holder()); + History* history = V8History::toNative(args.Holder()); history->stateObjectAdded(historyState.release(), title, url, History::StateObjectReplace, ec); return throwError(ec); } +bool V8History::indexedSecurityCheck(v8::Local<v8::Object> host, uint32_t index, v8::AccessType type, v8::Local<v8::Value> data) +{ + ASSERT(V8ClassIndex::FromInt(data->Int32Value()) == V8ClassIndex::HISTORY); + // Only allow same origin access. + History* history = V8History::toNative(host); + return V8BindingSecurity::canAccessFrame(V8BindingState::Only(), history->frame(), false); +} + +bool V8History::namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value> data) +{ + ASSERT(V8ClassIndex::FromInt(data->Int32Value()) == V8ClassIndex::HISTORY); + // Only allow same origin access. + History* history = V8History::toNative(host); + return V8BindingSecurity::canAccessFrame(V8BindingState::Only(), history->frame(), false); +} + } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8XPathEvaluatorConstructor.cpp b/WebCore/bindings/v8/custom/V8IDBRequestCustom.cpp index 69a8635..5ee9542 100644 --- a/WebCore/bindings/v8/custom/V8XPathEvaluatorConstructor.cpp +++ b/WebCore/bindings/v8/custom/V8IDBRequestCustom.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Google Inc. All rights reserved. + * Copyright (C) 2010 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -14,7 +14,7 @@ * * Neither the name of Google Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -29,17 +29,21 @@ */ #include "config.h" -#include "XPathEvaluator.h" +#include "V8IDBRequest.h" -#include "V8Binding.h" +#include "SerializedScriptValue.h" #include "V8Proxy.h" namespace WebCore { -CALLBACK_FUNC_DECL(XPathEvaluatorConstructor) +v8::Handle<v8::Value> V8IDBRequest::resultAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { - INC_STATS("DOM.XPathEvaluator.Constructor"); - return V8Proxy::constructDOMObject<V8ClassIndex::XPATHEVALUATOR, XPathEvaluator>(args); + IDBRequest* request = V8IDBRequest::toNative(info.Holder()); + SerializedScriptValue* result = request->result(); + if (!result) + return v8::Null(); + + return result->deserialize(); } } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8IndexedDatabaseRequestCustom.cpp b/WebCore/bindings/v8/custom/V8IndexedDatabaseRequestCustom.cpp new file mode 100644 index 0000000..66220ea --- /dev/null +++ b/WebCore/bindings/v8/custom/V8IndexedDatabaseRequestCustom.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "V8IndexedDatabaseRequest.h" + +#include "V8Binding.h" +#include "V8Proxy.h" + +namespace WebCore { + +v8::Handle<v8::Value> V8IndexedDatabaseRequest::openCallback(const v8::Arguments& args) +{ + IndexedDatabaseRequest* imp = V8IndexedDatabaseRequest::toNative(args.Holder()); + if (args.Length() < 2) + return throwError(V8Proxy::TypeError); + V8Parameter<> name = args[0]; + V8Parameter<> description = args[1]; + bool modifyDatabase = true; + if (args.Length() > 2) + modifyDatabase = args[2]->BooleanValue(); + + ExceptionCode ec = 0; + imp->open(name, description, modifyDatabase, ec); + if (ec) + return throwError(ec); + return v8::Handle<v8::Value>(); +} + +} // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp b/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp index fac6733..0ddcf97 100644 --- a/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp +++ b/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp @@ -29,45 +29,98 @@ */ #include "config.h" -#include "InjectedScriptHost.h" +#include "V8InjectedScriptHost.h" -#include "Database.h" #include "DOMWindow.h" +#include "Database.h" #include "Frame.h" +#include "InjectedScriptHost.h" #include "InspectorController.h" #include "Node.h" #include "Page.h" #include "V8Binding.h" #include "V8CustomBinding.h" +#include "V8Database.h" +#include "V8Node.h" #include "V8Proxy.h" +#include "V8Storage.h" namespace WebCore { -CALLBACK_FUNC_DECL(InjectedScriptHostInspectedWindow) +static void WeakReferenceCallback(v8::Persistent<v8::Value> object, void* parameter) { - INC_STATS("InjectedScriptHost.inspectedWindow()"); + InjectedScriptHost* nativeObject = static_cast<InjectedScriptHost*>(parameter); + nativeObject->deref(); + object.Dispose(); +} - InjectedScriptHost* host = V8DOMWrapper::convertToNativeObject<InjectedScriptHost>(V8ClassIndex::INJECTEDSCRIPTHOST, args.Holder()); - InspectorController* ic = host->inspectorController(); - if (!ic) - return v8::Undefined(); - return V8DOMWrapper::convertToV8Object<DOMWindow>(V8ClassIndex::DOMWINDOW, ic->inspectedPage()->mainFrame()->domWindow()); +static v8::Local<v8::Object> createInjectedScriptHostV8Wrapper(InjectedScriptHost* host) +{ + V8ClassIndex::V8WrapperType descriptorType = V8ClassIndex::INJECTEDSCRIPTHOST; + v8::Local<v8::Function> function = V8DOMWrapper::getTemplate(descriptorType)->GetFunction(); + if (function.IsEmpty()) { + // Return if allocation failed. + return v8::Local<v8::Object>(); + } + v8::Local<v8::Object> instance = SafeAllocation::newInstance(function); + if (instance.IsEmpty()) { + // Avoid setting the wrapper if allocation failed. + return v8::Local<v8::Object>(); + } + V8DOMWrapper::setDOMWrapper(instance, V8ClassIndex::ToInt(descriptorType), host); + // Create a weak reference to the v8 wrapper of InspectorBackend to deref + // InspectorBackend when the wrapper is garbage collected. + host->ref(); + v8::Persistent<v8::Object> weakHandle = v8::Persistent<v8::Object>::New(instance); + weakHandle.MakeWeak(host, &WeakReferenceCallback); + return instance; } -CALLBACK_FUNC_DECL(InjectedScriptHostWrapCallback) +static ScriptObject createInjectedScript(const String& scriptSource, InjectedScriptHost* injectedScriptHost, ScriptState* inspectedScriptState, long id) { - INC_STATS("InjectedScriptHost.wrapCallback()"); - return args[0]; + v8::HandleScope scope; + + v8::Local<v8::Context> inspectedContext = inspectedScriptState->context(); + v8::Context::Scope contextScope(inspectedContext); + + // Call custom code to create InjectedScripHost wrapper specific for the context + // instead of calling V8DOMWrapper::convertToV8Object that would create the + // wrapper in the current context. + // FIXME: make it possible to use generic bindings factory for InjectedScriptHost. + v8::Local<v8::Object> scriptHostWrapper = createInjectedScriptHostV8Wrapper(injectedScriptHost); + if (scriptHostWrapper.IsEmpty()) + return ScriptObject(); + + v8::Local<v8::Object> windowGlobal = inspectedContext->Global(); + + // Inject javascript into the context. The compiled script is supposed to evaluate into + // a single anonymous function(it's anonymous to avoid cluttering the global object with + // inspector's stuff) the function is called a few lines below with InjectedScriptHost wrapper, + // injected script id and explicit reference to the inspected global object. The function is expected + // to create and configure InjectedScript instance that is going to be used by the inspector. + v8::Local<v8::Script> script = v8::Script::Compile(v8String(scriptSource)); + v8::Local<v8::Value> v = script->Run(); + ASSERT(!v.IsEmpty()); + ASSERT(v->IsFunction()); + + v8::Handle<v8::Value> args[] = { + scriptHostWrapper, + windowGlobal, + v8::Number::New(id) + }; + v8::Local<v8::Value> injectedScriptValue = v8::Function::Cast(*v)->Call(windowGlobal, 3, args); + v8::Local<v8::Object> injectedScript(v8::Object::Cast(*injectedScriptValue)); + return ScriptObject(inspectedScriptState, injectedScript); } -CALLBACK_FUNC_DECL(InjectedScriptHostNodeForId) +v8::Handle<v8::Value> V8InjectedScriptHost::nodeForIdCallback(const v8::Arguments& args) { INC_STATS("InjectedScriptHost.nodeForId()"); if (args.Length() < 1) return v8::Undefined(); - InjectedScriptHost* host = V8DOMWrapper::convertToNativeObject<InjectedScriptHost>(V8ClassIndex::INJECTEDSCRIPTHOST, args.Holder()); + InjectedScriptHost* host = V8InjectedScriptHost::toNative(args.Holder()); Node* node = host->nodeForId(args[0]->ToInt32()->Value()); if (!node) @@ -80,63 +133,44 @@ CALLBACK_FUNC_DECL(InjectedScriptHostNodeForId) return V8DOMWrapper::convertToV8Object(V8ClassIndex::NODE, node); } -CALLBACK_FUNC_DECL(InjectedScriptHostWrapObject) -{ - INC_STATS("InjectedScriptHost.wrapObject()"); - if (args.Length() < 2) - return v8::Undefined(); - - InjectedScriptHost* host = V8DOMWrapper::convertToNativeObject<InjectedScriptHost>(V8ClassIndex::INJECTEDSCRIPTHOST, args.Holder()); - return host->wrapObject(ScriptValue(args[0]), toWebCoreStringWithNullCheck(args[1])).v8Value(); -} - -CALLBACK_FUNC_DECL(InjectedScriptHostUnwrapObject) -{ - INC_STATS("InjectedScriptHost.unwrapObject()"); - if (args.Length() < 1) - return v8::Undefined(); - - InjectedScriptHost* host = V8DOMWrapper::convertToNativeObject<InjectedScriptHost>(V8ClassIndex::INJECTEDSCRIPTHOST, args.Holder()); - return host->unwrapObject(toWebCoreStringWithNullCheck(args[0])).v8Value(); -} - -CALLBACK_FUNC_DECL(InjectedScriptHostPushNodePathToFrontend) +v8::Handle<v8::Value> V8InjectedScriptHost::pushNodePathToFrontendCallback(const v8::Arguments& args) { INC_STATS("InjectedScriptHost.pushNodePathToFrontend()"); - if (args.Length() < 2) + if (args.Length() < 3) return v8::Undefined(); - InjectedScriptHost* host = V8DOMWrapper::convertToNativeObject<InjectedScriptHost>(V8ClassIndex::INJECTEDSCRIPTHOST, args.Holder()); - Node* node = V8DOMWrapper::convertDOMWrapperToNode<Node>(v8::Handle<v8::Object>::Cast(args[0])); - bool selectInUI = args[1]->ToBoolean()->Value(); + InjectedScriptHost* host = V8InjectedScriptHost::toNative(args.Holder()); + Node* node = V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])); + bool withChildren = args[1]->ToBoolean()->Value(); + bool selectInUI = args[2]->ToBoolean()->Value(); if (node) - return v8::Number::New(host->pushNodePathToFrontend(node, selectInUI)); + return v8::Number::New(host->pushNodePathToFrontend(node, withChildren, selectInUI)); return v8::Undefined(); } #if ENABLE(DATABASE) -CALLBACK_FUNC_DECL(InjectedScriptHostDatabaseForId) +v8::Handle<v8::Value> V8InjectedScriptHost::databaseForIdCallback(const v8::Arguments& args) { INC_STATS("InjectedScriptHost.databaseForId()"); if (args.Length() < 1) return v8::Undefined(); - InjectedScriptHost* host = V8DOMWrapper::convertToNativeObject<InjectedScriptHost>(V8ClassIndex::INJECTEDSCRIPTHOST, args.Holder()); + InjectedScriptHost* host = V8InjectedScriptHost::toNative(args.Holder()); Database* database = host->databaseForId(args[0]->ToInt32()->Value()); if (!database) return v8::Undefined(); return V8DOMWrapper::convertToV8Object<Database>(V8ClassIndex::DATABASE, database); } -CALLBACK_FUNC_DECL(InjectedScriptHostSelectDatabase) +v8::Handle<v8::Value> V8InjectedScriptHost::selectDatabaseCallback(const v8::Arguments& args) { INC_STATS("InjectedScriptHost.selectDatabase()"); if (args.Length() < 1) return v8::Undefined(); - InjectedScriptHost* host = V8DOMWrapper::convertToNativeObject<InjectedScriptHost>(V8ClassIndex::INJECTEDSCRIPTHOST, args.Holder()); - Database* database = V8DOMWrapper::convertToNativeObject<Database>(V8ClassIndex::DATABASE, v8::Handle<v8::Object>::Cast(args[0])); + InjectedScriptHost* host = V8InjectedScriptHost::toNative(args.Holder()); + Database* database = V8Database::toNative(v8::Handle<v8::Object>::Cast(args[0])); if (database) host->selectDatabase(database); @@ -145,14 +179,14 @@ CALLBACK_FUNC_DECL(InjectedScriptHostSelectDatabase) #endif #if ENABLE(DOM_STORAGE) -CALLBACK_FUNC_DECL(InjectedScriptHostSelectDOMStorage) +v8::Handle<v8::Value> V8InjectedScriptHost::selectDOMStorageCallback(const v8::Arguments& args) { INC_STATS("InjectedScriptHost.selectDOMStorage()"); if (args.Length() < 1) return v8::Undefined(); - InjectedScriptHost* host = V8DOMWrapper::convertToNativeObject<InjectedScriptHost>(V8ClassIndex::INJECTEDSCRIPTHOST, args.Holder()); - Storage* storage = V8DOMWrapper::convertToNativeObject<Storage>(V8ClassIndex::STORAGE, v8::Handle<v8::Object>::Cast(args[0])); + InjectedScriptHost* host = V8InjectedScriptHost::toNative(args.Holder()); + Storage* storage = V8Storage::toNative(v8::Handle<v8::Object>::Cast(args[0])); if (storage) host->selectDOMStorage(storage); @@ -160,4 +194,28 @@ CALLBACK_FUNC_DECL(InjectedScriptHostSelectDOMStorage) } #endif +ScriptObject InjectedScriptHost::injectedScriptFor(ScriptState* inspectedScriptState) +{ + v8::HandleScope handleScope; + v8::Local<v8::Context> context = inspectedScriptState->context(); + v8::Context::Scope contextScope(context); + + v8::Local<v8::Object> global = context->Global(); + // Skip proxy object. The proxy object will survive page navigation while we need + // an object whose lifetime consides with that of the inspected context. + global = v8::Local<v8::Object>::Cast(global->GetPrototype()); + + v8::Local<v8::String> key = v8::String::New("Devtools_InjectedScript"); + v8::Local<v8::Value> val = global->GetHiddenValue(key); + if (!val.IsEmpty() && val->IsObject()) + return ScriptObject(inspectedScriptState, v8::Local<v8::Object>::Cast(val)); + + ASSERT(!m_injectedScriptSource.isEmpty()); + ScriptObject injectedScriptObject = createInjectedScript(m_injectedScriptSource, this, inspectedScriptState, m_nextInjectedScriptId); + m_idToInjectedScript.set(m_nextInjectedScriptId, injectedScriptObject); + ++m_nextInjectedScriptId; + global->SetHiddenValue(key, injectedScriptObject.v8Object()); + return injectedScriptObject; +} + } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8InspectorFrontendHostCustom.cpp b/WebCore/bindings/v8/custom/V8InspectorFrontendHostCustom.cpp index 15b45e9..df63bf1 100644 --- a/WebCore/bindings/v8/custom/V8InspectorFrontendHostCustom.cpp +++ b/WebCore/bindings/v8/custom/V8InspectorFrontendHostCustom.cpp @@ -29,15 +29,10 @@ */ #include "config.h" -#include "InspectorFrontendHost.h" +#include "V8InspectorFrontendHost.h" -#include "ExceptionCode.h" #include "InspectorController.h" -#include "Node.h" -#include "Range.h" -#include "Page.h" -#include "TextIterator.h" -#include "VisiblePosition.h" +#include "InspectorFrontendHost.h" #include "V8Binding.h" #include "V8CustomBinding.h" @@ -45,46 +40,7 @@ namespace WebCore { -CALLBACK_FUNC_DECL(InspectorFrontendHostSearch) -{ - INC_STATS("InspectorFrontendHost.search()"); - - if (args.Length() < 2) - return v8::Undefined(); - - Node* node = V8DOMWrapper::convertDOMWrapperToNode<Node>(v8::Handle<v8::Object>::Cast(args[0])); - if (!node) - return v8::Undefined(); - - String target = toWebCoreStringWithNullCheck(args[1]); - if (target.isEmpty()) - return v8::Undefined(); - - v8::Local<v8::Array> result = v8::Array::New(); - RefPtr<Range> searchRange(rangeOfContents(node)); - - ExceptionCode ec = 0; - int index = 0; - do { - RefPtr<Range> resultRange(findPlainText(searchRange.get(), target, true, false)); - if (resultRange->collapsed(ec)) - break; - - // A non-collapsed result range can in some funky whitespace cases still not - // advance the range's start position (4509328). Break to avoid infinite loop. - VisiblePosition newStart = endVisiblePosition(resultRange.get(), DOWNSTREAM); - if (newStart == startVisiblePosition(searchRange.get(), DOWNSTREAM)) - break; - - result->Set(v8::Number::New(index++), V8DOMWrapper::convertToV8Object(V8ClassIndex::RANGE, resultRange.release())); - - setStart(searchRange.get(), newStart); - } while (true); - - return result; -} - -CALLBACK_FUNC_DECL(InspectorFrontendHostShowContextMenu) +v8::Handle<v8::Value> V8InspectorFrontendHost::showContextMenuCallback(const v8::Arguments& args) { return v8::Undefined(); } diff --git a/WebCore/bindings/v8/custom/V8LocationCustom.cpp b/WebCore/bindings/v8/custom/V8LocationCustom.cpp index 1ed4c51..ce816b6 100644 --- a/WebCore/bindings/v8/custom/V8LocationCustom.cpp +++ b/WebCore/bindings/v8/custom/V8LocationCustom.cpp @@ -29,23 +29,24 @@ */ #include "config.h" -#include "Location.h" +#include "V8Location.h" +#include "CSSHelper.h" +#include "Document.h" +#include "Frame.h" +#include "FrameLoader.h" +#include "KURL.h" +#include "Location.h" +#include "PlatformString.h" +#include "ScriptController.h" #include "V8Binding.h" +#include "V8BindingState.h" #include "V8CustomBinding.h" #include "V8CustomEventListener.h" #include "V8Location.h" #include "V8Utilities.h" #include "V8Proxy.h" -#include "PlatformString.h" -#include "KURL.h" -#include "Document.h" -#include "FrameLoader.h" -#include "ScriptController.h" -#include "CSSHelper.h" -#include "Frame.h" - namespace WebCore { // Notes about V8/JSC porting of this file. @@ -58,11 +59,11 @@ namespace WebCore { // we're just making all these custom for now. The functionality is simple // and mirrors JSLocationCustom.cpp. -ACCESSOR_SETTER(LocationHash) +void V8Location::hashAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.Location.hash._set"); v8::Handle<v8::Object> holder = info.Holder(); - Location* imp = V8DOMWrapper::convertToNativeObject<Location>(V8ClassIndex::LOCATION, holder); + Location* imp = V8Location::toNative(holder); String hash = toWebCoreString(value); Frame* frame = imp->frame(); @@ -81,11 +82,11 @@ ACCESSOR_SETTER(LocationHash) navigateIfAllowed(frame, url, false, false); } -ACCESSOR_SETTER(LocationHost) +void V8Location::hostAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.Location.host._set"); v8::Handle<v8::Object> holder = info.Holder(); - Location* imp = V8DOMWrapper::convertToNativeObject<Location>(V8ClassIndex::LOCATION, holder); + Location* imp = V8Location::toNative(holder); String host = toWebCoreString(value); Frame* frame = imp->frame(); @@ -101,11 +102,11 @@ ACCESSOR_SETTER(LocationHost) navigateIfAllowed(frame, url, false, false); } -ACCESSOR_SETTER(LocationHostname) +void V8Location::hostnameAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.Location.hostname._set"); v8::Handle<v8::Object> holder = info.Holder(); - Location* imp = V8DOMWrapper::convertToNativeObject<Location>(V8ClassIndex::LOCATION, holder); + Location* imp = V8Location::toNative(holder); String hostname = toWebCoreString(value); Frame* frame = imp->frame(); @@ -118,11 +119,11 @@ ACCESSOR_SETTER(LocationHostname) navigateIfAllowed(frame, url, false, false); } -ACCESSOR_SETTER(LocationHref) +void V8Location::hrefAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.Location.href._set"); v8::Handle<v8::Object> holder = info.Holder(); - Location* imp = V8DOMWrapper::convertToNativeObject<Location>(V8ClassIndex::LOCATION, holder); + Location* imp = V8Location::toNative(holder); Frame* frame = imp->frame(); if (!frame) @@ -138,11 +139,11 @@ ACCESSOR_SETTER(LocationHref) navigateIfAllowed(frame, url, false, false); } -ACCESSOR_SETTER(LocationPathname) +void V8Location::pathnameAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.Location.pathname._set"); v8::Handle<v8::Object> holder = info.Holder(); - Location* imp = V8DOMWrapper::convertToNativeObject<Location>(V8ClassIndex::LOCATION, holder); + Location* imp = V8Location::toNative(holder); String pathname = toWebCoreString(value); Frame* frame = imp->frame(); @@ -155,11 +156,11 @@ ACCESSOR_SETTER(LocationPathname) navigateIfAllowed(frame, url, false, false); } -ACCESSOR_SETTER(LocationPort) +void V8Location::portAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.Location.port._set"); v8::Handle<v8::Object> holder = info.Holder(); - Location* imp = V8DOMWrapper::convertToNativeObject<Location>(V8ClassIndex::LOCATION, holder); + Location* imp = V8Location::toNative(holder); String port = toWebCoreString(value); Frame* frame = imp->frame(); @@ -172,11 +173,11 @@ ACCESSOR_SETTER(LocationPort) navigateIfAllowed(frame, url, false, false); } -ACCESSOR_SETTER(LocationProtocol) +void V8Location::protocolAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.Location.protocol._set"); v8::Handle<v8::Object> holder = info.Holder(); - Location* imp = V8DOMWrapper::convertToNativeObject<Location>(V8ClassIndex::LOCATION, holder); + Location* imp = V8Location::toNative(holder); String protocol = toWebCoreString(value); Frame* frame = imp->frame(); @@ -189,11 +190,11 @@ ACCESSOR_SETTER(LocationProtocol) navigateIfAllowed(frame, url, false, false); } -ACCESSOR_SETTER(LocationSearch) +void V8Location::searchAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.Location.search._set"); v8::Handle<v8::Object> holder = info.Holder(); - Location* imp = V8DOMWrapper::convertToNativeObject<Location>(V8ClassIndex::LOCATION, holder); + Location* imp = V8Location::toNative(holder); String query = toWebCoreString(value); Frame* frame = imp->frame(); @@ -206,68 +207,68 @@ ACCESSOR_SETTER(LocationSearch) navigateIfAllowed(frame, url, false, false); } -ACCESSOR_GETTER(LocationReload) +v8::Handle<v8::Value> V8Location::reloadAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.Location.reload._get"); - static v8::Persistent<v8::FunctionTemplate> privateTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(v8LocationReloadCallback, v8::Handle<v8::Value>(), v8::Signature::New(V8Location::GetRawTemplate()))); + static v8::Persistent<v8::FunctionTemplate> privateTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(V8Location::reloadCallback, v8::Handle<v8::Value>(), v8::Signature::New(V8Location::GetRawTemplate()))); v8::Handle<v8::Object> holder = V8DOMWrapper::lookupDOMWrapper(V8ClassIndex::LOCATION, info.This()); if (holder.IsEmpty()) { // can only reach here by 'object.__proto__.func', and it should passed // domain security check already return privateTemplate->GetFunction(); } - Location* imp = V8DOMWrapper::convertToNativeObject<Location>(V8ClassIndex::LOCATION, holder); - if (!V8Proxy::canAccessFrame(imp->frame(), false)) { - static v8::Persistent<v8::FunctionTemplate> sharedTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(v8LocationReloadCallback, v8::Handle<v8::Value>(), v8::Signature::New(V8Location::GetRawTemplate()))); + Location* imp = V8Location::toNative(holder); + if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), false)) { + static v8::Persistent<v8::FunctionTemplate> sharedTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(V8Location::reloadCallback, v8::Handle<v8::Value>(), v8::Signature::New(V8Location::GetRawTemplate()))); return sharedTemplate->GetFunction(); - } else - return privateTemplate->GetFunction(); + } + return privateTemplate->GetFunction(); } -ACCESSOR_GETTER(LocationReplace) +v8::Handle<v8::Value> V8Location::replaceAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.Location.replace._get"); - static v8::Persistent<v8::FunctionTemplate> privateTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(v8LocationReplaceCallback, v8::Handle<v8::Value>(), v8::Signature::New(V8Location::GetRawTemplate()))); + static v8::Persistent<v8::FunctionTemplate> privateTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(V8Location::replaceCallback, v8::Handle<v8::Value>(), v8::Signature::New(V8Location::GetRawTemplate()))); v8::Handle<v8::Object> holder = V8DOMWrapper::lookupDOMWrapper(V8ClassIndex::LOCATION, info.This()); if (holder.IsEmpty()) { // can only reach here by 'object.__proto__.func', and it should passed // domain security check already return privateTemplate->GetFunction(); } - Location* imp = V8DOMWrapper::convertToNativeObject<Location>(V8ClassIndex::LOCATION, holder); - if (!V8Proxy::canAccessFrame(imp->frame(), false)) { - static v8::Persistent<v8::FunctionTemplate> sharedTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(v8LocationReplaceCallback, v8::Handle<v8::Value>(), v8::Signature::New(V8Location::GetRawTemplate()))); + Location* imp = V8Location::toNative(holder); + if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), false)) { + static v8::Persistent<v8::FunctionTemplate> sharedTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(V8Location::replaceCallback, v8::Handle<v8::Value>(), v8::Signature::New(V8Location::GetRawTemplate()))); return sharedTemplate->GetFunction(); - } else - return privateTemplate->GetFunction(); + } + return privateTemplate->GetFunction(); } -ACCESSOR_GETTER(LocationAssign) +v8::Handle<v8::Value> V8Location::assignAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.Location.assign._get"); static v8::Persistent<v8::FunctionTemplate> privateTemplate = - v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(v8LocationAssignCallback, v8::Handle<v8::Value>(), v8::Signature::New(V8Location::GetRawTemplate()))); + v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(V8Location::assignCallback, v8::Handle<v8::Value>(), v8::Signature::New(V8Location::GetRawTemplate()))); v8::Handle<v8::Object> holder = V8DOMWrapper::lookupDOMWrapper(V8ClassIndex::LOCATION, info.This()); if (holder.IsEmpty()) { // can only reach here by 'object.__proto__.func', and it should passed // domain security check already return privateTemplate->GetFunction(); } - Location* imp = V8DOMWrapper::convertToNativeObject<Location>(V8ClassIndex::LOCATION, holder); - if (!V8Proxy::canAccessFrame(imp->frame(), false)) { - static v8::Persistent<v8::FunctionTemplate> sharedTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(v8LocationAssignCallback, v8::Handle<v8::Value>(), v8::Signature::New(V8Location::GetRawTemplate()))); + Location* imp = V8Location::toNative(holder); + if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), false)) { + static v8::Persistent<v8::FunctionTemplate> sharedTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(V8Location::assignCallback, v8::Handle<v8::Value>(), v8::Signature::New(V8Location::GetRawTemplate()))); return sharedTemplate->GetFunction(); - } else - return privateTemplate->GetFunction(); + } + return privateTemplate->GetFunction(); } -CALLBACK_FUNC_DECL(LocationReload) +v8::Handle<v8::Value> V8Location::reloadCallback(const v8::Arguments& args) { // FIXME: we ignore the "forceget" parameter. INC_STATS("DOM.Location.reload"); v8::Handle<v8::Object> holder = args.Holder(); - Location* imp = V8DOMWrapper::convertToNativeObject<Location>(V8ClassIndex::LOCATION, holder); + Location* imp = V8Location::toNative(holder); Frame* frame = imp->frame(); if (!frame || !ScriptController::isSafeScript(frame)) @@ -278,11 +279,11 @@ CALLBACK_FUNC_DECL(LocationReload) return v8::Undefined(); } -CALLBACK_FUNC_DECL(LocationReplace) +v8::Handle<v8::Value> V8Location::replaceCallback(const v8::Arguments& args) { INC_STATS("DOM.Location.replace"); v8::Handle<v8::Object> holder = args.Holder(); - Location* imp = V8DOMWrapper::convertToNativeObject<Location>(V8ClassIndex::LOCATION, holder); + Location* imp = V8Location::toNative(holder); Frame* frame = imp->frame(); if (!frame) @@ -299,11 +300,11 @@ CALLBACK_FUNC_DECL(LocationReplace) return v8::Undefined(); } -CALLBACK_FUNC_DECL(LocationAssign) +v8::Handle<v8::Value> V8Location::assignCallback(const v8::Arguments& args) { INC_STATS("DOM.Location.assign"); v8::Handle<v8::Object> holder = args.Holder(); - Location* imp = V8DOMWrapper::convertToNativeObject<Location>(V8ClassIndex::LOCATION, holder); + Location* imp = V8Location::toNative(holder); Frame* frame = imp->frame(); if (!frame) @@ -320,7 +321,7 @@ CALLBACK_FUNC_DECL(LocationAssign) return v8::Undefined(); } -CALLBACK_FUNC_DECL(LocationValueOf) +v8::Handle<v8::Value> V8Location::valueOfCallback(const v8::Arguments& args) { // Just return the this object the way the normal valueOf function // on the Object prototype would. The valueOf function is only @@ -330,31 +331,31 @@ CALLBACK_FUNC_DECL(LocationValueOf) return args.This(); } -CALLBACK_FUNC_DECL(LocationToString) +v8::Handle<v8::Value> V8Location::toStringCallback(const v8::Arguments& args) { INC_STATS("DOM.Location.toString"); v8::Handle<v8::Object> holder = args.Holder(); - Location* imp = V8DOMWrapper::convertToNativeObject<Location>(V8ClassIndex::LOCATION, holder); - if (!V8Proxy::canAccessFrame(imp->frame(), true)) + Location* imp = V8Location::toNative(holder); + if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), true)) return v8::Undefined(); String result = imp->href(); return v8String(result); } -INDEXED_ACCESS_CHECK(Location) +bool V8Location::indexedSecurityCheck(v8::Local<v8::Object> host, uint32_t index, v8::AccessType type, v8::Local<v8::Value> data) { ASSERT(V8ClassIndex::FromInt(data->Int32Value()) == V8ClassIndex::LOCATION); // Only allow same origin access - Location* imp = V8DOMWrapper::convertToNativeObject<Location>(V8ClassIndex::LOCATION, host); - return V8Proxy::canAccessFrame(imp->frame(), false); + Location* imp = V8Location::toNative(host); + return V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), false); } -NAMED_ACCESS_CHECK(Location) +bool V8Location::namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value> data) { ASSERT(V8ClassIndex::FromInt(data->Int32Value()) == V8ClassIndex::LOCATION); // Only allow same origin access - Location* imp = V8DOMWrapper::convertToNativeObject<Location>(V8ClassIndex::LOCATION, host); - return V8Proxy::canAccessFrame(imp->frame(), false); + Location* imp = V8Location::toNative(host); + return V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), false); } } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8MessageChannelConstructor.cpp b/WebCore/bindings/v8/custom/V8MessageChannelConstructor.cpp index ca02b16..3ea8e26 100644 --- a/WebCore/bindings/v8/custom/V8MessageChannelConstructor.cpp +++ b/WebCore/bindings/v8/custom/V8MessageChannelConstructor.cpp @@ -29,13 +29,13 @@ */ #include "config.h" -#include "MessageChannel.h" - -#include "V8Binding.h" -#include "V8Proxy.h" +#include "V8MessageChannel.h" #include "Document.h" #include "Frame.h" +#include "MessageChannel.h" +#include "V8Binding.h" +#include "V8Proxy.h" #include "V8Utilities.h" #include "WorkerContext.h" #include "WorkerContextExecutionProxy.h" @@ -44,7 +44,7 @@ namespace WebCore { -CALLBACK_FUNC_DECL(MessageChannelConstructor) +v8::Handle<v8::Value> V8MessageChannel::constructorCallback(const v8::Arguments& args) { INC_STATS("DOM.MessageChannel.Constructor"); // FIXME: The logic here is almost exact duplicate of V8::constructDOMObject. @@ -66,8 +66,8 @@ CALLBACK_FUNC_DECL(MessageChannelConstructor) // Create references from the MessageChannel wrapper to the two // MessagePort wrappers to make sure that the MessagePort wrappers // stay alive as long as the MessageChannel wrapper is around. - messageChannel->SetInternalField(kMessageChannelPort1Index, V8DOMWrapper::convertToV8Object(V8ClassIndex::MESSAGEPORT, obj->port1())); - messageChannel->SetInternalField(kMessageChannelPort2Index, V8DOMWrapper::convertToV8Object(V8ClassIndex::MESSAGEPORT, obj->port2())); + messageChannel->SetInternalField(V8MessageChannel::port1Index, V8DOMWrapper::convertToV8Object(V8ClassIndex::MESSAGEPORT, obj->port1())); + messageChannel->SetInternalField(V8MessageChannel::port2Index, V8DOMWrapper::convertToV8Object(V8ClassIndex::MESSAGEPORT, obj->port2())); // Setup the standard wrapper object internal fields. V8DOMWrapper::setDOMWrapper(messageChannel, V8ClassIndex::MESSAGECHANNEL, obj.get()); diff --git a/WebCore/bindings/v8/custom/V8MessageEventCustom.cpp b/WebCore/bindings/v8/custom/V8MessageEventCustom.cpp index c5af635..9e40855 100644 --- a/WebCore/bindings/v8/custom/V8MessageEventCustom.cpp +++ b/WebCore/bindings/v8/custom/V8MessageEventCustom.cpp @@ -29,6 +29,8 @@ */ #include "config.h" +#include "V8MessageEvent.h" + #include "MessageEvent.h" #include "SerializedScriptValue.h" @@ -40,10 +42,10 @@ namespace WebCore { -ACCESSOR_GETTER(MessageEventPorts) +v8::Handle<v8::Value> V8MessageEvent::portsAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.MessageEvent.ports"); - MessageEvent* event = V8DOMWrapper::convertToNativeObject<MessageEvent>(V8ClassIndex::MESSAGEEVENT, info.Holder()); + MessageEvent* event = V8MessageEvent::toNative(info.Holder()); MessagePortArray* ports = event->ports(); if (!ports || ports->isEmpty()) @@ -56,17 +58,24 @@ ACCESSOR_GETTER(MessageEventPorts) return portArray; } -CALLBACK_FUNC_DECL(MessageEventInitMessageEvent) +v8::Handle<v8::Value> V8MessageEvent::initMessageEventCallback(const v8::Arguments& args) { INC_STATS("DOM.MessageEvent.initMessageEvent"); - MessageEvent* event = V8DOMWrapper::convertToNativeObject<MessageEvent>(V8ClassIndex::MESSAGEEVENT, args.Holder()); + MessageEvent* event = V8MessageEvent::toNative(args.Holder()); String typeArg = v8ValueToWebCoreString(args[0]); bool canBubbleArg = args[1]->BooleanValue(); bool cancelableArg = args[2]->BooleanValue(); - RefPtr<SerializedScriptValue> dataArg = SerializedScriptValue::create(v8ValueToWebCoreString(args[3])); + RefPtr<SerializedScriptValue> dataArg = SerializedScriptValue::create(args[3]); String originArg = v8ValueToWebCoreString(args[4]); String lastEventIdArg = v8ValueToWebCoreString(args[5]); - DOMWindow* sourceArg = V8DOMWindow::HasInstance(args[6]) ? V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, v8::Handle<v8::Object>::Cast(args[6])) : 0; + + DOMWindow* sourceArg = 0; + if (args[6]->IsObject()) { + v8::Handle<v8::Object> wrapper = v8::Handle<v8::Object>::Cast(args[6]); + v8::Handle<v8::Object> window = V8DOMWrapper::lookupDOMWrapper(V8ClassIndex::DOMWINDOW, wrapper); + if (!window.IsEmpty()) + sourceArg = V8DOMWindow::toNative(window); + } OwnPtr<MessagePortArray> portArray; if (!isUndefinedOrNull(args[7])) { diff --git a/WebCore/bindings/v8/custom/V8MessagePortCustom.cpp b/WebCore/bindings/v8/custom/V8MessagePortCustom.cpp index 0d8631f..cc70bc5 100644 --- a/WebCore/bindings/v8/custom/V8MessagePortCustom.cpp +++ b/WebCore/bindings/v8/custom/V8MessagePortCustom.cpp @@ -43,42 +43,42 @@ namespace WebCore { -CALLBACK_FUNC_DECL(MessagePortAddEventListener) +v8::Handle<v8::Value> V8MessagePort::addEventListenerCallback(const v8::Arguments& args) { INC_STATS("DOM.MessagePort.addEventListener()"); - MessagePort* messagePort = V8DOMWrapper::convertToNativeObject<MessagePort>(V8ClassIndex::MESSAGEPORT, args.Holder()); + MessagePort* messagePort = V8MessagePort::toNative(args.Holder()); RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(messagePort, args[1], false, ListenerFindOrCreate); if (listener) { String type = toWebCoreString(args[0]); bool useCapture = args[2]->BooleanValue(); messagePort->addEventListener(type, listener, useCapture); - createHiddenDependency(args.Holder(), args[1], V8Custom::kMessagePortRequestCacheIndex); + createHiddenDependency(args.Holder(), args[1], cacheIndex); } return v8::Undefined(); } -CALLBACK_FUNC_DECL(MessagePortRemoveEventListener) +v8::Handle<v8::Value> V8MessagePort::removeEventListenerCallback(const v8::Arguments& args) { INC_STATS("DOM.MessagePort.removeEventListener()"); - MessagePort* messagePort = V8DOMWrapper::convertToNativeObject<MessagePort>(V8ClassIndex::MESSAGEPORT, args.Holder()); + MessagePort* messagePort = V8MessagePort::toNative(args.Holder()); RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(messagePort, args[1], false, ListenerFindOnly); if (listener) { String type = toWebCoreString(args[0]); bool useCapture = args[2]->BooleanValue(); messagePort->removeEventListener(type, listener.get(), useCapture); - removeHiddenDependency(args.Holder(), args[1], V8Custom::kMessagePortRequestCacheIndex); + removeHiddenDependency(args.Holder(), args[1], cacheIndex); } return v8::Undefined(); } -CALLBACK_FUNC_DECL(MessagePortPostMessage) +v8::Handle<v8::Value> V8MessagePort::postMessageCallback(const v8::Arguments& args) { INC_STATS("DOM.MessagePort.postMessage"); - MessagePort* messagePort = V8DOMWrapper::convertToNativeObject<MessagePort>(V8ClassIndex::MESSAGEPORT, args.Holder()); - RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(toWebCoreString(args[0])); + MessagePort* messagePort = V8MessagePort::toNative(args.Holder()); + RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0]); MessagePortArray portArray; if (args.Length() > 1) { if (!getMessagePortArray(args[1], portArray)) @@ -129,7 +129,7 @@ bool getMessagePortArray(v8::Local<v8::Value> value, MessagePortArray& portArray throwError("MessagePortArray argument must contain only MessagePorts"); return false; } - portArray[i] = V8DOMWrapper::convertToNativeObject<MessagePort>(V8ClassIndex::MESSAGEPORT, v8::Handle<v8::Object>::Cast(port)); + portArray[i] = V8MessagePort::toNative(v8::Handle<v8::Object>::Cast(port)); } return true; } diff --git a/WebCore/bindings/v8/custom/V8NamedNodeMapCustom.cpp b/WebCore/bindings/v8/custom/V8NamedNodeMapCustom.cpp index afa90b7..c7fff5a 100644 --- a/WebCore/bindings/v8/custom/V8NamedNodeMapCustom.cpp +++ b/WebCore/bindings/v8/custom/V8NamedNodeMapCustom.cpp @@ -29,8 +29,9 @@ */ #include "config.h" -#include "NamedNodeMap.h" +#include "V8NamedNodeMap.h" +#include "NamedNodeMap.h" #include "V8Binding.h" #include "V8CustomBinding.h" #include "V8Proxy.h" @@ -39,10 +40,10 @@ namespace WebCore { -INDEXED_PROPERTY_GETTER(NamedNodeMap) +v8::Handle<v8::Value> V8NamedNodeMap::indexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info) { INC_STATS("DOM.NamedNodeMap.IndexedPropertyGetter"); - NamedNodeMap* imp = V8DOMWrapper::convertToNativeObject<NamedNodeMap>(V8ClassIndex::NAMEDNODEMAP, info.Holder()); + NamedNodeMap* imp = V8NamedNodeMap::toNative(info.Holder()); RefPtr<Node> result = imp->item(index); if (!result) return notHandledByInterceptor(); @@ -50,7 +51,7 @@ INDEXED_PROPERTY_GETTER(NamedNodeMap) return V8DOMWrapper::convertNodeToV8Object(result.release()); } -NAMED_PROPERTY_GETTER(NamedNodeMap) +v8::Handle<v8::Value> V8NamedNodeMap::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.NamedNodeMap.NamedPropertyGetter"); // Search the prototype chain first. @@ -63,7 +64,7 @@ NAMED_PROPERTY_GETTER(NamedNodeMap) return notHandledByInterceptor(); // Finally, search the DOM. - NamedNodeMap* imp = V8DOMWrapper::convertToNativeObject<NamedNodeMap>(V8ClassIndex::NAMEDNODEMAP, info.Holder()); + NamedNodeMap* imp = V8NamedNodeMap::toNative(info.Holder()); RefPtr<Node> result = imp->getNamedItem(toWebCoreString(name)); if (!result) return notHandledByInterceptor(); diff --git a/WebCore/bindings/v8/custom/V8NavigatorCustom.cpp b/WebCore/bindings/v8/custom/V8NavigatorCustom.cpp index 6a7b209..266745d 100644 --- a/WebCore/bindings/v8/custom/V8NavigatorCustom.cpp +++ b/WebCore/bindings/v8/custom/V8NavigatorCustom.cpp @@ -1,10 +1,10 @@ /* - * Copyright (C) 2007-2009 Google Inc. All rights reserved. - * + * Copyright (C) 2010 Google Inc. All rights reserved. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above @@ -14,7 +14,7 @@ * * Neither the name of Google Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -29,20 +29,17 @@ */ #include "config.h" -#include "Navigator.h" +#include "V8Navigator.h" -#include "V8Binding.h" -#include "V8CustomBinding.h" -#include "V8Proxy.h" +#include "RuntimeEnabledFeatures.h" namespace WebCore { -ACCESSOR_GETTER(NavigatorAppVersion) +#if ENABLE(GEOLOCATION) +bool V8Navigator::GeolocationEnabled() { - INC_STATS("DOM.Navigator.appVersion"); - v8::Handle<v8::Object> holder = info.Holder(); - Navigator* navigator = V8DOMWrapper::convertToNativeObject<Navigator>(V8ClassIndex::NAVIGATOR, holder); - return v8StringOrUndefined(navigator->appVersion()); + return RuntimeEnabledFeatures::geolocationEnabled(); } +#endif } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8NodeCustom.cpp b/WebCore/bindings/v8/custom/V8NodeCustom.cpp index 9b4b9aa..79afbe8 100644 --- a/WebCore/bindings/v8/custom/V8NodeCustom.cpp +++ b/WebCore/bindings/v8/custom/V8NodeCustom.cpp @@ -45,25 +45,25 @@ namespace WebCore { -CALLBACK_FUNC_DECL(NodeAddEventListener) +v8::Handle<v8::Value> V8Node::addEventListenerCallback(const v8::Arguments& args) { INC_STATS("DOM.Node.addEventListener()"); - Node* node = V8DOMWrapper::convertDOMWrapperToNode<Node>(args.Holder()); + Node* node = V8Node::toNative(args.Holder()); RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(node, args[1], false, ListenerFindOrCreate); if (listener) { String type = toWebCoreString(args[0]); bool useCapture = args[2]->BooleanValue(); node->addEventListener(type, listener, useCapture); - createHiddenDependency(args.Holder(), args[1], V8Custom::kNodeEventListenerCacheIndex); + createHiddenDependency(args.Holder(), args[1], cacheIndex); } return v8::Undefined(); } -CALLBACK_FUNC_DECL(NodeRemoveEventListener) +v8::Handle<v8::Value> V8Node::removeEventListenerCallback(const v8::Arguments& args) { INC_STATS("DOM.Node.removeEventListener()"); - Node* node = V8DOMWrapper::convertDOMWrapperToNode<Node>(args.Holder()); + Node* node = V8Node::toNative(args.Holder()); // It is possbile that the owner document of the node is detached // from the frame. @@ -73,21 +73,21 @@ CALLBACK_FUNC_DECL(NodeRemoveEventListener) AtomicString type = v8ValueToAtomicWebCoreString(args[0]); bool useCapture = args[2]->BooleanValue(); node->removeEventListener(type, listener.get(), useCapture); - removeHiddenDependency(args.Holder(), args[1], V8Custom::kNodeEventListenerCacheIndex); + removeHiddenDependency(args.Holder(), args[1], cacheIndex); } return v8::Undefined(); } // This function is customized to take advantage of the optional 4th argument: shouldLazyAttach -CALLBACK_FUNC_DECL(NodeInsertBefore) +v8::Handle<v8::Value> V8Node::insertBeforeCallback(const v8::Arguments& args) { INC_STATS("DOM.Node.insertBefore"); v8::Handle<v8::Object> holder = args.Holder(); - Node* imp = V8DOMWrapper::convertDOMWrapperToNode<Node>(holder); + Node* imp = V8Node::toNative(holder); ExceptionCode ec = 0; - Node* newChild = V8Node::HasInstance(args[0]) ? V8DOMWrapper::convertDOMWrapperToNode<Node>(v8::Handle<v8::Object>::Cast(args[0])) : 0; - Node* refChild = V8Node::HasInstance(args[1]) ? V8DOMWrapper::convertDOMWrapperToNode<Node>(v8::Handle<v8::Object>::Cast(args[1])) : 0; + Node* newChild = V8Node::HasInstance(args[0]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; + Node* refChild = V8Node::HasInstance(args[1]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[1])) : 0; bool success = imp->insertBefore(newChild, refChild, ec, true); if (ec) { V8Proxy::setDOMException(ec); @@ -99,14 +99,14 @@ CALLBACK_FUNC_DECL(NodeInsertBefore) } // This function is customized to take advantage of the optional 4th argument: shouldLazyAttach -CALLBACK_FUNC_DECL(NodeReplaceChild) +v8::Handle<v8::Value> V8Node::replaceChildCallback(const v8::Arguments& args) { INC_STATS("DOM.Node.replaceChild"); v8::Handle<v8::Object> holder = args.Holder(); - Node* imp = V8DOMWrapper::convertDOMWrapperToNode<Node>(holder); + Node* imp = V8Node::toNative(holder); ExceptionCode ec = 0; - Node* newChild = V8Node::HasInstance(args[0]) ? V8DOMWrapper::convertDOMWrapperToNode<Node>(v8::Handle<v8::Object>::Cast(args[0])) : 0; - Node* oldChild = V8Node::HasInstance(args[1]) ? V8DOMWrapper::convertDOMWrapperToNode<Node>(v8::Handle<v8::Object>::Cast(args[1])) : 0; + Node* newChild = V8Node::HasInstance(args[0]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; + Node* oldChild = V8Node::HasInstance(args[1]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[1])) : 0; bool success = imp->replaceChild(newChild, oldChild, ec, true); if (ec) { V8Proxy::setDOMException(ec); @@ -117,13 +117,13 @@ CALLBACK_FUNC_DECL(NodeReplaceChild) return v8::Null(); } -CALLBACK_FUNC_DECL(NodeRemoveChild) +v8::Handle<v8::Value> V8Node::removeChildCallback(const v8::Arguments& args) { INC_STATS("DOM.Node.removeChild"); v8::Handle<v8::Object> holder = args.Holder(); - Node* imp = V8DOMWrapper::convertDOMWrapperToNode<Node>(holder); + Node* imp = V8Node::toNative(holder); ExceptionCode ec = 0; - Node* oldChild = V8Node::HasInstance(args[0]) ? V8DOMWrapper::convertDOMWrapperToNode<Node>(v8::Handle<v8::Object>::Cast(args[0])) : 0; + Node* oldChild = V8Node::HasInstance(args[0]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; bool success = imp->removeChild(oldChild, ec); if (ec) { V8Proxy::setDOMException(ec); @@ -135,13 +135,13 @@ CALLBACK_FUNC_DECL(NodeRemoveChild) } // This function is customized to take advantage of the optional 4th argument: shouldLazyAttach -CALLBACK_FUNC_DECL(NodeAppendChild) +v8::Handle<v8::Value> V8Node::appendChildCallback(const v8::Arguments& args) { INC_STATS("DOM.Node.appendChild"); v8::Handle<v8::Object> holder = args.Holder(); - Node* imp = V8DOMWrapper::convertDOMWrapperToNode<Node>(holder); + Node* imp = V8Node::toNative(holder); ExceptionCode ec = 0; - Node* newChild = V8Node::HasInstance(args[0]) ? V8DOMWrapper::convertDOMWrapperToNode<Node>(v8::Handle<v8::Object>::Cast(args[0])) : 0; + Node* newChild = V8Node::HasInstance(args[0]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; bool success = imp->appendChild(newChild, ec, true ); if (ec) { V8Proxy::setDOMException(ec); diff --git a/WebCore/bindings/v8/custom/V8NodeFilterCustom.cpp b/WebCore/bindings/v8/custom/V8NodeFilterCustom.cpp index 8839420..032900c 100644 --- a/WebCore/bindings/v8/custom/V8NodeFilterCustom.cpp +++ b/WebCore/bindings/v8/custom/V8NodeFilterCustom.cpp @@ -29,9 +29,10 @@ */ #include "config.h" -#include "NodeFilter.h" +#include "V8NodeFilter.h" #include "ExceptionCode.h" +#include "NodeFilter.h" #include "V8Binding.h" #include "V8CustomBinding.h" @@ -39,7 +40,7 @@ namespace WebCore { -CALLBACK_FUNC_DECL(NodeFilterAcceptNode) +v8::Handle<v8::Value> V8NodeFilter::acceptNodeCallback(const v8::Arguments& args) { INC_STATS("DOM.NodeFilter.acceptNode()"); return throwError(NOT_SUPPORTED_ERR); diff --git a/WebCore/bindings/v8/custom/V8NodeIteratorCustom.cpp b/WebCore/bindings/v8/custom/V8NodeIteratorCustom.cpp index 47ae8ee..074eac3 100644 --- a/WebCore/bindings/v8/custom/V8NodeIteratorCustom.cpp +++ b/WebCore/bindings/v8/custom/V8NodeIteratorCustom.cpp @@ -29,8 +29,9 @@ */ #include "config.h" -#include "NodeIterator.h" +#include "V8NodeIterator.h" +#include "NodeIterator.h" #include "ScriptState.h" #include "V8Binding.h" @@ -56,24 +57,24 @@ static inline v8::Handle<v8::Value> toV8(PassRefPtr<Node> object, ExceptionCode return V8DOMWrapper::convertNodeToV8Object(object); } -CALLBACK_FUNC_DECL(NodeIteratorNextNode) +v8::Handle<v8::Value> V8NodeIterator::nextNodeCallback(const v8::Arguments& args) { INC_STATS("DOM.NodeIterator.nextNode()"); - NodeIterator* nodeIterator = V8DOMWrapper::convertToNativeObject<NodeIterator>(V8ClassIndex::NODEITERATOR, args.Holder()); + NodeIterator* nodeIterator = V8NodeIterator::toNative(args.Holder()); ExceptionCode ec = 0; - ScriptState state; + EmptyScriptState state; RefPtr<Node> result = nodeIterator->nextNode(&state, ec); return toV8(result.release(), ec, &state); } -CALLBACK_FUNC_DECL(NodeIteratorPreviousNode) +v8::Handle<v8::Value> V8NodeIterator::previousNodeCallback(const v8::Arguments& args) { INC_STATS("DOM.NodeIterator.previousNode()"); - NodeIterator* nodeIterator = V8DOMWrapper::convertToNativeObject<NodeIterator>(V8ClassIndex::NODEITERATOR, args.Holder()); + NodeIterator* nodeIterator = V8NodeIterator::toNative(args.Holder()); ExceptionCode ec = 0; - ScriptState state; + EmptyScriptState state; RefPtr<Node> result = nodeIterator->previousNode(&state, ec); return toV8(result.release(), ec, &state); } diff --git a/WebCore/bindings/v8/custom/V8NodeListCustom.cpp b/WebCore/bindings/v8/custom/V8NodeListCustom.cpp index ad10952..5721a7e 100644 --- a/WebCore/bindings/v8/custom/V8NodeListCustom.cpp +++ b/WebCore/bindings/v8/custom/V8NodeListCustom.cpp @@ -29,6 +29,8 @@ */ #include "config.h" +#include "V8NodeList.h" + #include "NodeList.h" #include "V8Binding.h" @@ -40,10 +42,10 @@ namespace WebCore { -NAMED_PROPERTY_GETTER(NodeList) +v8::Handle<v8::Value> V8NodeList::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.NodeList.NamedPropertyGetter"); - NodeList* list = V8DOMWrapper::convertToNativeObject<NodeList>(V8ClassIndex::NODELIST, info.Holder()); + NodeList* list = V8NodeList::toNative(info.Holder()); String key = toWebCoreString(name); // Length property cannot be overridden. @@ -58,4 +60,22 @@ NAMED_PROPERTY_GETTER(NodeList) return V8DOMWrapper::convertNodeToV8Object(result.release()); } +// Need to support call so that list(0) works. +v8::Handle<v8::Value> V8NodeList::callAsFunctionCallback(const v8::Arguments& args) +{ + INC_STATS("DOM.NodeList.callAsFunction()"); + if (args.Length() < 1) + return v8::Undefined(); + + NodeList* list = V8NodeList::toNative(args.Holder()); + + // The first argument must be a number. + v8::Local<v8::Uint32> index = args[0]->ToArrayIndex(); + if (index.IsEmpty()) + return v8::Undefined(); + + RefPtr<Node> result = list->item(index->Uint32Value()); + return V8DOMWrapper::convertNodeToV8Object(result.release()); +} + } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8NotificationCenterCustom.cpp b/WebCore/bindings/v8/custom/V8NotificationCenterCustom.cpp index a1f20cc..1cb4554 100644 --- a/WebCore/bindings/v8/custom/V8NotificationCenterCustom.cpp +++ b/WebCore/bindings/v8/custom/V8NotificationCenterCustom.cpp @@ -31,6 +31,7 @@ #include "config.h" #if ENABLE(NOTIFICATIONS) +#include "V8NotificationCenter.h" #include "NotImplemented.h" #include "Notification.h" @@ -39,6 +40,7 @@ #include "V8CustomBinding.h" #include "V8CustomEventListener.h" #include "V8CustomVoidCallback.h" +#include "V8Notification.h" #include "V8Proxy.h" #include "V8Utilities.h" #include "WorkerContext.h" @@ -46,42 +48,42 @@ namespace WebCore { -CALLBACK_FUNC_DECL(NotificationAddEventListener) +v8::Handle<v8::Value> V8Notification::addEventListenerCallback(const v8::Arguments& args) { INC_STATS("DOM.Notification.addEventListener()"); - Notification* notification = V8DOMWrapper::convertToNativeObject<Notification>(V8ClassIndex::NOTIFICATION, args.Holder()); + Notification* notification = V8Notification::toNative(args.Holder()); RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(notification, args[1], false, ListenerFindOrCreate); if (listener) { String type = toWebCoreString(args[0]); bool useCapture = args[2]->BooleanValue(); notification->addEventListener(type, listener, useCapture); - createHiddenDependency(args.Holder(), args[1], V8Custom::kNotificationRequestCacheIndex); + createHiddenDependency(args.Holder(), args[1], cacheIndex); } return v8::Undefined(); } -CALLBACK_FUNC_DECL(NotificationRemoveEventListener) +v8::Handle<v8::Value> V8Notification::removeEventListenerCallback(const v8::Arguments& args) { INC_STATS("DOM.Notification.removeEventListener()"); - Notification* notification = V8DOMWrapper::convertToNativeObject<Notification>(V8ClassIndex::NOTIFICATION, args.Holder()); + Notification* notification = V8Notification::toNative(args.Holder()); RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(notification, args[1], false, ListenerFindOnly); if (listener) { String type = toWebCoreString(args[0]); bool useCapture = args[2]->BooleanValue(); notification->removeEventListener(type, listener.get(), useCapture); - removeHiddenDependency(args.Holder(), args[1], V8Custom::kNotificationRequestCacheIndex); + removeHiddenDependency(args.Holder(), args[1], cacheIndex); } return v8::Undefined(); } -CALLBACK_FUNC_DECL(NotificationCenterCreateHTMLNotification) +v8::Handle<v8::Value> V8NotificationCenter::createHTMLNotificationCallback(const v8::Arguments& args) { INC_STATS(L"DOM.NotificationCenter.CreateHTMLNotification()"); - NotificationCenter* notificationCenter = V8DOMWrapper::convertToNativeObject<NotificationCenter>(V8ClassIndex::NOTIFICATIONCENTER, args.Holder()); + NotificationCenter* notificationCenter = V8NotificationCenter::toNative(args.Holder()); ExceptionCode ec = 0; String url = toWebCoreString(args[0]); @@ -96,10 +98,10 @@ CALLBACK_FUNC_DECL(NotificationCenterCreateHTMLNotification) return V8DOMWrapper::convertToV8Object(V8ClassIndex::NOTIFICATION, notification.get()); } -CALLBACK_FUNC_DECL(NotificationCenterCreateNotification) +v8::Handle<v8::Value> V8NotificationCenter::createNotificationCallback(const v8::Arguments& args) { INC_STATS(L"DOM.NotificationCenter.CreateNotification()"); - NotificationCenter* notificationCenter = V8DOMWrapper::convertToNativeObject<NotificationCenter>(V8ClassIndex::NOTIFICATIONCENTER, args.Holder()); + NotificationCenter* notificationCenter = V8NotificationCenter::toNative(args.Holder()); ExceptionCode ec = 0; RefPtr<Notification> notification = notificationCenter->createNotification(toWebCoreString(args[0]), toWebCoreString(args[1]), toWebCoreString(args[2]), ec); @@ -113,10 +115,10 @@ CALLBACK_FUNC_DECL(NotificationCenterCreateNotification) return V8DOMWrapper::convertToV8Object(V8ClassIndex::NOTIFICATION, notification.get()); } -CALLBACK_FUNC_DECL(NotificationCenterRequestPermission) +v8::Handle<v8::Value> V8NotificationCenter::requestPermissionCallback(const v8::Arguments& args) { INC_STATS(L"DOM.NotificationCenter.RequestPermission()"); - NotificationCenter* notificationCenter = V8DOMWrapper::convertToNativeObject<NotificationCenter>(V8ClassIndex::NOTIFICATIONCENTER, args.Holder()); + NotificationCenter* notificationCenter = V8NotificationCenter::toNative(args.Holder()); ScriptExecutionContext* context = notificationCenter->context(); // Requesting permission is only valid from a page context. diff --git a/WebCore/bindings/v8/custom/V8PopStateEventCustom.cpp b/WebCore/bindings/v8/custom/V8PopStateEventCustom.cpp new file mode 100644 index 0000000..46e9929 --- /dev/null +++ b/WebCore/bindings/v8/custom/V8PopStateEventCustom.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "V8PopStateEvent.h" + +#include "PopStateEvent.h" +#include "SerializedScriptValue.h" +#include "V8Proxy.h" + +namespace WebCore { + +v8::Handle<v8::Value> V8PopStateEvent::initPopStateEventCallback(const v8::Arguments& args) +{ + INC_STATS("DOM.PopStateEvent.initPopStateEvent"); + + String typeArg = v8ValueToWebCoreString(args[0]); + bool canBubbleArg = args[1]->BooleanValue(); + bool cancelableArg = args[2]->BooleanValue(); + RefPtr<SerializedScriptValue> stateArg = SerializedScriptValue::create(args[3]); + + PopStateEvent* event = V8PopStateEvent::toNative(args.Holder()); + event->initPopStateEvent(typeArg, canBubbleArg, cancelableArg, stateArg.release()); + + return v8::Undefined(); +} + +v8::Handle<v8::Value> V8PopStateEvent::stateAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.PopStateEvent.state"); + + PopStateEvent* event = V8PopStateEvent::toNative(info.Holder()); + SerializedScriptValue* state = event->state(); + if (!state) + return v8::Null(); + + return state->deserialize(); +} + +} // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8SQLResultSetRowListCustom.cpp b/WebCore/bindings/v8/custom/V8SQLResultSetRowListCustom.cpp index 73aae12..ab58d1c 100644 --- a/WebCore/bindings/v8/custom/V8SQLResultSetRowListCustom.cpp +++ b/WebCore/bindings/v8/custom/V8SQLResultSetRowListCustom.cpp @@ -31,6 +31,7 @@ #include "config.h" #if ENABLE(DATABASE) +#include "V8SQLResultSetRowList.h" #include "SQLResultSetRowList.h" #include "V8Binding.h" @@ -39,7 +40,7 @@ namespace WebCore { -CALLBACK_FUNC_DECL(SQLResultSetRowListItem) +v8::Handle<v8::Value> V8SQLResultSetRowList::itemCallback(const v8::Arguments& args) { INC_STATS("DOM.SQLResultSetRowList.item()"); @@ -53,7 +54,7 @@ CALLBACK_FUNC_DECL(SQLResultSetRowListItem) return v8::Undefined(); } - SQLResultSetRowList* rowList = V8DOMWrapper::convertToNativeObject<SQLResultSetRowList>(V8ClassIndex::SQLRESULTSETROWLIST, args.Holder()); + SQLResultSetRowList* rowList = V8SQLResultSetRowList::toNative(args.Holder()); unsigned long index = args[0]->IntegerValue(); if (index < 0 || index >= rowList->length()) { diff --git a/WebCore/bindings/v8/custom/V8SQLTransactionCustom.cpp b/WebCore/bindings/v8/custom/V8SQLTransactionCustom.cpp index dc801bd..98fbd9a 100644 --- a/WebCore/bindings/v8/custom/V8SQLTransactionCustom.cpp +++ b/WebCore/bindings/v8/custom/V8SQLTransactionCustom.cpp @@ -32,6 +32,8 @@ #if ENABLE(DATABASE) +#include "V8SQLTransaction.h" + #include "Database.h" #include "SQLValue.h" #include "V8Binding.h" @@ -45,7 +47,7 @@ using namespace WTF; namespace WebCore { -CALLBACK_FUNC_DECL(SQLTransactionExecuteSql) +v8::Handle<v8::Value> V8SQLTransaction::executeSqlCallback(const v8::Arguments& args) { INC_STATS("DOM.SQLTransaction.executeSql()"); @@ -94,7 +96,7 @@ CALLBACK_FUNC_DECL(SQLTransactionExecuteSql) return throwError("sqlArgs should be array or object!", V8Proxy::TypeError); } - SQLTransaction* transaction = V8DOMWrapper::convertToNativeObject<SQLTransaction>(V8ClassIndex::SQLTRANSACTION, args.Holder()); + SQLTransaction* transaction = V8SQLTransaction::toNative(args.Holder()); Frame* frame = V8Proxy::retrieveFrameForCurrentContext(); diff --git a/WebCore/bindings/v8/custom/V8SVGElementInstanceCustom.cpp b/WebCore/bindings/v8/custom/V8SVGElementInstanceCustom.cpp index dff4ff4..23b5b06 100644 --- a/WebCore/bindings/v8/custom/V8SVGElementInstanceCustom.cpp +++ b/WebCore/bindings/v8/custom/V8SVGElementInstanceCustom.cpp @@ -31,10 +31,10 @@ #include <config.h> #if ENABLE(SVG) - -#include "SVGElementInstance.h" +#include "V8SVGElementInstance.h" #include "EventListener.h" +#include "SVGElementInstance.h" #include "V8Binding.h" #include "V8CustomBinding.h" @@ -44,33 +44,33 @@ namespace WebCore { -CALLBACK_FUNC_DECL(SVGElementInstanceAddEventListener) +v8::Handle<v8::Value> V8SVGElementInstance::addEventListenerCallback(const v8::Arguments& args) { INC_STATS("DOM.SVGElementInstance.AddEventListener()"); - SVGElementInstance* instance = V8DOMWrapper::convertDOMWrapperToNative<SVGElementInstance>(args.Holder()); + SVGElementInstance* instance = V8SVGElementInstance::toNative(args.Holder()); RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(instance, args[1], false, ListenerFindOrCreate); if (listener) { String type = toWebCoreString(args[0]); bool useCapture = args[2]->BooleanValue(); instance->addEventListener(type, listener, useCapture); - createHiddenDependency(args.Holder(), args[1], V8Custom::kNodeEventListenerCacheIndex); + createHiddenDependency(args.Holder(), args[1], cacheIndex); } return v8::Undefined(); } -CALLBACK_FUNC_DECL(SVGElementInstanceRemoveEventListener) +v8::Handle<v8::Value> V8SVGElementInstance::removeEventListenerCallback(const v8::Arguments& args) { INC_STATS("DOM.SVGElementInstance.RemoveEventListener()"); - SVGElementInstance* instance = V8DOMWrapper::convertDOMWrapperToNative<SVGElementInstance>(args.Holder()); + SVGElementInstance* instance = V8SVGElementInstance::toNative(args.Holder()); RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(instance, args[1], false, ListenerFindOnly); if (listener) { String type = toWebCoreString(args[0]); bool useCapture = args[2]->BooleanValue(); instance->removeEventListener(type, listener.get(), useCapture); - removeHiddenDependency(args.Holder(), args[1], V8Custom::kNodeEventListenerCacheIndex); + removeHiddenDependency(args.Holder(), args[1], cacheIndex); } return v8::Undefined(); diff --git a/WebCore/bindings/v8/custom/V8SVGLengthCustom.cpp b/WebCore/bindings/v8/custom/V8SVGLengthCustom.cpp index 9f75f5a..129801d 100644 --- a/WebCore/bindings/v8/custom/V8SVGLengthCustom.cpp +++ b/WebCore/bindings/v8/custom/V8SVGLengthCustom.cpp @@ -31,9 +31,9 @@ #include <config.h> #if ENABLE(SVG) +#include "V8SVGLength.h" #include "SVGLength.h" - #include "V8Binding.h" #include "V8CustomBinding.h" #include "V8SVGPODTypeWrapper.h" @@ -41,18 +41,18 @@ namespace WebCore { -ACCESSOR_GETTER(SVGLengthValue) +v8::Handle<v8::Value> V8SVGLength::valueAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.SVGLength.value"); - V8SVGPODTypeWrapper<SVGLength>* wrapper = V8DOMWrapper::convertToNativeObject<V8SVGPODTypeWrapper<SVGLength> >(V8ClassIndex::SVGLENGTH, info.Holder()); + V8SVGPODTypeWrapper<SVGLength>* wrapper = V8SVGPODTypeWrapper<SVGLength>::toNative(info.Holder()); SVGLength imp = *wrapper; return v8::Number::New(imp.value(V8Proxy::svgContext(wrapper))); } -CALLBACK_FUNC_DECL(SVGLengthConvertToSpecifiedUnits) +v8::Handle<v8::Value> V8SVGLength::convertToSpecifiedUnitsCallback(const v8::Arguments& args) { INC_STATS("DOM.SVGLength.convertToSpecifiedUnits"); - V8SVGPODTypeWrapper<SVGLength>* wrapper = V8DOMWrapper::convertToNativeObject<V8SVGPODTypeWrapper<SVGLength> >(V8ClassIndex::SVGLENGTH, args.Holder()); + V8SVGPODTypeWrapper<SVGLength>* wrapper = V8SVGPODTypeWrapper<SVGLength>::toNative(args.Holder()); SVGLength imp = *wrapper; SVGElement* context = V8Proxy::svgContext(wrapper); imp.convertToSpecifiedUnits(toInt32(args[0]), context); diff --git a/WebCore/bindings/v8/custom/V8SVGMatrixCustom.cpp b/WebCore/bindings/v8/custom/V8SVGMatrixCustom.cpp index 690eac1..78284cd 100644 --- a/WebCore/bindings/v8/custom/V8SVGMatrixCustom.cpp +++ b/WebCore/bindings/v8/custom/V8SVGMatrixCustom.cpp @@ -44,7 +44,7 @@ namespace WebCore { -CALLBACK_FUNC_DECL(SVGMatrixMultiply) +v8::Handle<v8::Value> V8SVGMatrix::multiplyCallback(const v8::Arguments& args) { INC_STATS("DOM.SVGMatrix.multiply()"); if (args.Length() < 1) @@ -53,16 +53,16 @@ CALLBACK_FUNC_DECL(SVGMatrixMultiply) if (!V8SVGMatrix::HasInstance(args[0])) return throwError("secondMatrix argument was not a SVGMatrix"); - TransformationMatrix m1 = *V8DOMWrapper::convertToNativeObject<V8SVGPODTypeWrapper<TransformationMatrix> >(V8ClassIndex::SVGMATRIX, args.Holder()); - TransformationMatrix m2 = *V8DOMWrapper::convertToNativeObject<V8SVGPODTypeWrapper<TransformationMatrix> >(V8ClassIndex::SVGMATRIX, v8::Handle<v8::Object>::Cast(args[0])); + TransformationMatrix m1 = *V8SVGPODTypeWrapper<TransformationMatrix>::toNative(args.Holder()); + TransformationMatrix m2 = *V8SVGPODTypeWrapper<TransformationMatrix>::toNative(v8::Handle<v8::Object>::Cast(args[0])); return V8DOMWrapper::convertToV8Object(V8ClassIndex::SVGMATRIX, V8SVGStaticPODTypeWrapper<TransformationMatrix>::create(m1.multLeft(m2))); } -CALLBACK_FUNC_DECL(SVGMatrixInverse) +v8::Handle<v8::Value> V8SVGMatrix::inverseCallback(const v8::Arguments& args) { INC_STATS("DOM.SVGMatrix.inverse()"); - TransformationMatrix matrix = *V8DOMWrapper::convertToNativeObject<V8SVGPODTypeWrapper<TransformationMatrix> >(V8ClassIndex::SVGMATRIX, args.Holder()); + TransformationMatrix matrix = *V8SVGPODTypeWrapper<TransformationMatrix>::toNative(args.Holder()); ExceptionCode ec = 0; TransformationMatrix result = matrix.inverse(); @@ -77,10 +77,10 @@ CALLBACK_FUNC_DECL(SVGMatrixInverse) return V8DOMWrapper::convertToV8Object(V8ClassIndex::SVGMATRIX, V8SVGStaticPODTypeWrapper<TransformationMatrix>::create(result)); } -CALLBACK_FUNC_DECL(SVGMatrixRotateFromVector) +v8::Handle<v8::Value> V8SVGMatrix::rotateFromVectorCallback(const v8::Arguments& args) { INC_STATS("DOM.SVGMatrix.rotateFromVector()"); - TransformationMatrix matrix = *V8DOMWrapper::convertToNativeObject<V8SVGPODTypeWrapper<TransformationMatrix> >(V8ClassIndex::SVGMATRIX, args.Holder()); + TransformationMatrix matrix = *V8SVGPODTypeWrapper<TransformationMatrix>::toNative(args.Holder()); ExceptionCode ec = 0; float x = toFloat(args[0]); float y = toFloat(args[1]); diff --git a/WebCore/bindings/v8/custom/V8SharedWorkerCustom.cpp b/WebCore/bindings/v8/custom/V8SharedWorkerCustom.cpp index de53ac7..549de94 100644 --- a/WebCore/bindings/v8/custom/V8SharedWorkerCustom.cpp +++ b/WebCore/bindings/v8/custom/V8SharedWorkerCustom.cpp @@ -32,7 +32,7 @@ #if ENABLE(SHARED_WORKERS) -#include "SharedWorker.h" +#include "V8SharedWorker.h" #include "ExceptionCode.h" #include "Frame.h" @@ -45,7 +45,7 @@ namespace WebCore { -CALLBACK_FUNC_DECL(SharedWorkerConstructor) +v8::Handle<v8::Value> V8SharedWorker::constructorCallback(const v8::Arguments& args) { INC_STATS(L"DOM.SharedWorker.Constructor"); diff --git a/WebCore/bindings/v8/custom/V8StorageCustom.cpp b/WebCore/bindings/v8/custom/V8StorageCustom.cpp index f3f4687..ff3ac5e 100755 --- a/WebCore/bindings/v8/custom/V8StorageCustom.cpp +++ b/WebCore/bindings/v8/custom/V8StorageCustom.cpp @@ -31,6 +31,7 @@ #include "config.h" #if ENABLE(DOM_STORAGE) +#include "V8Storage.h" #include "Storage.h" #include "V8Binding.h" @@ -40,9 +41,9 @@ namespace WebCore { // Get an array containing the names of indexed properties in a collection. -v8::Handle<v8::Array> V8Custom::v8StorageNamedPropertyEnumerator(const v8::AccessorInfo& info) +v8::Handle<v8::Array> V8Storage::namedPropertyEnumerator(const v8::AccessorInfo& info) { - Storage* storage = V8DOMWrapper::convertToNativeObject<Storage>(V8ClassIndex::STORAGE, info.Holder()); + Storage* storage = V8Storage::toNative(info.Holder()); unsigned int length = storage->length(); v8::Handle<v8::Array> properties = v8::Array::New(length); for (unsigned int i = 0; i < length; ++i) { @@ -57,7 +58,7 @@ v8::Handle<v8::Array> V8Custom::v8StorageNamedPropertyEnumerator(const v8::Acces static v8::Handle<v8::Value> storageGetter(v8::Local<v8::String> v8Name, const v8::AccessorInfo& info) { - Storage* storage = V8DOMWrapper::convertToNativeObject<Storage>(V8ClassIndex::STORAGE, info.Holder()); + Storage* storage = V8Storage::toNative(info.Holder()); String name = toWebCoreString(v8Name); if (storage->contains(name) && name != "length") @@ -66,14 +67,14 @@ static v8::Handle<v8::Value> storageGetter(v8::Local<v8::String> v8Name, const v return notHandledByInterceptor(); } -INDEXED_PROPERTY_GETTER(Storage) +v8::Handle<v8::Value> V8Storage::indexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info) { INC_STATS("DOM.Storage.IndexedPropertyGetter"); v8::Local<v8::Integer> indexV8 = v8::Integer::New(index); return storageGetter(indexV8->ToString(), info); } -NAMED_PROPERTY_GETTER(Storage) +v8::Handle<v8::Value> V8Storage::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.Storage.NamedPropertyGetter"); return storageGetter(name, info); @@ -81,7 +82,7 @@ NAMED_PROPERTY_GETTER(Storage) static v8::Handle<v8::Value> storageSetter(v8::Local<v8::String> v8Name, v8::Local<v8::Value> v8Value, const v8::AccessorInfo& info) { - Storage* storage = V8DOMWrapper::convertToNativeObject<Storage>(V8ClassIndex::STORAGE, info.Holder()); + Storage* storage = V8Storage::toNative(info.Holder()); String name = toWebCoreString(v8Name); String value = toWebCoreString(v8Value); @@ -101,14 +102,14 @@ static v8::Handle<v8::Value> storageSetter(v8::Local<v8::String> v8Name, v8::Loc return v8Value; } -INDEXED_PROPERTY_SETTER(Storage) +v8::Handle<v8::Value> V8Storage::indexedPropertySetter(uint32_t index, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.Storage.NamedPropertyGetter"); v8::Local<v8::Integer> indexV8 = v8::Integer::New(index); return storageSetter(indexV8->ToString(), value, info); } -NAMED_PROPERTY_SETTER(Storage) +v8::Handle<v8::Value> V8Storage::namedPropertySetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.Storage.NamedPropertySetter"); return storageSetter(name, value, info); @@ -116,7 +117,7 @@ NAMED_PROPERTY_SETTER(Storage) static v8::Handle<v8::Boolean> storageDeleter(v8::Local<v8::String> v8Name, const v8::AccessorInfo& info) { - Storage* storage = V8DOMWrapper::convertToNativeObject<Storage>(V8ClassIndex::STORAGE, info.Holder()); + Storage* storage = V8Storage::toNative(info.Holder()); String name = toWebCoreString(v8Name); if (storage->contains(name)) { @@ -127,14 +128,14 @@ static v8::Handle<v8::Boolean> storageDeleter(v8::Local<v8::String> v8Name, cons return deletionNotHandledByInterceptor(); } -INDEXED_PROPERTY_DELETER(Storage) +v8::Handle<v8::Boolean> V8Storage::indexedPropertyDeleter(uint32_t index, const v8::AccessorInfo& info) { INC_STATS("DOM.Storage.IndexedPropertyDeleter"); v8::Local<v8::Integer> indexV8 = v8::Integer::New(index); return storageDeleter(indexV8->ToString(), info); } -NAMED_PROPERTY_DELETER(Storage) +v8::Handle<v8::Boolean> V8Storage::namedPropertyDeleter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.Storage.NamedPropertyDeleter"); return storageDeleter(name, info); diff --git a/WebCore/bindings/v8/custom/V8StyleSheetListCustom.cpp b/WebCore/bindings/v8/custom/V8StyleSheetListCustom.cpp index 32a48eb..a718451 100644 --- a/WebCore/bindings/v8/custom/V8StyleSheetListCustom.cpp +++ b/WebCore/bindings/v8/custom/V8StyleSheetListCustom.cpp @@ -29,16 +29,17 @@ */ #include "config.h" +#include "V8StyleSheetList.h" + #include "HTMLStyleElement.h" #include "StyleSheetList.h" - #include "V8Binding.h" #include "V8CustomBinding.h" #include "V8Proxy.h" namespace WebCore { -NAMED_PROPERTY_GETTER(StyleSheetList) +v8::Handle<v8::Value> V8StyleSheetList::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.StyleSheetList.NamedPropertyGetter"); @@ -46,7 +47,7 @@ NAMED_PROPERTY_GETTER(StyleSheetList) return notHandledByInterceptor(); // Search style sheet. - StyleSheetList* imp = V8DOMWrapper::convertToNativeObject<StyleSheetList>(V8ClassIndex::STYLESHEETLIST, info.Holder()); + StyleSheetList* imp = V8StyleSheetList::toNative(info.Holder()); HTMLStyleElement* item = imp->getNamedItem(toWebCoreString(name)); if (!item) return notHandledByInterceptor(); diff --git a/WebCore/bindings/v8/custom/V8TreeWalkerCustom.cpp b/WebCore/bindings/v8/custom/V8TreeWalkerCustom.cpp index 5052b7a..b848197 100644 --- a/WebCore/bindings/v8/custom/V8TreeWalkerCustom.cpp +++ b/WebCore/bindings/v8/custom/V8TreeWalkerCustom.cpp @@ -29,10 +29,11 @@ */ #include "config.h" -#include "TreeWalker.h" +#include "V8TreeWalker.h" #include "Node.h" #include "ScriptState.h" +#include "TreeWalker.h" #include "V8Binding.h" #include "V8CustomBinding.h" @@ -54,72 +55,72 @@ static inline v8::Handle<v8::Value> toV8(PassRefPtr<Node> object, ScriptState* s return V8DOMWrapper::convertNodeToV8Object(object); } -CALLBACK_FUNC_DECL(TreeWalkerParentNode) +v8::Handle<v8::Value> V8TreeWalker::parentNodeCallback(const v8::Arguments& args) { INC_STATS("DOM.TreeWalker.parentNode()"); - TreeWalker* treeWalker = V8DOMWrapper::convertToNativeObject<TreeWalker>(V8ClassIndex::TREEWALKER, args.Holder()); + TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder()); - ScriptState state; + EmptyScriptState state; RefPtr<Node> result = treeWalker->parentNode(&state); return toV8(result.release(), &state); } -CALLBACK_FUNC_DECL(TreeWalkerFirstChild) +v8::Handle<v8::Value> V8TreeWalker::firstChildCallback(const v8::Arguments& args) { INC_STATS("DOM.TreeWalker.firstChild()"); - TreeWalker* treeWalker = V8DOMWrapper::convertToNativeObject<TreeWalker>(V8ClassIndex::TREEWALKER, args.Holder()); + TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder()); - ScriptState state; + EmptyScriptState state; RefPtr<Node> result = treeWalker->firstChild(&state); return toV8(result.release(), &state); } -CALLBACK_FUNC_DECL(TreeWalkerLastChild) +v8::Handle<v8::Value> V8TreeWalker::lastChildCallback(const v8::Arguments& args) { INC_STATS("DOM.TreeWalker.lastChild()"); - TreeWalker* treeWalker = V8DOMWrapper::convertToNativeObject<TreeWalker>(V8ClassIndex::TREEWALKER, args.Holder()); + TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder()); - ScriptState state; + EmptyScriptState state; RefPtr<Node> result = treeWalker->lastChild(&state); return toV8(result.release(), &state); } -CALLBACK_FUNC_DECL(TreeWalkerNextNode) +v8::Handle<v8::Value> V8TreeWalker::nextNodeCallback(const v8::Arguments& args) { INC_STATS("DOM.TreeWalker.nextNode()"); - TreeWalker* treeWalker = V8DOMWrapper::convertToNativeObject<TreeWalker>(V8ClassIndex::TREEWALKER, args.Holder()); + TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder()); - ScriptState state; + EmptyScriptState state; RefPtr<Node> result = treeWalker->nextNode(&state); return toV8(result.release(), &state); } -CALLBACK_FUNC_DECL(TreeWalkerPreviousNode) +v8::Handle<v8::Value> V8TreeWalker::previousNodeCallback(const v8::Arguments& args) { INC_STATS("DOM.TreeWalker.previousNode()"); - TreeWalker* treeWalker = V8DOMWrapper::convertToNativeObject<TreeWalker>(V8ClassIndex::TREEWALKER, args.Holder()); + TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder()); - ScriptState state; + EmptyScriptState state; RefPtr<Node> result = treeWalker->previousNode(&state); return toV8(result.release(), &state); } -CALLBACK_FUNC_DECL(TreeWalkerNextSibling) +v8::Handle<v8::Value> V8TreeWalker::nextSiblingCallback(const v8::Arguments& args) { INC_STATS("DOM.TreeWalker.nextSibling()"); - TreeWalker* treeWalker = V8DOMWrapper::convertToNativeObject<TreeWalker>(V8ClassIndex::TREEWALKER, args.Holder()); + TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder()); - ScriptState state; + EmptyScriptState state; RefPtr<Node> result = treeWalker->nextSibling(&state); return toV8(result.release(), &state); } -CALLBACK_FUNC_DECL(TreeWalkerPreviousSibling) +v8::Handle<v8::Value> V8TreeWalker::previousSiblingCallback(const v8::Arguments& args) { INC_STATS("DOM.TreeWalker.previousSibling()"); - TreeWalker* treeWalker = V8DOMWrapper::convertToNativeObject<TreeWalker>(V8ClassIndex::TREEWALKER, args.Holder()); + TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder()); - ScriptState state; + EmptyScriptState state; RefPtr<Node> result = treeWalker->previousSibling(&state); return toV8(result.release(), &state); } diff --git a/WebCore/bindings/v8/custom/V8WebGLArrayBufferCustom.cpp b/WebCore/bindings/v8/custom/V8WebGLArrayBufferCustom.cpp index 16a1f51..bc167c5 100644 --- a/WebCore/bindings/v8/custom/V8WebGLArrayBufferCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WebGLArrayBufferCustom.cpp @@ -41,7 +41,7 @@ namespace WebCore { -CALLBACK_FUNC_DECL(WebGLArrayBufferConstructor) +v8::Handle<v8::Value> V8WebGLArrayBuffer::constructorCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLArrayBuffer.Constructor"); diff --git a/WebCore/bindings/v8/custom/V8WebGLArrayCustom.h b/WebCore/bindings/v8/custom/V8WebGLArrayCustom.h index 1a4b6a4..6a702f5 100644 --- a/WebCore/bindings/v8/custom/V8WebGLArrayCustom.h +++ b/WebCore/bindings/v8/custom/V8WebGLArrayCustom.h @@ -75,9 +75,7 @@ v8::Handle<v8::Value> constructWebGLArray(const v8::Arguments& args, if (argLen > 3) return throwError("Wrong number of arguments to new WebGL<T>Array(WebGLArrayBuffer, int, int)"); - WebGLArrayBuffer* buf = - V8DOMWrapper::convertToNativeObject<WebGLArrayBuffer>(V8ClassIndex::WEBGLARRAYBUFFER, - args[0]->ToObject()); + WebGLArrayBuffer* buf = V8WebGLArrayBuffer::toNative(args[0]->ToObject()); if (buf == NULL) return throwError("Could not convert argument 0 to a WebGLArrayBuffer"); bool ok; @@ -155,7 +153,7 @@ v8::Handle<v8::Value> getWebGLArrayElement(const v8::Arguments& args, V8Proxy::setDOMException(SYNTAX_ERR); return notHandledByInterceptor(); } - T* array = V8DOMWrapper::convertToNativeObject<T>(wrapperType, args.Holder()); + T* array = reinterpret_cast<T*>(args.Holder()->GetPointerFromInternalField(v8DOMWrapperObjectIndex)); if (index >= array->length()) return v8::Undefined(); ElementType result; @@ -174,9 +172,11 @@ v8::Handle<v8::Value> setWebGLArrayFromArray(T* webGLArray, const v8::Arguments& if (args.Length() == 2) offset = toInt32(args[1]); uint32_t length = toInt32(array->Get(v8::String::New("length"))); - for (uint32_t i = 0; i < length; i++) { - webGLArray->set(offset + i, array->Get(v8::Integer::New(i))->NumberValue()); - } + if (offset + length > webGLArray->length()) + V8Proxy::setDOMException(INDEX_SIZE_ERR); + else + for (uint32_t i = 0; i < length; i++) + webGLArray->set(offset + i, array->Get(v8::Integer::New(i))->NumberValue()); } return v8::Undefined(); @@ -191,10 +191,10 @@ v8::Handle<v8::Value> setWebGLArray(const v8::Arguments& args, return notHandledByInterceptor(); } - CPlusPlusArrayType* array = V8DOMWrapper::convertToNativeObject<CPlusPlusArrayType>(wrapperType, args.Holder()); + CPlusPlusArrayType* array = JavaScriptWrapperArrayType::toNative(args.Holder()); if (args.Length() == 2 && args[0]->IsInt32()) { - // void set(in unsigned long index, in long value); + // void set(in unsigned long index, in {long|float} value); uint32_t index = toInt32(args[0]); array->set(index, args[1]->NumberValue()); return v8::Undefined(); @@ -202,7 +202,7 @@ v8::Handle<v8::Value> setWebGLArray(const v8::Arguments& args, if (JavaScriptWrapperArrayType::HasInstance(args[0])) { // void set(in WebGL<T>Array array, [Optional] in unsigned long offset); - CPlusPlusArrayType* src = V8DOMWrapper::convertToNativeObject<CPlusPlusArrayType>(wrapperType, args[0]->ToObject()); + CPlusPlusArrayType* src = JavaScriptWrapperArrayType::toNative(args[0]->ToObject()); uint32_t offset = 0; if (args.Length() == 2) offset = toInt32(args[1]); diff --git a/WebCore/bindings/v8/custom/V8WebGLByteArrayCustom.cpp b/WebCore/bindings/v8/custom/V8WebGLByteArrayCustom.cpp index 5719c8a..6d52c83 100644 --- a/WebCore/bindings/v8/custom/V8WebGLByteArrayCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WebGLByteArrayCustom.cpp @@ -44,48 +44,20 @@ namespace WebCore { -CALLBACK_FUNC_DECL(WebGLByteArrayConstructor) +v8::Handle<v8::Value> V8WebGLByteArray::constructorCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLByteArray.Contructor"); return constructWebGLArray<WebGLByteArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLBYTEARRAY)); } -// Get the specified value from the byte buffer and return it wrapped as a JavaScript Number object to V8. Accesses outside the valid byte buffer range return "undefined". -INDEXED_PROPERTY_GETTER(WebGLByteArray) -{ - INC_STATS("DOM.WebGLByteArray.IndexedPropertyGetter"); - WebGLByteArray* byteBuffer = V8DOMWrapper::convertToNativeObject<WebGLByteArray>(V8ClassIndex::WEBGLBYTEARRAY, info.Holder()); - - if ((index < 0) || (index >= byteBuffer->length())) - return v8::Undefined(); - signed char result; - if (!byteBuffer->get(index, result)) - return v8::Undefined(); - return v8::Number::New(result); -} - -// Set the specified value in the byte buffer. Accesses outside the valid byte buffer range are silently ignored. -INDEXED_PROPERTY_SETTER(WebGLByteArray) -{ - INC_STATS("DOM.WebGLByteArray.IndexedPropertySetter"); - WebGLByteArray* array = V8DOMWrapper::convertToNativeObject<WebGLByteArray>(V8ClassIndex::WEBGLBYTEARRAY, info.Holder()); - - if ((index >= 0) && (index < array->length())) { - if (!value->IsNumber()) - return throwError("Could not convert value argument to a number"); - array->set(index, value->NumberValue()); - } - return value; -} - -CALLBACK_FUNC_DECL(WebGLByteArrayGet) +v8::Handle<v8::Value> V8WebGLByteArray::getCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLByteArray.get()"); return getWebGLArrayElement<WebGLByteArray, signed char>(args, V8ClassIndex::WEBGLBYTEARRAY); } -CALLBACK_FUNC_DECL(WebGLByteArraySet) +v8::Handle<v8::Value> V8WebGLByteArray::setCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLByteArray.set()"); return setWebGLArray<WebGLByteArray, V8WebGLByteArray>(args, V8ClassIndex::WEBGLBYTEARRAY); diff --git a/WebCore/bindings/v8/custom/V8WebGLFloatArrayCustom.cpp b/WebCore/bindings/v8/custom/V8WebGLFloatArrayCustom.cpp index 6e56760..4d4b0e2 100644 --- a/WebCore/bindings/v8/custom/V8WebGLFloatArrayCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WebGLFloatArrayCustom.cpp @@ -44,45 +44,20 @@ namespace WebCore { -CALLBACK_FUNC_DECL(WebGLFloatArrayConstructor) +v8::Handle<v8::Value> V8WebGLFloatArray::constructorCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLFloatArray.Contructor"); return constructWebGLArray<WebGLFloatArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLFLOATARRAY)); } -// Get the specified value from the array and return it wrapped as a JavaScript Number object to V8. Accesses outside the valid array range return "undefined". -INDEXED_PROPERTY_GETTER(WebGLFloatArray) -{ - INC_STATS("DOM.WebGLFloatArray.IndexedPropertyGetter"); - WebGLFloatArray* array = V8DOMWrapper::convertToNativeObject<WebGLFloatArray>(V8ClassIndex::WEBGLFLOATARRAY, info.Holder()); - - if ((index < 0) || (index >= array->length())) - return v8::Undefined(); - float result; - if (!array->get(index, result)) - return v8::Undefined(); - return v8::Number::New(result); -} - -// Set the specified value in the array. Accesses outside the valid array range are silently ignored. -INDEXED_PROPERTY_SETTER(WebGLFloatArray) -{ - INC_STATS("DOM.WebGLFloatArray.IndexedPropertySetter"); - WebGLFloatArray* array = V8DOMWrapper::convertToNativeObject<WebGLFloatArray>(V8ClassIndex::WEBGLFLOATARRAY, info.Holder()); - - if ((index >= 0) && (index < array->length())) - array->set(index, value->NumberValue()); - return value; -} - -CALLBACK_FUNC_DECL(WebGLFloatArrayGet) +v8::Handle<v8::Value> V8WebGLFloatArray::getCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLFloatArray.get()"); return getWebGLArrayElement<WebGLFloatArray, float>(args, V8ClassIndex::WEBGLFLOATARRAY); } -CALLBACK_FUNC_DECL(WebGLFloatArraySet) +v8::Handle<v8::Value> V8WebGLFloatArray::setCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLFloatArray.set()"); return setWebGLArray<WebGLFloatArray, V8WebGLFloatArray>(args, V8ClassIndex::WEBGLFLOATARRAY); diff --git a/WebCore/bindings/v8/custom/V8WebGLIntArrayCustom.cpp b/WebCore/bindings/v8/custom/V8WebGLIntArrayCustom.cpp index 1bd30b2..7dde0a0 100644 --- a/WebCore/bindings/v8/custom/V8WebGLIntArrayCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WebGLIntArrayCustom.cpp @@ -44,48 +44,20 @@ namespace WebCore { -CALLBACK_FUNC_DECL(WebGLIntArrayConstructor) +v8::Handle<v8::Value> V8WebGLIntArray::constructorCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLIntArray.Contructor"); return constructWebGLArray<WebGLIntArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLINTARRAY)); } -// Get the specified value from the integer array and return it wrapped as a JavaScript Number object to V8. Accesses outside the valid pixel buffer range return "undefined". -INDEXED_PROPERTY_GETTER(WebGLIntArray) -{ - INC_STATS("DOM.WebGLIntArray.IndexedPropertyGetter"); - WebGLIntArray* array = V8DOMWrapper::convertToNativeObject<WebGLIntArray>(V8ClassIndex::WEBGLINTARRAY, info.Holder()); - - if ((index < 0) || (index >= array->length())) - return v8::Undefined(); - int result; - if (!array->get(index, result)) - return v8::Undefined(); - return v8::Number::New(result); -} - -// Set the specified value in the integer array. Accesses outside the valid integer array range are silently ignored. -INDEXED_PROPERTY_SETTER(WebGLIntArray) -{ - INC_STATS("DOM.WebGLIntArray.IndexedPropertySetter"); - WebGLIntArray* array = V8DOMWrapper::convertToNativeObject<WebGLIntArray>(V8ClassIndex::WEBGLINTARRAY, info.Holder()); - - if ((index >= 0) && (index < array->length())) { - if (!value->IsNumber()) - return throwError("Could not convert value argument to a number"); - array->set(index, value->NumberValue()); - } - return value; -} - -CALLBACK_FUNC_DECL(WebGLIntArrayGet) +v8::Handle<v8::Value> V8WebGLIntArray::getCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLIntArray.get()"); return getWebGLArrayElement<WebGLIntArray, int>(args, V8ClassIndex::WEBGLINTARRAY); } -CALLBACK_FUNC_DECL(WebGLIntArraySet) +v8::Handle<v8::Value> V8WebGLIntArray::setCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLIntArray.set()"); return setWebGLArray<WebGLIntArray, V8WebGLIntArray>(args, V8ClassIndex::WEBGLINTARRAY); diff --git a/WebCore/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp b/WebCore/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp index fd73a5b..19b73d4 100644 --- a/WebCore/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp @@ -32,7 +32,7 @@ #if ENABLE(3D_CANVAS) -#include "WebGLRenderingContext.h" +#include "V8WebGLRenderingContext.h" #include "ExceptionCode.h" @@ -54,7 +54,10 @@ #include "V8WebGLUnsignedShortArray.h" #include "V8HTMLCanvasElement.h" #include "V8HTMLImageElement.h" +#include "V8HTMLVideoElement.h" +#include "V8ImageData.h" #include "V8Proxy.h" +#include "WebGLRenderingContext.h" namespace WebCore { @@ -98,7 +101,7 @@ static int* jsArrayToIntArray(v8::Handle<v8::Array> array, uint32_t len) return data; } -CALLBACK_FUNC_DECL(WebGLRenderingContextBufferData) +v8::Handle<v8::Value> V8WebGLRenderingContext::bufferDataCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.bufferData()"); @@ -112,8 +115,7 @@ CALLBACK_FUNC_DECL(WebGLRenderingContextBufferData) return notHandledByInterceptor(); } - WebGLRenderingContext* context = - V8DOMWrapper::convertDOMWrapperToNative<WebGLRenderingContext>(args.Holder()); + WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder()); bool ok; int target = toInt32(args[0], ok); if (!ok) { @@ -130,7 +132,7 @@ CALLBACK_FUNC_DECL(WebGLRenderingContextBufferData) ExceptionCode exceptionCode; context->bufferData(target, size, usage, exceptionCode); } else if (V8WebGLArray::HasInstance(args[1])) { - WebGLArray* array = V8DOMWrapper::convertToNativeObject<WebGLArray>(V8ClassIndex::WEBGLARRAY, args[1]->ToObject()); + WebGLArray* array = V8WebGLArray::toNative(args[1]->ToObject()); ExceptionCode exceptionCode; context->bufferData(target, array, usage, exceptionCode); } else { @@ -140,7 +142,7 @@ CALLBACK_FUNC_DECL(WebGLRenderingContextBufferData) return v8::Undefined(); } -CALLBACK_FUNC_DECL(WebGLRenderingContextBufferSubData) +v8::Handle<v8::Value> V8WebGLRenderingContext::bufferSubDataCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.bufferSubData()"); @@ -151,8 +153,7 @@ CALLBACK_FUNC_DECL(WebGLRenderingContextBufferSubData) return notHandledByInterceptor(); } - WebGLRenderingContext* context = - V8DOMWrapper::convertDOMWrapperToNative<WebGLRenderingContext>(args.Holder()); + WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder()); bool ok; int target = toInt32(args[0], ok); if (!ok) { @@ -168,7 +169,7 @@ CALLBACK_FUNC_DECL(WebGLRenderingContextBufferSubData) V8Proxy::setDOMException(SYNTAX_ERR); return notHandledByInterceptor(); } - WebGLArray* array = V8DOMWrapper::convertToNativeObject<WebGLArray>(V8ClassIndex::WEBGLARRAY, args[2]->ToObject()); + WebGLArray* array = V8WebGLArray::toNative(args[2]->ToObject()); ExceptionCode exceptionCode; context->bufferSubData(target, offset, array, exceptionCode); return v8::Undefined(); @@ -225,8 +226,7 @@ static v8::Handle<v8::Value> getObjectParameter(const v8::Arguments& args, Objec } ExceptionCode ec = 0; - WebGLRenderingContext* context = - V8DOMWrapper::convertDOMWrapperToNative<WebGLRenderingContext>(args.Holder()); + WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder()); bool ok; unsigned target = toInt32(args[0], ok); if (!ok) { @@ -269,8 +269,7 @@ static WebGLUniformLocation* toWebGLUniformLocation(v8::Handle<v8::Value> value, ok = false; WebGLUniformLocation* location = 0; if (V8WebGLUniformLocation::HasInstance(value)) { - location = V8DOMWrapper::convertToNativeObject<WebGLUniformLocation>( - V8ClassIndex::WEBGLUNIFORMLOCATION, value->ToObject()); + location = V8WebGLUniformLocation::toNative(value->ToObject()); ok = true; } return location; @@ -280,13 +279,13 @@ enum WhichProgramCall { kProgramParameter, kUniform }; -CALLBACK_FUNC_DECL(WebGLRenderingContextGetBufferParameter) +v8::Handle<v8::Value> V8WebGLRenderingContext::getBufferParameterCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.getBufferParameter()"); return getObjectParameter(args, kBuffer); } -CALLBACK_FUNC_DECL(WebGLRenderingContextGetFramebufferAttachmentParameter) +v8::Handle<v8::Value> V8WebGLRenderingContext::getFramebufferAttachmentParameterCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.getFramebufferAttachmentParameter()"); @@ -296,8 +295,7 @@ CALLBACK_FUNC_DECL(WebGLRenderingContextGetFramebufferAttachmentParameter) } ExceptionCode ec = 0; - WebGLRenderingContext* context = - V8DOMWrapper::convertDOMWrapperToNative<WebGLRenderingContext>(args.Holder()); + WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder()); bool ok; unsigned target = toInt32(args[0], ok); if (!ok) { @@ -322,7 +320,7 @@ CALLBACK_FUNC_DECL(WebGLRenderingContextGetFramebufferAttachmentParameter) return toV8(info); } -CALLBACK_FUNC_DECL(WebGLRenderingContextGetParameter) +v8::Handle<v8::Value> V8WebGLRenderingContext::getParameterCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.getParameter()"); @@ -332,8 +330,7 @@ CALLBACK_FUNC_DECL(WebGLRenderingContextGetParameter) } ExceptionCode ec = 0; - WebGLRenderingContext* context = - V8DOMWrapper::convertDOMWrapperToNative<WebGLRenderingContext>(args.Holder()); + WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder()); bool ok; unsigned pname = toInt32(args[0], ok); if (!ok) { @@ -348,7 +345,7 @@ CALLBACK_FUNC_DECL(WebGLRenderingContextGetParameter) return toV8(info); } -CALLBACK_FUNC_DECL(WebGLRenderingContextGetProgramParameter) +v8::Handle<v8::Value> V8WebGLRenderingContext::getProgramParameterCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.getProgramParameter()"); @@ -358,9 +355,8 @@ CALLBACK_FUNC_DECL(WebGLRenderingContextGetProgramParameter) } ExceptionCode ec = 0; - WebGLRenderingContext* context = - V8DOMWrapper::convertDOMWrapperToNative<WebGLRenderingContext>(args.Holder()); - WebGLProgram* program = V8WebGLProgram::HasInstance(args[0]) ? v8DOMWrapperTo<WebGLProgram>(V8ClassIndex::WEBGLPROGRAM, v8::Handle<v8::Object>::Cast(args[0])) : 0; + WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder()); + WebGLProgram* program = V8WebGLProgram::HasInstance(args[0]) ? V8WebGLProgram::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; bool ok; unsigned pname = toInt32(args[1], ok); if (!ok) { @@ -375,13 +371,13 @@ CALLBACK_FUNC_DECL(WebGLRenderingContextGetProgramParameter) return toV8(info); } -CALLBACK_FUNC_DECL(WebGLRenderingContextGetRenderbufferParameter) +v8::Handle<v8::Value> V8WebGLRenderingContext::getRenderbufferParameterCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.getRenderbufferParameter()"); return getObjectParameter(args, kRenderbuffer); } -CALLBACK_FUNC_DECL(WebGLRenderingContextGetShaderParameter) +v8::Handle<v8::Value> V8WebGLRenderingContext::getShaderParameterCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.getShaderParameter()"); @@ -391,9 +387,8 @@ CALLBACK_FUNC_DECL(WebGLRenderingContextGetShaderParameter) } ExceptionCode ec = 0; - WebGLRenderingContext* context = - V8DOMWrapper::convertDOMWrapperToNative<WebGLRenderingContext>(args.Holder()); - WebGLShader* shader = V8WebGLShader::HasInstance(args[0]) ? v8DOMWrapperTo<WebGLShader>(V8ClassIndex::WEBGLSHADER, v8::Handle<v8::Object>::Cast(args[0])) : 0; + WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder()); + WebGLShader* shader = V8WebGLShader::HasInstance(args[0]) ? V8WebGLShader::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; bool ok; unsigned pname = toInt32(args[1], ok); if (!ok) { @@ -408,13 +403,13 @@ CALLBACK_FUNC_DECL(WebGLRenderingContextGetShaderParameter) return toV8(info); } -CALLBACK_FUNC_DECL(WebGLRenderingContextGetTexParameter) +v8::Handle<v8::Value> V8WebGLRenderingContext::getTexParameterCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.getTexParameter()"); return getObjectParameter(args, kTexture); } -CALLBACK_FUNC_DECL(WebGLRenderingContextGetUniform) +v8::Handle<v8::Value> V8WebGLRenderingContext::getUniformCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.getUniform()"); @@ -424,9 +419,8 @@ CALLBACK_FUNC_DECL(WebGLRenderingContextGetUniform) } ExceptionCode ec = 0; - WebGLRenderingContext* context = - V8DOMWrapper::convertDOMWrapperToNative<WebGLRenderingContext>(args.Holder()); - WebGLProgram* program = V8WebGLProgram::HasInstance(args[0]) ? v8DOMWrapperTo<WebGLProgram>(V8ClassIndex::WEBGLPROGRAM, v8::Handle<v8::Object>::Cast(args[0])) : 0; + WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder()); + WebGLProgram* program = V8WebGLProgram::HasInstance(args[0]) ? V8WebGLProgram::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; bool ok = false; WebGLUniformLocation* location = toWebGLUniformLocation(args[1], ok); @@ -443,13 +437,13 @@ CALLBACK_FUNC_DECL(WebGLRenderingContextGetUniform) return toV8(info); } -CALLBACK_FUNC_DECL(WebGLRenderingContextGetVertexAttrib) +v8::Handle<v8::Value> V8WebGLRenderingContext::getVertexAttribCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.getVertexAttrib()"); return getObjectParameter(args, kVertexAttrib); } -CALLBACK_FUNC_DECL(WebGLRenderingContextTexImage2D) +v8::Handle<v8::Value> V8WebGLRenderingContext::texImage2DCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.texImage2D()"); @@ -458,10 +452,14 @@ CALLBACK_FUNC_DECL(WebGLRenderingContextTexImage2D) // in GLint internalformat, // in GLsizei width, in GLsizei height, in GLint border, // in GLenum format, in GLenum type, in WebGLArray pixels); + // * void texImage2D(in GLenum target, in GLint level, in ImageData pixels, + // [Optional] in GLboolean flipY, [Optional] in GLboolean premulitplyAlpha); // * void texImage2D(in GLenum target, in GLint level, in HTMLImageElement image, // [Optional] in GLboolean flipY, [Optional] in GLboolean premultiplyAlpha); // * void texImage2D(in GLenum target, in GLint level, in HTMLCanvasElement image, // [Optional] in GLboolean flipY, [Optional] in GLboolean premultiplyAlpha); + // * void texImage2D(in GLenum target, in GLint level, in HTMLVideoElement image, + // [Optional] in GLboolean flipY, [Optional] in GLboolean premultiplyAlpha); if (args.Length() != 3 && args.Length() != 4 && args.Length() != 5 && @@ -470,8 +468,7 @@ CALLBACK_FUNC_DECL(WebGLRenderingContextTexImage2D) return notHandledByInterceptor(); } - WebGLRenderingContext* context = - V8DOMWrapper::convertDOMWrapperToNative<WebGLRenderingContext>(args.Holder()); + WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder()); bool ok; int target = toInt32(args[0], ok); if (!ok) { @@ -488,21 +485,28 @@ CALLBACK_FUNC_DECL(WebGLRenderingContextTexImage2D) if (args.Length() == 3 || args.Length() == 4 || args.Length() == 5) { - v8::Handle<v8::Value> arg = args[2]; bool flipY = false; bool premultiplyAlpha = false; if (args.Length() >= 4) flipY = args[3]->BooleanValue(); if (args.Length() >= 5) premultiplyAlpha = args[4]->BooleanValue(); + + v8::Handle<v8::Value> arg = args[2]; if (V8HTMLImageElement::HasInstance(arg)) { - HTMLImageElement* element = V8DOMWrapper::convertDOMWrapperToNode<HTMLImageElement>(v8::Handle<v8::Object>::Cast(arg)); + HTMLImageElement* element = V8HTMLImageElement::toNative(v8::Handle<v8::Object>::Cast(arg)); context->texImage2D(target, level, element, flipY, premultiplyAlpha, ec); } else if (V8HTMLCanvasElement::HasInstance(arg)) { - HTMLCanvasElement* element = V8DOMWrapper::convertDOMWrapperToNode<HTMLCanvasElement>(v8::Handle<v8::Object>::Cast(arg)); + HTMLCanvasElement* element = V8HTMLCanvasElement::toNative(v8::Handle<v8::Object>::Cast(arg)); context->texImage2D(target, level, element, flipY, premultiplyAlpha, ec); - } else { - // FIXME: support HTMLVideoElement and ImageData. + } else if(V8ImageData::HasInstance(arg)) { + ImageData* imageElement = V8ImageData::toNative(v8::Handle<v8::Object>::Cast(arg)); + context->texImage2D(target, level, imageElement, flipY, premultiplyAlpha, ec); + } else if (V8HTMLVideoElement::HasInstance(arg)) { + HTMLVideoElement* element = V8HTMLVideoElement::toNative(v8::Handle<v8::Object>::Cast(arg)); + context->texImage2D(target, level, element, flipY, premultiplyAlpha, ec); + } + else { // FIXME: consider different / better exception type. V8Proxy::setDOMException(SYNTAX_ERR); return notHandledByInterceptor(); @@ -540,10 +544,20 @@ CALLBACK_FUNC_DECL(WebGLRenderingContextTexImage2D) return notHandledByInterceptor(); } v8::Handle<v8::Value> arg = args[8]; - if (V8WebGLArray::HasInstance(arg)) { - WebGLArray* array = V8DOMWrapper::convertToNativeObject<WebGLArray>(V8ClassIndex::WEBGLARRAY, arg->ToObject()); - // FIXME: must do validation similar to JOGL's to ensure that - // the incoming array is of the appropriate length and type + if (!arg->IsObject()) + // Assume that the user is passing null for texture + context->texImage2D(target, + level, + internalformat, + width, + height, + border, + format, + type, + 0, + ec); + else if (V8WebGLArray::HasInstance(arg)) { + WebGLArray* array = V8WebGLArray::toNative(arg->ToObject()); context->texImage2D(target, level, internalformat, @@ -571,13 +585,145 @@ CALLBACK_FUNC_DECL(WebGLRenderingContextTexImage2D) return v8::Undefined(); } -CALLBACK_FUNC_DECL(WebGLRenderingContextTexSubImage2D) +v8::Handle<v8::Value> V8WebGLRenderingContext::texSubImage2DCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.texSubImage2D()"); - // FIXME: implement - notImplemented(); + // Currently supported forms: + // * void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, + // in GLsizei width, in GLsizei height, + // in GLenum format, in GLenum type, in WebGLArray pixels); + // * void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, + // in ImageData pixels, [Optional] GLboolean flipY, [Optional] in premultiplyAlpha); + // * void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, + // in HTMLImageElement image, [Optional] GLboolean flipY, [Optional] in premultiplyAlpha); + // * void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, + // in HTMLCanvasElement canvas, [Optional] GLboolean flipY, [Optional] in premultiplyAlpha); + // * void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, + // in HTMLVideoElement video, [Optional] GLboolean flipY, [Optional] in premultiplyAlpha); + + if (args.Length() != 5 && + args.Length() != 6 && + args.Length() != 7 && + args.Length() != 9) { + V8Proxy::setDOMException(SYNTAX_ERR); + return notHandledByInterceptor(); + } + WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder()); + bool ok; + int target = toInt32(args[0], ok); + if (!ok) { + V8Proxy::setDOMException(SYNTAX_ERR); + return notHandledByInterceptor(); + } + int level = toInt32(args[1], ok); + if (!ok) { + V8Proxy::setDOMException(SYNTAX_ERR); + return notHandledByInterceptor(); + } + int xoff = toInt32(args[2], ok); + if (!ok) { + V8Proxy::setDOMException(SYNTAX_ERR); + return notHandledByInterceptor(); + } + int yoff = toInt32(args[3], ok); + if (!ok) { + V8Proxy::setDOMException(SYNTAX_ERR); + return notHandledByInterceptor(); + } + + ExceptionCode ec = 0; + if (args.Length() == 5 || + args.Length() == 6 || + args.Length() == 7) { + bool flipY = false; + bool premultiplyAlpha = false; + if (args.Length() >= 6) + flipY = args[5]->BooleanValue(); + if (args.Length() >= 7) + premultiplyAlpha = args[6]->BooleanValue(); + + v8::Handle<v8::Value> arg = args[4]; + if (V8HTMLImageElement::HasInstance(arg)) { + HTMLImageElement* element = V8HTMLImageElement::toNative(v8::Handle<v8::Object>::Cast(arg)); + context->texSubImage2D(target, level, xoff, yoff, element, flipY, premultiplyAlpha, ec); + } else if (V8HTMLCanvasElement::HasInstance(arg)) { + HTMLCanvasElement* element = V8HTMLCanvasElement::toNative(v8::Handle<v8::Object>::Cast(arg)); + context->texSubImage2D(target, level, xoff, yoff, element, flipY, premultiplyAlpha, ec); + } else if(V8ImageData::HasInstance(arg)) { + ImageData* imageElement = V8ImageData::toNative(v8::Handle<v8::Object>::Cast(arg)); + context->texSubImage2D(target, level, xoff, yoff, imageElement, flipY, premultiplyAlpha, ec); + } else if (V8HTMLVideoElement::HasInstance(arg)) { + HTMLVideoElement* element = V8HTMLVideoElement::toNative(v8::Handle<v8::Object>::Cast(arg)); + context->texSubImage2D(target, level, xoff, yoff, element, flipY, premultiplyAlpha, ec); + } + else { + // FIXME: consider different / better exception type. + V8Proxy::setDOMException(SYNTAX_ERR); + return notHandledByInterceptor(); + } + // Fall through + } else if (args.Length() == 9) { + int width = toInt32(args[4], ok); + if (!ok) { + V8Proxy::setDOMException(SYNTAX_ERR); + return notHandledByInterceptor(); + } + int height = toInt32(args[5], ok); + if (!ok) { + V8Proxy::setDOMException(SYNTAX_ERR); + return notHandledByInterceptor(); + } + int format = toInt32(args[6], ok); + if (!ok) { + V8Proxy::setDOMException(SYNTAX_ERR); + return notHandledByInterceptor(); + } + int type = toInt32(args[7], ok); + if (!ok) { + V8Proxy::setDOMException(SYNTAX_ERR); + return notHandledByInterceptor(); + } + v8::Handle<v8::Value> arg = args[8]; + if (!arg->IsObject()) + // Assume that the user is passing null for texture + context->texSubImage2D(target, + level, + xoff, + yoff, + width, + height, + format, + type, + 0, + ec); + else if (V8WebGLArray::HasInstance(arg)) { + WebGLArray* array = V8WebGLArray::toNative(arg->ToObject()); + context->texSubImage2D(target, + level, + xoff, + yoff, + width, + height, + format, + type, + array, + ec); + // Fall through + } else { + V8Proxy::setDOMException(SYNTAX_ERR); + return notHandledByInterceptor(); + } + } else { + ASSERT_NOT_REACHED(); + V8Proxy::setDOMException(SYNTAX_ERR); + return notHandledByInterceptor(); + } + if (ec) { + V8Proxy::setDOMException(ec); + return v8::Handle<v8::Value>(); + } return v8::Undefined(); } @@ -634,16 +780,14 @@ static v8::Handle<v8::Value> vertexAttribAndUniformHelperf(const v8::Arguments& else location = toWebGLUniformLocation(args[0], ok); - WebGLRenderingContext* context = - V8DOMWrapper::convertDOMWrapperToNative<WebGLRenderingContext>(args.Holder()); + WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder()); if (!ok) { V8Proxy::setDOMException(SYNTAX_ERR); return notHandledByInterceptor(); } if (V8WebGLFloatArray::HasInstance(args[1])) { - WebGLFloatArray* array = - V8DOMWrapper::convertToNativeObject<WebGLFloatArray>(V8ClassIndex::WEBGLFLOATARRAY, args[1]->ToObject()); + WebGLFloatArray* array = V8WebGLFloatArray::toNative(args[1]->ToObject()); ASSERT(array != NULL); ExceptionCode ec = 0; switch (functionToCall) { @@ -710,8 +854,7 @@ static v8::Handle<v8::Value> uniformHelperi(const v8::Arguments& args, return notHandledByInterceptor(); } - WebGLRenderingContext* context = - V8DOMWrapper::convertDOMWrapperToNative<WebGLRenderingContext>(args.Holder()); + WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder()); bool ok = false; WebGLUniformLocation* location = toWebGLUniformLocation(args[0], ok); @@ -720,8 +863,7 @@ static v8::Handle<v8::Value> uniformHelperi(const v8::Arguments& args, return notHandledByInterceptor(); } if (V8WebGLIntArray::HasInstance(args[1])) { - WebGLIntArray* array = - V8DOMWrapper::convertToNativeObject<WebGLIntArray>(V8ClassIndex::WEBGLINTARRAY, args[1]->ToObject()); + WebGLIntArray* array = V8WebGLIntArray::toNative(args[1]->ToObject()); ASSERT(array != NULL); ExceptionCode ec = 0; switch (functionToCall) { @@ -763,49 +905,49 @@ static v8::Handle<v8::Value> uniformHelperi(const v8::Arguments& args, return v8::Undefined(); } -CALLBACK_FUNC_DECL(WebGLRenderingContextUniform1fv) +v8::Handle<v8::Value> V8WebGLRenderingContext::uniform1fvCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.uniform1fv()"); return vertexAttribAndUniformHelperf(args, kUniform1v); } -CALLBACK_FUNC_DECL(WebGLRenderingContextUniform1iv) +v8::Handle<v8::Value> V8WebGLRenderingContext::uniform1ivCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.uniform1iv()"); return uniformHelperi(args, kUniform1v); } -CALLBACK_FUNC_DECL(WebGLRenderingContextUniform2fv) +v8::Handle<v8::Value> V8WebGLRenderingContext::uniform2fvCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.uniform2fv()"); return vertexAttribAndUniformHelperf(args, kUniform2v); } -CALLBACK_FUNC_DECL(WebGLRenderingContextUniform2iv) +v8::Handle<v8::Value> V8WebGLRenderingContext::uniform2ivCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.uniform2iv()"); return uniformHelperi(args, kUniform2v); } -CALLBACK_FUNC_DECL(WebGLRenderingContextUniform3fv) +v8::Handle<v8::Value> V8WebGLRenderingContext::uniform3fvCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.uniform3fv()"); return vertexAttribAndUniformHelperf(args, kUniform3v); } -CALLBACK_FUNC_DECL(WebGLRenderingContextUniform3iv) +v8::Handle<v8::Value> V8WebGLRenderingContext::uniform3ivCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.uniform3iv()"); return uniformHelperi(args, kUniform3v); } -CALLBACK_FUNC_DECL(WebGLRenderingContextUniform4fv) +v8::Handle<v8::Value> V8WebGLRenderingContext::uniform4fvCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.uniform4fv()"); return vertexAttribAndUniformHelperf(args, kUniform4v); } -CALLBACK_FUNC_DECL(WebGLRenderingContextUniform4iv) +v8::Handle<v8::Value> V8WebGLRenderingContext::uniform4ivCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.uniform4iv()"); return uniformHelperi(args, kUniform4v); @@ -828,8 +970,7 @@ static v8::Handle<v8::Value> uniformMatrixHelper(const v8::Arguments& args, return notHandledByInterceptor(); } - WebGLRenderingContext* context = - V8DOMWrapper::convertDOMWrapperToNative<WebGLRenderingContext>(args.Holder()); + WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder()); bool ok = false; WebGLUniformLocation* location = toWebGLUniformLocation(args[0], ok); @@ -840,8 +981,7 @@ static v8::Handle<v8::Value> uniformMatrixHelper(const v8::Arguments& args, } bool transpose = args[1]->BooleanValue(); if (V8WebGLFloatArray::HasInstance(args[2])) { - WebGLFloatArray* array = - V8DOMWrapper::convertToNativeObject<WebGLFloatArray>(V8ClassIndex::WEBGLFLOATARRAY, args[2]->ToObject()); + WebGLFloatArray* array = V8WebGLFloatArray::toNative(args[2]->ToObject()); ASSERT(array != NULL); ExceptionCode ec = 0; switch (matrixSize) { @@ -881,43 +1021,43 @@ static v8::Handle<v8::Value> uniformMatrixHelper(const v8::Arguments& args, return v8::Undefined(); } -CALLBACK_FUNC_DECL(WebGLRenderingContextUniformMatrix2fv) +v8::Handle<v8::Value> V8WebGLRenderingContext::uniformMatrix2fvCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.uniformMatrix2fv()"); return uniformMatrixHelper(args, 2); } -CALLBACK_FUNC_DECL(WebGLRenderingContextUniformMatrix3fv) +v8::Handle<v8::Value> V8WebGLRenderingContext::uniformMatrix3fvCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.uniformMatrix3fv()"); return uniformMatrixHelper(args, 3); } -CALLBACK_FUNC_DECL(WebGLRenderingContextUniformMatrix4fv) +v8::Handle<v8::Value> V8WebGLRenderingContext::uniformMatrix4fvCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.uniformMatrix4fv()"); return uniformMatrixHelper(args, 4); } -CALLBACK_FUNC_DECL(WebGLRenderingContextVertexAttrib1fv) +v8::Handle<v8::Value> V8WebGLRenderingContext::vertexAttrib1fvCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.vertexAttrib1fv()"); return vertexAttribAndUniformHelperf(args, kVertexAttrib1v); } -CALLBACK_FUNC_DECL(WebGLRenderingContextVertexAttrib2fv) +v8::Handle<v8::Value> V8WebGLRenderingContext::vertexAttrib2fvCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.vertexAttrib2fv()"); return vertexAttribAndUniformHelperf(args, kVertexAttrib2v); } -CALLBACK_FUNC_DECL(WebGLRenderingContextVertexAttrib3fv) +v8::Handle<v8::Value> V8WebGLRenderingContext::vertexAttrib3fvCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.vertexAttrib3fv()"); return vertexAttribAndUniformHelperf(args, kVertexAttrib3v); } -CALLBACK_FUNC_DECL(WebGLRenderingContextVertexAttrib4fv) +v8::Handle<v8::Value> V8WebGLRenderingContext::vertexAttrib4fvCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLRenderingContext.vertexAttrib4fv()"); return vertexAttribAndUniformHelperf(args, kVertexAttrib4v); diff --git a/WebCore/bindings/v8/custom/V8WebGLShortArrayCustom.cpp b/WebCore/bindings/v8/custom/V8WebGLShortArrayCustom.cpp index f8a26c3..9d3b478 100644 --- a/WebCore/bindings/v8/custom/V8WebGLShortArrayCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WebGLShortArrayCustom.cpp @@ -44,48 +44,20 @@ namespace WebCore { -CALLBACK_FUNC_DECL(WebGLShortArrayConstructor) +v8::Handle<v8::Value> V8WebGLShortArray::constructorCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLShortArray.Contructor"); return constructWebGLArray<WebGLShortArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLSHORTARRAY)); } -// Get the specified value from the array and return it wrapped as a JavaScript Number object to V8. Accesses outside the valid array range return "undefined". -INDEXED_PROPERTY_GETTER(WebGLShortArray) -{ - INC_STATS("DOM.WebGLShortArray.IndexedPropertyGetter"); - WebGLShortArray* array = V8DOMWrapper::convertToNativeObject<WebGLShortArray>(V8ClassIndex::WEBGLSHORTARRAY, info.Holder()); - - if ((index < 0) || (index >= array->length())) - return v8::Undefined(); - short result; - if (!array->get(index, result)) - return v8::Undefined(); - return v8::Number::New(result); -} - -// Set the specified value in the array. Accesses outside the valid array range are silently ignored. -INDEXED_PROPERTY_SETTER(WebGLShortArray) -{ - INC_STATS("DOM.WebGLShortArray.IndexedPropertySetter"); - WebGLShortArray* array = V8DOMWrapper::convertToNativeObject<WebGLShortArray>(V8ClassIndex::WEBGLSHORTARRAY, info.Holder()); - - if ((index >= 0) && (index < array->length())) { - if (!value->IsNumber()) - return throwError("Could not convert value argument to a number"); - array->set(index, value->NumberValue()); - } - return value; -} - -CALLBACK_FUNC_DECL(WebGLShortArrayGet) +v8::Handle<v8::Value> V8WebGLShortArray::getCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLShortArray.get()"); return getWebGLArrayElement<WebGLShortArray, short>(args, V8ClassIndex::WEBGLSHORTARRAY); } -CALLBACK_FUNC_DECL(WebGLShortArraySet) +v8::Handle<v8::Value> V8WebGLShortArray::setCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLShortArray.set()"); return setWebGLArray<WebGLShortArray, V8WebGLShortArray>(args, V8ClassIndex::WEBGLSHORTARRAY); diff --git a/WebCore/bindings/v8/custom/V8WebGLUnsignedByteArrayCustom.cpp b/WebCore/bindings/v8/custom/V8WebGLUnsignedByteArrayCustom.cpp index 391f213..3cc658a 100644 --- a/WebCore/bindings/v8/custom/V8WebGLUnsignedByteArrayCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WebGLUnsignedByteArrayCustom.cpp @@ -44,48 +44,20 @@ namespace WebCore { -CALLBACK_FUNC_DECL(WebGLUnsignedByteArrayConstructor) +v8::Handle<v8::Value> V8WebGLUnsignedByteArray::constructorCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLUnsignedByteArray.Contructor"); return constructWebGLArray<WebGLUnsignedByteArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLUNSIGNEDBYTEARRAY)); } -// Get the specified value from the array and return it wrapped as a JavaScript Number object to V8. Accesses outside the valid array range return "undefined". -INDEXED_PROPERTY_GETTER(WebGLUnsignedByteArray) -{ - INC_STATS("DOM.WebGLUnsignedByteArray.IndexedPropertyGetter"); - WebGLUnsignedByteArray* array = V8DOMWrapper::convertToNativeObject<WebGLUnsignedByteArray>(V8ClassIndex::WEBGLUNSIGNEDBYTEARRAY, info.Holder()); - - if ((index < 0) || (index >= array->length())) - return v8::Undefined(); - unsigned char result; - if (!array->get(index, result)) - return v8::Undefined(); - return v8::Number::New(result); -} - -// Set the specified value in the array. Accesses outside the valid array range are silently ignored. -INDEXED_PROPERTY_SETTER(WebGLUnsignedByteArray) -{ - INC_STATS("DOM.WebGLUnsignedByteArray.IndexedPropertySetter"); - WebGLUnsignedByteArray* array = V8DOMWrapper::convertToNativeObject<WebGLUnsignedByteArray>(V8ClassIndex::WEBGLUNSIGNEDBYTEARRAY, info.Holder()); - - if ((index >= 0) && (index < array->length())) { - if (!value->IsNumber()) - return throwError("Could not convert value argument to a number"); - array->set(index, value->NumberValue()); - } - return value; -} - -CALLBACK_FUNC_DECL(WebGLUnsignedByteArrayGet) +v8::Handle<v8::Value> V8WebGLUnsignedByteArray::getCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLUnsignedByteArray.get()"); return getWebGLArrayElement<WebGLUnsignedByteArray, unsigned char>(args, V8ClassIndex::WEBGLUNSIGNEDBYTEARRAY); } -CALLBACK_FUNC_DECL(WebGLUnsignedByteArraySet) +v8::Handle<v8::Value> V8WebGLUnsignedByteArray::setCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLUnsignedByteArray.set()"); return setWebGLArray<WebGLUnsignedByteArray, V8WebGLUnsignedByteArray>(args, V8ClassIndex::WEBGLUNSIGNEDBYTEARRAY); diff --git a/WebCore/bindings/v8/custom/V8WebGLUnsignedIntArrayCustom.cpp b/WebCore/bindings/v8/custom/V8WebGLUnsignedIntArrayCustom.cpp index 92b9fe0..93ccbd4 100644 --- a/WebCore/bindings/v8/custom/V8WebGLUnsignedIntArrayCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WebGLUnsignedIntArrayCustom.cpp @@ -44,48 +44,20 @@ namespace WebCore { -CALLBACK_FUNC_DECL(WebGLUnsignedIntArrayConstructor) +v8::Handle<v8::Value> V8WebGLUnsignedIntArray::constructorCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLUnsignedIntArray.Contructor"); return constructWebGLArray<WebGLUnsignedIntArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLUNSIGNEDINTARRAY)); } -// Get the specified value from the integer array and return it wrapped as a JavaScript Number object to V8. Accesses outside the valid pixel buffer range return "undefined". -INDEXED_PROPERTY_GETTER(WebGLUnsignedIntArray) -{ - INC_STATS("DOM.WebGLUnsignedIntArray.IndexedPropertyGetter"); - WebGLUnsignedIntArray* array = V8DOMWrapper::convertToNativeObject<WebGLUnsignedIntArray>(V8ClassIndex::WEBGLUNSIGNEDINTARRAY, info.Holder()); - - if ((index < 0) || (index >= array->length())) - return v8::Undefined(); - unsigned int result; - if (!array->get(index, result)) - return v8::Undefined(); - return v8::Number::New(result); -} - -// Set the specified value in the integer array. Accesses outside the valid integer array range are silently ignored. -INDEXED_PROPERTY_SETTER(WebGLUnsignedIntArray) -{ - INC_STATS("DOM.WebGLUnsignedIntArray.IndexedPropertySetter"); - WebGLUnsignedIntArray* array = V8DOMWrapper::convertToNativeObject<WebGLUnsignedIntArray>(V8ClassIndex::WEBGLUNSIGNEDINTARRAY, info.Holder()); - - if ((index >= 0) && (index < array->length())) { - if (!value->IsNumber()) - return throwError("Could not convert value argument to a number"); - array->set(index, value->NumberValue()); - } - return value; -} - -CALLBACK_FUNC_DECL(WebGLUnsignedIntArrayGet) +v8::Handle<v8::Value> V8WebGLUnsignedIntArray::getCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLUnsignedIntArray.get()"); return getWebGLArrayElement<WebGLUnsignedIntArray, unsigned int>(args, V8ClassIndex::WEBGLUNSIGNEDINTARRAY); } -CALLBACK_FUNC_DECL(WebGLUnsignedIntArraySet) +v8::Handle<v8::Value> V8WebGLUnsignedIntArray::setCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLUnsignedIntArray.set()"); return setWebGLArray<WebGLUnsignedIntArray, V8WebGLUnsignedIntArray>(args, V8ClassIndex::WEBGLUNSIGNEDINTARRAY); diff --git a/WebCore/bindings/v8/custom/V8WebGLUnsignedShortArrayCustom.cpp b/WebCore/bindings/v8/custom/V8WebGLUnsignedShortArrayCustom.cpp index ce261e9..d9e47cd 100644 --- a/WebCore/bindings/v8/custom/V8WebGLUnsignedShortArrayCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WebGLUnsignedShortArrayCustom.cpp @@ -44,48 +44,20 @@ namespace WebCore { -CALLBACK_FUNC_DECL(WebGLUnsignedShortArrayConstructor) +v8::Handle<v8::Value> V8WebGLUnsignedShortArray::constructorCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLUnsignedShortArray.Contructor"); return constructWebGLArray<WebGLUnsignedShortArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLUNSIGNEDSHORTARRAY)); } -// Get the specified value from the array and return it wrapped as a JavaScript Number object to V8. Accesses outside the valid array range return "undefined". -INDEXED_PROPERTY_GETTER(WebGLUnsignedShortArray) -{ - INC_STATS("DOM.WebGLUnsignedShortArray.IndexedPropertyGetter"); - WebGLUnsignedShortArray* array = V8DOMWrapper::convertToNativeObject<WebGLUnsignedShortArray>(V8ClassIndex::WEBGLUNSIGNEDSHORTARRAY, info.Holder()); - - if ((index < 0) || (index >= array->length())) - return v8::Undefined(); - unsigned short result; - if (!array->get(index, result)) - return v8::Undefined(); - return v8::Number::New(result); -} - -// Set the specified value in the array. Accesses outside the valid array range are silently ignored. -INDEXED_PROPERTY_SETTER(WebGLUnsignedShortArray) -{ - INC_STATS("DOM.WebGLUnsignedShortArray.IndexedPropertySetter"); - WebGLUnsignedShortArray* array = V8DOMWrapper::convertToNativeObject<WebGLUnsignedShortArray>(V8ClassIndex::WEBGLUNSIGNEDSHORTARRAY, info.Holder()); - - if ((index >= 0) && (index < array->length())) { - if (!value->IsNumber()) - return throwError("Could not convert value argument to a number"); - array->set(index, value->NumberValue()); - } - return value; -} - -CALLBACK_FUNC_DECL(WebGLUnsignedShortArrayGet) +v8::Handle<v8::Value> V8WebGLUnsignedShortArray::getCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLUnsignedShortArray.get()"); return getWebGLArrayElement<WebGLUnsignedShortArray, unsigned short>(args, V8ClassIndex::WEBGLUNSIGNEDSHORTARRAY); } -CALLBACK_FUNC_DECL(WebGLUnsignedShortArraySet) +v8::Handle<v8::Value> V8WebGLUnsignedShortArray::setCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLUnsignedShortArray.set()"); return setWebGLArray<WebGLUnsignedShortArray, V8WebGLUnsignedShortArray>(args, V8ClassIndex::WEBGLUNSIGNEDSHORTARRAY); diff --git a/WebCore/bindings/v8/custom/V8WebKitCSSMatrixConstructor.cpp b/WebCore/bindings/v8/custom/V8WebKitCSSMatrixConstructor.cpp index 4819064..55518d2 100644 --- a/WebCore/bindings/v8/custom/V8WebKitCSSMatrixConstructor.cpp +++ b/WebCore/bindings/v8/custom/V8WebKitCSSMatrixConstructor.cpp @@ -29,7 +29,7 @@ */ #include "config.h" -#include "WebKitCSSMatrix.h" +#include "V8WebKitCSSMatrix.h" #include "Document.h" #include "DocumentFragment.h" @@ -44,7 +44,7 @@ namespace WebCore { -CALLBACK_FUNC_DECL(WebKitCSSMatrixConstructor) +v8::Handle<v8::Value> V8WebKitCSSMatrix::constructorCallback(const v8::Arguments& args) { INC_STATS("DOM.WebKitCSSMatrix.Constructor"); diff --git a/WebCore/bindings/v8/custom/V8WebKitPointConstructor.cpp b/WebCore/bindings/v8/custom/V8WebKitPointConstructor.cpp index b2a807d..4e0d575 100755 --- a/WebCore/bindings/v8/custom/V8WebKitPointConstructor.cpp +++ b/WebCore/bindings/v8/custom/V8WebKitPointConstructor.cpp @@ -29,19 +29,19 @@ */ #include "config.h" +#include "V8WebKitPoint.h" #include "V8Binding.h" #include "V8CustomBinding.h" #include "V8DOMWrapper.h" #include "V8Index.h" #include "V8Proxy.h" -#include "WebKitPoint.h" #include <wtf/MathExtras.h> namespace WebCore { -CALLBACK_FUNC_DECL(WebKitPointConstructor) +v8::Handle<v8::Value> V8WebKitPoint::constructorCallback(const v8::Arguments& args) { INC_STATS("DOM.WebKitPoint.Constructor"); float x = 0; diff --git a/WebCore/bindings/v8/custom/V8WebSocketCustom.cpp b/WebCore/bindings/v8/custom/V8WebSocketCustom.cpp index b20635b..2451b90 100644 --- a/WebCore/bindings/v8/custom/V8WebSocketCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WebSocketCustom.cpp @@ -32,22 +32,23 @@ #if ENABLE(WEB_SOCKETS) -#include "WebSocket.h" +#include "V8WebSocket.h" #include "Frame.h" #include "Settings.h" #include "V8Binding.h" #include "V8Proxy.h" #include "V8Utilities.h" +#include "WebSocket.h" #include "WorkerContext.h" #include "WorkerContextExecutionProxy.h" namespace WebCore { -CALLBACK_FUNC_DECL(WebSocketAddEventListener) +v8::Handle<v8::Value> V8WebSocket::addEventListenerCallback(const v8::Arguments& args) { INC_STATS("DOM.WebSocket.addEventListener()"); - WebSocket* webSocket = V8DOMWrapper::convertToNativeObject<WebSocket>(V8ClassIndex::WEBSOCKET, args.Holder()); + WebSocket* webSocket = V8WebSocket::toNative(args.Holder()); RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(webSocket, args[1], false, ListenerFindOrCreate); if (listener) { @@ -55,27 +56,27 @@ CALLBACK_FUNC_DECL(WebSocketAddEventListener) bool useCapture = args[2]->BooleanValue(); webSocket->addEventListener(type, listener, useCapture); - createHiddenDependency(args.Holder(), args[1], V8Custom::kWebSocketCacheIndex); + createHiddenDependency(args.Holder(), args[1], cacheIndex); } return v8::Undefined(); } -CALLBACK_FUNC_DECL(WebSocketRemoveEventListener) +v8::Handle<v8::Value> V8WebSocket::removeEventListenerCallback(const v8::Arguments& args) { INC_STATS("DOM.WebSocket.removeEventListener()"); - WebSocket* webSocket = V8DOMWrapper::convertToNativeObject<WebSocket>(V8ClassIndex::WEBSOCKET, args.Holder()); + WebSocket* webSocket = V8WebSocket::toNative(args.Holder()); RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(webSocket, args[1], false, ListenerFindOnly); if (listener) { String type = toWebCoreString(args[0]); bool useCapture = args[2]->BooleanValue(); webSocket->removeEventListener(type, listener.get(), useCapture); - removeHiddenDependency(args.Holder(), args[1], V8Custom::kWebSocketCacheIndex); + removeHiddenDependency(args.Holder(), args[1], cacheIndex); } return v8::Undefined(); } -CALLBACK_FUNC_DECL(WebSocketConstructor) +v8::Handle<v8::Value> V8WebSocket::constructorCallback(const v8::Arguments& args) { INC_STATS("DOM.WebSocket.Constructor"); @@ -92,14 +93,9 @@ CALLBACK_FUNC_DECL(WebSocketConstructor) return throwError("Empty URL", V8Proxy::SyntaxError); // Get the script execution context. - ScriptExecutionContext* context = 0; - // TODO: Workers - if (!context) { - Frame* frame = V8Proxy::retrieveFrameForCurrentContext(); - if (!frame) - return throwError("WebSocket constructor's associated frame is not available", V8Proxy::ReferenceError); - context = frame->document(); - } + ScriptExecutionContext* context = getScriptExecutionContext(); + if (!context) + return throwError("WebSocket constructor's associated frame is not available", V8Proxy::ReferenceError); const KURL& url = context->completeURL(toWebCoreString(urlstring)); @@ -128,10 +124,10 @@ CALLBACK_FUNC_DECL(WebSocketConstructor) return args.Holder(); } -CALLBACK_FUNC_DECL(WebSocketSend) +v8::Handle<v8::Value> V8WebSocket::sendCallback(const v8::Arguments& args) { INC_STATS("DOM.WebSocket.send()"); - WebSocket* webSocket = V8DOMWrapper::convertToNativeObject<WebSocket>(V8ClassIndex::WEBSOCKET, args.Holder()); + WebSocket* webSocket = V8WebSocket::toNative(args.Holder()); ExceptionCode ec = 0; bool ret = false; @@ -146,15 +142,6 @@ CALLBACK_FUNC_DECL(WebSocketSend) return v8Boolean(ret); } -CALLBACK_FUNC_DECL(WebSocketClose) -{ - INC_STATS("DOM.WebSocket.close()"); - WebSocket* webSocket = V8DOMWrapper::convertToNativeObject<WebSocket>(V8ClassIndex::WEBSOCKET, args.Holder()); - - webSocket->close(); - return v8::Undefined(); -} - } // namespace WebCore #endif // ENABLE(WEB_SOCKETS) diff --git a/WebCore/bindings/v8/custom/V8WorkerContextCustom.cpp b/WebCore/bindings/v8/custom/V8WorkerContextCustom.cpp index 9b68ac0..9d54f8e 100755 --- a/WebCore/bindings/v8/custom/V8WorkerContextCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WorkerContextCustom.cpp @@ -31,6 +31,7 @@ #include "config.h" #if ENABLE(WORKERS) +#include "V8WorkerContext.h" #include "DOMTimer.h" #include "ExceptionCode.h" @@ -41,28 +42,29 @@ #include "V8Proxy.h" #include "V8Utilities.h" #include "V8WorkerContextEventListener.h" +#include "WebSocket.h" #include "WorkerContext.h" #include "WorkerContextExecutionProxy.h" namespace WebCore { #if ENABLE(NOTIFICATIONS) -ACCESSOR_RUNTIME_ENABLER(WorkerContextWebkitNotifications) +bool V8WorkerContext::WebkitNotificationsEnabled() { return RuntimeEnabledFeatures::notificationsEnabled(); } #endif -ACCESSOR_GETTER(WorkerContextSelf) +#if ENABLE(WEB_SOCKETS) +bool V8WorkerContext::WebSocketEnabled() { - INC_STATS(L"DOM.WorkerContext.self._get"); - WorkerContext* workerContext = V8DOMWrapper::convertDOMWrapperToNative<WorkerContext>(info.Holder()); - return WorkerContextExecutionProxy::convertWorkerContextToV8Object(workerContext); + return WebSocket::isAvailable(); } +#endif v8::Handle<v8::Value> SetTimeoutOrInterval(const v8::Arguments& args, bool singleShot) { - WorkerContext* workerContext = V8DOMWrapper::convertDOMWrapperToNative<WorkerContext>(args.Holder()); + WorkerContext* workerContext = V8WorkerContext::toNative(args.Holder()); int argumentCount = args.Length(); if (argumentCount < 1) @@ -94,7 +96,7 @@ v8::Handle<v8::Value> SetTimeoutOrInterval(const v8::Arguments& args, bool singl return v8::Integer::New(timerId); } -CALLBACK_FUNC_DECL(WorkerContextImportScripts) +v8::Handle<v8::Value> V8WorkerContext::importScriptsCallback(const v8::Arguments& args) { INC_STATS(L"DOM.WorkerContext.importScripts()"); if (!args.Length()) @@ -117,7 +119,7 @@ CALLBACK_FUNC_DECL(WorkerContextImportScripts) urls.append(toWebCoreString(scriptUrl)); } - WorkerContext* workerContext = V8DOMWrapper::convertDOMWrapperToNative<WorkerContext>(args.Holder()); + WorkerContext* workerContext = V8WorkerContext::toNative(args.Holder()); ExceptionCode ec = 0; workerContext->importScripts(urls, callerURL, callerLine, ec); @@ -128,22 +130,22 @@ CALLBACK_FUNC_DECL(WorkerContextImportScripts) return v8::Undefined(); } -CALLBACK_FUNC_DECL(WorkerContextSetTimeout) +v8::Handle<v8::Value> V8WorkerContext::setTimeoutCallback(const v8::Arguments& args) { INC_STATS(L"DOM.WorkerContext.setTimeout()"); return SetTimeoutOrInterval(args, true); } -CALLBACK_FUNC_DECL(WorkerContextSetInterval) +v8::Handle<v8::Value> V8WorkerContext::setIntervalCallback(const v8::Arguments& args) { INC_STATS(L"DOM.WorkerContext.setInterval()"); return SetTimeoutOrInterval(args, false); } -CALLBACK_FUNC_DECL(WorkerContextAddEventListener) +v8::Handle<v8::Value> V8WorkerContext::addEventListenerCallback(const v8::Arguments& args) { INC_STATS(L"DOM.WorkerContext.addEventListener()"); - WorkerContext* workerContext = V8DOMWrapper::convertDOMWrapperToNative<WorkerContext>(args.Holder()); + WorkerContext* workerContext = V8WorkerContext::toNative(args.Holder()); RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(workerContext, args[1], false, ListenerFindOrCreate); if (listener) { @@ -151,15 +153,15 @@ CALLBACK_FUNC_DECL(WorkerContextAddEventListener) bool useCapture = args[2]->BooleanValue(); workerContext->addEventListener(type, listener, useCapture); - createHiddenDependency(args.Holder(), args[1], V8Custom::kWorkerContextRequestCacheIndex); + createHiddenDependency(args.Holder(), args[1], cacheIndex); } return v8::Undefined(); } -CALLBACK_FUNC_DECL(WorkerContextRemoveEventListener) +v8::Handle<v8::Value> V8WorkerContext::removeEventListenerCallback(const v8::Arguments& args) { INC_STATS(L"DOM.WorkerContext.removeEventListener()"); - WorkerContext* workerContext = V8DOMWrapper::convertDOMWrapperToNative<WorkerContext>(args.Holder()); + WorkerContext* workerContext = V8WorkerContext::toNative(args.Holder()); RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(workerContext, args[1], false, ListenerFindOnly); if (listener) { @@ -167,7 +169,7 @@ CALLBACK_FUNC_DECL(WorkerContextRemoveEventListener) bool useCapture = args[2]->BooleanValue(); workerContext->removeEventListener(type, listener.get(), useCapture); - removeHiddenDependency(args.Holder(), args[1], V8Custom::kWorkerContextRequestCacheIndex); + removeHiddenDependency(args.Holder(), args[1], cacheIndex); } return v8::Undefined(); } diff --git a/WebCore/bindings/v8/custom/V8WorkerCustom.cpp b/WebCore/bindings/v8/custom/V8WorkerCustom.cpp index 454e41f..ffca2a4 100755 --- a/WebCore/bindings/v8/custom/V8WorkerCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WorkerCustom.cpp @@ -31,6 +31,7 @@ #include "config.h" #if ENABLE(WORKERS) +#include "V8Worker.h" #include "Worker.h" @@ -47,7 +48,7 @@ namespace WebCore { -CALLBACK_FUNC_DECL(WorkerConstructor) +v8::Handle<v8::Value> V8Worker::constructorCallback(const v8::Arguments& args) { INC_STATS(L"DOM.Worker.Constructor"); @@ -87,11 +88,11 @@ CALLBACK_FUNC_DECL(WorkerConstructor) return wrapperObject; } -CALLBACK_FUNC_DECL(WorkerPostMessage) +v8::Handle<v8::Value> V8Worker::postMessageCallback(const v8::Arguments& args) { INC_STATS("DOM.Worker.postMessage"); - Worker* worker = V8DOMWrapper::convertToNativeObject<Worker>(V8ClassIndex::WORKER, args.Holder()); - RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(toWebCoreString(args[0])); + Worker* worker = V8Worker::toNative(args.Holder()); + RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0]); MessagePortArray portArray; if (args.Length() > 1) { if (!getMessagePortArray(args[1], portArray)) diff --git a/WebCore/bindings/v8/custom/V8XMLHttpRequestConstructor.cpp b/WebCore/bindings/v8/custom/V8XMLHttpRequestConstructor.cpp index af647cd..e31e05f 100644 --- a/WebCore/bindings/v8/custom/V8XMLHttpRequestConstructor.cpp +++ b/WebCore/bindings/v8/custom/V8XMLHttpRequestConstructor.cpp @@ -29,19 +29,19 @@ */ #include "config.h" +#include "V8XMLHttpRequest.h" #include "Frame.h" #include "V8Binding.h" #include "V8CustomBinding.h" #include "V8Proxy.h" #include "V8Utilities.h" -#include "XMLHttpRequest.h" #include "WorkerContext.h" #include "WorkerContextExecutionProxy.h" namespace WebCore { -CALLBACK_FUNC_DECL(XMLHttpRequestConstructor) +v8::Handle<v8::Value> V8XMLHttpRequest::constructorCallback(const v8::Arguments& args) { INC_STATS("DOM.XMLHttpRequest.Constructor"); diff --git a/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp b/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp index c3e4645..d7cdcd1 100644 --- a/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp +++ b/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp @@ -29,32 +29,33 @@ */ #include "config.h" -#include "XMLHttpRequest.h" +#include "V8XMLHttpRequest.h" #include "Frame.h" #include "V8Binding.h" +#include "V8Blob.h" #include "V8CustomBinding.h" #include "V8Document.h" -#include "V8File.h" #include "V8HTMLDocument.h" #include "V8Proxy.h" #include "V8Utilities.h" #include "WorkerContext.h" #include "WorkerContextExecutionProxy.h" +#include "XMLHttpRequest.h" namespace WebCore { -ACCESSOR_GETTER(XMLHttpRequestResponseText) +v8::Handle<v8::Value> V8XMLHttpRequest::responseTextAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.XMLHttpRequest.responsetext._get"); - XMLHttpRequest* xmlHttpRequest = V8DOMWrapper::convertToNativeObject<XMLHttpRequest>(V8ClassIndex::XMLHTTPREQUEST, info.Holder()); + XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(info.Holder()); return xmlHttpRequest->responseText().v8StringOrNull(); } -CALLBACK_FUNC_DECL(XMLHttpRequestAddEventListener) +v8::Handle<v8::Value> V8XMLHttpRequest::addEventListenerCallback(const v8::Arguments& args) { INC_STATS("DOM.XMLHttpRequest.addEventListener()"); - XMLHttpRequest* xmlHttpRequest = V8DOMWrapper::convertToNativeObject<XMLHttpRequest>(V8ClassIndex::XMLHTTPREQUEST, args.Holder()); + XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(args.Holder()); RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(xmlHttpRequest, args[1], false, ListenerFindOrCreate); if (listener) { @@ -62,15 +63,15 @@ CALLBACK_FUNC_DECL(XMLHttpRequestAddEventListener) bool useCapture = args[2]->BooleanValue(); xmlHttpRequest->addEventListener(type, listener, useCapture); - createHiddenDependency(args.Holder(), args[1], V8Custom::kXMLHttpRequestCacheIndex); + createHiddenDependency(args.Holder(), args[1], cacheIndex); } return v8::Undefined(); } -CALLBACK_FUNC_DECL(XMLHttpRequestRemoveEventListener) +v8::Handle<v8::Value> V8XMLHttpRequest::removeEventListenerCallback(const v8::Arguments& args) { INC_STATS("DOM.XMLHttpRequest.removeEventListener()"); - XMLHttpRequest* xmlHttpRequest = V8DOMWrapper::convertToNativeObject<XMLHttpRequest>(V8ClassIndex::XMLHTTPREQUEST, args.Holder()); + XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(args.Holder()); RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(xmlHttpRequest, args[1], false, ListenerFindOnly); if (listener) { @@ -78,13 +79,13 @@ CALLBACK_FUNC_DECL(XMLHttpRequestRemoveEventListener) bool useCapture = args[2]->BooleanValue(); xmlHttpRequest->removeEventListener(type, listener.get(), useCapture); - removeHiddenDependency(args.Holder(), args[1], V8Custom::kXMLHttpRequestCacheIndex); + removeHiddenDependency(args.Holder(), args[1], cacheIndex); } return v8::Undefined(); } -CALLBACK_FUNC_DECL(XMLHttpRequestOpen) +v8::Handle<v8::Value> V8XMLHttpRequest::openCallback(const v8::Arguments& args) { INC_STATS("DOM.XMLHttpRequest.open()"); // Four cases: @@ -96,7 +97,7 @@ CALLBACK_FUNC_DECL(XMLHttpRequestOpen) if (args.Length() < 2) return throwError("Not enough arguments", V8Proxy::SyntaxError); - XMLHttpRequest* xmlHttpRequest = V8DOMWrapper::convertToNativeObject<XMLHttpRequest>(V8ClassIndex::XMLHTTPREQUEST, args.Holder()); + XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(args.Holder()); String method = toWebCoreString(args[0]); String urlstring = toWebCoreString(args[1]); @@ -133,10 +134,10 @@ static bool IsDocumentType(v8::Handle<v8::Value> value) return V8Document::HasInstance(value) || V8HTMLDocument::HasInstance(value); } -CALLBACK_FUNC_DECL(XMLHttpRequestSend) +v8::Handle<v8::Value> V8XMLHttpRequest::sendCallback(const v8::Arguments& args) { INC_STATS("DOM.XMLHttpRequest.send()"); - XMLHttpRequest* xmlHttpRequest = V8DOMWrapper::convertToNativeObject<XMLHttpRequest>(V8ClassIndex::XMLHTTPREQUEST, args.Holder()); + XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(args.Holder()); ExceptionCode ec = 0; if (args.Length() < 1) @@ -145,14 +146,14 @@ CALLBACK_FUNC_DECL(XMLHttpRequestSend) v8::Handle<v8::Value> arg = args[0]; if (IsDocumentType(arg)) { v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg); - Document* document = V8DOMWrapper::convertDOMWrapperToNode<Document>(object); + Document* document = V8Document::toNative(object); ASSERT(document); xmlHttpRequest->send(document, ec); - } else if (V8File::HasInstance(arg)) { + } else if (V8Blob::HasInstance(arg)) { v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg); - File* file = V8DOMWrapper::convertDOMWrapperToNative<File>(object); - ASSERT(file); - xmlHttpRequest->send(file, ec); + Blob* blob = V8Blob::toNative(object); + ASSERT(blob); + xmlHttpRequest->send(blob, ec); } else xmlHttpRequest->send(toWebCoreStringWithNullCheck(arg), ec); } @@ -163,12 +164,13 @@ CALLBACK_FUNC_DECL(XMLHttpRequestSend) return v8::Undefined(); } -CALLBACK_FUNC_DECL(XMLHttpRequestSetRequestHeader) { +v8::Handle<v8::Value> V8XMLHttpRequest::setRequestHeaderCallback(const v8::Arguments& args) +{ INC_STATS("DOM.XMLHttpRequest.setRequestHeader()"); if (args.Length() < 2) return throwError("Not enough arguments", V8Proxy::SyntaxError); - XMLHttpRequest* xmlHttpRequest = V8DOMWrapper::convertToNativeObject<XMLHttpRequest>(V8ClassIndex::XMLHTTPREQUEST, args.Holder()); + XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(args.Holder()); ExceptionCode ec = 0; String header = toWebCoreString(args[0]); String value = toWebCoreString(args[1]); @@ -178,13 +180,13 @@ CALLBACK_FUNC_DECL(XMLHttpRequestSetRequestHeader) { return v8::Undefined(); } -CALLBACK_FUNC_DECL(XMLHttpRequestGetResponseHeader) +v8::Handle<v8::Value> V8XMLHttpRequest::getResponseHeaderCallback(const v8::Arguments& args) { INC_STATS("DOM.XMLHttpRequest.getResponseHeader()"); if (args.Length() < 1) return throwError("Not enough arguments", V8Proxy::SyntaxError); - XMLHttpRequest* xmlHttpRequest = V8DOMWrapper::convertToNativeObject<XMLHttpRequest>(V8ClassIndex::XMLHTTPREQUEST, args.Holder()); + XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(args.Holder()); ExceptionCode ec = 0; String header = toWebCoreString(args[0]); String result = xmlHttpRequest->getResponseHeader(header, ec); @@ -193,19 +195,19 @@ CALLBACK_FUNC_DECL(XMLHttpRequestGetResponseHeader) return v8StringOrNull(result); } -CALLBACK_FUNC_DECL(XMLHttpRequestOverrideMimeType) +v8::Handle<v8::Value> V8XMLHttpRequest::overrideMimeTypeCallback(const v8::Arguments& args) { INC_STATS("DOM.XMLHttpRequest.overrideMimeType()"); if (args.Length() < 1) return throwError("Not enough arguments", V8Proxy::SyntaxError); - XMLHttpRequest* xmlHttpRequest = V8DOMWrapper::convertToNativeObject<XMLHttpRequest>(V8ClassIndex::XMLHTTPREQUEST, args.Holder()); + XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(args.Holder()); String value = toWebCoreString(args[0]); xmlHttpRequest->overrideMimeType(value); return v8::Undefined(); } -CALLBACK_FUNC_DECL(XMLHttpRequestDispatchEvent) +v8::Handle<v8::Value> V8XMLHttpRequest::dispatchEventCallback(const v8::Arguments& args) { INC_STATS("DOM.XMLHttpRequest.dispatchEvent()"); return v8::Undefined(); diff --git a/WebCore/bindings/v8/custom/V8XMLHttpRequestUploadCustom.cpp b/WebCore/bindings/v8/custom/V8XMLHttpRequestUploadCustom.cpp index 9323f71..0690189 100644 --- a/WebCore/bindings/v8/custom/V8XMLHttpRequestUploadCustom.cpp +++ b/WebCore/bindings/v8/custom/V8XMLHttpRequestUploadCustom.cpp @@ -29,7 +29,7 @@ */ #include "config.h" -#include "XMLHttpRequestUpload.h" +#include "V8XMLHttpRequestUpload.h" #include "ExceptionCode.h" #include "V8Binding.h" @@ -37,15 +37,16 @@ #include "V8Proxy.h" #include "V8Utilities.h" #include "XMLHttpRequest.h" +#include "XMLHttpRequestUpload.h" #include <wtf/Assertions.h> namespace WebCore { -CALLBACK_FUNC_DECL(XMLHttpRequestUploadAddEventListener) +v8::Handle<v8::Value> V8XMLHttpRequestUpload::addEventListenerCallback(const v8::Arguments& args) { INC_STATS("DOM.XMLHttpRequestUpload.addEventListener()"); - XMLHttpRequestUpload* xmlHttpRequestUpload = V8DOMWrapper::convertToNativeObject<XMLHttpRequestUpload>(V8ClassIndex::XMLHTTPREQUESTUPLOAD, args.Holder()); + XMLHttpRequestUpload* xmlHttpRequestUpload = V8XMLHttpRequestUpload::toNative(args.Holder()); XMLHttpRequest* xmlHttpRequest = xmlHttpRequestUpload->associatedXMLHttpRequest(); @@ -55,15 +56,15 @@ CALLBACK_FUNC_DECL(XMLHttpRequestUploadAddEventListener) bool useCapture = args[2]->BooleanValue(); xmlHttpRequestUpload->addEventListener(type, listener, useCapture); - createHiddenDependency(args.Holder(), args[1], V8Custom::kXMLHttpRequestCacheIndex); + createHiddenDependency(args.Holder(), args[1], cacheIndex); } return v8::Undefined(); } -CALLBACK_FUNC_DECL(XMLHttpRequestUploadRemoveEventListener) +v8::Handle<v8::Value> V8XMLHttpRequestUpload::removeEventListenerCallback(const v8::Arguments& args) { INC_STATS("DOM.XMLHttpRequestUpload.removeEventListener()"); - XMLHttpRequestUpload* xmlHttpRequestUpload = V8DOMWrapper::convertToNativeObject<XMLHttpRequestUpload>(V8ClassIndex::XMLHTTPREQUESTUPLOAD, args.Holder()); + XMLHttpRequestUpload* xmlHttpRequestUpload = V8XMLHttpRequestUpload::toNative(args.Holder()); XMLHttpRequest* xmlHttpRequest = xmlHttpRequestUpload->associatedXMLHttpRequest(); @@ -73,13 +74,13 @@ CALLBACK_FUNC_DECL(XMLHttpRequestUploadRemoveEventListener) bool useCapture = args[2]->BooleanValue(); xmlHttpRequestUpload->removeEventListener(type, listener.get(), useCapture); - removeHiddenDependency(args.Holder(), args[1], V8Custom::kXMLHttpRequestCacheIndex); + removeHiddenDependency(args.Holder(), args[1], cacheIndex); } return v8::Undefined(); } -CALLBACK_FUNC_DECL(XMLHttpRequestUploadDispatchEvent) +v8::Handle<v8::Value> V8XMLHttpRequestUpload::dispatchEventCallback(const v8::Arguments& args) { INC_STATS("DOM.XMLHttpRequestUpload.dispatchEvent()"); return throwError(NOT_SUPPORTED_ERR); diff --git a/WebCore/bindings/v8/custom/V8XSLTProcessorCustom.cpp b/WebCore/bindings/v8/custom/V8XSLTProcessorCustom.cpp index 1ad7d4a..fd0305a 100644 --- a/WebCore/bindings/v8/custom/V8XSLTProcessorCustom.cpp +++ b/WebCore/bindings/v8/custom/V8XSLTProcessorCustom.cpp @@ -29,7 +29,7 @@ */ #include "config.h" -#include "XSLTProcessor.h" +#include "V8XSLTProcessor.h" #include "Document.h" #include "DocumentFragment.h" @@ -40,57 +40,58 @@ #include "V8Document.h" #include "V8Node.h" #include "V8Proxy.h" +#include "XSLTProcessor.h" #include <wtf/RefPtr.h> namespace WebCore { -CALLBACK_FUNC_DECL(XSLTProcessorConstructor) +v8::Handle<v8::Value> V8XSLTProcessor::constructorCallback(const v8::Arguments& args) { INC_STATS("DOM.XSLTProcessor.Constructor"); return V8Proxy::constructDOMObject<V8ClassIndex::XSLTPROCESSOR, XSLTProcessor>(args); } -CALLBACK_FUNC_DECL(XSLTProcessorImportStylesheet) +v8::Handle<v8::Value> V8XSLTProcessor::importStylesheetCallback(const v8::Arguments& args) { INC_STATS("DOM.XSLTProcessor.importStylesheet"); if (!V8Node::HasInstance(args[0])) return v8::Undefined(); - XSLTProcessor* imp = V8DOMWrapper::convertToNativeObject<XSLTProcessor>(V8ClassIndex::XSLTPROCESSOR, args.Holder()); + XSLTProcessor* imp = V8XSLTProcessor::toNative(args.Holder()); - Node* node = V8DOMWrapper::convertDOMWrapperToNode<Node>(v8::Handle<v8::Object>::Cast(args[0])); + Node* node = V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])); imp->importStylesheet(node); return v8::Undefined(); } -CALLBACK_FUNC_DECL(XSLTProcessorTransformToFragment) +v8::Handle<v8::Value> V8XSLTProcessor::transformToFragmentCallback(const v8::Arguments& args) { INC_STATS("DOM.XSLTProcessor.transformToFragment"); if (!V8Node::HasInstance(args[0]) || !V8Document::HasInstance(args[1])) return v8::Undefined(); - XSLTProcessor* imp = V8DOMWrapper::convertToNativeObject<XSLTProcessor>(V8ClassIndex::XSLTPROCESSOR, args.Holder()); + XSLTProcessor* imp = V8XSLTProcessor::toNative(args.Holder()); - Node* source = V8DOMWrapper::convertDOMWrapperToNode<Node>(v8::Handle<v8::Object>::Cast(args[0])); - Document* owner = V8DOMWrapper::convertDOMWrapperToNode<Document>(v8::Handle<v8::Object>::Cast(args[1])); + Node* source = V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])); + Document* owner = V8Document::toNative(v8::Handle<v8::Object>::Cast(args[1])); RefPtr<DocumentFragment> result = imp->transformToFragment(source, owner); return V8DOMWrapper::convertNodeToV8Object(result.release()); } -CALLBACK_FUNC_DECL(XSLTProcessorTransformToDocument) +v8::Handle<v8::Value> V8XSLTProcessor::transformToDocumentCallback(const v8::Arguments& args) { INC_STATS("DOM.XSLTProcessor.transformToDocument"); if (!V8Node::HasInstance(args[0])) return v8::Undefined(); - XSLTProcessor* imp = V8DOMWrapper::convertToNativeObject<XSLTProcessor>(V8ClassIndex::XSLTPROCESSOR, args.Holder()); + XSLTProcessor* imp = V8XSLTProcessor::toNative(args.Holder()); - Node* source = V8DOMWrapper::convertDOMWrapperToNode<Node>(v8::Handle<v8::Object>::Cast(args[0])); + Node* source = V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])); if (!source) return v8::Undefined(); @@ -102,13 +103,13 @@ CALLBACK_FUNC_DECL(XSLTProcessorTransformToDocument) } -CALLBACK_FUNC_DECL(XSLTProcessorSetParameter) +v8::Handle<v8::Value> V8XSLTProcessor::setParameterCallback(const v8::Arguments& args) { INC_STATS("DOM.XSLTProcessor.setParameter"); if (isUndefinedOrNull(args[1]) || isUndefinedOrNull(args[2])) return v8::Undefined(); - XSLTProcessor* imp = V8DOMWrapper::convertToNativeObject<XSLTProcessor>(V8ClassIndex::XSLTPROCESSOR, args.Holder()); + XSLTProcessor* imp = V8XSLTProcessor::toNative(args.Holder()); String namespaceURI = toWebCoreString(args[0]); String localName = toWebCoreString(args[1]); @@ -119,13 +120,13 @@ CALLBACK_FUNC_DECL(XSLTProcessorSetParameter) } -CALLBACK_FUNC_DECL(XSLTProcessorGetParameter) +v8::Handle<v8::Value> V8XSLTProcessor::getParameterCallback(const v8::Arguments& args) { INC_STATS("DOM.XSLTProcessor.getParameter"); if (isUndefinedOrNull(args[1])) return v8::Undefined(); - XSLTProcessor* imp = V8DOMWrapper::convertToNativeObject<XSLTProcessor>(V8ClassIndex::XSLTPROCESSOR, args.Holder()); + XSLTProcessor* imp = V8XSLTProcessor::toNative(args.Holder()); String namespaceURI = toWebCoreString(args[0]); String localName = toWebCoreString(args[1]); @@ -136,13 +137,13 @@ CALLBACK_FUNC_DECL(XSLTProcessorGetParameter) return v8String(result); } -CALLBACK_FUNC_DECL(XSLTProcessorRemoveParameter) +v8::Handle<v8::Value> V8XSLTProcessor::removeParameterCallback(const v8::Arguments& args) { INC_STATS("DOM.XSLTProcessor.removeParameter"); if (isUndefinedOrNull(args[1])) return v8::Undefined(); - XSLTProcessor* imp = V8DOMWrapper::convertToNativeObject<XSLTProcessor>(V8ClassIndex::XSLTPROCESSOR, args.Holder()); + XSLTProcessor* imp = V8XSLTProcessor::toNative(args.Holder()); String namespaceURI = toWebCoreString(args[0]); String localName = toWebCoreString(args[1]); diff --git a/WebCore/bindings/v8/specialization/V8BindingDOMWindow.h b/WebCore/bindings/v8/specialization/V8BindingDOMWindow.h new file mode 100644 index 0000000..0c4069f --- /dev/null +++ b/WebCore/bindings/v8/specialization/V8BindingDOMWindow.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef V8BindingDOMWindow_h +#define V8BindingDOMWindow_h + +#include "BindingDOMWindow.h" +#include "GenericBinding.h" +#include "V8Proxy.h" + +namespace WebCore { + +class V8Binding; + +class V8BindingDOMWindow : public BindingDOMWindow<V8Binding> { +public: + static void storeDialogArgs(State<V8Binding>*, Frame* newFrame, v8::Handle<v8::Value> dialogArgs) + { + // Set dialog arguments on the global object of the new frame. + if (!dialogArgs.IsEmpty()) { + v8::Local<v8::Context> context = V8Proxy::context(newFrame); + if (!context.IsEmpty()) { + v8::Context::Scope scope(context); + context->Global()->Set(v8::String::New("dialogArguments"), dialogArgs); + } + } + } +}; + +} // namespace WebCore + +#endif // V8BindingDOMWindow_h diff --git a/WebCore/bindings/v8/specialization/V8BindingState.cpp b/WebCore/bindings/v8/specialization/V8BindingState.cpp new file mode 100644 index 0000000..4710271 --- /dev/null +++ b/WebCore/bindings/v8/specialization/V8BindingState.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "V8BindingState.h" + +#include "V8Proxy.h" +#include <wtf/StdLibExtras.h> + +namespace WebCore { + +State<V8Binding>* State<V8Binding>::Only() +{ + DEFINE_STATIC_LOCAL(State, globalV8BindingState, ()); + return &globalV8BindingState; +} + +DOMWindow* State<V8Binding>::getActiveWindow() +{ + v8::Local<v8::Context> activeContext = v8::Context::GetCalling(); + if (activeContext.IsEmpty()) { + // There is a single activation record on the stack, so that must + // be the activeContext. + activeContext = v8::Context::GetCurrent(); + } + return V8Proxy::retrieveWindow(activeContext); +} + +void State<V8Binding>::immediatelyReportUnsafeAccessTo(Frame* target) +{ + V8Proxy::reportUnsafeAccessTo(target, V8Proxy::ReportNow); +} + +} // namespace WebCore diff --git a/WebCore/bindings/v8/specialization/V8BindingState.h b/WebCore/bindings/v8/specialization/V8BindingState.h new file mode 100644 index 0000000..f305c14 --- /dev/null +++ b/WebCore/bindings/v8/specialization/V8BindingState.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef V8BindingState_h +#define V8BindingState_h + +#include "GenericBinding.h" +#include "V8Binding.h" + +namespace WebCore { + +// Singleton implementation of State<V8Binding>. Uses V8's global data +// structures to return information about relevant execution state. +template <> +class State<V8Binding> : public State<GenericBinding> { +public: + // Singleton + static State* Only(); + + // The DOMWindow corresponding to the 'calling context' of execution. + DOMWindow* getActiveWindow(); + + // Reports an error message (without delay) if the security check fails. + static void immediatelyReportUnsafeAccessTo(Frame*); + +private: + explicit State() {} + ~State(); +}; + +typedef State<V8Binding> V8BindingState; + +} + +#endif // V8BindingState_h |