tizen beta release
[framework/web/webkit-efl.git] / DerivedSources / WebCore / JSDOMSelection.cpp
1 /*
2     This file is part of the WebKit open source project.
3     This file has been generated by generate-bindings.pl. DO NOT MODIFY!
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Library General Public
7     License as published by the Free Software Foundation; either
8     version 2 of the License, or (at your option) any later version.
9
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13     Library General Public License for more details.
14
15     You should have received a copy of the GNU Library General Public License
16     along with this library; see the file COPYING.LIB.  If not, write to
17     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18     Boston, MA 02110-1301, USA.
19 */
20
21 #include "config.h"
22 #include "JSDOMSelection.h"
23
24 #include "DOMSelection.h"
25 #include "ExceptionCode.h"
26 #include "JSDOMBinding.h"
27 #include "JSNode.h"
28 #include "JSRange.h"
29 #include "KURL.h"
30 #include "Node.h"
31 #include "Range.h"
32 #include <runtime/Error.h>
33 #include <runtime/JSString.h>
34 #include <wtf/GetPtr.h>
35
36 using namespace JSC;
37
38 namespace WebCore {
39
40 ASSERT_CLASS_FITS_IN_CELL(JSDOMSelection);
41
42 /* Hash table */
43 #if ENABLE(JIT)
44 #define THUNK_GENERATOR(generator) , generator
45 #else
46 #define THUNK_GENERATOR(generator)
47 #endif
48 #if ENABLE(DFG_JIT)
49 #define INTRINSIC(intrinsic) , intrinsic
50 #else
51 #define INTRINSIC(intrinsic)
52 #endif
53
54 static const HashTableValue JSDOMSelectionTableValues[] =
55 {
56     { "anchorNode", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMSelectionAnchorNode), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
57     { "anchorOffset", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMSelectionAnchorOffset), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
58     { "focusNode", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMSelectionFocusNode), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
59     { "focusOffset", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMSelectionFocusOffset), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
60     { "isCollapsed", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMSelectionIsCollapsed), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
61     { "rangeCount", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMSelectionRangeCount), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
62     { "baseNode", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMSelectionBaseNode), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
63     { "baseOffset", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMSelectionBaseOffset), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
64     { "extentNode", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMSelectionExtentNode), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
65     { "extentOffset", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMSelectionExtentOffset), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
66     { "type", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMSelectionType), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
67     { 0, 0, 0, 0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) }
68 };
69
70 #undef THUNK_GENERATOR
71 static const HashTable JSDOMSelectionTable = { 34, 31, JSDOMSelectionTableValues, 0 };
72 /* Hash table for prototype */
73 #if ENABLE(JIT)
74 #define THUNK_GENERATOR(generator) , generator
75 #else
76 #define THUNK_GENERATOR(generator)
77 #endif
78 #if ENABLE(DFG_JIT)
79 #define INTRINSIC(intrinsic) , intrinsic
80 #else
81 #define INTRINSIC(intrinsic)
82 #endif
83
84 static const HashTableValue JSDOMSelectionPrototypeTableValues[] =
85 {
86     { "collapse", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsDOMSelectionPrototypeFunctionCollapse), (intptr_t)2 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
87     { "collapseToEnd", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsDOMSelectionPrototypeFunctionCollapseToEnd), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
88     { "collapseToStart", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsDOMSelectionPrototypeFunctionCollapseToStart), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
89     { "deleteFromDocument", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsDOMSelectionPrototypeFunctionDeleteFromDocument), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
90     { "containsNode", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsDOMSelectionPrototypeFunctionContainsNode), (intptr_t)2 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
91     { "selectAllChildren", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsDOMSelectionPrototypeFunctionSelectAllChildren), (intptr_t)1 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
92     { "extend", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsDOMSelectionPrototypeFunctionExtend), (intptr_t)2 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
93     { "getRangeAt", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsDOMSelectionPrototypeFunctionGetRangeAt), (intptr_t)1 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
94     { "removeAllRanges", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsDOMSelectionPrototypeFunctionRemoveAllRanges), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
95     { "addRange", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsDOMSelectionPrototypeFunctionAddRange), (intptr_t)1 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
96     { "toString", DontDelete | DontEnum | Function, (intptr_t)static_cast<NativeFunction>(jsDOMSelectionPrototypeFunctionToString), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
97     { "modify", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsDOMSelectionPrototypeFunctionModify), (intptr_t)3 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
98     { "setBaseAndExtent", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsDOMSelectionPrototypeFunctionSetBaseAndExtent), (intptr_t)4 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
99     { "setPosition", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsDOMSelectionPrototypeFunctionSetPosition), (intptr_t)2 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
100     { "empty", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsDOMSelectionPrototypeFunctionEmpty), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
101     { 0, 0, 0, 0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) }
102 };
103
104 #undef THUNK_GENERATOR
105 static const HashTable JSDOMSelectionPrototypeTable = { 34, 31, JSDOMSelectionPrototypeTableValues, 0 };
106 const ClassInfo JSDOMSelectionPrototype::s_info = { "DOMSelectionPrototype", &JSC::JSNonFinalObject::s_info, &JSDOMSelectionPrototypeTable, 0, CREATE_METHOD_TABLE(JSDOMSelectionPrototype) };
107
108 JSObject* JSDOMSelectionPrototype::self(ExecState* exec, JSGlobalObject* globalObject)
109 {
110     return getDOMPrototype<JSDOMSelection>(exec, globalObject);
111 }
112
113 bool JSDOMSelectionPrototype::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
114 {
115     JSDOMSelectionPrototype* thisObject = jsCast<JSDOMSelectionPrototype*>(cell);
116     return getStaticFunctionSlot<JSObject>(exec, &JSDOMSelectionPrototypeTable, thisObject, propertyName, slot);
117 }
118
119 bool JSDOMSelectionPrototype::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
120 {
121     JSDOMSelectionPrototype* thisObject = jsCast<JSDOMSelectionPrototype*>(object);
122     return getStaticFunctionDescriptor<JSObject>(exec, &JSDOMSelectionPrototypeTable, thisObject, propertyName, descriptor);
123 }
124
125 const ClassInfo JSDOMSelection::s_info = { "DOMSelection", &JSDOMWrapper::s_info, &JSDOMSelectionTable, 0 , CREATE_METHOD_TABLE(JSDOMSelection) };
126
127 JSDOMSelection::JSDOMSelection(Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<DOMSelection> impl)
128     : JSDOMWrapper(structure, globalObject)
129     , m_impl(impl.leakRef())
130 {
131 }
132
133 void JSDOMSelection::finishCreation(JSGlobalData& globalData)
134 {
135     Base::finishCreation(globalData);
136     ASSERT(inherits(&s_info));
137 }
138
139 JSObject* JSDOMSelection::createPrototype(ExecState* exec, JSGlobalObject* globalObject)
140 {
141     return JSDOMSelectionPrototype::create(exec->globalData(), globalObject, JSDOMSelectionPrototype::createStructure(globalObject->globalData(), globalObject, globalObject->objectPrototype()));
142 }
143
144 bool JSDOMSelection::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
145 {
146     JSDOMSelection* thisObject = jsCast<JSDOMSelection*>(cell);
147     ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
148     return getStaticValueSlot<JSDOMSelection, Base>(exec, &JSDOMSelectionTable, thisObject, propertyName, slot);
149 }
150
151 bool JSDOMSelection::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
152 {
153     JSDOMSelection* thisObject = jsCast<JSDOMSelection*>(object);
154     ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
155     return getStaticValueDescriptor<JSDOMSelection, Base>(exec, &JSDOMSelectionTable, thisObject, propertyName, descriptor);
156 }
157
158 JSValue jsDOMSelectionAnchorNode(ExecState* exec, JSValue slotBase, const Identifier&)
159 {
160     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(slotBase));
161     UNUSED_PARAM(exec);
162     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
163     JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->anchorNode()));
164     return result;
165 }
166
167
168 JSValue jsDOMSelectionAnchorOffset(ExecState* exec, JSValue slotBase, const Identifier&)
169 {
170     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(slotBase));
171     UNUSED_PARAM(exec);
172     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
173     JSValue result = jsNumber(imp->anchorOffset());
174     return result;
175 }
176
177
178 JSValue jsDOMSelectionFocusNode(ExecState* exec, JSValue slotBase, const Identifier&)
179 {
180     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(slotBase));
181     UNUSED_PARAM(exec);
182     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
183     JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->focusNode()));
184     return result;
185 }
186
187
188 JSValue jsDOMSelectionFocusOffset(ExecState* exec, JSValue slotBase, const Identifier&)
189 {
190     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(slotBase));
191     UNUSED_PARAM(exec);
192     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
193     JSValue result = jsNumber(imp->focusOffset());
194     return result;
195 }
196
197
198 JSValue jsDOMSelectionIsCollapsed(ExecState* exec, JSValue slotBase, const Identifier&)
199 {
200     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(slotBase));
201     UNUSED_PARAM(exec);
202     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
203     JSValue result = jsBoolean(imp->isCollapsed());
204     return result;
205 }
206
207
208 JSValue jsDOMSelectionRangeCount(ExecState* exec, JSValue slotBase, const Identifier&)
209 {
210     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(slotBase));
211     UNUSED_PARAM(exec);
212     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
213     JSValue result = jsNumber(imp->rangeCount());
214     return result;
215 }
216
217
218 JSValue jsDOMSelectionBaseNode(ExecState* exec, JSValue slotBase, const Identifier&)
219 {
220     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(slotBase));
221     UNUSED_PARAM(exec);
222     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
223     JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->baseNode()));
224     return result;
225 }
226
227
228 JSValue jsDOMSelectionBaseOffset(ExecState* exec, JSValue slotBase, const Identifier&)
229 {
230     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(slotBase));
231     UNUSED_PARAM(exec);
232     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
233     JSValue result = jsNumber(imp->baseOffset());
234     return result;
235 }
236
237
238 JSValue jsDOMSelectionExtentNode(ExecState* exec, JSValue slotBase, const Identifier&)
239 {
240     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(slotBase));
241     UNUSED_PARAM(exec);
242     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
243     JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->extentNode()));
244     return result;
245 }
246
247
248 JSValue jsDOMSelectionExtentOffset(ExecState* exec, JSValue slotBase, const Identifier&)
249 {
250     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(slotBase));
251     UNUSED_PARAM(exec);
252     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
253     JSValue result = jsNumber(imp->extentOffset());
254     return result;
255 }
256
257
258 JSValue jsDOMSelectionType(ExecState* exec, JSValue slotBase, const Identifier&)
259 {
260     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(slotBase));
261     UNUSED_PARAM(exec);
262     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
263     JSValue result = jsString(exec, imp->type());
264     return result;
265 }
266
267
268 EncodedJSValue JSC_HOST_CALL jsDOMSelectionPrototypeFunctionCollapse(ExecState* exec)
269 {
270     JSValue thisValue = exec->hostThisValue();
271     if (!thisValue.inherits(&JSDOMSelection::s_info))
272         return throwVMTypeError(exec);
273     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(thisValue));
274     ASSERT_GC_OBJECT_INHERITS(castedThis, &JSDOMSelection::s_info);
275     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
276     ExceptionCode ec = 0;
277     Node* node(toNode(MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined)));
278     if (exec->hadException())
279         return JSValue::encode(jsUndefined());
280     int index(MAYBE_MISSING_PARAMETER(exec, 1, MissingIsUndefined).toInt32(exec));
281     if (exec->hadException())
282         return JSValue::encode(jsUndefined());
283     imp->collapse(node, index, ec);
284     setDOMException(exec, ec);
285     return JSValue::encode(jsUndefined());
286 }
287
288 EncodedJSValue JSC_HOST_CALL jsDOMSelectionPrototypeFunctionCollapseToEnd(ExecState* exec)
289 {
290     JSValue thisValue = exec->hostThisValue();
291     if (!thisValue.inherits(&JSDOMSelection::s_info))
292         return throwVMTypeError(exec);
293     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(thisValue));
294     ASSERT_GC_OBJECT_INHERITS(castedThis, &JSDOMSelection::s_info);
295     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
296     ExceptionCode ec = 0;
297     imp->collapseToEnd(ec);
298     setDOMException(exec, ec);
299     return JSValue::encode(jsUndefined());
300 }
301
302 EncodedJSValue JSC_HOST_CALL jsDOMSelectionPrototypeFunctionCollapseToStart(ExecState* exec)
303 {
304     JSValue thisValue = exec->hostThisValue();
305     if (!thisValue.inherits(&JSDOMSelection::s_info))
306         return throwVMTypeError(exec);
307     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(thisValue));
308     ASSERT_GC_OBJECT_INHERITS(castedThis, &JSDOMSelection::s_info);
309     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
310     ExceptionCode ec = 0;
311     imp->collapseToStart(ec);
312     setDOMException(exec, ec);
313     return JSValue::encode(jsUndefined());
314 }
315
316 EncodedJSValue JSC_HOST_CALL jsDOMSelectionPrototypeFunctionDeleteFromDocument(ExecState* exec)
317 {
318     JSValue thisValue = exec->hostThisValue();
319     if (!thisValue.inherits(&JSDOMSelection::s_info))
320         return throwVMTypeError(exec);
321     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(thisValue));
322     ASSERT_GC_OBJECT_INHERITS(castedThis, &JSDOMSelection::s_info);
323     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
324     imp->deleteFromDocument();
325     return JSValue::encode(jsUndefined());
326 }
327
328 EncodedJSValue JSC_HOST_CALL jsDOMSelectionPrototypeFunctionContainsNode(ExecState* exec)
329 {
330     JSValue thisValue = exec->hostThisValue();
331     if (!thisValue.inherits(&JSDOMSelection::s_info))
332         return throwVMTypeError(exec);
333     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(thisValue));
334     ASSERT_GC_OBJECT_INHERITS(castedThis, &JSDOMSelection::s_info);
335     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
336     Node* node(toNode(MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined)));
337     if (exec->hadException())
338         return JSValue::encode(jsUndefined());
339     bool allowPartial(MAYBE_MISSING_PARAMETER(exec, 1, MissingIsUndefined).toBoolean(exec));
340     if (exec->hadException())
341         return JSValue::encode(jsUndefined());
342
343     JSC::JSValue result = jsBoolean(imp->containsNode(node, allowPartial));
344     return JSValue::encode(result);
345 }
346
347 EncodedJSValue JSC_HOST_CALL jsDOMSelectionPrototypeFunctionSelectAllChildren(ExecState* exec)
348 {
349     JSValue thisValue = exec->hostThisValue();
350     if (!thisValue.inherits(&JSDOMSelection::s_info))
351         return throwVMTypeError(exec);
352     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(thisValue));
353     ASSERT_GC_OBJECT_INHERITS(castedThis, &JSDOMSelection::s_info);
354     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
355     ExceptionCode ec = 0;
356     Node* node(toNode(MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined)));
357     if (exec->hadException())
358         return JSValue::encode(jsUndefined());
359     imp->selectAllChildren(node, ec);
360     setDOMException(exec, ec);
361     return JSValue::encode(jsUndefined());
362 }
363
364 EncodedJSValue JSC_HOST_CALL jsDOMSelectionPrototypeFunctionExtend(ExecState* exec)
365 {
366     JSValue thisValue = exec->hostThisValue();
367     if (!thisValue.inherits(&JSDOMSelection::s_info))
368         return throwVMTypeError(exec);
369     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(thisValue));
370     ASSERT_GC_OBJECT_INHERITS(castedThis, &JSDOMSelection::s_info);
371     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
372     ExceptionCode ec = 0;
373     Node* node(toNode(MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined)));
374     if (exec->hadException())
375         return JSValue::encode(jsUndefined());
376     int offset(MAYBE_MISSING_PARAMETER(exec, 1, MissingIsUndefined).toInt32(exec));
377     if (exec->hadException())
378         return JSValue::encode(jsUndefined());
379     imp->extend(node, offset, ec);
380     setDOMException(exec, ec);
381     return JSValue::encode(jsUndefined());
382 }
383
384 EncodedJSValue JSC_HOST_CALL jsDOMSelectionPrototypeFunctionGetRangeAt(ExecState* exec)
385 {
386     JSValue thisValue = exec->hostThisValue();
387     if (!thisValue.inherits(&JSDOMSelection::s_info))
388         return throwVMTypeError(exec);
389     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(thisValue));
390     ASSERT_GC_OBJECT_INHERITS(castedThis, &JSDOMSelection::s_info);
391     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
392     ExceptionCode ec = 0;
393     int index(MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined).toInt32(exec));
394     if (exec->hadException())
395         return JSValue::encode(jsUndefined());
396
397     JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->getRangeAt(index, ec)));
398     setDOMException(exec, ec);
399     return JSValue::encode(result);
400 }
401
402 EncodedJSValue JSC_HOST_CALL jsDOMSelectionPrototypeFunctionRemoveAllRanges(ExecState* exec)
403 {
404     JSValue thisValue = exec->hostThisValue();
405     if (!thisValue.inherits(&JSDOMSelection::s_info))
406         return throwVMTypeError(exec);
407     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(thisValue));
408     ASSERT_GC_OBJECT_INHERITS(castedThis, &JSDOMSelection::s_info);
409     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
410     imp->removeAllRanges();
411     return JSValue::encode(jsUndefined());
412 }
413
414 EncodedJSValue JSC_HOST_CALL jsDOMSelectionPrototypeFunctionAddRange(ExecState* exec)
415 {
416     JSValue thisValue = exec->hostThisValue();
417     if (!thisValue.inherits(&JSDOMSelection::s_info))
418         return throwVMTypeError(exec);
419     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(thisValue));
420     ASSERT_GC_OBJECT_INHERITS(castedThis, &JSDOMSelection::s_info);
421     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
422     Range* range(toRange(MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined)));
423     if (exec->hadException())
424         return JSValue::encode(jsUndefined());
425     imp->addRange(range);
426     return JSValue::encode(jsUndefined());
427 }
428
429 EncodedJSValue JSC_HOST_CALL jsDOMSelectionPrototypeFunctionToString(ExecState* exec)
430 {
431     JSValue thisValue = exec->hostThisValue();
432     if (!thisValue.inherits(&JSDOMSelection::s_info))
433         return throwVMTypeError(exec);
434     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(thisValue));
435     ASSERT_GC_OBJECT_INHERITS(castedThis, &JSDOMSelection::s_info);
436     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
437
438     JSC::JSValue result = jsString(exec, imp->toString());
439     return JSValue::encode(result);
440 }
441
442 EncodedJSValue JSC_HOST_CALL jsDOMSelectionPrototypeFunctionModify(ExecState* exec)
443 {
444     JSValue thisValue = exec->hostThisValue();
445     if (!thisValue.inherits(&JSDOMSelection::s_info))
446         return throwVMTypeError(exec);
447     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(thisValue));
448     ASSERT_GC_OBJECT_INHERITS(castedThis, &JSDOMSelection::s_info);
449     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
450     const String& alter(ustringToString(MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined).isEmpty() ? UString() : MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined).toString(exec)));
451     if (exec->hadException())
452         return JSValue::encode(jsUndefined());
453     const String& direction(ustringToString(MAYBE_MISSING_PARAMETER(exec, 1, MissingIsUndefined).isEmpty() ? UString() : MAYBE_MISSING_PARAMETER(exec, 1, MissingIsUndefined).toString(exec)));
454     if (exec->hadException())
455         return JSValue::encode(jsUndefined());
456     const String& granularity(ustringToString(MAYBE_MISSING_PARAMETER(exec, 2, MissingIsUndefined).isEmpty() ? UString() : MAYBE_MISSING_PARAMETER(exec, 2, MissingIsUndefined).toString(exec)));
457     if (exec->hadException())
458         return JSValue::encode(jsUndefined());
459     imp->modify(alter, direction, granularity);
460     return JSValue::encode(jsUndefined());
461 }
462
463 EncodedJSValue JSC_HOST_CALL jsDOMSelectionPrototypeFunctionSetBaseAndExtent(ExecState* exec)
464 {
465     JSValue thisValue = exec->hostThisValue();
466     if (!thisValue.inherits(&JSDOMSelection::s_info))
467         return throwVMTypeError(exec);
468     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(thisValue));
469     ASSERT_GC_OBJECT_INHERITS(castedThis, &JSDOMSelection::s_info);
470     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
471     ExceptionCode ec = 0;
472     Node* baseNode(toNode(MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined)));
473     if (exec->hadException())
474         return JSValue::encode(jsUndefined());
475     int baseOffset(MAYBE_MISSING_PARAMETER(exec, 1, MissingIsUndefined).toInt32(exec));
476     if (exec->hadException())
477         return JSValue::encode(jsUndefined());
478     Node* extentNode(toNode(MAYBE_MISSING_PARAMETER(exec, 2, MissingIsUndefined)));
479     if (exec->hadException())
480         return JSValue::encode(jsUndefined());
481     int extentOffset(MAYBE_MISSING_PARAMETER(exec, 3, MissingIsUndefined).toInt32(exec));
482     if (exec->hadException())
483         return JSValue::encode(jsUndefined());
484     imp->setBaseAndExtent(baseNode, baseOffset, extentNode, extentOffset, ec);
485     setDOMException(exec, ec);
486     return JSValue::encode(jsUndefined());
487 }
488
489 EncodedJSValue JSC_HOST_CALL jsDOMSelectionPrototypeFunctionSetPosition(ExecState* exec)
490 {
491     JSValue thisValue = exec->hostThisValue();
492     if (!thisValue.inherits(&JSDOMSelection::s_info))
493         return throwVMTypeError(exec);
494     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(thisValue));
495     ASSERT_GC_OBJECT_INHERITS(castedThis, &JSDOMSelection::s_info);
496     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
497     ExceptionCode ec = 0;
498     Node* node(toNode(MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined)));
499     if (exec->hadException())
500         return JSValue::encode(jsUndefined());
501     int offset(MAYBE_MISSING_PARAMETER(exec, 1, MissingIsUndefined).toInt32(exec));
502     if (exec->hadException())
503         return JSValue::encode(jsUndefined());
504     imp->setPosition(node, offset, ec);
505     setDOMException(exec, ec);
506     return JSValue::encode(jsUndefined());
507 }
508
509 EncodedJSValue JSC_HOST_CALL jsDOMSelectionPrototypeFunctionEmpty(ExecState* exec)
510 {
511     JSValue thisValue = exec->hostThisValue();
512     if (!thisValue.inherits(&JSDOMSelection::s_info))
513         return throwVMTypeError(exec);
514     JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(thisValue));
515     ASSERT_GC_OBJECT_INHERITS(castedThis, &JSDOMSelection::s_info);
516     DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
517     imp->empty();
518     return JSValue::encode(jsUndefined());
519 }
520
521 static inline bool isObservable(JSDOMSelection* jsDOMSelection)
522 {
523     if (jsDOMSelection->hasCustomProperties())
524         return true;
525     return false;
526 }
527
528 bool JSDOMSelectionOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
529 {
530     JSDOMSelection* jsDOMSelection = static_cast<JSDOMSelection*>(handle.get().asCell());
531     if (!isObservable(jsDOMSelection))
532         return false;
533     Frame* root = jsDOMSelection->impl()->frame();
534     if (!root)
535         return false;
536     return visitor.containsOpaqueRoot(root);
537 }
538
539 void JSDOMSelectionOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
540 {
541     JSDOMSelection* jsDOMSelection = static_cast<JSDOMSelection*>(handle.get().asCell());
542     DOMWrapperWorld* world = static_cast<DOMWrapperWorld*>(context);
543     uncacheWrapper(world, jsDOMSelection->impl(), jsDOMSelection);
544     jsDOMSelection->releaseImpl();
545 }
546
547 JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, DOMSelection* impl)
548 {
549     return wrap<JSDOMSelection>(exec, globalObject, impl);
550 }
551
552 DOMSelection* toDOMSelection(JSC::JSValue value)
553 {
554     return value.inherits(&JSDOMSelection::s_info) ? static_cast<JSDOMSelection*>(asObject(value))->impl() : 0;
555 }
556
557 }