Changeset 7239 in webkit for trunk/JavaScriptCore/kjs/testkjs.cpp


Ignore:
Timestamp:
Aug 12, 2004, 10:21:29 AM (21 years ago)
Author:
darin
Message:

Reviewed by Ken.

  • fixed 43 Mozilla JavaScript tests
  • kjs/date_object.h: Change parseDate and timeClip to take and return doubles.
  • kjs/date_object.cpp: (DateObjectImp::construct): Change to use a timeClip function that takes and returns a double rather than constructing a number object to pass to it. (DateObjectFuncImp::call): Change to use a parseDate function that returns a double. (KJS::parseDate): Change to return a double instead of creating the Number object here. (KJS::timeClip): Implement this as specified in the language standard.
  • kjs/error_object.cpp: (NativeErrorImp::NativeErrorImp): Set the DontDelete, ReadOnly, and DontEnum flags on the prototype property.
  • kjs/function.cpp: (KJS::FunctionImp::get): Return null rather than undefined for arguments when the function is not currently in scope. (KJS::isStrWhiteSpace): Added. Matches specification for StrWhiteSpace. Could move it to some utility file later. (KJS::parseDigit): Added. Helper function for parseInt. (KJS::parseInt): Added. Integer parser that puts result in a double so we're not limited to what strtoll can handle. Also matches standard more closely. (KJS::parseFloat): Added. Handles "0x" properly and passes flag to make empty string turn into NaN instead of 0. (KJS::GlobalFuncImp::call): Use the new parseInt and parseFloat.
  • kjs/function_object.cpp: (FunctionPrototypeImp::FunctionPrototypeImp): Add a length property.
  • kjs/lexer.h: Added error flag and sawError() function for detecting errors.
  • kjs/lexer.cpp: (Lexer::setCode): Clear error state. (Lexer::lex): Set error state if the lexer encounters an error
  • kjs/internal.cpp: (NumberImp::toString): Roll in change from KDE version to special case 0 so we handle -0 correctly. (Parser::parse): Use new lexer error method so those errors are treated like parser errors.
  • kjs/math_object.cpp: (MathFuncImp::call): Change min and max to treat -0 as less than +0. Change round to round values between -0.5 and -0 to -0 instead of +0.
  • kjs/nodes.h: Add evaluateReference function to GroupNode.
  • kjs/nodes.cpp: (GroupNode::evaluateReference): Pass references through groups (parenthesized expressions) properly so that expressions like "delete (x.y)" work. Before, the parentheses would change x.y into a value that can't be deleted as a side effect.
  • kjs/string_object.cpp: Change parameter count for indexOf and lastIndexOf from 2 to 1 to match the specification.
  • kjs/testkjs.cpp: Rolled in changes from KDE to add a "quit" function to the test tool and get rid of the fixed size limit for code.
  • kjs/ustring.cpp: (KJS::UString::substr): Added optimized case for substr(0, length) so it just returns the string without creating a new Rep, since I'm using substr in a place where it will often be passed a 0.
  • tests/mozilla/ecma/String/15.5.4.11-1.js: Fixed one wrong entry in the Unicode table I added to the other day that was making a couple tests fail.
  • tests/mozilla/ecma/String/15.5.4.12-1.js: Ditto.
  • tests/mozilla/ecma/String/15.5.4.12-2.js: Ditto.
  • tests/mozilla/ecma/String/15.5.4.12-3.js: Ditto.
  • tests/mozilla/ecma/String/15.5.4.12-4.js: Ditto.
  • tests/mozilla/ecma/String/15.5.4.12-5.js: Ditto.
  • kjs/string_object.lut.h: Regenerated.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/testkjs.cpp

    r7121 r7239  
    2323
    2424#include <stdio.h>
     25#include <stdlib.h>
    2526#include <string.h>
    2627
     
    3435class TestFunctionImp : public ObjectImp {
    3536public:
    36   TestFunctionImp() : ObjectImp() {}
     37  TestFunctionImp(int i, int length);
    3738  virtual bool implementsCall() const { return true; }
    3839  virtual Value call(ExecState *exec, Object &thisObj, const List &args);
     40
     41  enum { Print, Debug, Quit };
     42
     43private:
     44  int id;
    3945};
     46
     47TestFunctionImp::TestFunctionImp(int i, int length) : ObjectImp(), id(i)
     48{
     49  putDirect(lengthPropertyName,length,DontDelete|ReadOnly|DontEnum);
     50}
    4051
    4152Value TestFunctionImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)
    4253{
    43   fprintf(stderr,"--> %s\n",args[0].toString(exec).ascii());
     54  switch (id) {
     55  case Print:
     56  case Debug:
     57    fprintf(stderr,"--> %s\n",args[0].toString(exec).ascii());
     58    return Undefined();
     59  case Quit:
     60    exit(0);
     61    return Undefined();
     62  default:
     63    break;
     64  }
     65
    4466  return Undefined();
    4567}
     
    5274};
    5375
    54 Value VersionFunctionImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)
     76Value VersionFunctionImp::call(ExecState */*exec*/, Object &/*thisObj*/, const List &/*args*/)
    5577{
    5678  // We need this function for compatibility with the Mozilla JS tests but for now
     
    81103    Interpreter interp(global);
    82104    // add debug() function
    83     global.put(interp.globalExec(), Identifier("debug"), Object(new TestFunctionImp()));
     105    global.put(interp.globalExec(), "debug", Object(new TestFunctionImp(TestFunctionImp::Debug,1)));
    84106    // add "print" for compatibility with the mozilla js shell
    85     global.put(interp.globalExec(), Identifier("print"), Object(new TestFunctionImp()));
     107    global.put(interp.globalExec(), "print", Object(new TestFunctionImp(TestFunctionImp::Print,1)));
     108    // add "quit" for compatibility with the mozilla js shell
     109    global.put(interp.globalExec(), "quit", Object(new TestFunctionImp(TestFunctionImp::Quit,0)));
    86110    // add "version" for compatibility with the mozilla js shell
    87     global.put(interp.globalExec(), Identifier("version"), Object(new VersionFunctionImp()));
    88 
    89     const int BufferSize = 200000;
    90     char code[BufferSize];
     111    global.put(interp.globalExec(), "version", Object(new VersionFunctionImp()));
    91112
    92113    for (int i = 1; i < argc; i++) {
     114      int code_len = 0;
     115      int code_alloc = 1024;
     116      char *code = (char*)malloc(code_alloc);
     117
    93118      const char *file = argv[i];
    94119      if (strcmp(file, "-f") == 0)
     
    99124        return 2;
    100125      }
    101       int num = fread(code, 1, BufferSize, f);
    102       code[num] = '\0';
    103       if(num >= BufferSize)
    104         fprintf(stderr, "Warning: File may have been too long.\n");
     126
     127      while (!feof(f) && !ferror(f)) {
     128        size_t len = fread(code+code_len,1,code_alloc-code_len,f);
     129        code_len += len;
     130        if (code_len >= code_alloc) {
     131          code_alloc *= 2;
     132          code = (char*)realloc(code,code_alloc);
     133        }
     134      }
     135      code = (char*)realloc(code,code_len+1);
     136      code[code_len] = '\0';
    105137
    106138      // run
     
    115147        int lineno = -1;
    116148        if (exVal.type() == ObjectType) {
    117           Value lineVal = Object::dynamicCast(exVal).get(exec,Identifier("line"));
     149          Value lineVal = Object::dynamicCast(exVal).get(exec,"line");
    118150          if (lineVal.type() == NumberType)
    119151            lineno = int(lineVal.toNumber(exec));
     
    129161        fprintf(stderr,"Return value: %s\n",msg);
    130162      }
     163
     164      free(code);
    131165    }
    132166
Note: See TracChangeset for help on using the changeset viewer.