source: webkit/trunk/JavaScriptCore/kjs/MathObject.cpp@ 37868

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

JavaScriptCore:

2008-10-24 Darin Adler <Darin Adler>

  • 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/DatePrototype.h:
  • 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/FunctionPrototype.h:
  • 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/MathObject.h:
  • 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:
  • profiler/Profiler.cpp:
  • profiler/Profiler.h: Use JSValue* instead of JSValuePtr.

JavaScriptGlue:

2008-10-24 Darin Adler <Darin Adler>

  • JSObject.cpp: (nativeCallFunction):
  • JSUtils.cpp: (KJSValueToJSObject): (JSObjectKJSValue): (KJSValueToCFTypeInternal): (KJSValueToCFType):
  • JSUtils.h:
  • JSValueWrapper.cpp: (JSValueWrapper::JSValueWrapper): (JSValueWrapper::GetValue): (JSValueWrapper::JSObjectCopyProperty): (JSValueWrapper::JSObjectSetProperty): (JSValueWrapper::JSObjectCallFunction):
  • JSValueWrapper.h:
  • UserObjectImp.cpp: (UserObjectImp::callAsFunction): (UserObjectImp::userObjectGetter): (UserObjectImp::getOwnPropertySlot): (UserObjectImp::put): (UserObjectImp::toPrimitive):
  • UserObjectImp.h: (UserObjectImp::createStructureID): Use JSValue* instead of JSValuePtr.

WebCore:

2008-10-24 Darin Adler <Darin Adler>

  • 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/JSCustomXPathNSResolver.h:
  • 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/JSDedicatedWorkerCustom.cpp:
  • bindings/js/JSDocumentCustom.cpp:
  • bindings/js/JSElementCustom.cpp:
  • bindings/js/JSEventCustom.cpp:
  • bindings/js/JSEventListener.cpp:
  • bindings/js/JSEventTarget.cpp:
  • bindings/js/JSEventTarget.h:
  • 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/JSNodeFilterCondition.h:
  • 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/objc/WebScriptObjectPrivate.h:
  • 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/c/c_utility.h:
  • bridge/jni/jni_instance.cpp:
  • bridge/jni/jni_instance.h:
  • bridge/jni/jni_jsobject.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/jni/jni_utility.h:
  • bridge/objc/WebScriptObject.h:
  • bridge/objc/objc_class.h:
  • 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/qt/qt_class.cpp:
  • bridge/qt/qt_class.h:
  • bridge/qt/qt_instance.cpp:
  • bridge/qt/qt_instance.h:
  • bridge/qt/qt_runtime.cpp:
  • bridge/qt/qt_runtime.h:
  • bridge/runtime.cpp:
  • 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:
  • bridge/testqtbindings.cpp:
  • inspector/JavaScriptCallFrame.cpp:
  • inspector/JavaScriptCallFrame.h:
  • inspector/JavaScriptProfile.cpp:
  • inspector/JavaScriptProfile.h:
  • inspector/JavaScriptProfileNode.cpp:
  • inspector/JavaScriptProfileNode.h:
  • loader/FrameLoader.cpp:
  • loader/FrameLoader.h:
  • page/Console.cpp:
  • page/Console.h:
  • plugins/MimeTypeArray.h:
  • plugins/Plugin.h:
  • plugins/PluginArray.h:
  • plugins/PluginView.cpp:
  • xml/XMLHttpRequest.cpp: Use JSValue* instead of JSValuePtr.

WebKit/mac:

2008-10-24 Darin Adler <Darin Adler>

  • WebView/WebFrame.mm: (-[WebFrame _stringByEvaluatingJavaScriptFromString:forceUserGesture:]):
  • WebView/WebScriptDebugDelegate.mm: (-[WebScriptCallFrame _convertValueToObjcValue:]): (-[WebScriptCallFrame exception]): (-[WebScriptCallFrame evaluateWebScript:]):
  • WebView/WebView.mm: (aeDescFromJSValue): (-[WebView aeDescByEvaluatingJavaScriptFromString:]): Use JSValue* instead of JSValuePtr.

WebKit/qt:

2008-10-24 Darin Adler <Darin Adler>

  • Api/qwebframe.cpp: (QWebFrame::evaluateJavaScript): Use JSValue* instead of JSValuePtr.

WebKit/win:

2008-10-24 Darin Adler <Darin Adler>

  • WebScriptCallFrame.cpp: (WebScriptCallFrame::jsValueToString): (WebScriptCallFrame::stringByEvaluatingJavaScriptFromString): (WebScriptCallFrame::valueForVariable): (WebScriptCallFrame::valueByEvaluatingJavaScriptFromString):
  • WebScriptCallFrame.h:
  • WebView.cpp: (WebView::stringByEvaluatingJavaScriptFromString): Use JSValue* instead of JSValuePtr.

WebKit/wx:

2008-10-24 Darin Adler <Darin Adler>

  • WebFrame.cpp: (wxWebFrame::RunScript): Use JSValue* instead of JSValuePtr.
  • Property svn:eol-style set to native
