Changeset 14834 in webkit for trunk/JavaScriptCore/kjs/ExecState.cpp
- Timestamp:
- Jun 12, 2006, 11:08:52 PM (19 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/ExecState.cpp
r14827 r14834 23 23 */ 24 24 25 #include "config.h" 26 #include "interpreter.h" 27 28 #include <assert.h> 29 #include <math.h> 30 #include <stdio.h> 31 32 #include "collector.h" 33 #include "context.h" 34 #include "error_object.h" 25 #include "Context.h" 26 #include "ExecState.h" 35 27 #include "internal.h" 36 #include "nodes.h"37 #include "object.h"38 #include "operations.h"39 #include "types.h"40 #include "value.h"41 42 #if PLATFORM(MAC)43 #include "runtime.h"44 #endif45 28 46 29 namespace KJS { 47 30 48 // ------------------------------ Interpreter ---------------------------------- 49 50 Interpreter::Interpreter(JSObject *global) 51 : rep(0) 52 , m_argumentsPropertyName(&argumentsPropertyName) 53 , m_specialPrototypePropertyName(&specialPrototypePropertyName) 54 { 55 rep = new InterpreterImp(this, global); 56 } 57 58 Interpreter::Interpreter() 59 : rep(0) 60 , m_argumentsPropertyName(&argumentsPropertyName) 61 , m_specialPrototypePropertyName(&specialPrototypePropertyName) 62 { 63 rep = new InterpreterImp(this, new JSObject); 64 } 65 66 Interpreter::~Interpreter() 67 { 68 delete rep; 69 } 70 71 JSObject *Interpreter::globalObject() const 72 { 73 return rep->globalObject(); 74 } 75 76 void Interpreter::initGlobalObject() 77 { 78 rep->initGlobalObject(); 79 } 80 81 ExecState *Interpreter::globalExec() 82 { 83 return rep->globalExec(); 84 } 85 86 bool Interpreter::checkSyntax(const UString &code) 87 { 88 return rep->checkSyntax(code); 89 } 90 91 Completion Interpreter::evaluate(const UString& sourceURL, int startingLineNumber, const UString& code, JSValue*) 92 { 93 return evaluate(sourceURL, startingLineNumber, code.data(), code.size()); 94 } 95 96 Completion Interpreter::evaluate(const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength, JSValue* thisV) 97 { 98 Completion comp = rep->evaluate(code, codeLength, thisV, sourceURL, startingLineNumber); 99 100 if (shouldPrintExceptions() && comp.complType() == Throw) { 101 JSLock lock; 102 ExecState *exec = rep->globalExec(); 103 CString f = sourceURL.UTF8String(); 104 CString message = comp.value()->toObject(exec)->toString(exec).UTF8String(); 105 int line = comp.value()->toObject(exec)->get(exec, "line")->toUInt32(exec); 106 #if PLATFORM(WIN_OS) 107 printf("%s line %d: %s\n", f.c_str(), line, message.c_str()); 108 #else 109 printf("[%d] %s line %d: %s\n", getpid(), f.c_str(), line, message.c_str()); 110 #endif 111 } 112 113 return comp; 114 } 115 116 JSObject *Interpreter::builtinObject() const 117 { 118 return rep->builtinObject(); 119 } 120 121 JSObject *Interpreter::builtinFunction() const 122 { 123 return rep->builtinFunction(); 124 } 125 126 JSObject *Interpreter::builtinArray() const 127 { 128 return rep->builtinArray(); 129 } 130 131 JSObject *Interpreter::builtinBoolean() const 132 { 133 return rep->builtinBoolean(); 134 } 135 136 JSObject *Interpreter::builtinString() const 137 { 138 return rep->builtinString(); 139 } 140 141 JSObject *Interpreter::builtinNumber() const 142 { 143 return rep->builtinNumber(); 144 } 145 146 JSObject *Interpreter::builtinDate() const 147 { 148 return rep->builtinDate(); 149 } 150 151 JSObject *Interpreter::builtinRegExp() const 152 { 153 return rep->builtinRegExp(); 154 } 155 156 JSObject *Interpreter::builtinError() const 157 { 158 return rep->builtinError(); 159 } 160 161 JSObject *Interpreter::builtinObjectPrototype() const 162 { 163 return rep->builtinObjectPrototype(); 164 } 165 166 JSObject *Interpreter::builtinFunctionPrototype() const 167 { 168 return rep->builtinFunctionPrototype(); 169 } 170 171 JSObject *Interpreter::builtinArrayPrototype() const 172 { 173 return rep->builtinArrayPrototype(); 174 } 175 176 JSObject *Interpreter::builtinBooleanPrototype() const 177 { 178 return rep->builtinBooleanPrototype(); 179 } 180 181 JSObject *Interpreter::builtinStringPrototype() const 182 { 183 return rep->builtinStringPrototype(); 184 } 185 186 JSObject *Interpreter::builtinNumberPrototype() const 187 { 188 return rep->builtinNumberPrototype(); 189 } 190 191 JSObject *Interpreter::builtinDatePrototype() const 192 { 193 return rep->builtinDatePrototype(); 194 } 195 196 JSObject *Interpreter::builtinRegExpPrototype() const 197 { 198 return rep->builtinRegExpPrototype(); 199 } 200 201 JSObject *Interpreter::builtinErrorPrototype() const 202 { 203 return rep->builtinErrorPrototype(); 204 } 205 206 JSObject *Interpreter::builtinEvalError() const 207 { 208 return rep->builtinEvalError(); 209 } 210 211 JSObject *Interpreter::builtinRangeError() const 212 { 213 return rep->builtinRangeError(); 214 } 215 216 JSObject *Interpreter::builtinReferenceError() const 217 { 218 return rep->builtinReferenceError(); 219 } 220 221 JSObject *Interpreter::builtinSyntaxError() const 222 { 223 return rep->builtinSyntaxError(); 224 } 225 226 JSObject *Interpreter::builtinTypeError() const 227 { 228 return rep->builtinTypeError(); 229 } 230 231 JSObject *Interpreter::builtinURIError() const 232 { 233 return rep->builtinURIError(); 234 } 235 236 JSObject *Interpreter::builtinEvalErrorPrototype() const 237 { 238 return rep->builtinEvalErrorPrototype(); 239 } 240 241 JSObject *Interpreter::builtinRangeErrorPrototype() const 242 { 243 return rep->builtinRangeErrorPrototype(); 244 } 245 246 JSObject *Interpreter::builtinReferenceErrorPrototype() const 247 { 248 return rep->builtinReferenceErrorPrototype(); 249 } 250 251 JSObject *Interpreter::builtinSyntaxErrorPrototype() const 252 { 253 return rep->builtinSyntaxErrorPrototype(); 254 } 255 256 JSObject *Interpreter::builtinTypeErrorPrototype() const 257 { 258 return rep->builtinTypeErrorPrototype(); 259 } 260 261 JSObject *Interpreter::builtinURIErrorPrototype() const 262 { 263 return rep->builtinURIErrorPrototype(); 264 } 265 266 void Interpreter::setCompatMode(CompatMode mode) 267 { 268 rep->setCompatMode(mode); 269 } 270 271 Interpreter::CompatMode Interpreter::compatMode() const 272 { 273 return rep->compatMode(); 274 } 275 276 bool Interpreter::collect() 277 { 278 return Collector::collect(); 279 } 280 281 void Interpreter::mark(bool) 282 { 283 } 284 285 #ifdef KJS_DEBUG_MEM 286 #include "lexer.h" 287 void Interpreter::finalCheck() 288 { 289 fprintf(stderr,"Interpreter::finalCheck()\n"); 290 Collector::collect(); 291 292 Node::finalCheck(); 293 Collector::finalCheck(); 294 Lexer::globalClear(); 295 UString::globalClear(); 296 } 297 #endif 298 299 static bool printExceptions = false; 300 301 bool Interpreter::shouldPrintExceptions() 302 { 303 return printExceptions; 304 } 305 306 void Interpreter::setShouldPrintExceptions(bool print) 307 { 308 printExceptions = print; 309 } 310 311 // bindings are OS X WebKit-only for now 312 #if PLATFORM(MAC) 313 void *Interpreter::createLanguageInstanceForValue(ExecState *exec, int language, JSObject *value, const Bindings::RootObject *origin, const Bindings::RootObject *current) 314 { 315 return Bindings::Instance::createLanguageInstanceForValue (exec, (Bindings::Instance::BindingLanguage)language, value, origin, current); 316 } 317 #endif 318 319 void Interpreter::saveBuiltins (SavedBuiltins &builtins) const 320 { 321 rep->saveBuiltins(builtins); 322 } 323 324 void Interpreter::restoreBuiltins (const SavedBuiltins &builtins) 325 { 326 rep->restoreBuiltins(builtins); 327 } 328 329 SavedBuiltins::SavedBuiltins() : 330 _internal(0) 331 { 332 } 333 334 SavedBuiltins::~SavedBuiltins() 335 { 336 delete _internal; 337 } 338 339 Interpreter *ExecState::lexicalInterpreter() const 31 Interpreter* ExecState::lexicalInterpreter() const 340 32 { 341 33 if (!m_context) 342 34 return dynamicInterpreter(); 343 35 344 Interpreter Imp *result = InterpreterImp::interpreterWithGlobalObject(m_context->scopeChain().bottom());36 Interpreter* result = Interpreter::interpreterWithGlobalObject(m_context->scopeChain().bottom()); 345 37 346 38 if (!result) 347 39 return dynamicInterpreter(); 348 40 349 return result ->interpreter();41 return result; 350 42 } 351 43 352 } 44 } // namespace KJS
Note:
See TracChangeset
for help on using the changeset viewer.