Changeset 1623 in webkit for trunk/JavaScriptCore/kjs/function.cpp
- Timestamp:
- Jul 21, 2002, 10:38:39 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/function.cpp
r1326 r1623 2 2 /* 3 3 * This file is part of the KDE libraries 4 * Copyright (C) 1999-200 0Harri Porten ([email protected])4 * Copyright (C) 1999-2002 Harri Porten ([email protected]) 5 5 * Copyright (C) 2001 Peter Kelly ([email protected]) 6 6 * … … 32 32 33 33 #include <stdio.h> 34 #include <errno.h> 35 #include <stdlib.h> 34 36 #include <assert.h> 35 37 #include <string.h> … … 37 39 using namespace KJS; 38 40 39 // ----------------------------- -FunctionImp ----------------------------------41 // ----------------------------- FunctionImp ---------------------------------- 40 42 41 43 const ClassInfo FunctionImp::info = {"Function", &InternalFunctionImp::info, 0, 0}; … … 100 102 101 103 Object func(this); 102 intcont = dbg->callEvent(exec,sid,lineno,func,args);104 bool cont = dbg->callEvent(exec,sid,lineno,func,args); 103 105 if (!cont) { 104 106 dbg->imp()->abort(); … … 108 110 109 111 // enter a new execution context 110 ContextImp *ctx = new ContextImp(globalObj, exec, thisObj,111 codeType(),exec->context().imp(), this, args);112 ExecState *newExec = new ExecState(exec->interpreter(),ctx);113 newExec ->setException(exec->exception()); // could be null112 ContextImp ctx(globalObj, exec, thisObj, codeType(), 113 exec->context().imp(), this, args); 114 ExecState newExec(exec->interpreter(), &ctx); 115 newExec.setException(exec->exception()); // could be null 114 116 115 117 // In order to maintain our "arguments" property, we maintain a list of arguments … … 118 120 // Note: this does not appear to be part of the spec 119 121 if (codeType() == FunctionCode) { 120 assert(ctx ->activationObject().inherits(&ActivationImp::info));121 Object argsObj = static_cast<ActivationImp*>(ctx ->activationObject().imp())->argumentsObject();122 put( newExec,"arguments", argsObj, DontDelete|DontEnum|ReadOnly);123 pushArgs( newExec,argsObj);122 assert(ctx.activationObject().inherits(&ActivationImp::info)); 123 Object argsObj = static_cast<ActivationImp*>(ctx.activationObject().imp())->argumentsObject(); 124 put(&newExec, "arguments", argsObj, DontDelete|DontEnum|ReadOnly); 125 pushArgs(&newExec, argsObj); 124 126 } 125 127 126 128 // assign user supplied arguments to parameters 127 processParameters( newExec,args);129 processParameters(&newExec, args); 128 130 // add variable declarations (initialized to undefined) 129 processVarDecls( newExec);130 131 Completion comp = execute( newExec);131 processVarDecls(&newExec); 132 133 Completion comp = execute(&newExec); 132 134 133 135 // if an exception occured, propogate it back to the previous execution object 134 if (newExec ->hadException())135 exec->setException(newExec ->exception());136 if (newExec.hadException()) 137 exec->setException(newExec.exception()); 136 138 if (codeType() == FunctionCode) 137 popArgs(newExec); 138 delete newExec; 139 delete ctx; 139 popArgs(&newExec); 140 140 141 141 #ifdef KJS_VERBOSE … … 431 431 } 432 432 case ParseInt: { 433 String str = args[0].toString(exec);433 CString cstr = args[0].toString(exec).cstring(); 434 434 int radix = args[1].toInt32(exec); 435 if (radix == 0) 436 radix = 10; 437 else if (radix < 2 || radix > 36) { 435 436 char* endptr; 437 errno = 0; 438 long value = strtol(cstr.c_str(), &endptr, radix); 439 if (errno != 0 || endptr == cstr.c_str()) 438 440 res = Number(NaN); 439 return res;440 }441 /* TODO: use radix */442 // Can't use toULong(), we want to accept floating point values too443 double value = str.value().toDouble( true /*tolerant*/ );444 if ( isNaN(value) )445 res = Number(NaN);446 441 else 447 res = Number(static_cast<long>(value)); // remove floating-point part 448 break; 449 } 450 case ParseFloat: { 451 String str = args[0].toString(exec); 452 res = Number(str.value().toDouble( true /*tolerant*/ )); 453 break; 454 } 442 res = Number(value); 443 break; 444 } 445 case ParseFloat: 446 res = Number(args[0].toString(exec).toDouble( true /*tolerant*/ )); 447 break; 455 448 case IsNaN: 456 449 res = Boolean(isNaN(args[0].toNumber(exec))); 457 450 break; 458 451 case IsFinite: { 459 Numbern = args[0].toNumber(exec);460 res = Boolean(! n.isNaN() && !n.isInf());452 double n = args[0].toNumber(exec); 453 res = Boolean(!isNaN(n) && !isInf(n)); 461 454 break; 462 455 } … … 485 478 UString s, str = args[0].toString(exec); 486 479 int k = 0, len = str.size(); 480 UChar u; 487 481 while (k < len) { 488 482 const UChar *c = str.data() + k; 489 UChar u;490 483 if (*c == UChar('%') && k <= len - 6 && *(c+1) == UChar('u')) { 491 484 u = Lexer::convertUnicode((c+2)->unicode(), (c+3)->unicode(),
Note:
See TracChangeset
for help on using the changeset viewer.