source: webkit/trunk/JavaScriptCore/API/JSValueRef.cpp@ 37684

Last change on this file since 37684 was 37684, checked in by Darin Adler, 17 years ago

JavaScriptCore:

2008-10-18 Darin Adler <Darin Adler>

Reviewed by Cameron Zwarich.

Use JSValuePtr everywhere instead of JSValue*. In the future, we'll be
changing JSValuePtr to be a class, and then eventually renaming it
to JSValue once that's done.

  • JavaScriptCore.exp: Update entry points, since some now take JSValue* instead of const JSValue*.
  • API/APICast.h:
  • API/JSCallbackConstructor.h:
  • API/JSCallbackFunction.cpp:
  • API/JSCallbackFunction.h:
  • API/JSCallbackObject.h:
  • API/JSCallbackObjectFunctions.h:
  • API/JSContextRef.cpp:
  • API/JSObjectRef.cpp:
  • API/JSValueRef.cpp:
  • VM/CTI.cpp:
  • VM/CTI.h:
  • VM/CodeBlock.cpp:
  • VM/CodeBlock.h:
  • VM/CodeGenerator.cpp:
  • VM/CodeGenerator.h:
  • VM/ExceptionHelpers.cpp:
  • VM/ExceptionHelpers.h:
  • VM/JSPropertyNameIterator.cpp:
  • VM/JSPropertyNameIterator.h:
  • VM/Machine.cpp:
  • VM/Machine.h:
  • VM/Register.h:
  • kjs/ArgList.cpp:
  • kjs/ArgList.h:
  • kjs/Arguments.cpp:
  • kjs/Arguments.h:
  • kjs/ArrayConstructor.cpp:
  • kjs/ArrayPrototype.cpp:
  • kjs/BooleanConstructor.cpp:
  • kjs/BooleanConstructor.h:
  • kjs/BooleanObject.h:
  • kjs/BooleanPrototype.cpp:
  • kjs/CallData.cpp:
  • kjs/CallData.h:
  • kjs/ConstructData.cpp:
  • kjs/ConstructData.h:
  • kjs/DateConstructor.cpp:
  • kjs/DateInstance.h:
  • kjs/DatePrototype.cpp:
  • kjs/DebuggerCallFrame.cpp:
  • kjs/DebuggerCallFrame.h:
  • kjs/ErrorConstructor.cpp:
  • kjs/ErrorPrototype.cpp:
  • kjs/ExecState.cpp:
  • kjs/ExecState.h:
  • kjs/FunctionConstructor.cpp:
  • kjs/FunctionPrototype.cpp:
  • kjs/GetterSetter.cpp:
  • kjs/GetterSetter.h:
  • kjs/InternalFunction.h:
  • kjs/JSActivation.cpp:
  • kjs/JSActivation.h:
  • kjs/JSArray.cpp:
  • kjs/JSArray.h:
  • kjs/JSCell.cpp:
  • kjs/JSCell.h:
  • kjs/JSFunction.cpp:
  • kjs/JSFunction.h:
  • kjs/JSGlobalData.h:
  • kjs/JSGlobalObject.cpp:
  • kjs/JSGlobalObject.h:
  • kjs/JSGlobalObjectFunctions.cpp:
  • kjs/JSGlobalObjectFunctions.h:
  • kjs/JSImmediate.cpp:
  • kjs/JSImmediate.h:
  • kjs/JSNotAnObject.cpp:
  • kjs/JSNotAnObject.h:
  • kjs/JSNumberCell.cpp:
  • kjs/JSNumberCell.h:
  • kjs/JSObject.cpp:
  • kjs/JSObject.h:
  • kjs/JSStaticScopeObject.cpp:
  • kjs/JSStaticScopeObject.h:
  • kjs/JSString.cpp:
  • kjs/JSString.h:
  • kjs/JSValue.h:
  • kjs/JSVariableObject.h:
  • kjs/JSWrapperObject.h:
  • kjs/MathObject.cpp:
  • kjs/NativeErrorConstructor.cpp:
  • kjs/NumberConstructor.cpp:
  • kjs/NumberConstructor.h:
  • kjs/NumberObject.cpp:
  • kjs/NumberObject.h:
  • kjs/NumberPrototype.cpp:
  • kjs/ObjectConstructor.cpp:
  • kjs/ObjectPrototype.cpp:
  • kjs/ObjectPrototype.h:
  • kjs/PropertyMap.h:
  • kjs/PropertySlot.cpp:
  • kjs/PropertySlot.h:
  • kjs/RegExpConstructor.cpp:
  • kjs/RegExpConstructor.h:
  • kjs/RegExpMatchesArray.h:
  • kjs/RegExpObject.cpp:
  • kjs/RegExpObject.h:
  • kjs/RegExpPrototype.cpp:
  • kjs/Shell.cpp:
  • kjs/StringConstructor.cpp:
  • kjs/StringObject.cpp:
  • kjs/StringObject.h:
  • kjs/StringObjectThatMasqueradesAsUndefined.h:
  • kjs/StringPrototype.cpp:
  • kjs/StructureID.cpp:
  • kjs/StructureID.h:
  • kjs/collector.cpp:
  • kjs/collector.h:
  • kjs/completion.h:
  • kjs/grammar.y:
  • kjs/interpreter.cpp:
  • kjs/interpreter.h:
  • kjs/lookup.cpp:
  • kjs/lookup.h:
  • kjs/nodes.h:
  • kjs/operations.cpp:
  • kjs/operations.h:
  • kjs/protect.h:
  • profiler/ProfileGenerator.cpp: Replace JSValue* with JSValuePtr.

