source: webkit/trunk/JavaScriptCore/API/JSNode.c@ 28097

Last change on this file since 28097 was 27207, checked in by darin, 18 years ago

Reviewed by Adam.

  • turn on unused parameter waring on Mac OS X because it's already on elsewhere
  • Configurations/Base.xcconfig: Took out -wno-unused-parameter.
  • API/JSNode.c:
  • API/JSNodeList.c:
  • API/minidom.c:
  • API/testapi.c: Fixed unused variables by using them or marked them with UNUSED_PARAM.
  • kjs/CollectorHeapIntrospector.h: (KJS::CollectorHeapIntrospector::zoneCalloc): Removed parameter names to indicate they are unused.
File size: 7.4 KB
Line 
1// -*- mode: c++; c-basic-offset: 4 -*-
2/*
3 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include "JSNode.h"
28#include "JSNodeList.h"
29#include "Node.h"
30#include "NodeList.h"
31#include "UnusedParam.h"
32#include <wtf/Assertions.h>
33
34static JSValueRef JSNode_appendChild(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
35{
36 UNUSED_PARAM(context);
37 UNUSED_PARAM(function);
38
39 // Example of throwing a type error for invalid values
40 if (!JSValueIsObjectOfClass(context, thisObject, JSNode_class(context))) {
41 JSStringRef message = JSStringCreateWithUTF8CString("TypeError: appendChild can only be called on nodes");
42 *exception = JSValueMakeString(context, message);
43 JSStringRelease(message);
44 } else if (argumentCount < 1 || !JSValueIsObjectOfClass(context, arguments[0], JSNode_class(context))) {
45 JSStringRef message = JSStringCreateWithUTF8CString("TypeError: first argument to appendChild must be a node");
46 *exception = JSValueMakeString(context, message);
47 JSStringRelease(message);
48 } else {
49 Node* node = JSObjectGetPrivate(thisObject);
50 Node* child = JSObjectGetPrivate(JSValueToObject(context, arguments[0], NULL));
51
52 Node_appendChild(node, child);
53 }
54
55 return JSValueMakeUndefined(context);
56}
57
58static JSValueRef JSNode_removeChild(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
59{
60 UNUSED_PARAM(context);
61 UNUSED_PARAM(function);
62
63 // Example of ignoring invalid values
64 if (argumentCount > 0) {
65 if (JSValueIsObjectOfClass(context, thisObject, JSNode_class(context))) {
66 if (JSValueIsObjectOfClass(context, arguments[0], JSNode_class(context))) {
67 Node* node = JSObjectGetPrivate(thisObject);
68 Node* child = JSObjectGetPrivate(JSValueToObject(context, arguments[0], exception));
69
70 Node_removeChild(node, child);
71 }
72 }
73 }
74
75 return JSValueMakeUndefined(context);
76}
77
78static JSValueRef JSNode_replaceChild(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
79{
80 UNUSED_PARAM(context);
81 UNUSED_PARAM(function);
82
83 if (argumentCount > 1) {
84 if (JSValueIsObjectOfClass(context, thisObject, JSNode_class(context))) {
85 if (JSValueIsObjectOfClass(context, arguments[0], JSNode_class(context))) {
86 if (JSValueIsObjectOfClass(context, arguments[1], JSNode_class(context))) {
87 Node* node = JSObjectGetPrivate(thisObject);
88 Node* newChild = JSObjectGetPrivate(JSValueToObject(context, arguments[0], exception));
89 Node* oldChild = JSObjectGetPrivate(JSValueToObject(context, arguments[1], exception));
90
91 Node_replaceChild(node, newChild, oldChild);
92 }
93 }
94 }
95 }
96
97 return JSValueMakeUndefined(context);
98}
99
100static JSStaticFunction JSNode_staticFunctions[] = {
101 { "appendChild", JSNode_appendChild, kJSPropertyAttributeDontDelete },
102 { "removeChild", JSNode_removeChild, kJSPropertyAttributeDontDelete },
103 { "replaceChild", JSNode_replaceChild, kJSPropertyAttributeDontDelete },
104 { 0, 0, 0 }
105};
106
107static JSValueRef JSNode_getNodeType(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
108{
109 UNUSED_PARAM(context);
110 UNUSED_PARAM(propertyName);
111 UNUSED_PARAM(exception);
112
113 Node* node = JSObjectGetPrivate(object);
114 if (node) {
115 JSStringRef nodeType = JSStringCreateWithUTF8CString(node->nodeType);
116 JSValueRef value = JSValueMakeString(context, nodeType);
117 JSStringRelease(nodeType);
118 return value;
119 }
120
121 return NULL;
122}
123
124static JSValueRef JSNode_getChildNodes(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
125{
126 UNUSED_PARAM(propertyName);
127 UNUSED_PARAM(exception);
128
129 Node* node = JSObjectGetPrivate(thisObject);
130 ASSERT(node);
131 return JSNodeList_new(context, NodeList_new(node));
132}
133
134static JSValueRef JSNode_getFirstChild(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
135{
136 UNUSED_PARAM(context);
137 UNUSED_PARAM(propertyName);
138 UNUSED_PARAM(object);
139 UNUSED_PARAM(exception);
140
141 return JSValueMakeUndefined(context);
142}
143
144static JSStaticValue JSNode_staticValues[] = {
145 { "nodeType", JSNode_getNodeType, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
146 { "childNodes", JSNode_getChildNodes, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
147 { "firstChild", JSNode_getFirstChild, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
148 { 0, 0, 0, 0 }
149};
150
151static void JSNode_initialize(JSContextRef context, JSObjectRef object)
152{
153 UNUSED_PARAM(context);
154
155 Node* node = JSObjectGetPrivate(object);
156 ASSERT(node);
157
158 Node_ref(node);
159}
160
161static void JSNode_finalize(JSObjectRef object)
162{
163 Node* node = JSObjectGetPrivate(object);
164 ASSERT(node);
165
166 Node_deref(node);
167}
168
169JSClassRef JSNode_class(JSContextRef context)
170{
171 UNUSED_PARAM(context);
172
173 static JSClassRef jsClass;
174 if (!jsClass) {
175 JSClassDefinition definition = kJSClassDefinitionEmpty;
176 definition.staticValues = JSNode_staticValues;
177 definition.staticFunctions = JSNode_staticFunctions;
178 definition.initialize = JSNode_initialize;
179 definition.finalize = JSNode_finalize;
180
181 jsClass = JSClassCreate(&definition);
182 }
183 return jsClass;
184}
185
186JSObjectRef JSNode_new(JSContextRef context, Node* node)
187{
188 return JSObjectMake(context, JSNode_class(context), node);
189}
190
191JSObjectRef JSNode_construct(JSContextRef context, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
192{
193 UNUSED_PARAM(object);
194 UNUSED_PARAM(argumentCount);
195 UNUSED_PARAM(arguments);
196 UNUSED_PARAM(exception);
197
198 return JSNode_new(context, Node_new());
199}
Note: See TracBrowser for help on using the repository browser.