File size: 9.4 KB
Line 
1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 2007, 2008 Apple Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser 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 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21#include "config.h"
22#include "MathObject.h"
23
24#include "ObjectPrototype.h"
25#include "operations.h"
26#include <time.h>
27#include <wtf/Assertions.h>
28#include <wtf/MathExtras.h>
29
30namespace JSC {
31
32ASSERT_CLASS_FITS_IN_CELL(MathObject);
33
34static JSValue* mathProtoFuncAbs(ExecState*, JSObject*, JSValue*, const ArgList&);
35static JSValue* mathProtoFuncACos(ExecState*, JSObject*, JSValue*, const ArgList&);
36static JSValue* mathProtoFuncASin(ExecState*, JSObject*, JSValue*, const ArgList&);
37static JSValue* mathProtoFuncATan(ExecState*, JSObject*, JSValue*, const ArgList&);
38static JSValue* mathProtoFuncATan2(ExecState*, JSObject*, JSValue*, const ArgList&);
39static JSValue* mathProtoFuncCeil(ExecState*, JSObject*, JSValue*, const ArgList&);
40static JSValue* mathProtoFuncCos(ExecState*, JSObject*, JSValue*, const ArgList&);
41static JSValue* mathProtoFuncExp(ExecState*, JSObject*, JSValue*, const ArgList&);
42static JSValue* mathProtoFuncFloor(ExecState*, JSObject*, JSValue*, const ArgList&);
43static JSValue* mathProtoFuncLog(ExecState*, JSObject*, JSValue*, const ArgList&);
44static JSValue* mathProtoFuncMax(ExecState*, JSObject*, JSValue*, const ArgList&);
45static JSValue* mathProtoFuncMin(ExecState*, JSObject*, JSValue*, const ArgList&);
46static JSValue* mathProtoFuncPow(ExecState*, JSObject*, JSValue*, const ArgList&);
47static JSValue* mathProtoFuncRandom(ExecState*, JSObject*, JSValue*, const ArgList&);
48static JSValue* mathProtoFuncRound(ExecState*, JSObject*, JSValue*, const ArgList&);
49static JSValue* mathProtoFuncSin(ExecState*, JSObject*, JSValue*, const ArgList&);
50static JSValue* mathProtoFuncSqrt(ExecState*, JSObject*, JSValue*, const ArgList&);
51static JSValue* mathProtoFuncTan(ExecState*, JSObject*, JSValue*, const ArgList&);
52
53}
54
55#include "MathObject.lut.h"
56
57namespace JSC {
58
59// ------------------------------ MathObject --------------------------------
60
61const ClassInfo MathObject::info = { "Math", 0, 0, ExecState::mathTable };
62
63/* Source for MathObject.lut.h
64@begin mathTable
65 abs mathProtoFuncAbs DontEnum|Function 1
66 acos mathProtoFuncACos DontEnum|Function 1
67 asin mathProtoFuncASin DontEnum|Function 1
68 atan mathProtoFuncATan DontEnum|Function 1
69 atan2 mathProtoFuncATan2 DontEnum|Function 2
70 ceil mathProtoFuncCeil DontEnum|Function 1
71 cos mathProtoFuncCos DontEnum|Function 1
72 exp mathProtoFuncExp DontEnum|Function 1
73 floor mathProtoFuncFloor DontEnum|Function 1
74 log mathProtoFuncLog DontEnum|Function 1
75 max mathProtoFuncMax DontEnum|Function 2
76 min mathProtoFuncMin DontEnum|Function 2
77 pow mathProtoFuncPow DontEnum|Function 2
78 random mathProtoFuncRandom DontEnum|Function 0
79 round mathProtoFuncRound DontEnum|Function 1
80 sin mathProtoFuncSin DontEnum|Function 1
81 sqrt mathProtoFuncSqrt DontEnum|Function 1
82 tan mathProtoFuncTan DontEnum|Function 1
83@end
84*/
85
86MathObject::MathObject(ExecState* exec, PassRefPtr<StructureID> structure)
87 : JSObject(structure)
88{
89 putDirectWithoutTransition(Identifier(exec, "E"), jsNumber(exec, exp(1.0)), DontDelete | DontEnum | ReadOnly);
90 putDirectWithoutTransition(Identifier(exec, "LN2"), jsNumber(exec, log(2.0)), DontDelete | DontEnum | ReadOnly);
91 putDirectWithoutTransition(Identifier(exec, "LN10"), jsNumber(exec, log(10.0)), DontDelete | DontEnum | ReadOnly);
92 putDirectWithoutTransition(Identifier(exec, "LOG2E"), jsNumber(exec, 1.0 / log(2.0)), DontDelete | DontEnum | ReadOnly);
93 putDirectWithoutTransition(Identifier(exec, "LOG10E"), jsNumber(exec, 1.0 / log(10.0)), DontDelete | DontEnum | ReadOnly);
94 putDirectWithoutTransition(Identifier(exec, "PI"), jsNumber(exec, piDouble), DontDelete | DontEnum | ReadOnly);
95 putDirectWithoutTransition(Identifier(exec, "SQRT1_2"), jsNumber(exec, sqrt(0.5)), DontDelete | DontEnum | ReadOnly);
96 putDirectWithoutTransition(Identifier(exec, "SQRT2"), jsNumber(exec, sqrt(2.0)), DontDelete | DontEnum | ReadOnly);
97}
98
99// ECMA 15.8
100
101bool MathObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot &slot)
102{
103 const HashEntry* entry = ExecState::mathTable(exec)->entry(exec, propertyName);
104
105 if (!entry)
106 return JSObject::getOwnPropertySlot(exec, propertyName, slot);
107
108 ASSERT(entry->attributes() & Function);
109 setUpStaticFunctionSlot(exec, entry, this, propertyName, slot);
110 return true;
111}
112
113// ------------------------------ Functions --------------------------------
114
115JSValue* mathProtoFuncAbs(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
116{
117 return jsNumber(exec, fabs(args.at(exec, 0)->toNumber(exec)));
118}
119
120JSValue* mathProtoFuncACos(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
121{
122 return jsNumber(exec, acos(args.at(exec, 0)->toNumber(exec)));
123}
124
125JSValue* mathProtoFuncASin(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
126{
127 return jsNumber(exec, asin(args.at(exec, 0)->toNumber(exec)));
128}
129
130JSValue* mathProtoFuncATan(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
131{
132 return jsNumber(exec, atan(args.at(exec, 0)->toNumber(exec)));
133}
134
135JSValue* mathProtoFuncATan2(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
136{
137 return jsNumber(exec, atan2(args.at(exec, 0)->toNumber(exec), args.at(exec, 1)->toNumber(exec)));
138}
139
140JSValue* mathProtoFuncCeil(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
141{
142 return jsNumber(exec, ceil(args.at(exec, 0)->toNumber(exec)));
143}
144
145JSValue* mathProtoFuncCos(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
146{
147 return jsNumber(exec, cos(args.at(exec, 0)->toNumber(exec)));
148}
149
150JSValue* mathProtoFuncExp(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
151{
152 return jsNumber(exec, exp(args.at(exec, 0)->toNumber(exec)));
153}
154
155JSValue* mathProtoFuncFloor(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
156{
157 return jsNumber(exec, floor(args.at(exec, 0)->toNumber(exec)));
158}
159
160JSValue* mathProtoFuncLog(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
161{
162 return jsNumber(exec, log(args.at(exec, 0)->toNumber(exec)));
163}
164
165JSValue* mathProtoFuncMax(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
166{
167 unsigned argsCount = args.size();
168 double result = -Inf;
169 for (unsigned k = 0; k < argsCount; ++k) {
170 double val = args.at(exec, k)->toNumber(exec);
171 if (isnan(val)) {
172 result = NaN;
173 break;
174 }
175 if (val > result || (val == 0 && result == 0 && !signbit(val)))
176 result = val;
177 }
178 return jsNumber(exec, result);
179}
180
181JSValue* mathProtoFuncMin(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
182{
183 unsigned argsCount = args.size();
184 double result = +Inf;
185 for (unsigned k = 0; k < argsCount; ++k) {
186 double val = args.at(exec, k)->toNumber(exec);
187 if (isnan(val)) {
188 result = NaN;
189 break;
190 }
191 if (val < result || (val == 0 && result == 0 && signbit(val)))
192 result = val;
193 }
194 return jsNumber(exec, result);
195}
196
197JSValue* mathProtoFuncPow(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
198{
199 // ECMA 15.8.2.1.13
200
201 double arg = args.at(exec, 0)->toNumber(exec);
202 double arg2 = args.at(exec, 1)->toNumber(exec);
203
204 if (isnan(arg2))
205 return jsNaN(exec);
206 if (isinf(arg2) && fabs(arg) == 1)
207 return jsNaN(exec);
208 return jsNumber(exec, pow(arg, arg2));
209}
210
211JSValue* mathProtoFuncRandom(ExecState* exec, JSObject*, JSValue*, const ArgList&)
212{
213#if !ENABLE(JSC_MULTIPLE_THREADS)
214 static bool didInitRandom;
215 if (!didInitRandom) {
216 wtf_random_init();
217 didInitRandom = true;
218 }
219#endif
220
221 return jsNumber(exec, wtf_random());
222}
223
224JSValue* mathProtoFuncRound(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
225{
226 double arg = args.at(exec, 0)->toNumber(exec);
227 if (signbit(arg) && arg >= -0.5)
228 return jsNumber(exec, -0.0);
229 return jsNumber(exec, floor(arg + 0.5));
230}
231
232JSValue* mathProtoFuncSin(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
233{
234 return jsNumber(exec, sin(args.at(exec, 0)->toNumber(exec)));
235}
236
237JSValue* mathProtoFuncSqrt(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
238{
239 return jsNumber(exec, sqrt(args.at(exec, 0)->toNumber(exec)));
240}
241
242JSValue* mathProtoFuncTan(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
243{
244 return jsNumber(exec, tan(args.at(exec, 0)->toNumber(exec)));
245}
246
247} // namespace JSC
Note: See TracBrowser for help on using the repository browser.