JavaScriptGlue:

2008-10-18 Darin Adler <Darin Adler>

Reviewed by Cameron Zwarich.

Use JSValuePtr everywhere instead of JSValue*. In the future, we'll be
changing JSValuePtr to be a class, and then eventually renaming it
to JSValue once that's done.

  • JSObject.cpp:
  • JSValueWrapper.cpp:
  • UserObjectImp.cpp:
  • UserObjectImp.h: Replace JSValue* with JSValuePtr.

WebCore:

2008-10-18 Darin Adler <Darin Adler>

Reviewed by Cameron Zwarich.

Use JSValuePtr everywhere instead of JSValue*. In the future, we'll be
changing JSValuePtr to be a class, and then eventually renaming it
to JSValue once that's done.

  • bindings/js/JSAttrCustom.cpp:
  • bindings/js/JSCSSRuleCustom.cpp:
  • bindings/js/JSCSSStyleDeclarationCustom.cpp:
  • bindings/js/JSCSSValueCustom.cpp:
  • bindings/js/JSCanvasPixelArrayCustom.h:
  • bindings/js/JSCanvasRenderingContext2DCustom.cpp:
  • bindings/js/JSClipboardCustom.cpp:
  • bindings/js/JSConsoleCustom.cpp:
  • bindings/js/JSCustomSQLStatementCallback.cpp:
  • bindings/js/JSCustomSQLStatementErrorCallback.cpp:
  • bindings/js/JSCustomSQLTransactionCallback.cpp:
  • bindings/js/JSCustomSQLTransactionErrorCallback.cpp:
  • bindings/js/JSCustomVoidCallback.cpp:
  • bindings/js/JSCustomVoidCallback.h:
  • bindings/js/JSCustomXPathNSResolver.cpp:
  • bindings/js/JSDOMApplicationCacheCustom.cpp:
  • bindings/js/JSDOMBinding.cpp:
  • bindings/js/JSDOMBinding.h:
  • bindings/js/JSDOMWindowBase.cpp:
  • bindings/js/JSDOMWindowBase.h:
  • bindings/js/JSDOMWindowCustom.cpp:
  • bindings/js/JSDOMWindowCustom.h:
  • bindings/js/JSDOMWindowShell.cpp:
  • bindings/js/JSDOMWindowShell.h:
  • bindings/js/JSDatabaseCustom.cpp:
  • bindings/js/JSDocumentCustom.cpp:
  • bindings/js/JSElementCustom.cpp:
  • bindings/js/JSEventCustom.cpp:
  • bindings/js/JSEventListener.cpp:
  • bindings/js/JSEventTarget.cpp:
  • bindings/js/JSEventTargetBase.h:
  • bindings/js/JSEventTargetNodeCustom.cpp:
  • bindings/js/JSHTMLAllCollection.h:
  • bindings/js/JSHTMLAppletElementCustom.cpp:
  • bindings/js/JSHTMLCollectionCustom.cpp:
  • bindings/js/JSHTMLDocumentCustom.cpp:
  • bindings/js/JSHTMLEmbedElementCustom.cpp:
  • bindings/js/JSHTMLFormElementCustom.cpp:
  • bindings/js/JSHTMLFrameElementCustom.cpp:
  • bindings/js/JSHTMLFrameSetElementCustom.cpp:
  • bindings/js/JSHTMLIFrameElementCustom.cpp:
  • bindings/js/JSHTMLInputElementCustom.cpp:
  • bindings/js/JSHTMLObjectElementCustom.cpp:
  • bindings/js/JSHTMLOptionsCollectionCustom.cpp:
  • bindings/js/JSHTMLSelectElementCustom.cpp:
  • bindings/js/JSHTMLSelectElementCustom.h:
  • bindings/js/JSHistoryCustom.cpp:
  • bindings/js/JSImageDataCustom.cpp:
  • bindings/js/JSInspectedObjectWrapper.cpp:
  • bindings/js/JSInspectedObjectWrapper.h:
  • bindings/js/JSInspectorCallbackWrapper.cpp:
  • bindings/js/JSInspectorCallbackWrapper.h:
  • bindings/js/JSJavaScriptCallFrameCustom.cpp:
  • bindings/js/JSLocationCustom.cpp:
  • bindings/js/JSMessagePortCustom.cpp:
  • bindings/js/JSMimeTypeArrayCustom.cpp:
  • bindings/js/JSNamedNodeMapCustom.cpp:
  • bindings/js/JSNamedNodesCollection.cpp:
  • bindings/js/JSNamedNodesCollection.h:
  • bindings/js/JSNavigatorCustom.cpp:
  • bindings/js/JSNodeCustom.cpp:
  • bindings/js/JSNodeFilterCondition.cpp:
  • bindings/js/JSNodeFilterCustom.cpp:
  • bindings/js/JSNodeIteratorCustom.cpp:
  • bindings/js/JSNodeListCustom.cpp:
  • bindings/js/JSPluginArrayCustom.cpp:
  • bindings/js/JSPluginCustom.cpp:
  • bindings/js/JSPluginElementFunctions.cpp:
  • bindings/js/JSPluginElementFunctions.h:
  • bindings/js/JSQuarantinedObjectWrapper.cpp:
  • bindings/js/JSQuarantinedObjectWrapper.h:
  • bindings/js/JSRGBColor.cpp:
  • bindings/js/JSRGBColor.h:
  • bindings/js/JSSQLResultSetRowListCustom.cpp:
  • bindings/js/JSSQLTransactionCustom.cpp:
  • bindings/js/JSSVGElementInstanceCustom.cpp:
  • bindings/js/JSSVGLengthCustom.cpp:
  • bindings/js/JSSVGMatrixCustom.cpp:
  • bindings/js/JSSVGPathSegCustom.cpp:
  • bindings/js/JSSVGPathSegListCustom.cpp:
  • bindings/js/JSSVGPointListCustom.cpp:
  • bindings/js/JSSVGTransformListCustom.cpp:
  • bindings/js/JSStorageCustom.cpp:
  • bindings/js/JSStyleSheetCustom.cpp:
  • bindings/js/JSStyleSheetListCustom.cpp:
  • bindings/js/JSTextCustom.cpp:
  • bindings/js/JSTreeWalkerCustom.cpp:
  • bindings/js/JSXMLHttpRequestCustom.cpp:
  • bindings/js/JSXMLHttpRequestUploadCustom.cpp:
  • bindings/js/JSXSLTProcessorCustom.cpp:
  • bindings/js/ScheduledAction.cpp:
  • bindings/js/ScheduledAction.h:
  • bindings/js/ScriptController.cpp:
  • bindings/js/ScriptController.h:
  • bindings/objc/WebScriptObject.mm:
  • bindings/scripts/CodeGeneratorJS.pm:
  • bridge/NP_jsobject.cpp:
  • bridge/c/c_instance.cpp:
  • bridge/c/c_instance.h:
  • bridge/c/c_runtime.cpp:
  • bridge/c/c_runtime.h:
  • bridge/c/c_utility.cpp:
  • bridge/jni/jni_instance.cpp:
  • bridge/jni/jni_instance.h:
  • bridge/jni/jni_jsobject.mm:
  • bridge/jni/jni_objc.mm:
  • bridge/jni/jni_runtime.cpp:
  • bridge/jni/jni_runtime.h:
  • bridge/jni/jni_utility.cpp:
  • bridge/objc/objc_class.mm:
  • bridge/objc/objc_instance.h:
  • bridge/objc/objc_instance.mm:
  • bridge/objc/objc_runtime.h:
  • bridge/objc/objc_runtime.mm:
  • bridge/objc/objc_utility.h:
  • bridge/objc/objc_utility.mm:
  • bridge/runtime.h:
  • bridge/runtime_array.cpp:
  • bridge/runtime_array.h:
  • bridge/runtime_method.cpp:
  • bridge/runtime_method.h:
  • bridge/runtime_object.cpp:
  • bridge/runtime_object.h:
  • inspector/JavaScriptCallFrame.cpp:
  • inspector/JavaScriptCallFrame.h:
  • inspector/JavaScriptProfile.cpp:
  • inspector/JavaScriptProfileNode.cpp:
  • loader/FrameLoader.cpp:
  • loader/FrameLoader.h:
  • page/Console.cpp:
  • page/Console.h:
  • plugins/MimeTypeArray.h:
  • plugins/Plugin.h:
  • plugins/PluginArray.h:
  • xml/XMLHttpRequest.cpp: Replace JSValue* with JSValuePtr.
  • Property svn:eol-style set to native
