Changeset 7239 in webkit for trunk/JavaScriptCore/kjs/testkjs.cpp
- Timestamp:
- Aug 12, 2004, 10:21:29 AM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/testkjs.cpp
r7121 r7239 23 23 24 24 #include <stdio.h> 25 #include <stdlib.h> 25 26 #include <string.h> 26 27 … … 34 35 class TestFunctionImp : public ObjectImp { 35 36 public: 36 TestFunctionImp( ) : ObjectImp() {}37 TestFunctionImp(int i, int length); 37 38 virtual bool implementsCall() const { return true; } 38 39 virtual Value call(ExecState *exec, Object &thisObj, const List &args); 40 41 enum { Print, Debug, Quit }; 42 43 private: 44 int id; 39 45 }; 46 47 TestFunctionImp::TestFunctionImp(int i, int length) : ObjectImp(), id(i) 48 { 49 putDirect(lengthPropertyName,length,DontDelete|ReadOnly|DontEnum); 50 } 40 51 41 52 Value TestFunctionImp::call(ExecState *exec, Object &/*thisObj*/, const List &args) 42 53 { 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 44 66 return Undefined(); 45 67 } … … 52 74 }; 53 75 54 Value VersionFunctionImp::call(ExecState * exec, Object &/*thisObj*/, const List &args)76 Value VersionFunctionImp::call(ExecState */*exec*/, Object &/*thisObj*/, const List &/*args*/) 55 77 { 56 78 // We need this function for compatibility with the Mozilla JS tests but for now … … 81 103 Interpreter interp(global); 82 104 // 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))); 84 106 // 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))); 86 110 // 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())); 91 112 92 113 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 93 118 const char *file = argv[i]; 94 119 if (strcmp(file, "-f") == 0) … … 99 124 return 2; 100 125 } 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'; 105 137 106 138 // run … … 115 147 int lineno = -1; 116 148 if (exVal.type() == ObjectType) { 117 Value lineVal = Object::dynamicCast(exVal).get(exec, Identifier("line"));149 Value lineVal = Object::dynamicCast(exVal).get(exec,"line"); 118 150 if (lineVal.type() == NumberType) 119 151 lineno = int(lineVal.toNumber(exec)); … … 129 161 fprintf(stderr,"Return value: %s\n",msg); 130 162 } 163 164 free(code); 131 165 } 132 166
Note:
See TracChangeset
for help on using the changeset viewer.