Changeset 54278 in webkit
- Timestamp:
- Feb 3, 2010 5:02:13 AM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 45 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r54277 r54278 1 2010-02-03 Shinichiro Hamaji <hamaji@chromium.org> 2 3 Unreviewed revert of r54259 as it seems to break chromium's unit tests. 4 The tests pass with r54257 but fail with r54260. 5 As r54258 and r54260 don't touch code, I'm reverting this change. 6 7 [V8] Generate toV8 conversion helpers, a la JSC bindings. 8 https://bugs.webkit.org/show_bug.cgi?id=32563 9 10 * bindings/v8/ScriptController.cpp: 11 (WebCore::ScriptController::processingUserGesture): 12 (WebCore::createScriptObject): 13 (WebCore::ScriptController::createScriptObjectForPluginElement): 14 * bindings/v8/ScriptObject.cpp: 15 (WebCore::ScriptGlobalObject::set): 16 * bindings/v8/V8AbstractEventListener.cpp: 17 (WebCore::V8AbstractEventListener::handleEvent): 18 * bindings/v8/V8Collection.h: 19 (WebCore::getV8Object): 20 (WebCore::toNativeCollection): 21 (WebCore::getNamedPropertyOfCollection): 22 (WebCore::collectionNamedPropertyGetter): 23 (WebCore::getIndexedPropertyOfCollection): 24 (WebCore::collectionIndexedPropertyGetter): 25 (WebCore::nodeCollectionIndexedPropertyEnumerator): 26 (WebCore::collectionIndexedPropertyEnumerator): 27 (WebCore::collectionStringOrNullIndexedPropertyGetter): 28 (WebCore::collectionStringIndexedPropertyGetter): 29 (WebCore::setCollectionIndexedGetter): 30 (WebCore::setCollectionNamedGetter): 31 (WebCore::setCollectionStringOrNullIndexedGetter): 32 (WebCore::setCollectionStringIndexedGetter): 33 * bindings/v8/V8DOMWindowShell.cpp: 34 (WebCore::V8DOMWindowShell::updateDocumentWrapperCache): 35 * bindings/v8/V8DOMWrapper.cpp: 36 (WebCore::downcastSVGPathSeg): 37 (WebCore::V8DOMWrapper::convertSVGElementInstanceToV8Object): 38 (WebCore::V8DOMWrapper::convertSVGObjectWithContextToV8Object): 39 (WebCore::V8DOMWrapper::convertToV8Object): 40 (WebCore::V8DOMWrapper::instantiateV8Object): 41 (WebCore::V8DOMWrapper::isDOMEventWrapper): 42 (WebCore::V8DOMWrapper::htmlElementType): 43 (WebCore::V8DOMWrapper::svgElementType): 44 (WebCore::V8DOMWrapper::convertEventToV8Object): 45 (WebCore::): 46 (WebCore::V8DOMWrapper::convertDocumentToV8Object): 47 (WebCore::V8DOMWrapper::convertNodeToV8Object): 48 (WebCore::V8DOMWrapper::convertNewNodeToV8Object): 49 (WebCore::V8DOMWrapper::convertEventListenerToV8Object): 50 (WebCore::V8DOMWrapper::convertDOMImplementationToV8Object): 51 (WebCore::V8DOMWrapper::convertStyleSheetToV8Object): 52 (WebCore::V8DOMWrapper::convertCSSValueToV8Object): 53 (WebCore::V8DOMWrapper::convertCSSRuleToV8Object): 54 (WebCore::V8DOMWrapper::convertWindowToV8Object): 55 (WebCore::V8DOMWrapper::convertNamedNodeMapToV8Object): 56 * bindings/v8/V8DOMWrapper.h: 57 (WebCore::V8DOMWrapper::convertToV8Object): 58 (WebCore::V8DOMWrapper::convertNodeToV8Object): 59 (WebCore::V8DOMWrapper::convertNewNodeToV8Object): 60 (WebCore::V8DOMWrapper::convertEventToV8Object): 61 (WebCore::V8DOMWrapper::convertEventListenerToV8Object): 62 (WebCore::V8DOMWrapper::instantiateV8Object): 63 * bindings/v8/V8NodeFilterCondition.cpp: 64 (WebCore::V8NodeFilterCondition::acceptNode): 65 * bindings/v8/V8Proxy.cpp: 66 (WebCore::V8Proxy::setDOMException): 67 * bindings/v8/custom/V8CanvasRenderingContext2DCustom.cpp: 68 (WebCore::toV8Object): 69 (WebCore::V8CanvasRenderingContext2D::createPatternCallback): 70 * bindings/v8/custom/V8CustomPositionCallback.cpp: 71 (WebCore::V8CustomPositionCallback::handleEvent): 72 * bindings/v8/custom/V8CustomPositionErrorCallback.cpp: 73 (WebCore::V8CustomPositionErrorCallback::handleEvent): 74 * bindings/v8/custom/V8CustomSQLStatementCallback.cpp: 75 (WebCore::V8CustomSQLStatementCallback::handleEvent): 76 * bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp: 77 (WebCore::V8CustomSQLStatementErrorCallback::handleEvent): 78 * bindings/v8/custom/V8CustomSQLTransactionCallback.cpp: 79 (WebCore::V8CustomSQLTransactionCallback::handleEvent): 80 * bindings/v8/custom/V8CustomSQLTransactionErrorCallback.cpp: 81 (WebCore::V8CustomSQLTransactionErrorCallback::handleEvent): 82 * bindings/v8/custom/V8DOMWindowCustom.cpp: 83 (WebCore::V8DOMWindow::openCallback): 84 (WebCore::V8DOMWindow::indexedPropertyGetter): 85 (WebCore::V8DOMWindow::namedPropertyGetter): 86 * bindings/v8/custom/V8DataGridColumnListCustom.cpp: 87 (WebCore::NAMED_PROPERTY_GETTER): 88 * bindings/v8/custom/V8DocumentCustom.cpp: 89 (WebCore::V8Document::evaluateCallback): 90 (WebCore::V8Document::getCSSCanvasContextCallback): 91 (WebCore::V8Document::implementationAccessorGetter): 92 * bindings/v8/custom/V8DocumentLocationCustom.cpp: 93 (WebCore::V8Document::locationAccessorGetter): 94 * bindings/v8/custom/V8ElementCustom.cpp: 95 (WebCore::V8Element::setAttributeNodeCallback): 96 (WebCore::V8Element::setAttributeNodeNSCallback): 97 * bindings/v8/custom/V8EventCustom.cpp: 98 (WebCore::V8Event::dataTransferAccessorGetter): 99 (WebCore::V8Event::clipboardDataAccessorGetter): 100 * bindings/v8/custom/V8HTMLAllCollectionCustom.cpp: 101 (WebCore::getNamedItems): 102 (WebCore::getItem): 103 (WebCore::V8HTMLAllCollection::callAsFunctionCallback): 104 * bindings/v8/custom/V8HTMLAudioElementConstructor.cpp: 105 (WebCore::V8Custom::v8HTMLAudioElementConstructorCallback): 106 * bindings/v8/custom/V8HTMLCanvasElementCustom.cpp: 107 (WebCore::V8HTMLCanvasElement::getContextCallback): 108 * bindings/v8/custom/V8HTMLCollectionCustom.cpp: 109 (WebCore::getNamedItems): 110 (WebCore::getItem): 111 (WebCore::V8HTMLCollection::callAsFunctionCallback): 112 * bindings/v8/custom/V8HTMLDocumentCustom.cpp: 113 (WebCore::V8HTMLDocument::namedPropertyGetter): 114 (WebCore::V8HTMLDocument::allAccessorGetter): 115 * bindings/v8/custom/V8HTMLFormElementCustom.cpp: 116 (WebCore::V8HTMLFormElement::indexedPropertyGetter): 117 (WebCore::V8HTMLFormElement::namedPropertyGetter): 118 * bindings/v8/custom/V8HTMLFrameSetElementCustom.cpp: 119 (WebCore::V8HTMLFrameSetElement::namedPropertyGetter): 120 * bindings/v8/custom/V8HTMLImageElementConstructor.cpp: 121 (WebCore::V8Custom::v8HTMLImageElementConstructorCallback): 122 * bindings/v8/custom/V8HTMLOptionsCollectionCustom.cpp: 123 (WebCore::V8HTMLOptionsCollection::indexedPropertyGetter): 124 * bindings/v8/custom/V8HTMLSelectElementCustom.cpp: 125 (WebCore::V8HTMLSelectElement::namedPropertyGetter): 126 (WebCore::V8HTMLSelectElement::indexedPropertyGetter): 127 * bindings/v8/custom/V8InjectedScriptHostCustom.cpp: 128 (WebCore::createInjectedScript): 129 (WebCore::V8InjectedScriptHost::nodeForIdCallback): 130 (WebCore::V8InjectedScriptHost::databaseForIdCallback): 131 * bindings/v8/custom/V8MessageChannelConstructor.cpp: 132 (WebCore::V8MessageChannel::constructorCallback): 133 * bindings/v8/custom/V8MessageEventCustom.cpp: 134 (WebCore::V8MessageEvent::portsAccessorGetter): 135 * bindings/v8/custom/V8NamedNodeMapCustom.cpp: 136 (WebCore::V8NamedNodeMap::indexedPropertyGetter): 137 (WebCore::V8NamedNodeMap::namedPropertyGetter): 138 * bindings/v8/custom/V8NodeIteratorCustom.cpp: 139 (WebCore::toV8): 140 * bindings/v8/custom/V8NodeListCustom.cpp: 141 (WebCore::V8NodeList::namedPropertyGetter): 142 (WebCore::V8NodeList::callAsFunctionCallback): 143 * bindings/v8/custom/V8NotificationCenterCustom.cpp: 144 (WebCore::V8NotificationCenter::createHTMLNotificationCallback): 145 (WebCore::V8NotificationCenter::createNotificationCallback): 146 * bindings/v8/custom/V8SVGMatrixCustom.cpp: 147 (WebCore::V8SVGMatrix::multiplyCallback): 148 (WebCore::V8SVGMatrix::inverseCallback): 149 (WebCore::V8SVGMatrix::rotateFromVectorCallback): 150 * bindings/v8/custom/V8StyleSheetListCustom.cpp: 151 (WebCore::V8StyleSheetList::namedPropertyGetter): 152 * bindings/v8/custom/V8TreeWalkerCustom.cpp: 153 (WebCore::toV8Object): 154 * bindings/v8/custom/V8WebGLRenderingContextCustom.cpp: 155 (WebCore::toV8Object): 156 * bindings/v8/custom/V8XSLTProcessorCustom.cpp: 157 (WebCore::V8XSLTProcessor::transformToFragmentCallback): 158 (WebCore::V8XSLTProcessor::transformToDocumentCallback): 159 1 160 2010-02-03 Mikhail Naganov <mnaganov@chromium.org> 2 161 -
trunk/WebCore/bindings/v8/ScriptController.cpp
r54259 r54278 51 51 #include "V8Binding.h" 52 52 #include "V8BindingState.h" 53 #include "V8DOMWindow.h"54 53 #include "V8Event.h" 55 #include "V8HTMLEmbedElement.h"56 54 #include "V8IsolatedContext.h" 57 55 #include "V8NPObject.h" … … 172 170 v8::Handle<v8::Object> global = v8Context->Global(); 173 171 v8::Handle<v8::Value> jsEvent = global->Get(v8::String::NewSymbol("event")); 174 if (jsEvent.IsEmpty() || !jsEvent->IsObject()) 175 return false; 176 Event* event = V8Event::toNative(v8::Handle<v8::Object>::Cast(jsEvent)); 172 Event* event = V8DOMWrapper::isDOMEventWrapper(jsEvent) ? V8Event::toNative(v8::Handle<v8::Object>::Cast(jsEvent)) : 0; 177 173 178 174 // Based on code from kjs_bindings.cpp. … … 382 378 v8::Context::Scope scope(v8Context); 383 379 DOMWindow* window = frame->domWindow(); 384 v8::Handle<v8::Value> global = toV8(window);380 v8::Handle<v8::Value> global = V8DOMWrapper::convertToV8Object(V8ClassIndex::DOMWINDOW, window); 385 381 ASSERT(global->IsObject()); 386 382 return npCreateV8ScriptObject(0, v8::Handle<v8::Object>::Cast(global), window); … … 419 415 420 416 DOMWindow* window = m_frame->domWindow(); 421 v8::Handle<v8::Value> v8plugin = toV8(static_cast<HTMLEmbedElement*>(plugin));417 v8::Handle<v8::Value> v8plugin = V8DOMWrapper::convertToV8Object(V8ClassIndex::HTMLEMBEDELEMENT, plugin); 422 418 if (!v8plugin->IsObject()) 423 419 return createNoScriptObject(); -
trunk/WebCore/bindings/v8/ScriptObject.cpp
r54259 r54278 37 37 #include "Document.h" 38 38 #include "Frame.h" 39 #include "InspectorBackend.h" 40 #include "InspectorFrontendHost.h" 39 41 #include "V8Binding.h" 40 #include "V8InjectedScriptHost.h"41 #include "V8InspectorBackend.h"42 #include "V8InspectorFrontendHost.h"43 42 #include "V8Proxy.h" 44 43 … … 146 145 { 147 146 ScriptScope scope(scriptState); 148 scope.global()->Set(v8::String::New(name), toV8(value));147 scope.global()->Set(v8::String::New(name), V8DOMWrapper::convertToV8Object(V8ClassIndex::INSPECTORBACKEND, value)); 149 148 return scope.success(); 150 149 } … … 153 152 { 154 153 ScriptScope scope(scriptState); 155 scope.global()->Set(v8::String::New(name), toV8(value));154 scope.global()->Set(v8::String::New(name), V8DOMWrapper::convertToV8Object(V8ClassIndex::INSPECTORFRONTENDHOST, value)); 156 155 return scope.success(); 157 156 } … … 160 159 { 161 160 ScriptScope scope(scriptState); 162 scope.global()->Set(v8::String::New(name), toV8(value));161 scope.global()->Set(v8::String::New(name), V8DOMWrapper::convertToV8Object(V8ClassIndex::INJECTEDSCRIPTHOST, value)); 163 162 return scope.success(); 164 163 } -
trunk/WebCore/bindings/v8/V8AbstractEventListener.cpp
r54259 r54278 37 37 #include "Frame.h" 38 38 #include "V8Binding.h" 39 #include "V8Event.h"40 39 #include "V8EventListenerList.h" 41 40 #include "V8Proxy.h" … … 86 85 87 86 // Get the V8 wrapper for the event object. 88 v8::Handle<v8::Value> jsEvent = toV8(event);87 v8::Handle<v8::Value> jsEvent = V8DOMWrapper::convertEventToV8Object(event); 89 88 90 89 invokeEventHandler(context, event, jsEvent); -
trunk/WebCore/bindings/v8/V8Collection.h
r54259 r54278 39 39 40 40 namespace WebCore { 41 // FIXME: These functions should be named using to* since they return the item (get* is used for method that take a ref param).42 // See https://bugs.webkit.org/show_bug.cgi?id=24664.41 // FIXME: These functions should be named using to* since they return the item (get* is used for method that take a ref param). 42 // See https://bugs.webkit.org/show_bug.cgi?id=24664. 43 43 44 template<class T> static v8::Handle<v8::Value> getV8Object(T* implementation) 45 { 46 if (!implementation) 47 return v8::Handle<v8::Value>(); 48 return toV8(implementation); 49 } 44 inline v8::Handle<v8::Value> getV8Object(void* implementation, v8::Local<v8::Value> implementationType) 45 { 46 if (!implementation) 47 return v8::Handle<v8::Value>(); 48 V8ClassIndex::V8WrapperType type = V8ClassIndex::FromInt(implementationType->Int32Value()); 49 if (type == V8ClassIndex::NODE) 50 return V8DOMWrapper::convertNodeToV8Object(static_cast<Node*>(implementation)); 51 return V8DOMWrapper::convertToV8Object(type, implementation); 52 } 50 53 51 template<class Collection> static Collection* toNativeCollection(v8::Local<v8::Object> object)52 {53 return reinterpret_cast<Collection*>(object->GetPointerFromInternalField(v8DOMWrapperObjectIndex));54 }54 template<class Collection> static Collection* toNativeCollection(v8::Local<v8::Object> object) 55 { 56 return reinterpret_cast<Collection*>(object->GetPointerFromInternalField(v8DOMWrapperObjectIndex)); 57 } 55 58 56 template<class T> static v8::Handle<v8::Value> getV8Object(PassRefPtr<T> implementation)57 {58 return getV8Object(implementation.get());59 }59 template<class T> static v8::Handle<v8::Value> getV8Object(PassRefPtr<T> implementation, v8::Local<v8::Value> implementationType) 60 { 61 return getV8Object(implementation.get(), implementationType); 62 } 60 63 61 // Returns named property of a collection. 62 template<class Collection, class ItemType> static v8::Handle<v8::Value> getNamedPropertyOfCollection(v8::Local<v8::String> name, v8::Local<v8::Object> object) 63 { 64 // FIXME: assert object is a collection type 65 ASSERT(V8DOMWrapper::maybeDOMWrapper(object)); 66 ASSERT(V8DOMWrapper::domWrapperType(object) != V8ClassIndex::NODE); 67 Collection* collection = toNativeCollection<Collection>(object); 68 AtomicString propertyName = toAtomicWebCoreStringWithNullCheck(name); 69 return getV8Object<ItemType>(collection->namedItem(propertyName)); 70 } 64 // Returns named property of a collection. 65 template<class Collection, class ItemType> static v8::Handle<v8::Value> getNamedPropertyOfCollection(v8::Local<v8::String> name, v8::Local<v8::Object> object, 66 v8::Local<v8::Value> implementationType) 67 { 68 // FIXME: assert object is a collection type 69 ASSERT(V8DOMWrapper::maybeDOMWrapper(object)); 70 ASSERT(V8DOMWrapper::domWrapperType(object) != V8ClassIndex::NODE); 71 Collection* collection = toNativeCollection<Collection>(object); 72 AtomicString propertyName = toAtomicWebCoreStringWithNullCheck(name); 73 return getV8Object<ItemType>(collection->namedItem(propertyName), implementationType); 74 } 71 75 72 // A template of named property accessor of collections.73 template<class Collection, class ItemType> static v8::Handle<v8::Value> collectionNamedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)74 {75 v8::Handle<v8::Value> value = info.Holder()->GetRealNamedPropertyInPrototypeChain(name);76 // A template of named property accessor of collections. 77 template<class Collection, class ItemType> static v8::Handle<v8::Value> collectionNamedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) 78 { 79 v8::Handle<v8::Value> value = info.Holder()->GetRealNamedPropertyInPrototypeChain(name); 76 80 77 if (!value.IsEmpty())78 return value;81 if (!value.IsEmpty()) 82 return value; 79 83 80 // Search local callback properties next to find IDL defined81 // properties.82 if (info.Holder()->HasRealNamedCallbackProperty(name))83 return notHandledByInterceptor();84 return getNamedPropertyOfCollection<Collection, ItemType>(name, info.Holder());85 }84 // Search local callback properties next to find IDL defined 85 // properties. 86 if (info.Holder()->HasRealNamedCallbackProperty(name)) 87 return notHandledByInterceptor(); 88 return getNamedPropertyOfCollection<Collection, ItemType>(name, info.Holder(), info.Data()); 89 } 86 90 87 // Returns the property at the index of a collection. 88 template<class Collection, class ItemType> static v8::Handle<v8::Value> getIndexedPropertyOfCollection(uint32_t index, v8::Local<v8::Object> object) 89 { 90 // FIXME: Assert that object must be a collection type. 91 ASSERT(V8DOMWrapper::maybeDOMWrapper(object)); 92 ASSERT(V8DOMWrapper::domWrapperType(object) != V8ClassIndex::NODE); 93 Collection* collection = toNativeCollection<Collection>(object); 94 return getV8Object<ItemType>(collection->item(index)); 95 } 91 // Returns the property at the index of a collection. 92 template<class Collection, class ItemType> static v8::Handle<v8::Value> getIndexedPropertyOfCollection(uint32_t index, v8::Local<v8::Object> object, 93 v8::Local<v8::Value> implementationType) 94 { 95 // FIXME: Assert that object must be a collection type. 96 ASSERT(V8DOMWrapper::maybeDOMWrapper(object)); 97 ASSERT(V8DOMWrapper::domWrapperType(object) != V8ClassIndex::NODE); 98 Collection* collection = toNativeCollection<Collection>(object); 99 return getV8Object<ItemType>(collection->item(index), implementationType); 100 } 96 101 97 // A template of index interceptor of collections.98 template<class Collection, class ItemType> static v8::Handle<v8::Value> collectionIndexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info)99 {100 return getIndexedPropertyOfCollection<Collection, ItemType>(index, info.Holder());101 }102 // A template of index interceptor of collections. 103 template<class Collection, class ItemType> static v8::Handle<v8::Value> collectionIndexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info) 104 { 105 return getIndexedPropertyOfCollection<Collection, ItemType>(index, info.Holder(), info.Data()); 106 } 102 107 103 // Get an array containing the names of indexed properties of HTMLSelectElement and HTMLFormElement. 104 template<class Collection> static v8::Handle<v8::Array> nodeCollectionIndexedPropertyEnumerator(const v8::AccessorInfo& info) 105 { 106 ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder())); 107 Collection* collection = toNativeCollection<Collection>(info.Holder()); 108 int length = collection->length(); 109 v8::Handle<v8::Array> properties = v8::Array::New(length); 110 for (int i = 0; i < length; ++i) { 111 // FIXME: Do we need to check that the item function returns a non-null value for this index? 112 v8::Handle<v8::Integer> integer = v8::Integer::New(i); 113 properties->Set(integer, integer); 108 // Get an array containing the names of indexed properties of HTMLSelectElement and HTMLFormElement. 109 template<class Collection> static v8::Handle<v8::Array> nodeCollectionIndexedPropertyEnumerator(const v8::AccessorInfo& info) 110 { 111 ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder())); 112 Collection* collection = toNativeCollection<Collection>(info.Holder()); 113 int length = collection->length(); 114 v8::Handle<v8::Array> properties = v8::Array::New(length); 115 for (int i = 0; i < length; ++i) { 116 // FIXME: Do we need to check that the item function returns a non-null value for this index? 117 v8::Handle<v8::Integer> integer = v8::Integer::New(i); 118 properties->Set(integer, integer); 119 } 120 return properties; 114 121 } 115 return properties;116 }117 122 118 // Get an array containing the names of indexed properties in a collection. 119 template<class Collection> static v8::Handle<v8::Array> collectionIndexedPropertyEnumerator(const v8::AccessorInfo& info) 120 { 121 ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder())); 122 Collection* collection = toNativeCollection<Collection>(info.Holder()); 123 int length = collection->length(); 124 v8::Handle<v8::Array> properties = v8::Array::New(length); 125 for (int i = 0; i < length; ++i) { 126 // FIXME: Do we need to check that the item function returns a non-null value for this index? 127 v8::Handle<v8::Integer> integer = v8::Integer::New(i); 128 properties->Set(integer, integer); 123 // Get an array containing the names of indexed properties in a collection. 124 template<class Collection> static v8::Handle<v8::Array> collectionIndexedPropertyEnumerator(const v8::AccessorInfo& info) 125 { 126 ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder())); 127 Collection* collection = toNativeCollection<Collection>(info.Holder()); 128 int length = collection->length(); 129 v8::Handle<v8::Array> properties = v8::Array::New(length); 130 for (int i = 0; i < length; ++i) { 131 // FIXME: Do we need to check that the item function returns a non-null value for this index? 132 v8::Handle<v8::Integer> integer = v8::Integer::New(i); 133 properties->Set(integer, integer); 134 } 135 return properties; 129 136 } 130 return properties;131 }132 137 133 138 134 // A template for indexed getters on collections of strings that should return null if the resulting string is a null string.135 template<class Collection> static v8::Handle<v8::Value> collectionStringOrNullIndexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info)136 {137 // FIXME: assert that object must be a collection type138 ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder()));139 Collection* collection = toNativeCollection<Collection>(info.Holder());140 String result = collection->item(index);141 return v8StringOrNull(result);142 }139 // A template for indexed getters on collections of strings that should return null if the resulting string is a null string. 140 template<class Collection> static v8::Handle<v8::Value> collectionStringOrNullIndexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info) 141 { 142 // FIXME: assert that object must be a collection type 143 ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder())); 144 Collection* collection = toNativeCollection<Collection>(info.Holder()); 145 String result = collection->item(index); 146 return v8StringOrNull(result); 147 } 143 148 144 149 145 // A template for indexed getters on collections of strings.146 template<class Collection> static v8::Handle<v8::Value> collectionStringIndexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info)147 {148 // FIXME: assert that object must be a collection type149 ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder()));150 Collection* collection = toNativeCollection<Collection>(info.Holder());151 String result = collection->item(index);152 return v8String(result);153 }150 // A template for indexed getters on collections of strings. 151 template<class Collection> static v8::Handle<v8::Value> collectionStringIndexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info) 152 { 153 // FIXME: assert that object must be a collection type 154 ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder())); 155 Collection* collection = toNativeCollection<Collection>(info.Holder()); 156 String result = collection->item(index); 157 return v8String(result); 158 } 154 159 155 160 156 // Add indexed getter to the function template for a collection.157 template<class Collection, class ItemType> static void setCollectionIndexedGetter(v8::Handle<v8::FunctionTemplate> desc, V8ClassIndex::V8WrapperType type)158 {159 desc->InstanceTemplate()->SetIndexedPropertyHandler(collectionIndexedPropertyGetter<Collection, ItemType>, 0, 0, 0, collectionIndexedPropertyEnumerator<Collection>,160 v8::Integer::New(V8ClassIndex::ToInt(type)));161 }161 // Add indexed getter to the function template for a collection. 162 template<class Collection, class ItemType> static void setCollectionIndexedGetter(v8::Handle<v8::FunctionTemplate> desc, V8ClassIndex::V8WrapperType type) 163 { 164 desc->InstanceTemplate()->SetIndexedPropertyHandler(collectionIndexedPropertyGetter<Collection, ItemType>, 0, 0, 0, collectionIndexedPropertyEnumerator<Collection>, 165 v8::Integer::New(V8ClassIndex::ToInt(type))); 166 } 162 167 163 168 164 // Add named getter to the function template for a collection.165 template<class Collection, class ItemType> static void setCollectionNamedGetter(v8::Handle<v8::FunctionTemplate> desc, V8ClassIndex::V8WrapperType type)166 {167 desc->InstanceTemplate()->SetNamedPropertyHandler(collectionNamedPropertyGetter<Collection, ItemType>, 0, 0, 0, 0, v8::Integer::New(V8ClassIndex::ToInt(type)));168 }169 // Add named getter to the function template for a collection. 170 template<class Collection, class ItemType> static void setCollectionNamedGetter(v8::Handle<v8::FunctionTemplate> desc, V8ClassIndex::V8WrapperType type) 171 { 172 desc->InstanceTemplate()->SetNamedPropertyHandler(collectionNamedPropertyGetter<Collection, ItemType>, 0, 0, 0, 0, v8::Integer::New(V8ClassIndex::ToInt(type))); 173 } 169 174 170 // Add indexed getter returning a string or null to a function template for a collection.171 template<class Collection> static void setCollectionStringOrNullIndexedGetter(v8::Handle<v8::FunctionTemplate> desc)172 {173 desc->InstanceTemplate()->SetIndexedPropertyHandler(collectionStringOrNullIndexedPropertyGetter<Collection>, 0, 0, 0, collectionIndexedPropertyEnumerator<Collection>);174 }175 // Add indexed getter returning a string or null to a function template for a collection. 176 template<class Collection> static void setCollectionStringOrNullIndexedGetter(v8::Handle<v8::FunctionTemplate> desc) 177 { 178 desc->InstanceTemplate()->SetIndexedPropertyHandler(collectionStringOrNullIndexedPropertyGetter<Collection>, 0, 0, 0, collectionIndexedPropertyEnumerator<Collection>); 179 } 175 180 176 181 177 // Add indexed getter returning a string to a function template for a collection.178 template<class Collection> static void setCollectionStringIndexedGetter(v8::Handle<v8::FunctionTemplate> desc)179 {180 desc->InstanceTemplate()->SetIndexedPropertyHandler(collectionStringIndexedPropertyGetter<Collection>, 0, 0, 0, collectionIndexedPropertyEnumerator<Collection>);181 }182 // Add indexed getter returning a string to a function template for a collection. 183 template<class Collection> static void setCollectionStringIndexedGetter(v8::Handle<v8::FunctionTemplate> desc) 184 { 185 desc->InstanceTemplate()->SetIndexedPropertyHandler(collectionStringIndexedPropertyGetter<Collection>, 0, 0, 0, collectionIndexedPropertyEnumerator<Collection>); 186 } 182 187 183 v8::Handle<v8::Value> toOptionsCollectionSetter(uint32_t index, v8::Handle<v8::Value>, HTMLSelectElement*);188 v8::Handle<v8::Value> toOptionsCollectionSetter(uint32_t index, v8::Handle<v8::Value>, HTMLSelectElement*); 184 189 185 190 } // namespace WebCore -
trunk/WebCore/bindings/v8/V8DOMWindowShell.cpp
r54259 r54278 49 49 #include "V8Collection.h" 50 50 #include "V8ConsoleMessage.h" 51 #include "V8CustomBinding.h" 51 52 #include "V8DOMMap.h" 52 53 #include "V8DOMWindow.h" 53 #include "V8Document.h"54 54 #include "V8HiddenPropertyName.h" 55 55 #include "V8History.h" … … 423 423 } 424 424 425 v8::Handle<v8::Value> documentWrapper = toV8(m_frame->document());425 v8::Handle<v8::Value> documentWrapper = V8DOMWrapper::convertNodeToV8Object(m_frame->document()); 426 426 427 427 // If instantiation of the document wrapper fails, clear the cache -
trunk/WebCore/bindings/v8/V8DOMWrapper.cpp
r54259 r54278 44 44 #include "V8Binding.h" 45 45 #include "V8Collection.h" 46 #include "V8CustomBinding.h" 46 47 #include "V8CustomEventListener.h" 47 48 #include "V8DOMApplicationCache.h" … … 84 85 typedef HashMap<void*, v8::Object*> DOMObjectMap; 85 86 87 #if ENABLE(SVG) 88 89 static V8ClassIndex::V8WrapperType downcastSVGPathSeg(void* pathSeg) 90 { 91 SVGPathSeg* realPathSeg = reinterpret_cast<SVGPathSeg*>(pathSeg); 92 93 switch (realPathSeg->pathSegType()) { 94 case SVGPathSeg::PATHSEG_CLOSEPATH: return V8ClassIndex::SVGPATHSEGCLOSEPATH; 95 case SVGPathSeg::PATHSEG_MOVETO_ABS: return V8ClassIndex::SVGPATHSEGMOVETOABS; 96 case SVGPathSeg::PATHSEG_MOVETO_REL: return V8ClassIndex::SVGPATHSEGMOVETOREL; 97 case SVGPathSeg::PATHSEG_LINETO_ABS: return V8ClassIndex::SVGPATHSEGLINETOABS; 98 case SVGPathSeg::PATHSEG_LINETO_REL: return V8ClassIndex::SVGPATHSEGLINETOREL; 99 case SVGPathSeg::PATHSEG_CURVETO_CUBIC_ABS: return V8ClassIndex::SVGPATHSEGCURVETOCUBICABS; 100 case SVGPathSeg::PATHSEG_CURVETO_CUBIC_REL: return V8ClassIndex::SVGPATHSEGCURVETOCUBICREL; 101 case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_ABS: return V8ClassIndex::SVGPATHSEGCURVETOQUADRATICABS; 102 case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_REL: return V8ClassIndex::SVGPATHSEGCURVETOQUADRATICREL; 103 case SVGPathSeg::PATHSEG_ARC_ABS: return V8ClassIndex::SVGPATHSEGARCABS; 104 case SVGPathSeg::PATHSEG_ARC_REL: return V8ClassIndex::SVGPATHSEGARCREL; 105 case SVGPathSeg::PATHSEG_LINETO_HORIZONTAL_ABS: return V8ClassIndex::SVGPATHSEGLINETOHORIZONTALABS; 106 case SVGPathSeg::PATHSEG_LINETO_HORIZONTAL_REL: return V8ClassIndex::SVGPATHSEGLINETOHORIZONTALREL; 107 case SVGPathSeg::PATHSEG_LINETO_VERTICAL_ABS: return V8ClassIndex::SVGPATHSEGLINETOVERTICALABS; 108 case SVGPathSeg::PATHSEG_LINETO_VERTICAL_REL: return V8ClassIndex::SVGPATHSEGLINETOVERTICALREL; 109 case SVGPathSeg::PATHSEG_CURVETO_CUBIC_SMOOTH_ABS: return V8ClassIndex::SVGPATHSEGCURVETOCUBICSMOOTHABS; 110 case SVGPathSeg::PATHSEG_CURVETO_CUBIC_SMOOTH_REL: return V8ClassIndex::SVGPATHSEGCURVETOCUBICSMOOTHREL; 111 case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS: return V8ClassIndex::SVGPATHSEGCURVETOQUADRATICSMOOTHABS; 112 case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL: return V8ClassIndex::SVGPATHSEGCURVETOQUADRATICSMOOTHREL; 113 default: return V8ClassIndex::INVALID_CLASS_INDEX; 114 } 115 } 116 117 v8::Handle<v8::Value> V8DOMWrapper::convertSVGElementInstanceToV8Object(SVGElementInstance* instance) 118 { 119 if (!instance) 120 return v8::Null(); 121 122 v8::Handle<v8::Object> existingInstance = getDOMSVGElementInstanceMap().get(instance); 123 if (!existingInstance.IsEmpty()) 124 return existingInstance; 125 126 instance->ref(); 127 128 // Instantiate the V8 object and remember it 129 v8::Handle<v8::Object> result = instantiateV8Object(V8ClassIndex::SVGELEMENTINSTANCE, V8ClassIndex::SVGELEMENTINSTANCE, instance); 130 if (!result.IsEmpty()) { 131 // Only update the DOM SVG element map if the result is non-empty. 132 getDOMSVGElementInstanceMap().set(instance, v8::Persistent<v8::Object>::New(result)); 133 } 134 return result; 135 } 136 137 v8::Handle<v8::Value> V8DOMWrapper::convertSVGObjectWithContextToV8Object(V8ClassIndex::V8WrapperType type, void* object) 138 { 139 if (!object) 140 return v8::Null(); 141 142 v8::Persistent<v8::Object> result = getDOMSVGObjectWithContextMap().get(object); 143 if (!result.IsEmpty()) 144 return result; 145 146 // Special case: SVGPathSegs need to be downcast to their real type 147 if (type == V8ClassIndex::SVGPATHSEG) 148 type = downcastSVGPathSeg(object); 149 150 v8::Local<v8::Object> v8Object = instantiateV8Object(type, type, object); 151 if (!v8Object.IsEmpty()) { 152 result = v8::Persistent<v8::Object>::New(v8Object); 153 switch (type) { 154 #define MAKE_CASE(TYPE, NAME) \ 155 case V8ClassIndex::TYPE: static_cast<NAME*>(object)->ref(); break; 156 SVG_OBJECT_TYPES(MAKE_CASE) 157 #undef MAKE_CASE 158 #define MAKE_CASE(TYPE, NAME) \ 159 case V8ClassIndex::TYPE: \ 160 static_cast<V8SVGPODTypeWrapper<NAME>*>(object)->ref(); break; 161 SVG_POD_NATIVE_TYPES(MAKE_CASE) 162 #undef MAKE_CASE 163 default: 164 ASSERT_NOT_REACHED(); 165 } 166 getDOMSVGObjectWithContextMap().set(object, result); 167 } 168 169 return result; 170 } 171 172 #endif // ENABLE(SVG) 173 86 174 #if ENABLE(3D_CANVAS) 87 175 void V8DOMWrapper::setIndexedPropertiesToExternalArray(v8::Handle<v8::Object> wrapper, … … 237 325 } 238 326 327 v8::Handle<v8::Value> V8DOMWrapper::convertToV8Object(V8ClassIndex::V8WrapperType type, void* impl) 328 { 329 ASSERT(type != V8ClassIndex::EVENTLISTENER); 330 ASSERT(type != V8ClassIndex::EVENTTARGET); 331 ASSERT(type != V8ClassIndex::EVENT); 332 333 // These objects can be constructed under WorkerContextExecutionProxy. They need special 334 // handling, since if we proceed below V8Proxy::retrieve() will get called and will crash. 335 // TODO(ukai): websocket? 336 if ((type == V8ClassIndex::DOMCOREEXCEPTION 337 || type == V8ClassIndex::RANGEEXCEPTION 338 || type == V8ClassIndex::EVENTEXCEPTION 339 || type == V8ClassIndex::XMLHTTPREQUESTEXCEPTION 340 || type == V8ClassIndex::MESSAGEPORT) 341 && WorkerContextExecutionProxy::retrieve()) { 342 return WorkerContextExecutionProxy::convertToV8Object(type, impl); 343 } 344 345 bool isActiveDomObject = false; 346 switch (type) { 347 #define MAKE_CASE(TYPE, NAME) case V8ClassIndex::TYPE: 348 DOM_NODE_TYPES(MAKE_CASE) 349 #if ENABLE(SVG) 350 SVG_NODE_TYPES(MAKE_CASE) 351 #endif 352 return convertNodeToV8Object(static_cast<Node*>(impl)); 353 case V8ClassIndex::CSSVALUE: 354 return convertCSSValueToV8Object(static_cast<CSSValue*>(impl)); 355 case V8ClassIndex::CSSRULE: 356 return convertCSSRuleToV8Object(static_cast<CSSRule*>(impl)); 357 case V8ClassIndex::STYLESHEET: 358 return convertStyleSheetToV8Object(static_cast<StyleSheet*>(impl)); 359 case V8ClassIndex::DOMWINDOW: 360 return convertWindowToV8Object(static_cast<DOMWindow*>(impl)); 361 case V8ClassIndex::NAMEDNODEMAP: 362 return convertNamedNodeMapToV8Object(static_cast<NamedNodeMap*>(impl)); 363 #if ENABLE(SVG) 364 SVG_NONNODE_TYPES(MAKE_CASE) 365 if (type == V8ClassIndex::SVGELEMENTINSTANCE) 366 return convertSVGElementInstanceToV8Object(static_cast<SVGElementInstance*>(impl)); 367 return convertSVGObjectWithContextToV8Object(type, impl); 368 #endif 369 370 ACTIVE_DOM_OBJECT_TYPES(MAKE_CASE) 371 isActiveDomObject = true; 372 break; 373 default: 374 break; 375 } 376 377 #undef MAKE_CASE 378 379 if (!impl) 380 return v8::Null(); 381 382 // Non DOM node 383 v8::Persistent<v8::Object> result = isActiveDomObject ? getActiveDOMObjectMap().get(impl) : getDOMObjectMap().get(impl); 384 if (result.IsEmpty()) { 385 #if ENABLE(3D_CANVAS) 386 if (type == V8ClassIndex::WEBGLARRAY && impl) { 387 // Determine which subclass we are wrapping. 388 WebGLArray* array = reinterpret_cast<WebGLArray*>(impl); 389 if (array->isByteArray()) 390 type = V8ClassIndex::WEBGLBYTEARRAY; 391 else if (array->isFloatArray()) 392 type = V8ClassIndex::WEBGLFLOATARRAY; 393 else if (array->isIntArray()) 394 type = V8ClassIndex::WEBGLINTARRAY; 395 else if (array->isShortArray()) 396 type = V8ClassIndex::WEBGLSHORTARRAY; 397 else if (array->isUnsignedByteArray()) 398 type = V8ClassIndex::WEBGLUNSIGNEDBYTEARRAY; 399 else if (array->isUnsignedIntArray()) 400 type = V8ClassIndex::WEBGLUNSIGNEDINTARRAY; 401 else if (array->isUnsignedShortArray()) 402 type = V8ClassIndex::WEBGLUNSIGNEDSHORTARRAY; 403 } 404 #endif 405 406 v8::Local<v8::Object> v8Object = instantiateV8Object(type, type, impl); 407 if (!v8Object.IsEmpty()) { 408 // Go through big switch statement, it has some duplications 409 // that were handled by code above (such as CSSVALUE, CSSRULE, etc). 410 switch (type) { 411 #define MAKE_CASE(TYPE, NAME) \ 412 case V8ClassIndex::TYPE: static_cast<NAME*>(impl)->ref(); break; 413 DOM_OBJECT_TYPES(MAKE_CASE) 414 #undef MAKE_CASE 415 default: 416 ASSERT_NOT_REACHED(); 417 } 418 result = v8::Persistent<v8::Object>::New(v8Object); 419 if (isActiveDomObject) 420 setJSWrapperForActiveDOMObject(impl, result); 421 else 422 setJSWrapperForDOMObject(impl, result); 423 424 if (type == V8ClassIndex::CANVASPIXELARRAY) { 425 CanvasPixelArray* pixels = reinterpret_cast<CanvasPixelArray*>(impl); 426 result->SetIndexedPropertiesToPixelData(pixels->data()->data(), pixels->length()); 427 } 428 429 #if ENABLE(3D_CANVAS) 430 // Set up WebGLArray subclasses' accesses similarly. 431 switch (type) { 432 case V8ClassIndex::WEBGLBYTEARRAY: 433 case V8ClassIndex::WEBGLUNSIGNEDBYTEARRAY: 434 case V8ClassIndex::WEBGLSHORTARRAY: 435 case V8ClassIndex::WEBGLUNSIGNEDSHORTARRAY: 436 case V8ClassIndex::WEBGLINTARRAY: 437 case V8ClassIndex::WEBGLUNSIGNEDINTARRAY: 438 case V8ClassIndex::WEBGLFLOATARRAY: { 439 WebGLArray* array = reinterpret_cast<WebGLArray*>(impl); 440 setIndexedPropertiesToExternalArray(result, 441 V8ClassIndex::ToInt(type), 442 array->baseAddress(), 443 array->length()); 444 break; 445 } 446 default: 447 break; 448 } 449 #endif 450 451 // Special case for non-node objects associated with a 452 // DOMWindow. Both Safari and FF let the JS wrappers for these 453 // objects survive GC. To mimic their behavior, V8 creates 454 // hidden references from the DOMWindow to these wrapper 455 // objects. These references get cleared when the DOMWindow is 456 // reused by a new page. 457 switch (type) { 458 case V8ClassIndex::CONSOLE: 459 setHiddenWindowReference(static_cast<Console*>(impl)->frame(), V8DOMWindow::consoleIndex, result); 460 break; 461 case V8ClassIndex::HISTORY: 462 setHiddenWindowReference(static_cast<History*>(impl)->frame(), V8DOMWindow::historyIndex, result); 463 break; 464 case V8ClassIndex::NAVIGATOR: 465 setHiddenWindowReference(static_cast<Navigator*>(impl)->frame(), V8DOMWindow::navigatorIndex, result); 466 break; 467 case V8ClassIndex::SCREEN: 468 setHiddenWindowReference(static_cast<Screen*>(impl)->frame(), V8DOMWindow::screenIndex, result); 469 break; 470 case V8ClassIndex::LOCATION: 471 setHiddenWindowReference(static_cast<Location*>(impl)->frame(), V8DOMWindow::locationIndex, result); 472 break; 473 case V8ClassIndex::DOMSELECTION: 474 setHiddenWindowReference(static_cast<DOMSelection*>(impl)->frame(), V8DOMWindow::domSelectionIndex, result); 475 break; 476 case V8ClassIndex::BARINFO: { 477 BarInfo* barInfo = static_cast<BarInfo*>(impl); 478 Frame* frame = barInfo->frame(); 479 switch (barInfo->type()) { 480 case BarInfo::Locationbar: 481 setHiddenWindowReference(frame, V8DOMWindow::locationbarIndex, result); 482 break; 483 case BarInfo::Menubar: 484 setHiddenWindowReference(frame, V8DOMWindow::menubarIndex, result); 485 break; 486 case BarInfo::Personalbar: 487 setHiddenWindowReference(frame, V8DOMWindow::personalbarIndex, result); 488 break; 489 case BarInfo::Scrollbars: 490 setHiddenWindowReference(frame, V8DOMWindow::scrollbarsIndex, result); 491 break; 492 case BarInfo::Statusbar: 493 setHiddenWindowReference(frame, V8DOMWindow::statusbarIndex, result); 494 break; 495 case BarInfo::Toolbar: 496 setHiddenWindowReference(frame, V8DOMWindow::toolbarIndex, result); 497 break; 498 } 499 break; 500 } 501 default: 502 break; 503 } 504 } 505 } 506 return result; 507 } 508 239 509 void V8DOMWrapper::setHiddenWindowReference(Frame* frame, const int internalIndex, v8::Handle<v8::Object> jsObject) 240 510 { … … 280 550 } 281 551 282 v8::Local<v8::Object> V8DOMWrapper::instantiateV8Object(V8Proxy* proxy, V8ClassIndex::V8WrapperType type, void* impl) 283 { 552 v8::Local<v8::Object> V8DOMWrapper::instantiateV8Object(V8Proxy* proxy, V8ClassIndex::V8WrapperType descriptorType, V8ClassIndex::V8WrapperType cptrType, void* impl) 553 { 554 // Make a special case for document.all 555 if (descriptorType == V8ClassIndex::HTMLCOLLECTION && static_cast<HTMLCollection*>(impl)->type() == DocAll) 556 descriptorType = V8ClassIndex::HTMLALLCOLLECTION; 557 284 558 if (V8IsolatedContext::getEntered()) { 285 559 // This effectively disables the wrapper cache for isolated worlds. … … 294 568 if (proxy) 295 569 // FIXME: Fix this to work properly with isolated worlds (see above). 296 instance = proxy->windowShell()->createWrapperFromCache( type);570 instance = proxy->windowShell()->createWrapperFromCache(descriptorType); 297 571 else { 298 v8::Local<v8::Function> function = getTemplate( type)->GetFunction();572 v8::Local<v8::Function> function = getTemplate(descriptorType)->GetFunction(); 299 573 instance = SafeAllocation::newInstance(function); 300 574 } 301 575 if (!instance.IsEmpty()) { 302 576 // Avoid setting the DOM wrapper for failed allocations. 303 setDOMWrapper(instance, V8ClassIndex::ToInt( type), impl);577 setDOMWrapper(instance, V8ClassIndex::ToInt(cptrType), impl); 304 578 } 305 579 return instance; … … 329 603 #endif 330 604 605 bool V8DOMWrapper::isDOMEventWrapper(v8::Handle<v8::Value> value) 606 { 607 // All kinds of events use EVENT as dom type in JS wrappers. 608 // See EventToV8Object 609 return isWrapperOfType(value, V8ClassIndex::EVENT); 610 } 611 331 612 bool V8DOMWrapper::isWrapperOfType(v8::Handle<v8::Value> value, V8ClassIndex::V8WrapperType classType) 332 613 { … … 348 629 349 630 return V8ClassIndex::FromInt(type->Int32Value()) == classType; 631 } 632 633 #if ENABLE(VIDEO) 634 #define FOR_EACH_VIDEO_TAG(macro) \ 635 macro(audio, AUDIO) \ 636 macro(source, SOURCE) \ 637 macro(video, VIDEO) 638 #else 639 #define FOR_EACH_VIDEO_TAG(macro) 640 #endif 641 642 #if ENABLE(DATAGRID) 643 #define FOR_EACH_DATAGRID_TAG(macro) \ 644 macro(datagrid, DATAGRID) \ 645 macro(dcell, DATAGRIDCELL) \ 646 macro(dcol, DATAGRIDCOL) \ 647 macro(drow, DATAGRIDROW) 648 #else 649 #define FOR_EACH_DATAGRID_TAG(macro) 650 #endif 651 652 #define FOR_EACH_TAG(macro) \ 653 FOR_EACH_DATAGRID_TAG(macro) \ 654 macro(a, ANCHOR) \ 655 macro(applet, APPLET) \ 656 macro(area, AREA) \ 657 macro(base, BASE) \ 658 macro(basefont, BASEFONT) \ 659 macro(blockquote, BLOCKQUOTE) \ 660 macro(body, BODY) \ 661 macro(br, BR) \ 662 macro(button, BUTTON) \ 663 macro(caption, TABLECAPTION) \ 664 macro(col, TABLECOL) \ 665 macro(colgroup, TABLECOL) \ 666 macro(del, MOD) \ 667 macro(canvas, CANVAS) \ 668 macro(dir, DIRECTORY) \ 669 macro(div, DIV) \ 670 macro(dl, DLIST) \ 671 macro(embed, EMBED) \ 672 macro(fieldset, FIELDSET) \ 673 macro(font, FONT) \ 674 macro(form, FORM) \ 675 macro(frame, FRAME) \ 676 macro(frameset, FRAMESET) \ 677 macro(h1, HEADING) \ 678 macro(h2, HEADING) \ 679 macro(h3, HEADING) \ 680 macro(h4, HEADING) \ 681 macro(h5, HEADING) \ 682 macro(h6, HEADING) \ 683 macro(head, HEAD) \ 684 macro(hr, HR) \ 685 macro(html, HTML) \ 686 macro(img, IMAGE) \ 687 macro(iframe, IFRAME) \ 688 macro(image, IMAGE) \ 689 macro(input, INPUT) \ 690 macro(ins, MOD) \ 691 macro(isindex, ISINDEX) \ 692 macro(keygen, SELECT) \ 693 macro(label, LABEL) \ 694 macro(legend, LEGEND) \ 695 macro(li, LI) \ 696 macro(link, LINK) \ 697 macro(listing, PRE) \ 698 macro(map, MAP) \ 699 macro(marquee, MARQUEE) \ 700 macro(menu, MENU) \ 701 macro(meta, META) \ 702 macro(object, OBJECT) \ 703 macro(ol, OLIST) \ 704 macro(optgroup, OPTGROUP) \ 705 macro(option, OPTION) \ 706 macro(p, PARAGRAPH) \ 707 macro(param, PARAM) \ 708 macro(pre, PRE) \ 709 macro(q, QUOTE) \ 710 macro(script, SCRIPT) \ 711 macro(select, SELECT) \ 712 macro(style, STYLE) \ 713 macro(table, TABLE) \ 714 macro(thead, TABLESECTION) \ 715 macro(tbody, TABLESECTION) \ 716 macro(tfoot, TABLESECTION) \ 717 macro(td, TABLECELL) \ 718 macro(th, TABLECELL) \ 719 macro(tr, TABLEROW) \ 720 macro(textarea, TEXTAREA) \ 721 macro(title, TITLE) \ 722 macro(ul, ULIST) \ 723 macro(xmp, PRE) 724 725 V8ClassIndex::V8WrapperType V8DOMWrapper::htmlElementType(HTMLElement* element) 726 { 727 typedef HashMap<String, V8ClassIndex::V8WrapperType> WrapperTypeMap; 728 DEFINE_STATIC_LOCAL(WrapperTypeMap, wrapperTypeMap, ()); 729 if (wrapperTypeMap.isEmpty()) { 730 #define ADD_TO_HASH_MAP(tag, name) \ 731 wrapperTypeMap.set(#tag, V8ClassIndex::HTML##name##ELEMENT); 732 FOR_EACH_TAG(ADD_TO_HASH_MAP) 733 #if ENABLE(VIDEO) 734 if (MediaPlayer::isAvailable()) { 735 FOR_EACH_VIDEO_TAG(ADD_TO_HASH_MAP) 736 } 737 #endif 738 #undef ADD_TO_HASH_MAP 739 } 740 741 V8ClassIndex::V8WrapperType type = wrapperTypeMap.get(element->localName().impl()); 742 if (!type) 743 return V8ClassIndex::HTMLELEMENT; 744 return type; 745 } 746 #undef FOR_EACH_TAG 747 748 #if ENABLE(SVG) 749 750 #if ENABLE(SVG_ANIMATION) 751 #define FOR_EACH_ANIMATION_TAG(macro) \ 752 macro(animateColor, ANIMATECOLOR) \ 753 macro(animate, ANIMATE) \ 754 macro(animateTransform, ANIMATETRANSFORM) \ 755 macro(set, SET) 756 #else 757 #define FOR_EACH_ANIMATION_TAG(macro) 758 #endif 759 760 #if ENABLE(SVG) && ENABLE(FILTERS) 761 #define FOR_EACH_FILTERS_TAG(macro) \ 762 macro(feBlend, FEBLEND) \ 763 macro(feColorMatrix, FECOLORMATRIX) \ 764 macro(feComponentTransfer, FECOMPONENTTRANSFER) \ 765 macro(feComposite, FECOMPOSITE) \ 766 macro(feDiffuseLighting, FEDIFFUSELIGHTING) \ 767 macro(feDisplacementMap, FEDISPLACEMENTMAP) \ 768 macro(feDistantLight, FEDISTANTLIGHT) \ 769 macro(feFlood, FEFLOOD) \ 770 macro(feFuncA, FEFUNCA) \ 771 macro(feFuncB, FEFUNCB) \ 772 macro(feFuncG, FEFUNCG) \ 773 macro(feFuncR, FEFUNCR) \ 774 macro(feGaussianBlur, FEGAUSSIANBLUR) \ 775 macro(feImage, FEIMAGE) \ 776 macro(feMerge, FEMERGE) \ 777 macro(feMergeNode, FEMERGENODE) \ 778 macro(feMorphology, FEMORPHOLOGY) \ 779 macro(feOffset, FEOFFSET) \ 780 macro(fePointLight, FEPOINTLIGHT) \ 781 macro(feSpecularLighting, FESPECULARLIGHTING) \ 782 macro(feSpotLight, FESPOTLIGHT) \ 783 macro(feTile, FETILE) \ 784 macro(feTurbulence, FETURBULENCE) \ 785 macro(filter, FILTER) 786 #else 787 #define FOR_EACH_FILTERS_TAG(macro) 788 #endif 789 790 #if ENABLE(SVG_FONTS) 791 #define FOR_EACH_FONTS_TAG(macro) \ 792 macro(font-face, FONTFACE) \ 793 macro(font-face-format, FONTFACEFORMAT) \ 794 macro(font-face-name, FONTFACENAME) \ 795 macro(font-face-src, FONTFACESRC) \ 796 macro(font-face-uri, FONTFACEURI) 797 #else 798 #define FOR_EACH_FONTS_TAG(marco) 799 #endif 800 801 #if ENABLE(SVG_FOREIGN_OBJECT) 802 #define FOR_EACH_FOREIGN_OBJECT_TAG(macro) \ 803 macro(foreignObject, FOREIGNOBJECT) 804 #else 805 #define FOR_EACH_FOREIGN_OBJECT_TAG(macro) 806 #endif 807 808 #if ENABLE(SVG_USE) 809 #define FOR_EACH_USE_TAG(macro) \ 810 macro(use, USE) 811 #else 812 #define FOR_EACH_USE_TAG(macro) 813 #endif 814 815 #define FOR_EACH_TAG(macro) \ 816 FOR_EACH_ANIMATION_TAG(macro) \ 817 FOR_EACH_FILTERS_TAG(macro) \ 818 FOR_EACH_FONTS_TAG(macro) \ 819 FOR_EACH_FOREIGN_OBJECT_TAG(macro) \ 820 FOR_EACH_USE_TAG(macro) \ 821 macro(a, A) \ 822 macro(altGlyph, ALTGLYPH) \ 823 macro(circle, CIRCLE) \ 824 macro(clipPath, CLIPPATH) \ 825 macro(cursor, CURSOR) \ 826 macro(defs, DEFS) \ 827 macro(desc, DESC) \ 828 macro(ellipse, ELLIPSE) \ 829 macro(g, G) \ 830 macro(glyph, GLYPH) \ 831 macro(image, IMAGE) \ 832 macro(linearGradient, LINEARGRADIENT) \ 833 macro(line, LINE) \ 834 macro(marker, MARKER) \ 835 macro(mask, MASK) \ 836 macro(metadata, METADATA) \ 837 macro(path, PATH) \ 838 macro(pattern, PATTERN) \ 839 macro(polyline, POLYLINE) \ 840 macro(polygon, POLYGON) \ 841 macro(radialGradient, RADIALGRADIENT) \ 842 macro(rect, RECT) \ 843 macro(script, SCRIPT) \ 844 macro(stop, STOP) \ 845 macro(style, STYLE) \ 846 macro(svg, SVG) \ 847 macro(switch, SWITCH) \ 848 macro(symbol, SYMBOL) \ 849 macro(text, TEXT) \ 850 macro(textPath, TEXTPATH) \ 851 macro(title, TITLE) \ 852 macro(tref, TREF) \ 853 macro(tspan, TSPAN) \ 854 macro(view, VIEW) \ 855 // end of macro 856 857 V8ClassIndex::V8WrapperType V8DOMWrapper::svgElementType(SVGElement* element) 858 { 859 typedef HashMap<String, V8ClassIndex::V8WrapperType> WrapperTypeMap; 860 DEFINE_STATIC_LOCAL(WrapperTypeMap, wrapperTypeMap, ()); 861 if (wrapperTypeMap.isEmpty()) { 862 #define ADD_TO_HASH_MAP(tag, name) \ 863 wrapperTypeMap.set(#tag, V8ClassIndex::SVG##name##ELEMENT); 864 FOR_EACH_TAG(ADD_TO_HASH_MAP) 865 #undef ADD_TO_HASH_MAP 866 } 867 868 V8ClassIndex::V8WrapperType type = wrapperTypeMap.get(element->localName().impl()); 869 if (!type) 870 return V8ClassIndex::SVGELEMENT; 871 return type; 872 } 873 #undef FOR_EACH_TAG 874 875 #endif // ENABLE(SVG) 876 877 v8::Handle<v8::Value> V8DOMWrapper::convertEventToV8Object(Event* event) 878 { 879 if (!event) 880 return v8::Null(); 881 882 v8::Handle<v8::Object> wrapper = getDOMObjectMap().get(event); 883 if (!wrapper.IsEmpty()) 884 return wrapper; 885 886 V8ClassIndex::V8WrapperType type = V8ClassIndex::EVENT; 887 888 if (event->isUIEvent()) { 889 if (event->isKeyboardEvent()) 890 type = V8ClassIndex::KEYBOARDEVENT; 891 else if (event->isTextEvent()) 892 type = V8ClassIndex::TEXTEVENT; 893 else if (event->isMouseEvent()) 894 type = V8ClassIndex::MOUSEEVENT; 895 else if (event->isWheelEvent()) 896 type = V8ClassIndex::WHEELEVENT; 897 #if ENABLE(SVG) 898 else if (event->isSVGZoomEvent()) 899 type = V8ClassIndex::SVGZOOMEVENT; 900 #endif 901 else if (event->isCompositionEvent()) 902 type = V8ClassIndex::COMPOSITIONEVENT; 903 else 904 type = V8ClassIndex::UIEVENT; 905 } else if (event->isMutationEvent()) 906 type = V8ClassIndex::MUTATIONEVENT; 907 else if (event->isOverflowEvent()) 908 type = V8ClassIndex::OVERFLOWEVENT; 909 else if (event->isMessageEvent()) 910 type = V8ClassIndex::MESSAGEEVENT; 911 else if (event->isPageTransitionEvent()) 912 type = V8ClassIndex::PAGETRANSITIONEVENT; 913 else if (event->isPopStateEvent()) 914 type = V8ClassIndex::POPSTATEEVENT; 915 else if (event->isProgressEvent()) { 916 if (event->isXMLHttpRequestProgressEvent()) 917 type = V8ClassIndex::XMLHTTPREQUESTPROGRESSEVENT; 918 else 919 type = V8ClassIndex::PROGRESSEVENT; 920 } else if (event->isWebKitAnimationEvent()) 921 type = V8ClassIndex::WEBKITANIMATIONEVENT; 922 else if (event->isWebKitTransitionEvent()) 923 type = V8ClassIndex::WEBKITTRANSITIONEVENT; 924 #if ENABLE(WORKERS) 925 else if (event->isErrorEvent()) 926 type = V8ClassIndex::ERROREVENT; 927 #endif 928 #if ENABLE(DOM_STORAGE) 929 else if (event->isStorageEvent()) 930 type = V8ClassIndex::STORAGEEVENT; 931 #endif 932 else if (event->isBeforeLoadEvent()) 933 type = V8ClassIndex::BEFORELOADEVENT; 934 935 936 v8::Handle<v8::Object> result = instantiateV8Object(type, V8ClassIndex::EVENT, event); 937 if (result.IsEmpty()) { 938 // Instantiation failed. Avoid updating the DOM object map and 939 // return null which is already handled by callers of this function 940 // in case the event is NULL. 941 return v8::Null(); 942 } 943 944 event->ref(); // fast ref 945 setJSWrapperForDOMObject(event, v8::Persistent<v8::Object>::New(result)); 946 947 return result; 948 } 949 950 static const V8ClassIndex::V8WrapperType mapping[] = { 951 V8ClassIndex::INVALID_CLASS_INDEX, // NONE 952 V8ClassIndex::INVALID_CLASS_INDEX, // ELEMENT_NODE needs special treatment 953 V8ClassIndex::ATTR, // ATTRIBUTE_NODE 954 V8ClassIndex::TEXT, // TEXT_NODE 955 V8ClassIndex::CDATASECTION, // CDATA_SECTION_NODE 956 V8ClassIndex::ENTITYREFERENCE, // ENTITY_REFERENCE_NODE 957 V8ClassIndex::ENTITY, // ENTITY_NODE 958 V8ClassIndex::PROCESSINGINSTRUCTION, // PROCESSING_INSTRUCTION_NODE 959 V8ClassIndex::COMMENT, // COMMENT_NODE 960 V8ClassIndex::INVALID_CLASS_INDEX, // DOCUMENT_NODE needs special treatment 961 V8ClassIndex::DOCUMENTTYPE, // DOCUMENT_TYPE_NODE 962 V8ClassIndex::DOCUMENTFRAGMENT, // DOCUMENT_FRAGMENT_NODE 963 V8ClassIndex::NOTATION, // NOTATION_NODE 964 V8ClassIndex::NODE, // XPATH_NAMESPACE_NODE 965 }; 966 967 v8::Handle<v8::Value> V8DOMWrapper::convertDocumentToV8Object(Document* document) 968 { 969 // Find a proxy for this node. 970 // 971 // Note that if proxy is found, we might initialize the context which can 972 // instantiate a document wrapper. Therefore, we get the proxy before 973 // checking if the node already has a wrapper. 974 V8Proxy* proxy = V8Proxy::retrieve(document->frame()); 975 if (proxy) 976 proxy->windowShell()->initContextIfNeeded(); 977 978 DOMNodeMapping& domNodeMap = getDOMNodeMap(); 979 v8::Handle<v8::Object> wrapper = domNodeMap.get(document); 980 if (wrapper.IsEmpty()) 981 return convertNewNodeToV8Object(document, proxy, domNodeMap); 982 983 return wrapper; 350 984 } 351 985 … … 365 999 } 366 1000 1001 v8::Handle<v8::Value> V8DOMWrapper::convertNodeToV8Object(Node* node) 1002 { 1003 if (!node) 1004 return v8::Null(); 1005 1006 v8::Handle<v8::Value> wrapper = getWrapper(node); 1007 if (!wrapper.IsEmpty()) 1008 return wrapper; 1009 1010 Document* document = node->document(); 1011 if (node == document) 1012 return convertDocumentToV8Object(document); 1013 1014 return convertNewNodeToV8Object(node, 0, getDOMNodeMap()); 1015 } 1016 1017 // Caller checks node is not null. 1018 v8::Handle<v8::Value> V8DOMWrapper::convertNewNodeToV8Object(Node* node, V8Proxy* proxy, DOMNodeMapping& domNodeMap) 1019 { 1020 if (!proxy && node->document()) 1021 proxy = V8Proxy::retrieve(node->document()->frame()); 1022 1023 bool isDocument = false; // document type node has special handling 1024 V8ClassIndex::V8WrapperType type; 1025 1026 Node::NodeType nodeType = node->nodeType(); 1027 if (nodeType == Node::ELEMENT_NODE) { 1028 if (node->isHTMLElement()) 1029 type = htmlElementType(static_cast<HTMLElement*>(node)); 1030 #if ENABLE(SVG) 1031 else if (node->isSVGElement()) 1032 type = svgElementType(static_cast<SVGElement*>(node)); 1033 #endif 1034 else 1035 type = V8ClassIndex::ELEMENT; 1036 } else if (nodeType == Node::DOCUMENT_NODE) { 1037 isDocument = true; 1038 Document* document = static_cast<Document*>(node); 1039 if (document->isHTMLDocument()) 1040 type = V8ClassIndex::HTMLDOCUMENT; 1041 #if ENABLE(SVG) 1042 else if (document->isSVGDocument()) 1043 type = V8ClassIndex::SVGDOCUMENT; 1044 #endif 1045 else 1046 type = V8ClassIndex::DOCUMENT; 1047 } else { 1048 ASSERT(nodeType < static_cast<int>(sizeof(mapping)/sizeof(mapping[0]))); 1049 type = mapping[nodeType]; 1050 ASSERT(type != V8ClassIndex::INVALID_CLASS_INDEX); 1051 } 1052 1053 v8::Handle<v8::Context> context; 1054 if (proxy) 1055 context = proxy->context(); 1056 1057 // Enter the node's context and create the wrapper in that context. 1058 if (!context.IsEmpty()) 1059 context->Enter(); 1060 1061 v8::Local<v8::Object> result = instantiateV8Object(proxy, type, V8ClassIndex::NODE, node); 1062 1063 // Exit the node's context if it was entered. 1064 if (!context.IsEmpty()) 1065 context->Exit(); 1066 1067 if (result.IsEmpty()) { 1068 // If instantiation failed it's important not to add the result 1069 // to the DOM node map. Instead we return an empty handle, which 1070 // should already be handled by callers of this function in case 1071 // the node is NULL. 1072 return result; 1073 } 1074 1075 node->ref(); 1076 domNodeMap.set(node, v8::Persistent<v8::Object>::New(result)); 1077 1078 if (isDocument) { 1079 if (proxy) 1080 proxy->windowShell()->updateDocumentWrapper(result); 1081 1082 if (type == V8ClassIndex::HTMLDOCUMENT) { 1083 // Create marker object and insert it in two internal fields. 1084 // This is used to implement temporary shadowing of 1085 // document.all. 1086 ASSERT(result->InternalFieldCount() == V8HTMLDocument::internalFieldCount); 1087 v8::Local<v8::Object> marker = v8::Object::New(); 1088 result->SetInternalField(V8HTMLDocument::markerIndex, marker); 1089 result->SetInternalField(V8HTMLDocument::shadowIndex, marker); 1090 } 1091 } 1092 1093 return result; 1094 } 1095 367 1096 // A JS object of type EventTarget is limited to a small number of possible classes. 368 1097 // Check EventTarget.h for new type conversion methods … … 437 1166 } 438 1167 1168 v8::Handle<v8::Value> V8DOMWrapper::convertEventListenerToV8Object(ScriptExecutionContext* context, EventListener* listener) 1169 { 1170 if (!listener) 1171 return v8::Null(); 1172 1173 // FIXME: can a user take a lazy event listener and set to other places? 1174 V8AbstractEventListener* v8listener = static_cast<V8AbstractEventListener*>(listener); 1175 return v8listener->getListenerObject(context); 1176 } 1177 439 1178 PassRefPtr<EventListener> V8DOMWrapper::getEventListener(Node* node, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup) 440 1179 { … … 522 1261 } 523 1262 1263 v8::Handle<v8::Value> V8DOMWrapper::convertDOMImplementationToV8Object(DOMImplementation* impl) 1264 { 1265 v8::Handle<v8::Object> result = instantiateV8Object(V8ClassIndex::DOMIMPLEMENTATION, V8ClassIndex::DOMIMPLEMENTATION, impl); 1266 if (result.IsEmpty()) { 1267 // If the instantiation failed, we ignore it and return null instead 1268 // of returning an empty handle. 1269 return v8::Null(); 1270 } 1271 return result; 1272 } 1273 1274 v8::Handle<v8::Value> V8DOMWrapper::convertStyleSheetToV8Object(StyleSheet* sheet) 1275 { 1276 if (!sheet) 1277 return v8::Null(); 1278 1279 v8::Handle<v8::Object> wrapper = getDOMObjectMap().get(sheet); 1280 if (!wrapper.IsEmpty()) 1281 return wrapper; 1282 1283 V8ClassIndex::V8WrapperType type = V8ClassIndex::STYLESHEET; 1284 if (sheet->isCSSStyleSheet()) 1285 type = V8ClassIndex::CSSSTYLESHEET; 1286 1287 v8::Handle<v8::Object> result = instantiateV8Object(type, V8ClassIndex::STYLESHEET, sheet); 1288 if (!result.IsEmpty()) { 1289 // Only update the DOM object map if the result is non-empty. 1290 sheet->ref(); 1291 setJSWrapperForDOMObject(sheet, v8::Persistent<v8::Object>::New(result)); 1292 } 1293 1294 // Add a hidden reference from stylesheet object to its owner node. 1295 Node* ownerNode = sheet->ownerNode(); 1296 if (ownerNode) { 1297 v8::Handle<v8::Object> owner = v8::Handle<v8::Object>::Cast(convertNodeToV8Object(ownerNode)); 1298 result->SetInternalField(V8StyleSheet::ownerNodeIndex, owner); 1299 } 1300 1301 return result; 1302 } 1303 1304 v8::Handle<v8::Value> V8DOMWrapper::convertCSSValueToV8Object(CSSValue* value) 1305 { 1306 if (!value) 1307 return v8::Null(); 1308 1309 v8::Handle<v8::Object> wrapper = getDOMObjectMap().get(value); 1310 if (!wrapper.IsEmpty()) 1311 return wrapper; 1312 1313 V8ClassIndex::V8WrapperType type; 1314 1315 if (value->isWebKitCSSTransformValue()) 1316 type = V8ClassIndex::WEBKITCSSTRANSFORMVALUE; 1317 else if (value->isValueList()) 1318 type = V8ClassIndex::CSSVALUELIST; 1319 else if (value->isPrimitiveValue()) 1320 type = V8ClassIndex::CSSPRIMITIVEVALUE; 1321 #if ENABLE(SVG) 1322 else if (value->isSVGPaint()) 1323 type = V8ClassIndex::SVGPAINT; 1324 else if (value->isSVGColor()) 1325 type = V8ClassIndex::SVGCOLOR; 1326 #endif 1327 else 1328 type = V8ClassIndex::CSSVALUE; 1329 1330 v8::Handle<v8::Object> result = instantiateV8Object(type, V8ClassIndex::CSSVALUE, value); 1331 if (!result.IsEmpty()) { 1332 // Only update the DOM object map if the result is non-empty. 1333 value->ref(); 1334 setJSWrapperForDOMObject(value, v8::Persistent<v8::Object>::New(result)); 1335 } 1336 1337 return result; 1338 } 1339 1340 v8::Handle<v8::Value> V8DOMWrapper::convertCSSRuleToV8Object(CSSRule* rule) 1341 { 1342 if (!rule) 1343 return v8::Null(); 1344 1345 v8::Handle<v8::Object> wrapper = getDOMObjectMap().get(rule); 1346 if (!wrapper.IsEmpty()) 1347 return wrapper; 1348 1349 V8ClassIndex::V8WrapperType type; 1350 1351 switch (rule->type()) { 1352 case CSSRule::STYLE_RULE: 1353 type = V8ClassIndex::CSSSTYLERULE; 1354 break; 1355 case CSSRule::CHARSET_RULE: 1356 type = V8ClassIndex::CSSCHARSETRULE; 1357 break; 1358 case CSSRule::IMPORT_RULE: 1359 type = V8ClassIndex::CSSIMPORTRULE; 1360 break; 1361 case CSSRule::MEDIA_RULE: 1362 type = V8ClassIndex::CSSMEDIARULE; 1363 break; 1364 case CSSRule::FONT_FACE_RULE: 1365 type = V8ClassIndex::CSSFONTFACERULE; 1366 break; 1367 case CSSRule::PAGE_RULE: 1368 type = V8ClassIndex::CSSPAGERULE; 1369 break; 1370 case CSSRule::VARIABLES_RULE: 1371 type = V8ClassIndex::CSSVARIABLESRULE; 1372 break; 1373 case CSSRule::WEBKIT_KEYFRAME_RULE: 1374 type = V8ClassIndex::WEBKITCSSKEYFRAMERULE; 1375 break; 1376 case CSSRule::WEBKIT_KEYFRAMES_RULE: 1377 type = V8ClassIndex::WEBKITCSSKEYFRAMESRULE; 1378 break; 1379 default: // CSSRule::UNKNOWN_RULE 1380 type = V8ClassIndex::CSSRULE; 1381 break; 1382 } 1383 1384 v8::Handle<v8::Object> result = instantiateV8Object(type, V8ClassIndex::CSSRULE, rule); 1385 if (!result.IsEmpty()) { 1386 // Only update the DOM object map if the result is non-empty. 1387 rule->ref(); 1388 setJSWrapperForDOMObject(rule, v8::Persistent<v8::Object>::New(result)); 1389 } 1390 return result; 1391 } 1392 1393 v8::Handle<v8::Value> V8DOMWrapper::convertWindowToV8Object(DOMWindow* window) 1394 { 1395 if (!window) 1396 return v8::Null(); 1397 // Initializes environment of a frame, and return the global object 1398 // of the frame. 1399 Frame* frame = window->frame(); 1400 if (!frame) 1401 return v8::Handle<v8::Object>(); 1402 1403 // Special case: Because of evaluateInIsolatedWorld() one DOMWindow can have 1404 // multiple contexts and multiple global objects associated with it. When 1405 // code running in one of those contexts accesses the window object, we 1406 // want to return the global object associated with that context, not 1407 // necessarily the first global object associated with that DOMWindow. 1408 v8::Handle<v8::Context> currentContext = v8::Context::GetCurrent(); 1409 v8::Handle<v8::Object> currentGlobal = currentContext->Global(); 1410 v8::Handle<v8::Object> windowWrapper = V8DOMWrapper::lookupDOMWrapper(V8ClassIndex::DOMWINDOW, currentGlobal); 1411 if (!windowWrapper.IsEmpty()) { 1412 if (V8DOMWindow::toNative(windowWrapper) == window) 1413 return currentGlobal; 1414 } 1415 1416 // Otherwise, return the global object associated with this frame. 1417 v8::Handle<v8::Context> context = V8Proxy::context(frame); 1418 if (context.IsEmpty()) 1419 return v8::Handle<v8::Object>(); 1420 1421 v8::Handle<v8::Object> global = context->Global(); 1422 ASSERT(!global.IsEmpty()); 1423 return global; 1424 } 1425 1426 v8::Handle<v8::Value> V8DOMWrapper::convertNamedNodeMapToV8Object(NamedNodeMap* map) 1427 { 1428 if (!map) 1429 return v8::Null(); 1430 1431 v8::Handle<v8::Object> wrapper = getDOMObjectMap().get(map); 1432 if (!wrapper.IsEmpty()) 1433 return wrapper; 1434 1435 v8::Handle<v8::Object> result = instantiateV8Object(V8ClassIndex::NAMEDNODEMAP, V8ClassIndex::NAMEDNODEMAP, map); 1436 if (result.IsEmpty()) 1437 return result; 1438 1439 // Only update the DOM object map if the result is non-empty. 1440 map->ref(); 1441 setJSWrapperForDOMObject(map, v8::Persistent<v8::Object>::New(result)); 1442 1443 // Add a hidden reference from named node map to its owner node. 1444 if (Element* element = map->element()) { 1445 v8::Handle<v8::Object> owner = v8::Handle<v8::Object>::Cast(convertNodeToV8Object(element)); 1446 result->SetInternalField(V8NamedNodeMap::ownerNodeIndex, owner); 1447 } 1448 1449 return result; 1450 } 1451 524 1452 } // namespace WebCore -
trunk/WebCore/bindings/v8/V8DOMWrapper.h
r54259 r54278 37 37 #include "NodeFilter.h" 38 38 #include "PlatformString.h" // for WebCore::String 39 #include "V8CustomBinding.h" 39 40 #include "V8CustomXPathNSResolver.h" 40 41 #include "V8DOMMap.h" … … 123 124 } 124 125 126 template<typename T> 127 static v8::Handle<v8::Value> convertToV8Object(V8ClassIndex::V8WrapperType type, PassRefPtr<T> imp) 128 { 129 return convertToV8Object(type, imp.get()); 130 } 131 132 static v8::Handle<v8::Value> convertToV8Object(V8ClassIndex::V8WrapperType, void*); 133 134 // Fast-path for Node objects. 135 static v8::Handle<v8::Value> convertNodeToV8Object(PassRefPtr<Node> node) 136 { 137 return convertNodeToV8Object(node.get()); 138 } 139 140 static v8::Handle<v8::Value> convertNodeToV8Object(Node*); 141 142 static v8::Handle<v8::Value> convertDocumentToV8Object(Document*); 143 144 static v8::Handle<v8::Value> convertNewNodeToV8Object(PassRefPtr<Node> node) 145 { 146 return convertNewNodeToV8Object(node.get()); 147 } 148 149 static v8::Handle<v8::Value> convertNewNodeToV8Object(Node* node) 150 { 151 return convertNewNodeToV8Object(node, 0, getDOMNodeMap()); 152 } 153 154 static v8::Handle<v8::Value> convertNewNodeToV8Object(Node*, V8Proxy*, DOMNodeMapping&); 155 125 156 static V8ClassIndex::V8WrapperType domWrapperType(v8::Handle<v8::Object>); 126 157 158 static v8::Handle<v8::Value> convertEventToV8Object(PassRefPtr<Event> event) 159 { 160 return convertEventToV8Object(event.get()); 161 } 162 163 static v8::Handle<v8::Value> convertEventToV8Object(Event*); 164 127 165 static v8::Handle<v8::Value> convertEventTargetToV8Object(PassRefPtr<EventTarget> eventTarget) 128 166 { … … 131 169 132 170 static v8::Handle<v8::Value> convertEventTargetToV8Object(EventTarget*); 171 172 // Wrap and unwrap JS event listeners. 173 static v8::Handle<v8::Value> convertEventListenerToV8Object(ScriptExecutionContext* context, PassRefPtr<EventListener> eventListener) 174 { 175 return convertEventListenerToV8Object(context, eventListener.get()); 176 } 177 178 static v8::Handle<v8::Value> convertEventListenerToV8Object(ScriptExecutionContext*, EventListener*); 133 179 134 180 static PassRefPtr<EventListener> getEventListener(Node* node, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup); … … 166 212 } 167 213 #endif 214 // DOMImplementation is a singleton and it is handled in a special 215 // way. A wrapper is generated per document and stored in an 216 // internal field of the document. 217 static v8::Handle<v8::Value> convertDOMImplementationToV8Object(DOMImplementation*); 168 218 169 219 // Wrap JS node filter in C++. … … 184 234 static bool isWrapperOfType(v8::Handle<v8::Value>, V8ClassIndex::V8WrapperType); 185 235 236 // Check whether a V8 value is a DOM Event wrapper. 237 static bool isDOMEventWrapper(v8::Handle<v8::Value>); 238 239 static v8::Handle<v8::Value> convertStyleSheetToV8Object(StyleSheet*); 240 static v8::Handle<v8::Value> convertCSSValueToV8Object(CSSValue*); 241 static v8::Handle<v8::Value> convertCSSRuleToV8Object(CSSRule*); 242 // Returns the JS wrapper of a window object, initializes the environment 243 // of the window frame if needed. 244 static v8::Handle<v8::Value> convertWindowToV8Object(DOMWindow*); 245 static v8::Handle<v8::Value> convertNamedNodeMapToV8Object(NamedNodeMap*); 246 247 #if ENABLE(SVG) 248 static v8::Handle<v8::Value> convertSVGElementInstanceToV8Object(SVGElementInstance*); 249 static v8::Handle<v8::Value> convertSVGObjectWithContextToV8Object(V8ClassIndex::V8WrapperType, void*); 250 #endif 251 186 252 #if ENABLE(3D_CANVAS) 187 253 static void setIndexedPropertiesToExternalArray(v8::Handle<v8::Object>, … … 190 256 int); 191 257 #endif 258 259 static V8ClassIndex::V8WrapperType htmlElementType(HTMLElement*); 260 #if ENABLE(SVG) 261 static V8ClassIndex::V8WrapperType svgElementType(SVGElement*); 262 #endif 192 263 // Set hidden references in a DOMWindow object of a frame. 193 264 static void setHiddenWindowReference(Frame*, const int internalIndex, v8::Handle<v8::Object>); 194 265 195 static v8::Local<v8::Object> instantiateV8Object(V8Proxy* proxy, V8ClassIndex::V8WrapperType type, void* impl); 266 static v8::Local<v8::Object> instantiateV8Object(V8Proxy* proxy, V8ClassIndex::V8WrapperType type, void* impl) 267 { 268 return instantiateV8Object(proxy, type, type, impl); 269 } 196 270 197 271 static v8::Handle<v8::Object> getWrapper(Node*); 272 273 private: 274 275 // The first V8WrapperType specifies the function descriptor 276 // used to create JS object. The second V8WrapperType specifies 277 // the actual type of the void* for type casting. 278 // For example, a HTML element has HTMLELEMENT for the first V8WrapperType, but always 279 // use NODE as the second V8WrapperType. JS wrapper stores the second 280 // V8WrapperType and the void* as internal fields. 281 static v8::Local<v8::Object> instantiateV8Object(V8ClassIndex::V8WrapperType descType, V8ClassIndex::V8WrapperType cptrType, void* impl) 282 { 283 return instantiateV8Object(NULL, descType, cptrType, impl); 284 } 285 286 static v8::Local<v8::Object> instantiateV8Object(V8Proxy*, V8ClassIndex::V8WrapperType, V8ClassIndex::V8WrapperType, void*); 198 287 }; 199 288 -
trunk/WebCore/bindings/v8/V8NodeFilterCondition.cpp
r54259 r54278 35 35 #include "NodeFilter.h" 36 36 #include "ScriptState.h" 37 #include "V8Node.h"38 37 #include "V8Proxy.h" 39 38 … … 71 70 v8::Handle<v8::Function> callback = v8::Handle<v8::Function>::Cast(m_filter); 72 71 OwnArrayPtr<v8::Handle<v8::Value> > args(new v8::Handle<v8::Value>[1]); 73 args[0] = toV8(node);72 args[0] = V8DOMWrapper::convertToV8Object(V8ClassIndex::NODE, node); 74 73 75 74 V8Proxy* proxy = V8Proxy::retrieve(); -
trunk/WebCore/bindings/v8/V8Proxy.cpp
r54259 r54278 47 47 #include "V8Collection.h" 48 48 #include "V8ConsoleMessage.h" 49 #include "V8 DOMCoreException.h"49 #include "V8CustomBinding.h" 50 50 #include "V8DOMMap.h" 51 51 #include "V8DOMWindow.h" 52 #include "V8EventException.h"53 52 #include "V8HiddenPropertyName.h" 54 53 #include "V8Index.h" 55 54 #include "V8IsolatedContext.h" 56 #include "V8RangeException.h"57 #include "V8SVGException.h"58 #include "V8XMLHttpRequestException.h"59 #include "V8XPathException.h"60 55 #include "WorkerContextExecutionProxy.h" 61 56 … … 613 608 switch (description.type) { 614 609 case DOMExceptionType: 615 exception = toV8(DOMCoreException::create(description));610 exception = V8DOMWrapper::convertToV8Object(V8ClassIndex::DOMCOREEXCEPTION, DOMCoreException::create(description)); 616 611 break; 617 612 case RangeExceptionType: 618 exception = toV8(RangeException::create(description));613 exception = V8DOMWrapper::convertToV8Object(V8ClassIndex::RANGEEXCEPTION, RangeException::create(description)); 619 614 break; 620 615 case EventExceptionType: 621 exception = toV8(EventException::create(description));616 exception = V8DOMWrapper::convertToV8Object(V8ClassIndex::EVENTEXCEPTION, EventException::create(description)); 622 617 break; 623 618 case XMLHttpRequestExceptionType: 624 exception = toV8(XMLHttpRequestException::create(description));619 exception = V8DOMWrapper::convertToV8Object(V8ClassIndex::XMLHTTPREQUESTEXCEPTION, XMLHttpRequestException::create(description)); 625 620 break; 626 621 #if ENABLE(SVG) 627 622 case SVGExceptionType: 628 exception = toV8(SVGException::create(description));623 exception = V8DOMWrapper::convertToV8Object(V8ClassIndex::SVGEXCEPTION, SVGException::create(description)); 629 624 break; 630 625 #endif 631 626 #if ENABLE(XPATH) 632 627 case XPathExceptionType: 633 exception = toV8(XPathException::create(description));628 exception = V8DOMWrapper::convertToV8Object(V8ClassIndex::XPATHEXCEPTION, XPathException::create(description)); 634 629 break; 635 630 #endif -
trunk/WebCore/bindings/v8/custom/V8CanvasRenderingContext2DCustom.cpp
r54259 r54278 54 54 { 55 55 if (style->canvasGradient()) 56 return toV8(style->canvasGradient());56 return V8DOMWrapper::convertToV8Object(V8ClassIndex::CANVASGRADIENT, style->canvasGradient()); 57 57 58 58 if (style->canvasPattern()) 59 return toV8(style->canvasPattern());59 return V8DOMWrapper::convertToV8Object(V8ClassIndex::CANVASPATTERN, style->canvasPattern()); 60 60 61 61 return v8String(style->color()); … … 349 349 return notHandledByInterceptor(); 350 350 } 351 return toV8(pattern.release());351 return V8DOMWrapper::convertToV8Object(V8ClassIndex::CANVASPATTERN, pattern.release()); 352 352 } 353 353 … … 360 360 return notHandledByInterceptor(); 361 361 } 362 return toV8(pattern.release());362 return V8DOMWrapper::convertToV8Object(V8ClassIndex::CANVASPATTERN, pattern.release()); 363 363 } 364 364 -
trunk/WebCore/bindings/v8/custom/V8CustomPositionCallback.cpp
r54259 r54278 29 29 #include "Frame.h" 30 30 #include "V8CustomVoidCallback.h" // For invokeCallback 31 #include "V8Geoposition.h"32 31 33 32 namespace WebCore { … … 55 54 56 55 v8::Handle<v8::Value> argv[] = { 57 toV8(position)56 V8DOMWrapper::convertToV8Object(V8ClassIndex::GEOPOSITION, position) 58 57 }; 59 58 -
trunk/WebCore/bindings/v8/custom/V8CustomPositionErrorCallback.cpp
r54259 r54278 29 29 #include "Frame.h" 30 30 #include "V8CustomVoidCallback.h" // For invokeCallback 31 #include "V8PositionError.h"32 31 33 32 namespace WebCore { … … 55 54 56 55 v8::Handle<v8::Value> argv[] = { 57 toV8(error)56 V8DOMWrapper::convertToV8Object(V8ClassIndex::POSITIONERROR, error) 58 57 }; 59 58 -
trunk/WebCore/bindings/v8/custom/V8CustomSQLStatementCallback.cpp
r54259 r54278 37 37 #include "Frame.h" 38 38 #include "V8CustomVoidCallback.h" 39 #include "V8SQLResultSet.h"40 #include "V8SQLTransaction.h"41 39 42 40 namespace WebCore { … … 64 62 65 63 v8::Handle<v8::Value> argv[] = { 66 toV8(transaction),67 toV8(resultSet)64 V8DOMWrapper::convertToV8Object(V8ClassIndex::SQLTRANSACTION, transaction), 65 V8DOMWrapper::convertToV8Object(V8ClassIndex::SQLRESULTSET, resultSet) 68 66 }; 69 67 -
trunk/WebCore/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp
r54259 r54278 37 37 #include "Frame.h" 38 38 #include "V8CustomVoidCallback.h" 39 #include "V8SQLError.h"40 #include "V8SQLTransaction.h"41 39 42 40 namespace WebCore { … … 64 62 65 63 v8::Handle<v8::Value> argv[] = { 66 toV8(transaction),67 toV8(error)64 V8DOMWrapper::convertToV8Object(V8ClassIndex::SQLTRANSACTION, transaction), 65 V8DOMWrapper::convertToV8Object(V8ClassIndex::SQLERROR, error) 68 66 }; 69 67 -
trunk/WebCore/bindings/v8/custom/V8CustomSQLTransactionCallback.cpp
r54259 r54278 37 37 #include "Frame.h" 38 38 #include "V8CustomVoidCallback.h" 39 #include "V8SQLTransaction.h"40 39 41 40 namespace WebCore { … … 64 63 65 64 v8::Handle<v8::Value> argv[] = { 66 toV8(transaction)65 V8DOMWrapper::convertToV8Object(V8ClassIndex::SQLTRANSACTION, transaction) 67 66 }; 68 67 -
trunk/WebCore/bindings/v8/custom/V8CustomSQLTransactionErrorCallback.cpp
r54259 r54278 37 37 #include "Frame.h" 38 38 #include "V8CustomVoidCallback.h" 39 #include "V8SQLError.h"40 39 41 40 namespace WebCore { … … 63 62 64 63 v8::Handle<v8::Value> argv[] = { 65 toV8(error)64 V8DOMWrapper::convertToV8Object(V8ClassIndex::SQLERROR, error) 66 65 }; 67 66 -
trunk/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp
r54259 r54278 58 58 #include "V8CustomBinding.h" 59 59 #include "V8CustomEventListener.h" 60 #include "V8HTMLCollection.h"61 60 #include "V8MessagePortCustom.h" 62 #include "V8Node.h"63 61 #include "V8Proxy.h" 64 62 #include "V8Utilities.h" … … 711 709 frame->redirectScheduler()->scheduleLocationChange(completedUrl, referrer, false, userGesture); 712 710 } 713 return toV8(frame->domWindow());711 return V8DOMWrapper::convertToV8Object(V8ClassIndex::DOMWINDOW, frame->domWindow()); 714 712 } 715 713 … … 771 769 return v8::Undefined(); 772 770 773 return toV8(frame->domWindow());771 return V8DOMWrapper::convertToV8Object(V8ClassIndex::DOMWINDOW, frame->domWindow()); 774 772 } 775 773 … … 789 787 Frame* child = frame->tree()->child(index); 790 788 if (child) 791 return toV8(child->domWindow());789 return V8DOMWrapper::convertToV8Object(V8ClassIndex::DOMWINDOW, child->domWindow()); 792 790 793 791 return notHandledByInterceptor(); … … 812 810 Frame* child = frame->tree()->child(propName); 813 811 if (child) 814 return toV8(child->domWindow());812 return V8DOMWrapper::convertToV8Object(V8ClassIndex::DOMWINDOW, child->domWindow()); 815 813 816 814 // Search IDL functions defined in the prototype … … 827 825 if (items->length() >= 1) { 828 826 if (items->length() == 1) 829 return toV8(items->firstItem());830 return toV8(items.release());827 return V8DOMWrapper::convertNodeToV8Object(items->firstItem()); 828 return V8DOMWrapper::convertToV8Object(V8ClassIndex::HTMLCOLLECTION, items.release()); 831 829 } 832 830 } -
trunk/WebCore/bindings/v8/custom/V8DataGridColumnListCustom.cpp
r54259 r54278 58 58 if (!result) 59 59 return notHandledByInterceptor(); 60 return toV8(result);60 return V8DOMWrapper::convertToV8Object(V8ClassIndex::DATAGRIDCOLUMN, result); 61 61 } 62 62 -
trunk/WebCore/bindings/v8/custom/V8DocumentCustom.cpp
r54259 r54278 38 38 #include "XPathNSResolver.h" 39 39 #include "XPathResult.h" 40 #include "CanvasRenderingContext.h" 40 41 41 42 #include "V8Binding.h" 42 #include "V8C anvasRenderingContext2D.h"43 #include "V8CustomBinding.h" 43 44 #include "V8CustomXPathNSResolver.h" 44 #include "V8DOMImplementation.h"45 45 #include "V8HTMLDocument.h" 46 46 #include "V8IsolatedContext.h" … … 48 48 #include "V8Proxy.h" 49 49 #include "V8SVGDocument.h" 50 #include "V8WebGLRenderingContext.h"51 50 #include "V8XPathNSResolver.h" 52 51 #include "V8XPathResult.h" … … 84 83 return throwError(ec); 85 84 86 return toV8(result.release());85 return V8DOMWrapper::convertToV8Object(V8ClassIndex::XPATHRESULT, result.release()); 87 86 } 88 87 … … 100 99 return v8::Undefined(); 101 100 if (result->is2d()) 102 return toV8(static_cast<CanvasRenderingContext2D*>(result));101 return V8DOMWrapper::convertToV8Object(V8ClassIndex::CANVASRENDERINGCONTEXT2D, result); 103 102 #if ENABLE(3D_CANVAS) 104 103 else if (result->is3d()) 105 return toV8(static_cast<WebGLRenderingContext*>(result));104 return V8DOMWrapper::convertToV8Object(V8ClassIndex::WEBGLRENDERINGCONTEXT, result); 106 105 #endif // ENABLE(3D_CANVAS) 107 106 ASSERT_NOT_REACHED(); … … 129 128 // Generate a wrapper. 130 129 Document* document = V8Document::toNative(info.Holder()); 131 v8::Handle<v8::Value> wrapper = toV8(document->implementation());130 v8::Handle<v8::Value> wrapper = V8DOMWrapper::convertDOMImplementationToV8Object(document->implementation()); 132 131 133 132 // Store the wrapper in the internal field. -
trunk/WebCore/bindings/v8/custom/V8DocumentLocationCustom.cpp
r54259 r54278 28 28 #include "Frame.h" 29 29 #include "V8Binding.h" 30 #include "V8Location.h" 30 #include "V8CustomBinding.h" 31 #include "V8Document.h" 31 32 #include "V8Proxy.h" 32 33 … … 40 41 41 42 DOMWindow* window = document->frame()->domWindow(); 42 return toV8(window->location());43 return V8DOMWrapper::convertToV8Object(V8ClassIndex::LOCATION, window->location()); 43 44 } 44 45 -
trunk/WebCore/bindings/v8/custom/V8ElementCustom.cpp
r54259 r54278 88 88 throwError(ec); 89 89 90 return toV8(result.release());90 return V8DOMWrapper::convertNodeToV8Object(result.release()); 91 91 } 92 92 … … 127 127 throwError(ec); 128 128 129 return toV8(result.release());129 return V8DOMWrapper::convertNodeToV8Object(result.release()); 130 130 } 131 131 -
trunk/WebCore/bindings/v8/custom/V8EventCustom.cpp
r54259 r54278 37 37 #include "V8BeforeLoadEvent.h" 38 38 #include "V8Binding.h" 39 #include "V8Clipboard.h"40 39 #include "V8CompositionEvent.h" 40 #include "V8CustomBinding.h" 41 41 #include "V8ErrorEvent.h" 42 42 #include "V8KeyboardEvent.h" … … 71 71 72 72 if (event->isDragEvent()) 73 return toV8(static_cast<MouseEvent*>(event)->clipboard());73 return V8DOMWrapper::convertToV8Object(V8ClassIndex::CLIPBOARD, static_cast<MouseEvent*>(event)->clipboard()); 74 74 75 75 return v8::Undefined(); … … 81 81 82 82 if (event->isClipboardEvent()) 83 return toV8(static_cast<ClipboardEvent*>(event)->clipboard());83 return V8DOMWrapper::convertToV8Object(V8ClassIndex::CLIPBOARD, static_cast<ClipboardEvent*>(event)->clipboard()); 84 84 85 85 return v8::Undefined(); -
trunk/WebCore/bindings/v8/custom/V8HTMLAllCollectionCustom.cpp
r54259 r54278 37 37 #include "V8CustomBinding.h" 38 38 #include "V8NamedNodesCollection.h" 39 #include "V8Node.h"40 #include "V8NodeList.h"41 39 #include "V8Proxy.h" 42 40 … … 52 50 53 51 if (namedItems.size() == 1) 54 return toV8(namedItems.at(0).release());52 return V8DOMWrapper::convertNodeToV8Object(namedItems.at(0).release()); 55 53 56 54 NodeList* list = new V8NamedNodesCollection(namedItems); 57 return toV8(list);55 return V8DOMWrapper::convertToV8Object(V8ClassIndex::NODELIST, list); 58 56 } 59 57 … … 71 69 72 70 RefPtr<Node> result = collection->item(index->Uint32Value()); 73 return toV8(result.release());71 return V8DOMWrapper::convertNodeToV8Object(result.release()); 74 72 } 75 73 … … 133 131 while (node) { 134 132 if (!current) 135 return toV8(node);133 return V8DOMWrapper::convertNodeToV8Object(node); 136 134 137 135 node = imp->nextNamedItem(name); -
trunk/WebCore/bindings/v8/custom/V8HTMLAudioElementConstructor.cpp
r54259 r54278 37 37 #include "HTMLNames.h" 38 38 #include "V8Binding.h" 39 #include "V8Document.h"40 39 #include "V8HTMLAudioElement.h" 41 40 #include "V8Proxy.h" … … 80 79 // Make sure the document is added to the DOM Node map. Otherwise, the HTMLAudioElement instance 81 80 // may end up being the only node in the map and get garbage-ccollected prematurely. 82 toV8(document);81 V8DOMWrapper::convertNodeToV8Object(document); 83 82 84 83 RefPtr<HTMLAudioElement> audio = new HTMLAudioElement(HTMLNames::audioTag, document); -
trunk/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp
r54259 r54278 37 37 #include "WebGLContextAttributes.h" 38 38 #include "V8Binding.h" 39 #include "V8C anvasRenderingContext2D.h"39 #include "V8CustomBinding.h" 40 40 #include "V8Node.h" 41 41 #include "V8Proxy.h" 42 #include "V8WebGLRenderingContext.h"43 42 44 43 namespace WebCore { … … 79 78 return v8::Undefined(); 80 79 if (result->is2d()) 81 return toV8(static_cast<CanvasRenderingContext2D*>(result));80 return V8DOMWrapper::convertToV8Object(V8ClassIndex::CANVASRENDERINGCONTEXT2D, result); 82 81 #if ENABLE(3D_CANVAS) 83 82 else if (result->is3d()) 84 return toV8(static_cast<WebGLRenderingContext*>(result));83 return V8DOMWrapper::convertToV8Object(V8ClassIndex::WEBGLRENDERINGCONTEXT, result); 85 84 #endif 86 85 ASSERT_NOT_REACHED(); -
trunk/WebCore/bindings/v8/custom/V8HTMLCollectionCustom.cpp
r54259 r54278 37 37 #include "V8HTMLAllCollection.h" 38 38 #include "V8NamedNodesCollection.h" 39 #include "V8Node.h"40 #include "V8NodeList.h"41 39 #include "V8Proxy.h" 42 40 … … 52 50 53 51 if (namedItems.size() == 1) 54 return toV8(namedItems.at(0).release());52 return V8DOMWrapper::convertNodeToV8Object(namedItems.at(0).release()); 55 53 56 54 NodeList* list = new V8NamedNodesCollection(namedItems); 57 return toV8(list);55 return V8DOMWrapper::convertToV8Object(V8ClassIndex::NODELIST, list); 58 56 } 59 57 … … 71 69 72 70 RefPtr<Node> result = collection->item(index->Uint32Value()); 73 return toV8(result.release());71 return V8DOMWrapper::convertNodeToV8Object(result.release()); 74 72 } 75 73 … … 133 131 while (node) { 134 132 if (!current) 135 return toV8(node);133 return V8DOMWrapper::convertNodeToV8Object(node); 136 134 137 135 node = imp->nextNamedItem(name); -
trunk/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp
r54259 r54278 39 39 #include "HTMLNames.h" 40 40 #include "V8Binding.h" 41 #include "V8DOMWindow.h"42 #include "V8HTMLAllCollection.h"43 #include "V8HTMLCollection.h"44 41 #include "V8IsolatedContext.h" 45 #include "V8Node.h"46 42 #include "V8Proxy.h" 47 43 #include <wtf/RefPtr.h> … … 97 93 Frame* frame = 0; 98 94 if (node->hasTagName(HTMLNames::iframeTag) && (frame = static_cast<HTMLIFrameElement*>(node)->contentFrame())) 99 return toV8(frame->domWindow());100 101 return toV8(node);102 } 103 104 return toV8(items.release());95 return V8DOMWrapper::convertToV8Object(V8ClassIndex::DOMWINDOW, frame->domWindow()); 96 97 return V8DOMWrapper::convertNodeToV8Object(node); 98 } 99 100 return V8DOMWrapper::convertToV8Object(V8ClassIndex::HTMLCOLLECTION, items.release()); 105 101 } 106 102 … … 187 183 { 188 184 INC_STATS("DOM.HTMLDocument.all._get"); 185 v8::HandleScope scope; 189 186 v8::Handle<v8::Object> holder = info.Holder(); 190 187 HTMLDocument* htmlDocument = V8HTMLDocument::toNative(holder); 191 return toV8(htmlDocument->all());188 return V8DOMWrapper::convertToV8Object(V8ClassIndex::HTMLCOLLECTION, htmlDocument->all()); 192 189 } 193 190 -
trunk/WebCore/bindings/v8/custom/V8HTMLFormElementCustom.cpp
r54259 r54278 35 35 #include "HTMLFormElement.h" 36 36 #include "V8Binding.h" 37 #include "V8CustomBinding.h" 37 38 #include "V8NamedNodesCollection.h" 38 #include "V8Node.h"39 #include "V8NodeList.h"40 39 #include "V8Proxy.h" 41 40 … … 50 49 if (!formElement) 51 50 return notHandledByInterceptor(); 52 return toV8(formElement.release());51 return V8DOMWrapper::convertNodeToV8Object(formElement.release()); 53 52 } 54 53 … … 76 75 77 76 if (elements.size() == 1) 78 return toV8(elements.at(0).release());77 return V8DOMWrapper::convertNodeToV8Object(elements.at(0).release()); 79 78 80 79 NodeList* collection = new V8NamedNodesCollection(elements); 81 return toV8(collection);80 return V8DOMWrapper::convertToV8Object(V8ClassIndex::NODELIST, collection); 82 81 } 83 82 -
trunk/WebCore/bindings/v8/custom/V8HTMLFrameSetElementCustom.cpp
r54259 r54278 41 41 42 42 #include "V8Binding.h" 43 #include "V8 DOMWindow.h"43 #include "V8CustomBinding.h" 44 44 #include "V8Proxy.h" 45 45 … … 56 56 return v8::Undefined(); 57 57 if (Frame* frame = doc->frame()) 58 return toV8(frame->domWindow());58 return V8DOMWrapper::convertToV8Object(V8ClassIndex::DOMWINDOW, frame->domWindow()); 59 59 } 60 60 return notHandledByInterceptor(); -
trunk/WebCore/bindings/v8/custom/V8HTMLImageElementConstructor.cpp
r54259 r54278 37 37 #include "HTMLNames.h" 38 38 #include "V8Binding.h" 39 #include "V8Document.h"40 39 #include "V8HTMLImageElement.h" 41 40 #include "V8Proxy.h" … … 80 79 // Make sure the document is added to the DOM Node map. Otherwise, the HTMLImageElement instance 81 80 // may end up being the only node in the map and get garbage-ccollected prematurely. 82 toV8(document);81 V8DOMWrapper::convertNodeToV8Object(document); 83 82 84 83 RefPtr<HTMLImageElement> image = new HTMLImageElement(HTMLNames::imgTag, document); -
trunk/WebCore/bindings/v8/custom/V8HTMLOptionsCollectionCustom.cpp
r54259 r54278 38 38 #include "V8Binding.h" 39 39 #include "V8Collection.h" 40 #include "V8CustomBinding.h" 40 41 #include "V8HTMLOptionElement.h" 41 42 #include "V8HTMLSelectElementCustom.h" 42 #include "V8Node.h"43 43 #include "V8Proxy.h" 44 44 … … 124 124 return notHandledByInterceptor(); 125 125 126 return toV8(result.release());126 return V8DOMWrapper::convertNodeToV8Object(result.release()); 127 127 } 128 128 -
trunk/WebCore/bindings/v8/custom/V8HTMLSelectElementCustom.cpp
r54259 r54278 38 38 #include "V8Binding.h" 39 39 #include "V8Collection.h" 40 #include "V8CustomBinding.h" 40 41 #include "V8HTMLOptionElement.h" 41 42 #include "V8HTMLSelectElement.h" 42 43 #include "V8NamedNodesCollection.h" 43 #include "V8Node.h"44 #include "V8NodeList.h"45 44 #include "V8Proxy.h" 46 45 … … 69 68 70 69 if (items.size() == 1) 71 return toV8(items.at(0).release());70 return V8DOMWrapper::convertNodeToV8Object(items.at(0).release()); 72 71 73 72 NodeList* list = new V8NamedNodesCollection(items); 74 return toV8(list);73 return V8DOMWrapper::convertToV8Object(V8ClassIndex::NODELIST, list); 75 74 } 76 75 … … 82 81 return notHandledByInterceptor(); 83 82 84 return toV8(result.release());83 return V8DOMWrapper::convertNodeToV8Object(result.release()); 85 84 } 86 85 -
trunk/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp
r54259 r54278 41 41 42 42 #include "V8Binding.h" 43 #include "V8CustomBinding.h" 43 44 #include "V8Database.h" 44 45 #include "V8Node.h" … … 85 86 86 87 // Call custom code to create InjectedScripHost wrapper specific for the context 87 // instead of calling toV8()that would create the88 // instead of calling V8DOMWrapper::convertToV8Object that would create the 88 89 // wrapper in the current context. 89 90 // FIXME: make it possible to use generic bindings factory for InjectedScriptHost. … … 130 131 return v8::Undefined(); 131 132 132 return toV8(node);133 return V8DOMWrapper::convertToV8Object(V8ClassIndex::NODE, node); 133 134 } 134 135 … … 160 161 if (!database) 161 162 return v8::Undefined(); 162 return toV8(database);163 return V8DOMWrapper::convertToV8Object<Database>(V8ClassIndex::DATABASE, database); 163 164 } 164 165 -
trunk/WebCore/bindings/v8/custom/V8MessageChannelConstructor.cpp
r54259 r54278 36 36 #include "MessageChannel.h" 37 37 #include "V8Binding.h" 38 #include "V8MessagePort.h"39 38 #include "V8Proxy.h" 40 39 #include "V8Utilities.h" … … 68 67 // MessagePort wrappers to make sure that the MessagePort wrappers 69 68 // stay alive as long as the MessageChannel wrapper is around. 70 messageChannel->SetInternalField(V8MessageChannel::port1Index, toV8(obj->port1()));71 messageChannel->SetInternalField(V8MessageChannel::port2Index, toV8(obj->port2()));69 messageChannel->SetInternalField(V8MessageChannel::port1Index, V8DOMWrapper::convertToV8Object(V8ClassIndex::MESSAGEPORT, obj->port1())); 70 messageChannel->SetInternalField(V8MessageChannel::port2Index, V8DOMWrapper::convertToV8Object(V8ClassIndex::MESSAGEPORT, obj->port2())); 72 71 73 72 // Setup the standard wrapper object internal fields. -
trunk/WebCore/bindings/v8/custom/V8MessageEventCustom.cpp
r54259 r54278 36 36 37 37 #include "V8Binding.h" 38 #include "V8CustomBinding.h" 38 39 #include "V8DOMWindow.h" 39 #include "V8MessagePort.h"40 40 #include "V8MessagePortCustom.h" 41 41 #include "V8Proxy.h" … … 54 54 v8::Local<v8::Array> portArray = v8::Array::New(ports->size()); 55 55 for (size_t i = 0; i < ports->size(); ++i) 56 portArray->Set(v8::Integer::New(i), toV8((*ports)[i].get()));56 portArray->Set(v8::Integer::New(i), V8DOMWrapper::convertToV8Object(V8ClassIndex::MESSAGEPORT, (*ports)[i].get())); 57 57 58 58 return portArray; -
trunk/WebCore/bindings/v8/custom/V8NamedNodeMapCustom.cpp
r54259 r54278 34 34 #include "NamedNodeMap.h" 35 35 #include "V8Binding.h" 36 #include "V8CustomBinding.h" 36 37 #include "V8Element.h" 37 #include "V8Node.h"38 38 #include "V8Proxy.h" 39 39 … … 50 50 return notHandledByInterceptor(); 51 51 52 return toV8(result.release());52 return V8DOMWrapper::convertNodeToV8Object(result.release()); 53 53 } 54 54 … … 71 71 return notHandledByInterceptor(); 72 72 73 return toV8(result.release());73 return V8DOMWrapper::convertNodeToV8Object(result.release()); 74 74 } 75 75 -
trunk/WebCore/bindings/v8/custom/V8NodeIteratorCustom.cpp
r54259 r54278 36 36 37 37 #include "V8Binding.h" 38 #include "V8 Node.h"38 #include "V8CustomBinding.h" 39 39 #include "V8Proxy.h" 40 40 … … 55 55 return v8::Null(); 56 56 57 return toV8(object);57 return V8DOMWrapper::convertNodeToV8Object(object); 58 58 } 59 59 -
trunk/WebCore/bindings/v8/custom/V8NodeListCustom.cpp
r54259 r54278 33 33 34 34 #include "NodeList.h" 35 35 36 #include "V8Binding.h" 36 #include "V8 Node.h"37 #include "V8CustomBinding.h" 37 38 #include "V8Proxy.h" 38 39 … … 57 58 return notHandledByInterceptor(); 58 59 59 return toV8(result.release());60 return V8DOMWrapper::convertNodeToV8Object(result.release()); 60 61 } 61 62 … … 75 76 76 77 RefPtr<Node> result = list->item(index->Uint32Value()); 77 return toV8(result.release());78 return V8DOMWrapper::convertNodeToV8Object(result.release()); 78 79 } 79 80 -
trunk/WebCore/bindings/v8/custom/V8NotificationCenterCustom.cpp
r54259 r54278 38 38 #include "NotificationCenter.h" 39 39 #include "V8Binding.h" 40 #include "V8CustomBinding.h" 40 41 #include "V8CustomEventListener.h" 41 42 #include "V8CustomVoidCallback.h" … … 95 96 return WorkerContextExecutionProxy::convertToV8Object(V8ClassIndex::NOTIFICATION, notification.get()); 96 97 97 return toV8(notification.get());98 return V8DOMWrapper::convertToV8Object(V8ClassIndex::NOTIFICATION, notification.get()); 98 99 } 99 100 … … 112 113 return WorkerContextExecutionProxy::convertToV8Object(V8ClassIndex::NOTIFICATION, notification.get()); 113 114 114 return toV8(notification.get());115 return V8DOMWrapper::convertToV8Object(V8ClassIndex::NOTIFICATION, notification.get()); 115 116 } 116 117 -
trunk/WebCore/bindings/v8/custom/V8SVGMatrixCustom.cpp
r54259 r54278 32 32 33 33 #if ENABLE(SVG) 34 34 35 #include "TransformationMatrix.h" 35 36 36 37 #include "SVGException.h" 38 37 39 #include "V8Binding.h" 38 #include "V8 Proxy.h"40 #include "V8CustomBinding.h" 39 41 #include "V8SVGMatrix.h" 40 42 #include "V8SVGPODTypeWrapper.h" 43 #include "V8Proxy.h" 41 44 42 45 namespace WebCore { … … 54 57 TransformationMatrix m2 = *V8SVGPODTypeWrapper<TransformationMatrix>::toNative(v8::Handle<v8::Object>::Cast(args[0])); 55 58 56 RefPtr<V8SVGStaticPODTypeWrapper<TransformationMatrix> > wrapper = V8SVGStaticPODTypeWrapper<TransformationMatrix>::create(m1.multLeft(m2)); 57 return toV8(wrapper.get()); 59 return V8DOMWrapper::convertToV8Object(V8ClassIndex::SVGMATRIX, V8SVGStaticPODTypeWrapper<TransformationMatrix>::create(m1.multLeft(m2))); 58 60 } 59 61 … … 73 75 } 74 76 75 RefPtr<V8SVGStaticPODTypeWrapper<TransformationMatrix> > wrapper = V8SVGStaticPODTypeWrapper<TransformationMatrix>::create(result); 76 return toV8(wrapper.get()); 77 return V8DOMWrapper::convertToV8Object(V8ClassIndex::SVGMATRIX, V8SVGStaticPODTypeWrapper<TransformationMatrix>::create(result)); 77 78 } 78 79 … … 94 95 } 95 96 96 RefPtr<V8SVGStaticPODTypeWrapper<TransformationMatrix> > wrapper = V8SVGStaticPODTypeWrapper<TransformationMatrix>::create(result); 97 return toV8(wrapper.get()); 97 return V8DOMWrapper::convertToV8Object(V8ClassIndex::SVGMATRIX, V8SVGStaticPODTypeWrapper<TransformationMatrix>::create(result)); 98 98 } 99 99 -
trunk/WebCore/bindings/v8/custom/V8StyleSheetListCustom.cpp
r54259 r54278 35 35 #include "StyleSheetList.h" 36 36 #include "V8Binding.h" 37 #include "V8CustomBinding.h" 37 38 #include "V8Proxy.h" 38 #include "V8StyleSheet.h"39 39 40 40 namespace WebCore { … … 53 53 return notHandledByInterceptor(); 54 54 55 return toV8(item->sheet());55 return V8DOMWrapper::convertToV8Object(V8ClassIndex::STYLESHEET, item->sheet()); 56 56 } 57 57 -
trunk/WebCore/bindings/v8/custom/V8TreeWalkerCustom.cpp
r54259 r54278 37 37 38 38 #include "V8Binding.h" 39 #include "V8 Node.h"39 #include "V8CustomBinding.h" 40 40 #include "V8Proxy.h" 41 41 … … 53 53 return v8::Null(); 54 54 55 return toV8(object);55 return V8DOMWrapper::convertNodeToV8Object(object); 56 56 } 57 57 -
trunk/WebCore/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp
r54259 r54278 43 43 #include "V8Binding.h" 44 44 #include "V8WebGLArray.h" 45 #include "V8WebGLBuffer.h"46 45 #include "V8WebGLByteArray.h" 47 46 #include "V8WebGLFloatArray.h" 48 #include "V8WebGLFramebuffer.h"49 47 #include "V8WebGLIntArray.h" 50 48 #include "V8WebGLProgram.h" 51 #include "V8WebGLRenderbuffer.h"52 49 #include "V8WebGLShader.h" 53 50 #include "V8WebGLShortArray.h" 54 #include "V8WebGLTexture.h"55 51 #include "V8WebGLUniformLocation.h" 56 52 #include "V8WebGLUnsignedByteArray.h" … … 196 192 return v8::Integer::NewFromUnsigned(info.getUnsignedLong()); 197 193 case WebGLGetInfo::kTypeWebGLBuffer: 198 return toV8(info.getWebGLBuffer());194 return V8DOMWrapper::convertToV8Object(V8ClassIndex::WEBGLBUFFER, info.getWebGLBuffer()); 199 195 case WebGLGetInfo::kTypeWebGLFloatArray: 200 return toV8(info.getWebGLFloatArray());196 return V8DOMWrapper::convertToV8Object(V8ClassIndex::WEBGLFLOATARRAY, info.getWebGLFloatArray()); 201 197 case WebGLGetInfo::kTypeWebGLFramebuffer: 202 return toV8(info.getWebGLFramebuffer());198 return V8DOMWrapper::convertToV8Object(V8ClassIndex::WEBGLFRAMEBUFFER, info.getWebGLFramebuffer()); 203 199 case WebGLGetInfo::kTypeWebGLIntArray: 204 return toV8(info.getWebGLIntArray());200 return V8DOMWrapper::convertToV8Object(V8ClassIndex::WEBGLINTARRAY, info.getWebGLIntArray()); 205 201 // FIXME: implement WebGLObjectArray 206 202 // case WebGLGetInfo::kTypeWebGLObjectArray: 207 203 case WebGLGetInfo::kTypeWebGLProgram: 208 return toV8(info.getWebGLProgram());204 return V8DOMWrapper::convertToV8Object(V8ClassIndex::WEBGLPROGRAM, info.getWebGLProgram()); 209 205 case WebGLGetInfo::kTypeWebGLRenderbuffer: 210 return toV8(info.getWebGLRenderbuffer());206 return V8DOMWrapper::convertToV8Object(V8ClassIndex::WEBGLRENDERBUFFER, info.getWebGLRenderbuffer()); 211 207 case WebGLGetInfo::kTypeWebGLTexture: 212 return toV8(info.getWebGLTexture());208 return V8DOMWrapper::convertToV8Object(V8ClassIndex::WEBGLTEXTURE, info.getWebGLTexture()); 213 209 case WebGLGetInfo::kTypeWebGLUnsignedByteArray: 214 return toV8(info.getWebGLUnsignedByteArray());210 return V8DOMWrapper::convertToV8Object(V8ClassIndex::WEBGLUNSIGNEDBYTEARRAY, info.getWebGLUnsignedByteArray()); 215 211 default: 216 212 notImplemented(); -
trunk/WebCore/bindings/v8/custom/V8XSLTProcessorCustom.cpp
r54259 r54278 37 37 38 38 #include "V8Binding.h" 39 #include "V8CustomBinding.h" 39 40 #include "V8Document.h" 40 #include "V8DocumentFragment.h"41 41 #include "V8Node.h" 42 42 #include "V8Proxy.h" … … 79 79 Document* owner = V8Document::toNative(v8::Handle<v8::Object>::Cast(args[1])); 80 80 RefPtr<DocumentFragment> result = imp->transformToFragment(source, owner); 81 return toV8(result.release());81 return V8DOMWrapper::convertNodeToV8Object(result.release()); 82 82 } 83 83 … … 100 100 return v8::Undefined(); 101 101 102 return toV8(result.release());102 return V8DOMWrapper::convertNodeToV8Object(result.release()); 103 103 } 104 104
Note: See TracChangeset
for help on using the changeset viewer.