File size: 7.6 KB
Line 
1/*
2 * Copyright (C) 2006, 2007 Apple 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
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "JSValueRef.h"
28
29#include <wtf/Platform.h>
30#include "APICast.h"
31#include "JSCallbackObject.h"
32
33#include <kjs/JSGlobalObject.h>
34#include <kjs/JSString.h>
35#include <kjs/operations.h>
36#include <kjs/protect.h>
37#include <kjs/ustring.h>
38#include <kjs/JSValue.h>
39
40#include <wtf/Assertions.h>
41
42#include <algorithm> // for std::min
43
44JSType JSValueGetType(JSContextRef, JSValueRef value)
45{
46 JSC::JSValuePtr jsValue = toJS(value);
47 if (jsValue->isUndefined())
48 return kJSTypeUndefined;
49 if (jsValue->isNull())
50 return kJSTypeNull;
51 if (jsValue->isBoolean())
52 return kJSTypeBoolean;
53 if (jsValue->isNumber())
54 return kJSTypeNumber;
55 if (jsValue->isString())
56 return kJSTypeString;
57 ASSERT(jsValue->isObject());
58 return kJSTypeObject;
59}
60
61using namespace JSC; // placed here to avoid conflict between JSC::JSType and JSType, above.
62
63bool JSValueIsUndefined(JSContextRef, JSValueRef value)
64{
65 JSValuePtr jsValue = toJS(value);
66 return jsValue->isUndefined();
67}
68
69bool JSValueIsNull(JSContextRef, JSValueRef value)
70{
71 JSValuePtr jsValue = toJS(value);
72 return jsValue->isNull();
73}
74
75bool JSValueIsBoolean(JSContextRef, JSValueRef value)
76{
77 JSValuePtr jsValue = toJS(value);
78 return jsValue->isBoolean();
79}
80
81bool JSValueIsNumber(JSContextRef, JSValueRef value)
82{
83 JSValuePtr jsValue = toJS(value);
84 return jsValue->isNumber();
85}
86
87bool JSValueIsString(JSContextRef, JSValueRef value)
88{
89 JSValuePtr jsValue = toJS(value);
90 return jsValue->isString();
91}
92
93bool JSValueIsObject(JSContextRef, JSValueRef value)
94{
95 JSValuePtr jsValue = toJS(value);
96 return jsValue->isObject();
97}
98
99bool JSValueIsObjectOfClass(JSContextRef, JSValueRef value, JSClassRef jsClass)
100{
101 JSValuePtr jsValue = toJS(value);
102
103 if (JSObject* o = jsValue->getObject()) {
104 if (o->inherits(&JSCallbackObject<JSGlobalObject>::info))
105 return static_cast<JSCallbackObject<JSGlobalObject>*>(o)->inherits(jsClass);
106 else if (o->inherits(&JSCallbackObject<JSObject>::info))
107 return static_cast<JSCallbackObject<JSObject>*>(o)->inherits(jsClass);
108 }
109 return false;
110}
111
112bool JSValueIsEqual(JSContextRef ctx, JSValueRef a, JSValueRef b, JSValueRef* exception)
113{
114 ExecState* exec = toJS(ctx);
115 exec->globalData().heap.registerThread();
116 JSLock lock(exec);
117
118 JSValuePtr jsA = toJS(a);
119 JSValuePtr jsB = toJS(b);
120
121 bool result = equal(exec, jsA, jsB); // false if an exception is thrown
122 if (exec->hadException()) {
123 if (exception)
124 *exception = toRef(exec->exception());
125 exec->clearException();
126 }
127 return result;
128}
129
130bool JSValueIsStrictEqual(JSContextRef, JSValueRef a, JSValueRef b)
131{
132 JSValuePtr jsA = toJS(a);
133 JSValuePtr jsB = toJS(b);
134
135 bool result = strictEqual(jsA, jsB);
136 return result;
137}
138
139bool JSValueIsInstanceOfConstructor(JSContextRef ctx, JSValueRef value, JSObjectRef constructor, JSValueRef* exception)
140{
141 ExecState* exec = toJS(ctx);
142 exec->globalData().heap.registerThread();
143 JSLock lock(exec);
144
145 JSValuePtr jsValue = toJS(value);
146 JSObject* jsConstructor = toJS(constructor);
147 if (!jsConstructor->structureID()->typeInfo().implementsHasInstance())
148 return false;
149 bool result = jsConstructor->hasInstance(exec, jsValue, jsConstructor->get(exec, exec->propertyNames().prototype)); // false if an exception is thrown
150 if (exec->hadException()) {
151 if (exception)
152 *exception = toRef(exec->exception());
153 exec->clearException();
154 }
155 return result;
156}
157
158JSValueRef JSValueMakeUndefined(JSContextRef)
159{
160 return toRef(jsUndefined());
161}
162
163JSValueRef JSValueMakeNull(JSContextRef)
164{
165 return toRef(jsNull());
166}
167
168JSValueRef JSValueMakeBoolean(JSContextRef, bool value)
169{
170 return toRef(jsBoolean(value));
171}
172
173JSValueRef JSValueMakeNumber(JSContextRef ctx, double value)
174{
175 ExecState* exec = toJS(ctx);
176 exec->globalData().heap.registerThread();
177 JSLock lock(exec);
178
179 return toRef(jsNumber(exec, value));
180}
181
182JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string)
183{
184 ExecState* exec = toJS(ctx);
185 exec->globalData().heap.registerThread();
186 JSLock lock(exec);
187
188 return toRef(jsString(exec, string->ustring()));
189}
190
191bool JSValueToBoolean(JSContextRef ctx, JSValueRef value)
192{
193 ExecState* exec = toJS(ctx);
194 JSValuePtr jsValue = toJS(value);
195 return jsValue->toBoolean(exec);
196}
197
198double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef* exception)
199{
200 ExecState* exec = toJS(ctx);
201 exec->globalData().heap.registerThread();
202 JSLock lock(exec);
203
204 JSValuePtr jsValue = toJS(value);
205
206 double number = jsValue->toNumber(exec);
207 if (exec->hadException()) {
208 if (exception)
209 *exception = toRef(exec->exception());
210 exec->clearException();
211 number = NaN;
212 }
213 return number;
214}
215
216JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JSValueRef* exception)
217{
218 ExecState* exec = toJS(ctx);
219 exec->globalData().heap.registerThread();
220 JSLock lock(exec);
221
222 JSValuePtr jsValue = toJS(value);
223
224 RefPtr<OpaqueJSString> stringRef(OpaqueJSString::create(jsValue->toString(exec)));
225 if (exec->hadException()) {
226 if (exception)
227 *exception = toRef(exec->exception());
228 exec->clearException();
229 stringRef.clear();
230 }
231 return stringRef.release().releaseRef();
232}
233
234JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exception)
235{
236 ExecState* exec = toJS(ctx);
237 exec->globalData().heap.registerThread();
238 JSLock lock(exec);
239
240 JSValuePtr jsValue = toJS(value);
241
242 JSObjectRef objectRef = toRef(jsValue->toObject(exec));
243 if (exec->hadException()) {
244 if (exception)
245 *exception = toRef(exec->exception());
246 exec->clearException();
247 objectRef = 0;
248 }
249 return objectRef;
250}
251
252void JSValueProtect(JSContextRef ctx, JSValueRef value)
253{
254 ExecState* exec = toJS(ctx);
255 exec->globalData().heap.registerThread();
256 JSLock lock(exec);
257
258 JSValuePtr jsValue = toJS(value);
259 gcProtect(jsValue);
260}
261
262void JSValueUnprotect(JSContextRef ctx, JSValueRef value)
263{
264 ExecState* exec = toJS(ctx);
265 exec->globalData().heap.registerThread();
266 JSLock lock(exec);
267
268 JSValuePtr jsValue = toJS(value);
269 gcUnprotect(jsValue);
270}
Note: See TracBrowser for help on using the repository browser.