~ubuntu-branches/ubuntu/karmic/webkit/karmic-proposed

« back to all changes in this revision

Viewing changes to JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gustavo Noronha Silva
  • Date: 2009-05-15 18:30:58 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090515183058-50q5exjo9b1kxy9s
Tags: 1.1.7-1
* New upstream release
* debian/libwebkit-1.0-2.symbols:
- updated with the new symbols in 1.1.7
* debian/libwebkit-dev.install, debian/libwebkit-dev.links,
  debian/rules:
- Build, and ship gtk-doc documentation (Closes: #526683)
* debian/copyright:
- updated.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include "CallFrame.h"
29
29
#include "GlobalEvalFunction.h"
30
30
#include "JSGlobalObject.h"
 
31
#include "LiteralParser.h"
31
32
#include "JSString.h"
32
33
#include "Interpreter.h"
33
34
#include "Parser.h"
47
48
 
48
49
namespace JSC {
49
50
 
50
 
static JSValuePtr encode(ExecState* exec, const ArgList& args, const char* doNotEscape)
 
51
static JSValue encode(ExecState* exec, const ArgList& args, const char* doNotEscape)
51
52
{
52
 
    UString str = args.at(exec, 0).toString(exec);
 
53
    UString str = args.at(0).toString(exec);
53
54
    CString cstr = str.UTF8String(true);
54
55
    if (!cstr.c_str())
55
56
        return throwError(exec, URIError, "String contained an illegal UTF-16 sequence.");
69
70
    return jsString(exec, result);
70
71
}
71
72
 
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)
73
74
{
74
75
    UString result = "";
75
 
    UString str = args.at(exec, 0).toString(exec);
 
76
    UString str = args.at(0).toString(exec);
76
77
    int k = 0;
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 */);
269
270
}
270
271
 
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)
272
273
{
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");
277
278
 
278
 
    JSValuePtr x = args.at(exec, 0);
 
279
    JSValue x = args.at(0);
279
280
    if (!x.isString())
280
281
        return x;
281
282
 
282
283
    UString s = x.toString(exec);
283
284
 
 
285
    LiteralParser preparser(exec, s);
 
286
    if (JSValue parsedObject = preparser.tryLiteralParse())
 
287
        return parsedObject;
 
288
 
284
289
    int errLine;
285
290
    UString errMsg;
286
291
 
293
298
    return exec->interpreter()->execute(evalNode.get(), exec, thisObject, static_cast<JSGlobalObject*>(unwrappedObject)->globalScopeChain().node(), exec->exceptionSlot());
294
299
}
295
300
 
296
 
JSValuePtr globalFuncParseInt(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
 
301
JSValue JSC_HOST_CALL globalFuncParseInt(ExecState* exec, JSObject*, JSValue, const ArgList& args)
297
302
{
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);
300
305
 
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());
309
 
        return js0();
 
314
        return jsNumber(exec, 0);
310
315
    }
311
316
 
312
317
    return jsNumber(exec, parseInt(value.toString(exec), radix));
313
318
}
314
319
 
315
 
JSValuePtr globalFuncParseFloat(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
316
 
{
317
 
    return jsNumber(exec, parseFloat(args.at(exec, 0).toString(exec)));
318
 
}
319
 
 
320
 
JSValuePtr globalFuncIsNaN(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
321
 
{
322
 
    return jsBoolean(isnan(args.at(exec, 0).toNumber(exec)));
323
 
}
324
 
 
325
 
JSValuePtr globalFuncIsFinite(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
326
 
{
327
 
    double n = args.at(exec, 0).toNumber(exec);
 
320
JSValue JSC_HOST_CALL globalFuncParseFloat(ExecState* exec, JSObject*, JSValue, const ArgList& args)
 
321
{
 
322
    return jsNumber(exec, parseFloat(args.at(0).toString(exec)));
 
323
}
 
324
 
 
325
JSValue JSC_HOST_CALL globalFuncIsNaN(ExecState* exec, JSObject*, JSValue, const ArgList& args)
 
326
{
 
327
    return jsBoolean(isnan(args.at(0).toNumber(exec)));
 
328
}
 
329
 
 
330
JSValue JSC_HOST_CALL globalFuncIsFinite(ExecState* exec, JSObject*, JSValue, const ArgList& args)
 
331
{
 
332
    double n = args.at(0).toNumber(exec);
328
333
    return jsBoolean(!isnan(n) && !isinf(n));
329
334
}
330
335
 
331
 
JSValuePtr globalFuncDecodeURI(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
 
336
JSValue JSC_HOST_CALL globalFuncDecodeURI(ExecState* exec, JSObject*, JSValue, const ArgList& args)
332
337
{
333
338
    static const char do_not_unescape_when_decoding_URI[] =
334
339
        "#$&+,/:;=?@";
336
341
    return decode(exec, args, do_not_unescape_when_decoding_URI, true);
337
342
}
338
343
 
339
 
JSValuePtr globalFuncDecodeURIComponent(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
 
344
JSValue JSC_HOST_CALL globalFuncDecodeURIComponent(ExecState* exec, JSObject*, JSValue, const ArgList& args)
340
345
{
341
346
    return decode(exec, args, "", true);
342
347
}
343
348
 
344
 
JSValuePtr globalFuncEncodeURI(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
 
349
JSValue JSC_HOST_CALL globalFuncEncodeURI(ExecState* exec, JSObject*, JSValue, const ArgList& args)
345
350
{
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);
353
358
}
354
359
 
355
 
JSValuePtr globalFuncEncodeURIComponent(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
 
360
JSValue JSC_HOST_CALL globalFuncEncodeURIComponent(ExecState* exec, JSObject*, JSValue, const ArgList& args)
356
361
{
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);
364
369
}
365
370
 
366
 
JSValuePtr globalFuncEscape(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
 
371
JSValue JSC_HOST_CALL globalFuncEscape(ExecState* exec, JSObject*, JSValue, const ArgList& args)
367
372
{
368
373
    static const char do_not_escape[] =
369
374
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
373
378
 
374
379
    UString result = "";
375
380
    UString s;
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++) {
379
384
        int u = c[0];
394
399
    return jsString(exec, result);
395
400
}
396
401
 
397
 
JSValuePtr globalFuncUnescape(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
 
402
JSValue JSC_HOST_CALL globalFuncUnescape(ExecState* exec, JSObject*, JSValue, const ArgList& args)
398
403
{
399
404
    UString result = "";
400
 
    UString str = args.at(exec, 0).toString(exec);
 
405
    UString str = args.at(0).toString(exec);
401
406
    int k = 0;
402
407
    int len = str.size();
403
408
    while (k < len) {
404
409
        const UChar* c = str.data() + k;
405
410
        UChar u;
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]);
409
414
                c = &u;
410
415
                k += 5;
411
416
            }
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]));
414
419
            c = &u;
415
420
            k += 2;
422
427
}
423
428
 
424
429
#ifndef NDEBUG
425
 
JSValuePtr globalFuncJSCPrint(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
 
430
JSValue JSC_HOST_CALL globalFuncJSCPrint(ExecState* exec, JSObject*, JSValue, const ArgList& args)
426
431
{
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();
431
436
}