50
static JSValuePtr encode(ExecState* exec, const ArgList& args, const char* doNotEscape)
51
static JSValue encode(ExecState* exec, const ArgList& args, const char* doNotEscape)
52
UString str = args.at(exec, 0).toString(exec);
53
UString str = args.at(0).toString(exec);
53
54
CString cstr = str.UTF8String(true);
55
56
return throwError(exec, URIError, "String contained an illegal UTF-16 sequence.");
69
70
return jsString(exec, result);
72
static JSValuePtr decode(ExecState* exec, const ArgList& args, const char* doNotUnescape, bool strict)
73
static JSValue decode(ExecState* exec, const ArgList& args, const char* doNotUnescape, bool strict)
74
75
UString result = "";
75
UString str = args.at(exec, 0).toString(exec);
76
UString str = args.at(0).toString(exec);
77
78
int len = str.size();
78
79
const UChar* d = str.data();
268
269
return s.toDouble(true /*tolerant*/, false /* NaN for empty string */);
271
JSValuePtr globalFuncEval(ExecState* exec, JSObject* function, JSValuePtr thisValue, const ArgList& args)
272
JSValue JSC_HOST_CALL globalFuncEval(ExecState* exec, JSObject* function, JSValue thisValue, const ArgList& args)
273
274
JSObject* thisObject = thisValue.toThisObject(exec);
274
275
JSObject* unwrappedObject = thisObject->unwrappedObject();
275
276
if (!unwrappedObject->isGlobalObject() || static_cast<JSGlobalObject*>(unwrappedObject)->evalFunction() != function)
276
277
return throwError(exec, EvalError, "The \"this\" value passed to eval must be the global object from which eval originated");
278
JSValuePtr x = args.at(exec, 0);
279
JSValue x = args.at(0);
279
280
if (!x.isString())
282
283
UString s = x.toString(exec);
285
LiteralParser preparser(exec, s);
286
if (JSValue parsedObject = preparser.tryLiteralParse())
293
298
return exec->interpreter()->execute(evalNode.get(), exec, thisObject, static_cast<JSGlobalObject*>(unwrappedObject)->globalScopeChain().node(), exec->exceptionSlot());
296
JSValuePtr globalFuncParseInt(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
301
JSValue JSC_HOST_CALL globalFuncParseInt(ExecState* exec, JSObject*, JSValue, const ArgList& args)
298
JSValuePtr value = args.at(exec, 0);
299
int32_t radix = args.at(exec, 1).toInt32(exec);
303
JSValue value = args.at(0);
304
int32_t radix = args.at(1).toInt32(exec);
301
306
if (value.isNumber() && (radix == 0 || radix == 10)) {
302
307
if (value.isInt32Fast())
306
311
return jsNumber(exec, (d > 0) ? floor(d) : ceil(d));
307
312
if (isnan(d) || isinf(d))
308
313
return jsNaN(&exec->globalData());
314
return jsNumber(exec, 0);
312
317
return jsNumber(exec, parseInt(value.toString(exec), radix));
315
JSValuePtr globalFuncParseFloat(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
317
return jsNumber(exec, parseFloat(args.at(exec, 0).toString(exec)));
320
JSValuePtr globalFuncIsNaN(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
322
return jsBoolean(isnan(args.at(exec, 0).toNumber(exec)));
325
JSValuePtr globalFuncIsFinite(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
327
double n = args.at(exec, 0).toNumber(exec);
320
JSValue JSC_HOST_CALL globalFuncParseFloat(ExecState* exec, JSObject*, JSValue, const ArgList& args)
322
return jsNumber(exec, parseFloat(args.at(0).toString(exec)));
325
JSValue JSC_HOST_CALL globalFuncIsNaN(ExecState* exec, JSObject*, JSValue, const ArgList& args)
327
return jsBoolean(isnan(args.at(0).toNumber(exec)));
330
JSValue JSC_HOST_CALL globalFuncIsFinite(ExecState* exec, JSObject*, JSValue, const ArgList& args)
332
double n = args.at(0).toNumber(exec);
328
333
return jsBoolean(!isnan(n) && !isinf(n));
331
JSValuePtr globalFuncDecodeURI(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
336
JSValue JSC_HOST_CALL globalFuncDecodeURI(ExecState* exec, JSObject*, JSValue, const ArgList& args)
333
338
static const char do_not_unescape_when_decoding_URI[] =
336
341
return decode(exec, args, do_not_unescape_when_decoding_URI, true);
339
JSValuePtr globalFuncDecodeURIComponent(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
344
JSValue JSC_HOST_CALL globalFuncDecodeURIComponent(ExecState* exec, JSObject*, JSValue, const ArgList& args)
341
346
return decode(exec, args, "", true);
344
JSValuePtr globalFuncEncodeURI(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
349
JSValue JSC_HOST_CALL globalFuncEncodeURI(ExecState* exec, JSObject*, JSValue, const ArgList& args)
346
351
static const char do_not_escape_when_encoding_URI[] =
347
352
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
352
357
return encode(exec, args, do_not_escape_when_encoding_URI);
355
JSValuePtr globalFuncEncodeURIComponent(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
360
JSValue JSC_HOST_CALL globalFuncEncodeURIComponent(ExecState* exec, JSObject*, JSValue, const ArgList& args)
357
362
static const char do_not_escape_when_encoding_URI_component[] =
358
363
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
363
368
return encode(exec, args, do_not_escape_when_encoding_URI_component);
366
JSValuePtr globalFuncEscape(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
371
JSValue JSC_HOST_CALL globalFuncEscape(ExecState* exec, JSObject*, JSValue, const ArgList& args)
368
373
static const char do_not_escape[] =
369
374
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
374
379
UString result = "";
376
UString str = args.at(exec, 0).toString(exec);
381
UString str = args.at(0).toString(exec);
377
382
const UChar* c = str.data();
378
383
for (int k = 0; k < str.size(); k++, c++) {
394
399
return jsString(exec, result);
397
JSValuePtr globalFuncUnescape(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
402
JSValue JSC_HOST_CALL globalFuncUnescape(ExecState* exec, JSObject*, JSValue, const ArgList& args)
399
404
UString result = "";
400
UString str = args.at(exec, 0).toString(exec);
405
UString str = args.at(0).toString(exec);
402
407
int len = str.size();
403
408
while (k < len) {
404
409
const UChar* c = str.data() + k;
406
411
if (c[0] == '%' && k <= len - 6 && c[1] == 'u') {
407
if (Lexer::isHexDigit(c[2]) && Lexer::isHexDigit(c[3]) && Lexer::isHexDigit(c[4]) && Lexer::isHexDigit(c[5])) {
412
if (isASCIIHexDigit(c[2]) && isASCIIHexDigit(c[3]) && isASCIIHexDigit(c[4]) && isASCIIHexDigit(c[5])) {
408
413
u = Lexer::convertUnicode(c[2], c[3], c[4], c[5]);
412
} else if (c[0] == '%' && k <= len - 3 && Lexer::isHexDigit(c[1]) && Lexer::isHexDigit(c[2])) {
417
} else if (c[0] == '%' && k <= len - 3 && isASCIIHexDigit(c[1]) && isASCIIHexDigit(c[2])) {
413
418
u = UChar(Lexer::convertHex(c[1], c[2]));
425
JSValuePtr globalFuncJSCPrint(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
430
JSValue JSC_HOST_CALL globalFuncJSCPrint(ExecState* exec, JSObject*, JSValue, const ArgList& args)
427
432
CStringBuffer string;
428
args.at(exec, 0).toString(exec).getCString(string);
433
args.at(0).toString(exec).getCString(string);
429
434
puts(string.data());
430
435
return jsUndefined();