| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #ifndef V8Collection_h | |
| 32 #define V8Collection_h | |
| 33 | |
| 34 #include "V8Node.h" | |
| 35 #include "bindings/v8/V8Binding.h" | |
| 36 #include "core/html/HTMLFormElement.h" | |
| 37 #include "core/html/HTMLSelectElement.h" | |
| 38 #include <v8.h> | |
| 39 | |
| 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. | |
| 43 | |
| 44 template<class T> static v8::Handle<v8::Value> getV8Object(T* implementation, v8
::Handle<v8::Object> creationContext, v8::Isolate* isolate) | |
| 45 { | |
| 46 if (!implementation) | |
| 47 return v8Undefined(); | |
| 48 return toV8(implementation, creationContext, isolate); | |
| 49 } | |
| 50 | |
| 51 template<class Collection> static Collection* toNativeCollection(v8::Local<v8::O
bject> object) | |
| 52 { | |
| 53 return reinterpret_cast<Collection*>(object->GetAlignedPointerFromInternalFi
eld(v8DOMWrapperObjectIndex)); | |
| 54 } | |
| 55 | |
| 56 template<class T> static v8::Handle<v8::Value> getV8Object(PassRefPtr<T> impleme
ntation, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) | |
| 57 { | |
| 58 return getV8Object(implementation.get(), creationContext, isolate); | |
| 59 } | |
| 60 | |
| 61 // Get an array containing the names of indexed properties of HTMLSelectElement
and HTMLFormElement. | |
| 62 template<class Collection> static void nodeCollectionIndexedPropertyEnumerator(c
onst v8::PropertyCallbackInfo<v8::Array>& info) | |
| 63 { | |
| 64 ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder())); | |
| 65 Collection* collection = toNativeCollection<Collection>(info.Holder()); | |
| 66 int length = collection->length(); | |
| 67 v8::Handle<v8::Array> properties = v8::Array::New(length); | |
| 68 for (int i = 0; i < length; ++i) { | |
| 69 // FIXME: Do we need to check that the item function returns a non-null
value for this index? | |
| 70 v8::Handle<v8::Integer> integer = v8::Integer::New(i, info.GetIsolate())
; | |
| 71 properties->Set(integer, integer); | |
| 72 } | |
| 73 v8SetReturnValue(info, properties); | |
| 74 } | |
| 75 | |
| 76 v8::Handle<v8::Value> toOptionsCollectionSetter(uint32_t index, v8::Handle<v8::V
alue>, HTMLSelectElement*, v8::Isolate*); | |
| 77 | |
| 78 } // namespace WebCore | |
| 79 | |
| 80 #endif // V8Collection_h | |
| OLD | NEW |