|
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 |
|
23 #include "JSNode.h" |
|
24 |
|
25 #include <wtf/GetPtr.h> |
|
26 |
|
27 #include "Document.h" |
|
28 #include "JSDocument.h" |
|
29 #include "JSNamedNodeMap.h" |
|
30 #include "JSNode.h" |
|
31 #include "JSNodeList.h" |
|
32 #include "NameNodeList.h" |
|
33 #include "NamedAttrMap.h" |
|
34 #include "NamedNodeMap.h" |
|
35 #include "Node.h" |
|
36 #include "NodeList.h" |
|
37 #include "PlatformString.h" |
|
38 |
|
39 using namespace KJS; |
|
40 |
|
41 namespace WebCore { |
|
42 |
|
43 /* Hash table */ |
|
44 |
|
45 static const HashEntry JSNodeTableEntries[] = |
|
46 { |
|
47 { "ownerDocument", JSNode::OwnerDocumentAttrNum, DontDelete|ReadOnly, 0, 0 }, |
|
48 { "firstChild", JSNode::FirstChildAttrNum, DontDelete|ReadOnly, 0, &JSNodeTableEntries[18] }, |
|
49 { "previousSibling", JSNode::PreviousSiblingAttrNum, DontDelete|ReadOnly, 0, 0 }, |
|
50 { "constructor", JSNode::ConstructorAttrNum, DontDelete|DontEnum|ReadOnly, 0, 0 }, |
|
51 { 0, 0, 0, 0, 0 }, |
|
52 { 0, 0, 0, 0, 0 }, |
|
53 { "nodeName", JSNode::NodeNameAttrNum, DontDelete|ReadOnly, 0, 0 }, |
|
54 { "nodeValue", JSNode::NodeValueAttrNum, DontDelete, 0, 0 }, |
|
55 { 0, 0, 0, 0, 0 }, |
|
56 { "lastChild", JSNode::LastChildAttrNum, DontDelete|ReadOnly, 0, &JSNodeTableEntries[19] }, |
|
57 { "localName", JSNode::LocalNameAttrNum, DontDelete|ReadOnly, 0, 0 }, |
|
58 { 0, 0, 0, 0, 0 }, |
|
59 { "nextSibling", JSNode::NextSiblingAttrNum, DontDelete|ReadOnly, 0, &JSNodeTableEntries[20] }, |
|
60 { "nodeType", JSNode::NodeTypeAttrNum, DontDelete|ReadOnly, 0, 0 }, |
|
61 { "childNodes", JSNode::ChildNodesAttrNum, DontDelete|ReadOnly, 0, 0 }, |
|
62 { "textContent", JSNode::TextContentAttrNum, DontDelete, 0, 0 }, |
|
63 { "baseURI", JSNode::BaseURIAttrNum, DontDelete|ReadOnly, 0, 0 }, |
|
64 { "parentNode", JSNode::ParentNodeAttrNum, DontDelete|ReadOnly, 0, &JSNodeTableEntries[21] }, |
|
65 { "attributes", JSNode::AttributesAttrNum, DontDelete|ReadOnly, 0, 0 }, |
|
66 { "namespaceURI", JSNode::NamespaceURIAttrNum, DontDelete|ReadOnly, 0, 0 }, |
|
67 { "prefix", JSNode::PrefixAttrNum, DontDelete, 0, 0 }, |
|
68 { "parentElement", JSNode::ParentElementAttrNum, DontDelete|ReadOnly, 0, 0 } |
|
69 }; |
|
70 |
|
71 static const HashTable JSNodeTable = |
|
72 { |
|
73 2, 22, JSNodeTableEntries, 18 |
|
74 }; |
|
75 |
|
76 /* Hash table for constructor */ |
|
77 |
|
78 static const HashEntry JSNodeConstructorTableEntries[] = |
|
79 { |
|
80 { "DOCUMENT_FRAGMENT_NODE", Node::DOCUMENT_FRAGMENT_NODE, DontDelete|ReadOnly, 0, 0 }, |
|
81 { "ENTITY_REFERENCE_NODE", Node::ENTITY_REFERENCE_NODE, DontDelete|ReadOnly, 0, &JSNodeConstructorTableEntries[14] }, |
|
82 { "CDATA_SECTION_NODE", Node::CDATA_SECTION_NODE, DontDelete|ReadOnly, 0, &JSNodeConstructorTableEntries[12] }, |
|
83 { 0, 0, 0, 0, 0 }, |
|
84 { "TEXT_NODE", Node::TEXT_NODE, DontDelete|ReadOnly, 0, 0 }, |
|
85 { 0, 0, 0, 0, 0 }, |
|
86 { "COMMENT_NODE", Node::COMMENT_NODE, DontDelete|ReadOnly, 0, &JSNodeConstructorTableEntries[13] }, |
|
87 { 0, 0, 0, 0, 0 }, |
|
88 { 0, 0, 0, 0, 0 }, |
|
89 { "ELEMENT_NODE", Node::ELEMENT_NODE, DontDelete|ReadOnly, 0, 0 }, |
|
90 { "ATTRIBUTE_NODE", Node::ATTRIBUTE_NODE, DontDelete|ReadOnly, 0, 0 }, |
|
91 { "ENTITY_NODE", Node::ENTITY_NODE, DontDelete|ReadOnly, 0, 0 }, |
|
92 { "PROCESSING_INSTRUCTION_NODE", Node::PROCESSING_INSTRUCTION_NODE, DontDelete|ReadOnly, 0, 0 }, |
|
93 { "DOCUMENT_NODE", Node::DOCUMENT_NODE, DontDelete|ReadOnly, 0, 0 }, |
|
94 { "DOCUMENT_TYPE_NODE", Node::DOCUMENT_TYPE_NODE, DontDelete|ReadOnly, 0, &JSNodeConstructorTableEntries[15] }, |
|
95 { "NOTATION_NODE", Node::NOTATION_NODE, DontDelete|ReadOnly, 0, 0 } |
|
96 }; |
|
97 |
|
98 static const HashTable JSNodeConstructorTable = |
|
99 { |
|
100 2, 16, JSNodeConstructorTableEntries, 12 |
|
101 }; |
|
102 |
|
103 class JSNodeConstructor : public DOMObject { |
|
104 public: |
|
105 JSNodeConstructor(ExecState* exec) |
|
106 { |
|
107 setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype()); |
|
108 putDirect(exec->propertyNames().prototype, JSNodePrototype::self(exec), None); |
|
109 } |
|
110 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); |
|
111 JSValue* getValueProperty(ExecState*, int token) const; |
|
112 virtual const ClassInfo* classInfo() const { return &info; } |
|
113 static const ClassInfo info; |
|
114 |
|
115 virtual bool implementsHasInstance() const { return true; } |
|
116 }; |
|
117 |
|
118 const ClassInfo JSNodeConstructor::info = { "NodeConstructor", 0, &JSNodeConstructorTable, 0 }; |
|
119 |
|
120 bool JSNodeConstructor::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) |
|
121 { |
|
122 return getStaticValueSlot<JSNodeConstructor, DOMObject>(exec, &JSNodeConstructorTable, this, propertyName, slot); |
|
123 } |
|
124 |
|
125 JSValue* JSNodeConstructor::getValueProperty(ExecState*, int token) const |
|
126 { |
|
127 // The token is the numeric value of its associated constant |
|
128 return jsNumber(token); |
|
129 } |
|
130 |
|
131 /* Hash table for prototype */ |
|
132 |
|
133 static const HashEntry JSNodePrototypeTableEntries[] = |
|
134 { |
|
135 { 0, 0, 0, 0, 0 }, |
|
136 { "cloneNode", JSNode::CloneNodeFuncNum, DontDelete|Function, 1, 0 }, |
|
137 { "DOCUMENT_NODE", Node::DOCUMENT_NODE, DontDelete|ReadOnly, 0, &JSNodePrototypeTableEntries[28] }, |
|
138 { 0, 0, 0, 0, 0 }, |
|
139 { 0, 0, 0, 0, 0 }, |
|
140 { "isSameNode", JSNode::IsSameNodeFuncNum, DontDelete|Function, 1, 0 }, |
|
141 { 0, 0, 0, 0, 0 }, |
|
142 { 0, 0, 0, 0, 0 }, |
|
143 { "hasChildNodes", JSNode::HasChildNodesFuncNum, DontDelete|Function, 0, &JSNodePrototypeTableEntries[32] }, |
|
144 { "appendChild", JSNode::AppendChildFuncNum, DontDelete|Function, 1, 0 }, |
|
145 { "PROCESSING_INSTRUCTION_NODE", Node::PROCESSING_INSTRUCTION_NODE, DontDelete|ReadOnly, 0, &JSNodePrototypeTableEntries[30] }, |
|
146 { "NOTATION_NODE", Node::NOTATION_NODE, DontDelete|ReadOnly, 0, 0 }, |
|
147 { "CDATA_SECTION_NODE", Node::CDATA_SECTION_NODE, DontDelete|ReadOnly, 0, &JSNodePrototypeTableEntries[33] }, |
|
148 { "ELEMENT_NODE", Node::ELEMENT_NODE, DontDelete|ReadOnly, 0, &JSNodePrototypeTableEntries[34] }, |
|
149 { "ATTRIBUTE_NODE", Node::ATTRIBUTE_NODE, DontDelete|ReadOnly, 0, &JSNodePrototypeTableEntries[29] }, |
|
150 { 0, 0, 0, 0, 0 }, |
|
151 { 0, 0, 0, 0, 0 }, |
|
152 { 0, 0, 0, 0, 0 }, |
|
153 { "DOCUMENT_FRAGMENT_NODE", Node::DOCUMENT_FRAGMENT_NODE, DontDelete|ReadOnly, 0, &JSNodePrototypeTableEntries[27] }, |
|
154 { "ENTITY_NODE", Node::ENTITY_NODE, DontDelete|ReadOnly, 0, 0 }, |
|
155 { "TEXT_NODE", Node::TEXT_NODE, DontDelete|ReadOnly, 0, 0 }, |
|
156 { 0, 0, 0, 0, 0 }, |
|
157 { "isEqualNode", JSNode::IsEqualNodeFuncNum, DontDelete|Function, 1, 0 }, |
|
158 { "isDefaultNamespace", JSNode::IsDefaultNamespaceFuncNum, DontDelete|Function, 1, 0 }, |
|
159 { "COMMENT_NODE", Node::COMMENT_NODE, DontDelete|ReadOnly, 0, &JSNodePrototypeTableEntries[31] }, |
|
160 { "ENTITY_REFERENCE_NODE", Node::ENTITY_REFERENCE_NODE, DontDelete|ReadOnly, 0, &JSNodePrototypeTableEntries[26] }, |
|
161 { "DOCUMENT_TYPE_NODE", Node::DOCUMENT_TYPE_NODE, DontDelete|ReadOnly, 0, 0 }, |
|
162 { "insertBefore", JSNode::InsertBeforeFuncNum, DontDelete|Function, 2, 0 }, |
|
163 { "replaceChild", JSNode::ReplaceChildFuncNum, DontDelete|Function, 2, 0 }, |
|
164 { "removeChild", JSNode::RemoveChildFuncNum, DontDelete|Function, 1, 0 }, |
|
165 { "normalize", JSNode::NormalizeFuncNum, DontDelete|Function, 0, 0 }, |
|
166 { "isSupported", JSNode::IsSupportedFuncNum, DontDelete|Function, 2, 0 }, |
|
167 { "hasAttributes", JSNode::HasAttributesFuncNum, DontDelete|Function, 0, 0 }, |
|
168 { "lookupPrefix", JSNode::LookupPrefixFuncNum, DontDelete|Function, 1, 0 }, |
|
169 { "lookupNamespaceURI", JSNode::LookupNamespaceURIFuncNum, DontDelete|Function, 1, 0 } |
|
170 }; |
|
171 |
|
172 static const HashTable JSNodePrototypeTable = |
|
173 { |
|
174 2, 35, JSNodePrototypeTableEntries, 26 |
|
175 }; |
|
176 |
|
177 const ClassInfo JSNodePrototype::info = { "NodePrototype", 0, &JSNodePrototypeTable, 0 }; |
|
178 |
|
179 JSObject* JSNodePrototype::self(ExecState* exec) |
|
180 { |
|
181 return KJS::cacheGlobalObject<JSNodePrototype>(exec, "[[JSNode.prototype]]"); |
|
182 } |
|
183 |
|
184 bool JSNodePrototype::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) |
|
185 { |
|
186 return getStaticPropertySlot<JSNodePrototypeFunction, JSNodePrototype, JSObject>(exec, &JSNodePrototypeTable, this, propertyName, slot); |
|
187 } |
|
188 |
|
189 JSValue* JSNodePrototype::getValueProperty(ExecState*, int token) const |
|
190 { |
|
191 // The token is the numeric value of its associated constant |
|
192 return jsNumber(token); |
|
193 } |
|
194 |
|
195 const ClassInfo JSNode::info = { "Node", 0, &JSNodeTable, 0 }; |
|
196 |
|
197 JSNode::JSNode(ExecState* exec, Node* impl) |
|
198 : m_impl(impl) |
|
199 { |
|
200 setPrototype(JSNodePrototype::self(exec)); |
|
201 } |
|
202 |
|
203 JSNode::~JSNode() |
|
204 { |
|
205 ScriptInterpreter::forgetDOMNodeForDocument(m_impl->document(), m_impl.get()); |
|
206 } |
|
207 |
|
208 bool JSNode::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) |
|
209 { |
|
210 return getStaticValueSlot<JSNode, KJS::DOMObject>(exec, &JSNodeTable, this, propertyName, slot); |
|
211 } |
|
212 |
|
213 JSValue* JSNode::getValueProperty(ExecState* exec, int token) const |
|
214 { |
|
215 switch (token) { |
|
216 case NodeNameAttrNum: { |
|
217 Node* imp = static_cast<Node*>(impl()); |
|
218 |
|
219 return jsStringOrNull(imp->nodeName()); |
|
220 } |
|
221 case NodeValueAttrNum: { |
|
222 Node* imp = static_cast<Node*>(impl()); |
|
223 |
|
224 return jsStringOrNull(imp->nodeValue()); |
|
225 } |
|
226 case NodeTypeAttrNum: { |
|
227 Node* imp = static_cast<Node*>(impl()); |
|
228 |
|
229 return jsNumber(imp->nodeType()); |
|
230 } |
|
231 case ParentNodeAttrNum: { |
|
232 Node* imp = static_cast<Node*>(impl()); |
|
233 |
|
234 return toJS(exec, WTF::getPtr(imp->parentNode())); |
|
235 } |
|
236 case ChildNodesAttrNum: { |
|
237 Node* imp = static_cast<Node*>(impl()); |
|
238 |
|
239 return toJS(exec, WTF::getPtr(imp->childNodes())); |
|
240 } |
|
241 case FirstChildAttrNum: { |
|
242 Node* imp = static_cast<Node*>(impl()); |
|
243 |
|
244 return toJS(exec, WTF::getPtr(imp->firstChild())); |
|
245 } |
|
246 case LastChildAttrNum: { |
|
247 Node* imp = static_cast<Node*>(impl()); |
|
248 |
|
249 return toJS(exec, WTF::getPtr(imp->lastChild())); |
|
250 } |
|
251 case PreviousSiblingAttrNum: { |
|
252 Node* imp = static_cast<Node*>(impl()); |
|
253 |
|
254 return toJS(exec, WTF::getPtr(imp->previousSibling())); |
|
255 } |
|
256 case NextSiblingAttrNum: { |
|
257 Node* imp = static_cast<Node*>(impl()); |
|
258 |
|
259 return toJS(exec, WTF::getPtr(imp->nextSibling())); |
|
260 } |
|
261 case AttributesAttrNum: { |
|
262 Node* imp = static_cast<Node*>(impl()); |
|
263 |
|
264 return toJS(exec, WTF::getPtr(imp->attributes())); |
|
265 } |
|
266 case OwnerDocumentAttrNum: { |
|
267 Node* imp = static_cast<Node*>(impl()); |
|
268 |
|
269 return toJS(exec, WTF::getPtr(imp->ownerDocument())); |
|
270 } |
|
271 case NamespaceURIAttrNum: { |
|
272 Node* imp = static_cast<Node*>(impl()); |
|
273 |
|
274 return jsStringOrNull(imp->namespaceURI()); |
|
275 } |
|
276 case PrefixAttrNum: { |
|
277 Node* imp = static_cast<Node*>(impl()); |
|
278 |
|
279 return jsStringOrNull(imp->prefix()); |
|
280 } |
|
281 case LocalNameAttrNum: { |
|
282 Node* imp = static_cast<Node*>(impl()); |
|
283 |
|
284 return jsStringOrNull(imp->localName()); |
|
285 } |
|
286 case BaseURIAttrNum: { |
|
287 Node* imp = static_cast<Node*>(impl()); |
|
288 |
|
289 return jsStringOrNull(imp->baseURI()); |
|
290 } |
|
291 case TextContentAttrNum: { |
|
292 Node* imp = static_cast<Node*>(impl()); |
|
293 |
|
294 return jsStringOrNull(imp->textContent()); |
|
295 } |
|
296 case ParentElementAttrNum: { |
|
297 Node* imp = static_cast<Node*>(impl()); |
|
298 |
|
299 return toJS(exec, WTF::getPtr(imp->parentElement())); |
|
300 } |
|
301 case ConstructorAttrNum: |
|
302 return getConstructor(exec); |
|
303 } |
|
304 return 0; |
|
305 } |
|
306 |
|
307 void JSNode::put(ExecState* exec, const Identifier& propertyName, JSValue* value, int attr) |
|
308 { |
|
309 lookupPut<JSNode, KJS::DOMObject>(exec, propertyName, value, attr, &JSNodeTable, this); |
|
310 } |
|
311 |
|
312 void JSNode::putValueProperty(ExecState* exec, int token, JSValue* value, int /*attr*/) |
|
313 { |
|
314 switch (token) { |
|
315 case NodeValueAttrNum: { |
|
316 Node* imp = static_cast<Node*>(impl()); |
|
317 |
|
318 ExceptionCode ec = 0; |
|
319 imp->setNodeValue(valueToStringWithNullCheck(exec, value), ec); |
|
320 setDOMException(exec, ec); |
|
321 break; |
|
322 } |
|
323 case PrefixAttrNum: { |
|
324 Node* imp = static_cast<Node*>(impl()); |
|
325 |
|
326 ExceptionCode ec = 0; |
|
327 imp->setPrefix(valueToStringWithNullCheck(exec, value), ec); |
|
328 setDOMException(exec, ec); |
|
329 break; |
|
330 } |
|
331 case TextContentAttrNum: { |
|
332 Node* imp = static_cast<Node*>(impl()); |
|
333 |
|
334 ExceptionCode ec = 0; |
|
335 imp->setTextContent(valueToStringWithNullCheck(exec, value), ec); |
|
336 setDOMException(exec, ec); |
|
337 break; |
|
338 } |
|
339 } |
|
340 } |
|
341 |
|
342 JSValue* JSNode::getConstructor(ExecState* exec) |
|
343 { |
|
344 return KJS::cacheGlobalObject<JSNodeConstructor>(exec, "[[Node.constructor]]"); |
|
345 } |
|
346 JSValue* JSNodePrototypeFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) |
|
347 { |
|
348 if (!thisObj->inherits(&JSNode::info)) |
|
349 return throwError(exec, TypeError); |
|
350 |
|
351 Node* imp = static_cast<Node*>(static_cast<JSNode*>(thisObj)->impl()); |
|
352 |
|
353 switch (id) { |
|
354 case JSNode::InsertBeforeFuncNum: { |
|
355 return static_cast<JSNode*>(thisObj)->insertBefore(exec, args); |
|
356 } |
|
357 case JSNode::ReplaceChildFuncNum: { |
|
358 return static_cast<JSNode*>(thisObj)->replaceChild(exec, args); |
|
359 } |
|
360 case JSNode::RemoveChildFuncNum: { |
|
361 return static_cast<JSNode*>(thisObj)->removeChild(exec, args); |
|
362 } |
|
363 case JSNode::AppendChildFuncNum: { |
|
364 return static_cast<JSNode*>(thisObj)->appendChild(exec, args); |
|
365 } |
|
366 case JSNode::HasChildNodesFuncNum: { |
|
367 |
|
368 |
|
369 KJS::JSValue* result = jsBoolean(imp->hasChildNodes()); |
|
370 return result; |
|
371 } |
|
372 case JSNode::CloneNodeFuncNum: { |
|
373 bool deep = args[0]->toBoolean(exec); |
|
374 |
|
375 |
|
376 KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->cloneNode(deep))); |
|
377 return result; |
|
378 } |
|
379 case JSNode::NormalizeFuncNum: { |
|
380 |
|
381 imp->normalize(); |
|
382 return jsUndefined(); |
|
383 } |
|
384 case JSNode::IsSupportedFuncNum: { |
|
385 String feature = args[0]->toString(exec); |
|
386 String version = valueToStringWithNullCheck(exec, args[1]); |
|
387 |
|
388 |
|
389 KJS::JSValue* result = jsBoolean(imp->isSupported(feature, version)); |
|
390 return result; |
|
391 } |
|
392 case JSNode::HasAttributesFuncNum: { |
|
393 |
|
394 |
|
395 KJS::JSValue* result = jsBoolean(imp->hasAttributes()); |
|
396 return result; |
|
397 } |
|
398 case JSNode::IsSameNodeFuncNum: { |
|
399 Node* other = toNode(args[0]); |
|
400 |
|
401 |
|
402 KJS::JSValue* result = jsBoolean(imp->isSameNode(other)); |
|
403 return result; |
|
404 } |
|
405 case JSNode::IsEqualNodeFuncNum: { |
|
406 Node* other = toNode(args[0]); |
|
407 |
|
408 |
|
409 KJS::JSValue* result = jsBoolean(imp->isEqualNode(other)); |
|
410 return result; |
|
411 } |
|
412 case JSNode::LookupPrefixFuncNum: { |
|
413 String namespaceURI = valueToStringWithNullCheck(exec, args[0]); |
|
414 |
|
415 |
|
416 KJS::JSValue* result = jsStringOrNull(imp->lookupPrefix(namespaceURI)); |
|
417 return result; |
|
418 } |
|
419 case JSNode::IsDefaultNamespaceFuncNum: { |
|
420 String namespaceURI = valueToStringWithNullCheck(exec, args[0]); |
|
421 |
|
422 |
|
423 KJS::JSValue* result = jsBoolean(imp->isDefaultNamespace(namespaceURI)); |
|
424 return result; |
|
425 } |
|
426 case JSNode::LookupNamespaceURIFuncNum: { |
|
427 String prefix = valueToStringWithNullCheck(exec, args[0]); |
|
428 |
|
429 |
|
430 KJS::JSValue* result = jsStringOrNull(imp->lookupNamespaceURI(prefix)); |
|
431 return result; |
|
432 } |
|
433 } |
|
434 return 0; |
|
435 } |
|
436 Node* toNode(KJS::JSValue* val) |
|
437 { |
|
438 return val->isObject(&JSNode::info) ? static_cast<JSNode*>(val)->impl() : 0; |
|
439 } |
|
440 |
|
441 } |