source: webkit/trunk/JavaScriptCore/kjs/JSGlobalObjectFunctions.cpp@ 37747

Last change on this file since 37747 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: 13.3 KB
Line 
1/*
2 * Copyright (C) 1999-2002 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
5 * Copyright (C) 2007 Cameron Zwarich ([email protected])
6 * Copyright (C) 2007 Maks Orlovich
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25#include "config.h"
26#include "JSGlobalObjectFunctions.h"
27
28#include "ExecState.h"
29#include "GlobalEvalFunction.h"
30#include "JSGlobalObject.h"
31#include "JSString.h"
32#include "Machine.h"
33#include "Parser.h"
34#include "dtoa.h"
35#include "lexer.h"
36#include "nodes.h"
37#include <errno.h>
38#include <stdio.h>
39#include <stdlib.h>
40#include <string.h>
41#include <wtf/ASCIICType.h>
42#include <wtf/Assertions.h>
43#include <wtf/MathExtras.h>
44#include <wtf/unicode/UTF8.h>
45
46using namespace WTF;
47using namespace Unicode;
48
49namespace JSC {
50
51static JSValuePtr encode(ExecState* exec, const ArgList& args, const char* doNotEscape)
52{
53 UString str = args.at(exec, 0)->toString(exec);
54 CString cstr = str.UTF8String(true);
55 if (!cstr.c_str())
56 return throwError(exec, URIError, "String contained an illegal UTF-16 sequence.");
57
58 UString result = "";
59 const char* p = cstr.c_str();
60 for (size_t k = 0; k < cstr.size(); k++, p++) {
61 char c = *p;
62 if (c && strchr(doNotEscape, c))
63 result.append(c);
64 else {
65 char tmp[4];
66 sprintf(tmp, "%%%02X", static_cast<unsigned char>(c));
67 result += tmp;
68 }
69 }
70 return jsString(exec, result);
71}
72
73static JSValuePtr decode(ExecState* exec, const ArgList& args, const char* doNotUnescape, bool strict)
74{
75 UString result = "";
76 UString str = args.at(exec, 0)->toString(exec);
77 int k = 0;
78 int len = str.size();
79 const UChar* d = str.data();
80 UChar u = 0;
81 while (k < len) {
82 const UChar* p = d + k;
83 UChar c = *p;
84 if (c == '%') {
85 int charLen = 0;
86 if (k <= len - 3 && isASCIIHexDigit(p[1]) && isASCIIHexDigit(p[2])) {
87 const char b0 = Lexer::convertHex(p[1], p[2]);
88 const int sequenceLen = UTF8SequenceLength(b0);
89 if (sequenceLen != 0 && k <= len - sequenceLen * 3) {
90 charLen = sequenceLen * 3;
91 char sequence[5];
92 sequence[0] = b0;
93 for (int i = 1; i < sequenceLen; ++i) {
94 const UChar* q = p + i * 3;
95 if (q[0] == '%' && isASCIIHexDigit(q[1]) && isASCIIHexDigit(q[2]))
96 sequence[i] = Lexer::convertHex(q[1], q[2]);
97 else {
98 charLen = 0;
99 break;
100 }
101 }
102 if (charLen != 0) {
103 sequence[sequenceLen] = 0;
104 const int character = decodeUTF8Sequence(sequence);
105 if (character < 0 || character >= 0x110000)
106 charLen = 0;
107 else if (character >= 0x10000) {
108 // Convert to surrogate pair.
109 result.append(static_cast<UChar>(0xD800 | ((character - 0x10000) >> 10)));
110 u = static_cast<UChar>(0xDC00 | ((character - 0x10000) & 0x3FF));
111 } else
112 u = static_cast<UChar>(character);
113 }
114 }
115 }
116 if (charLen == 0) {
117 if (strict)
118 return throwError(exec, URIError);
119 // The only case where we don't use "strict" mode is the "unescape" function.
120 // For that, it's good to support the wonky "%u" syntax for compatibility with WinIE.
121 if (k <= len - 6 && p[1] == 'u'
122 && isASCIIHexDigit(p[2]) && isASCIIHexDigit(p[3])
123 && isASCIIHexDigit(p[4]) && isASCIIHexDigit(p[5])) {
124 charLen = 6;
125 u = Lexer::convertUnicode(p[2], p[3], p[4], p[5]);
126 }
127 }
128 if (charLen && (u == 0 || u >= 128 || !strchr(doNotUnescape, u))) {
129 c = u;
130 k += charLen - 1;
131 }
132 }
133 k++;
134 result.append(c);
135 }
136 return jsString(exec, result);
137}
138
139bool isStrWhiteSpace(UChar c)
140{
141 switch (c) {
142 case 0x0009:
143 case 0x000A:
144 case 0x000B:
145 case 0x000C:
146 case 0x000D:
147 case 0x0020:
148 case 0x00A0:
149 case 0x2028:
150 case 0x2029:
151 return true;
152 default:
153 return c > 0xff && isSeparatorSpace(c);
154 }
155}
156
157static int parseDigit(unsigned short c, int radix)
158{
159 int digit = -1;
160
161 if (c >= '0' && c <= '9')
162 digit = c - '0';
163 else if (c >= 'A' && c <= 'Z')
164 digit = c - 'A' + 10;
165 else if (c >= 'a' && c <= 'z')
166 digit = c - 'a' + 10;
167
168 if (digit >= radix)
169 return -1;
170 return digit;
171}
172
173double parseIntOverflow(const char* s, int length, int radix)
174{
175 double number = 0.0;
176 double radixMultiplier = 1.0;
177
178 for (const char* p = s + length - 1; p >= s; p--) {
179 if (radixMultiplier == Inf) {
180 if (*p != '0') {
181 number = Inf;
182 break;
183 }
184 } else {
185 int digit = parseDigit(*p, radix);
186 number += digit * radixMultiplier;
187 }
188
189 radixMultiplier *= radix;
190 }
191
192 return number;
193}
194
195static double parseInt(const UString& s, int radix)
196{
197 int length = s.size();
198 const UChar* data = s.data();
199 int p = 0;
200
201 while (p < length && isStrWhiteSpace(data[p]))
202 ++p;
203
204 double sign = 1;
205 if (p < length) {
206 if (data[p] == '+')
207 ++p;
208 else if (data[p] == '-') {
209 sign = -1;
210 ++p;
211 }
212 }
213
214 if ((radix == 0 || radix == 16) && length - p >= 2 && data[p] == '0' && (data[p + 1] == 'x' || data[p + 1] == 'X')) {
215 radix = 16;
216 p += 2;
217 } else if (radix == 0) {
218 if (p < length && data[p] == '0')
219 radix = 8;
220 else
221 radix = 10;
222 }
223
224 if (radix < 2 || radix > 36)
225 return NaN;
226
227 int firstDigitPosition = p;
228 bool sawDigit = false;
229 double number = 0;
230 while (p < length) {
231 int digit = parseDigit(data[p], radix);
232 if (digit == -1)
233 break;
234 sawDigit = true;
235 number *= radix;
236 number += digit;
237 ++p;
238 }
239
240 if (number >= mantissaOverflowLowerBound) {
241 if (radix == 10)
242 number = strtod(s.substr(firstDigitPosition, p - firstDigitPosition).ascii(), 0);
243 else if (radix == 2 || radix == 4 || radix == 8 || radix == 16 || radix == 32)
244 number = parseIntOverflow(s.substr(firstDigitPosition, p - firstDigitPosition).ascii(), p - firstDigitPosition, radix);
245 }
246
247 if (!sawDigit)
248 return NaN;
249
250 return sign * number;
251}
252
253static double parseFloat(const UString& s)
254{
255 // Check for 0x prefix here, because toDouble allows it, but we must treat it as 0.
256 // Need to skip any whitespace and then one + or - sign.
257 int length = s.size();
258 const UChar* data = s.data();
259 int p = 0;
260 while (p < length && isStrWhiteSpace(data[p]))
261 ++p;
262
263 if (p < length && (data[p] == '+' || data[p] == '-'))
264 ++p;
265
266 if (length - p >= 2 && data[p] == '0' && (data[p + 1] == 'x' || data[p + 1] == 'X'))
267 return 0;
268
269 return s.toDouble(true /*tolerant*/, false /* NaN for empty string */);
270}
271
272JSValuePtr globalFuncEval(ExecState* exec, JSObject* function, JSValuePtr thisValue, const ArgList& args)
273{
274 JSObject* thisObject = thisValue->toThisObject(exec);
275 JSGlobalObject* globalObject = thisObject->toGlobalObject(exec);
276 if (!globalObject || globalObject->evalFunction() != function)
277 return throwError(exec, EvalError, "The \"this\" value passed to eval must be the global object from which eval originated");
278
279 JSValuePtr x = args.at(exec, 0);
280 if (!x->isString())
281 return x;
282
283 UString s = x->toString(exec);
284
285 int errLine;
286 UString errMsg;
287
288 SourceCode source = makeSource(s);
289 RefPtr<EvalNode> evalNode = exec->globalData().parser->parse<EvalNode>(exec, exec->dynamicGlobalObject()->debugger(), source, &errLine, &errMsg);
290
291 if (!evalNode)
292 return throwError(exec, SyntaxError, errMsg, errLine, source.provider()->asID(), NULL);
293
294 return exec->machine()->execute(evalNode.get(), exec, thisObject, globalObject->globalScopeChain().node(), exec->exceptionSlot());
295}
296
297JSValuePtr globalFuncParseInt(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
298{
299 JSValuePtr value = args.at(exec, 0);
300 int32_t radix = args.at(exec, 1)->toInt32(exec);
301
302 if (value->isNumber() && (radix == 0 || radix == 10)) {
303 if (JSImmediate::isImmediate(value))
304 return value;
305 double d = value->uncheckedGetNumber();
306 if (!isfinite(d))
307 return JSImmediate::zeroImmediate();
308 return jsNumber(exec, floor(d));
309 }
310
311 return jsNumber(exec, parseInt(value->toString(exec), radix));
312}
313
314JSValuePtr globalFuncParseFloat(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
315{
316 return jsNumber(exec, parseFloat(args.at(exec, 0)->toString(exec)));
317}
318
319JSValuePtr globalFuncIsNaN(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
320{
321 return jsBoolean(isnan(args.at(exec, 0)->toNumber(exec)));
322}
323
324JSValuePtr globalFuncIsFinite(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
325{
326 double n = args.at(exec, 0)->toNumber(exec);
327 return jsBoolean(!isnan(n) && !isinf(n));
328}
329
330JSValuePtr globalFuncDecodeURI(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
331{
332 static const char do_not_unescape_when_decoding_URI[] =
333 "#$&+,/:;=?@";
334
335 return decode(exec, args, do_not_unescape_when_decoding_URI, true);
336}
337
338JSValuePtr globalFuncDecodeURIComponent(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
339{
340 return decode(exec, args, "", true);
341}
342
343JSValuePtr globalFuncEncodeURI(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
344{
345 static const char do_not_escape_when_encoding_URI[] =
346 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
347 "abcdefghijklmnopqrstuvwxyz"
348 "0123456789"
349 "!#$&'()*+,-./:;=?@_~";
350
351 return encode(exec, args, do_not_escape_when_encoding_URI);
352}
353
354JSValuePtr globalFuncEncodeURIComponent(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
355{
356 static const char do_not_escape_when_encoding_URI_component[] =
357 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
358 "abcdefghijklmnopqrstuvwxyz"
359 "0123456789"
360 "!'()*-._~";
361
362 return encode(exec, args, do_not_escape_when_encoding_URI_component);
363}
364
365JSValuePtr globalFuncEscape(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
366{
367 static const char do_not_escape[] =
368 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
369 "abcdefghijklmnopqrstuvwxyz"
370 "0123456789"
371 "*+-./@_";
372
373 UString result = "";
374 UString s;
375 UString str = args.at(exec, 0)->toString(exec);
376 const UChar* c = str.data();
377 for (int k = 0; k < str.size(); k++, c++) {
378 int u = c[0];
379 if (u > 255) {
380 char tmp[7];
381 sprintf(tmp, "%%u%04X", u);
382 s = UString(tmp);
383 } else if (u != 0 && strchr(do_not_escape, static_cast<char>(u)))
384 s = UString(c, 1);
385 else {
386 char tmp[4];
387 sprintf(tmp, "%%%02X", u);
388 s = UString(tmp);
389 }
390 result += s;
391 }
392
393 return jsString(exec, result);
394}
395
396JSValuePtr globalFuncUnescape(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
397{
398 UString result = "";
399 UString str = args.at(exec, 0)->toString(exec);
400 int k = 0;
401 int len = str.size();
402 while (k < len) {
403 const UChar* c = str.data() + k;
404 UChar u;
405 if (c[0] == '%' && k <= len - 6 && c[1] == 'u') {
406 if (Lexer::isHexDigit(c[2]) && Lexer::isHexDigit(c[3]) && Lexer::isHexDigit(c[4]) && Lexer::isHexDigit(c[5])) {
407 u = Lexer::convertUnicode(c[2], c[3], c[4], c[5]);
408 c = &u;
409 k += 5;
410 }
411 } else if (c[0] == '%' && k <= len - 3 && Lexer::isHexDigit(c[1]) && Lexer::isHexDigit(c[2])) {
412 u = UChar(Lexer::convertHex(c[1], c[2]));
413 c = &u;
414 k += 2;
415 }
416 k++;
417 result.append(*c);
418 }
419
420 return jsString(exec, result);
421}
422
423#ifndef NDEBUG
424JSValuePtr globalFuncKJSPrint(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
425{
426 CStringBuffer string;
427 args.at(exec, 0)->toString(exec).getCString(string);
428 puts(string.data());
429 return jsUndefined();
430}
431#endif
432
433} // namespace JSC
Note: See TracBrowser for help on using the repository browser.