Ignore:
Timestamp:
Jun 12, 2006, 11:08:52 PM (19 years ago)
Author:
ggaren
Message:

JavaScriptCore:

Reviewed by TimO, Maciej.


  • Merged InterpreterImp code into Interpreter, which implements all interpreter functionality now. This is part of my continuing quest to create an external notion of JS "execution context" that is unified and simple -- something to replace the mix of Context, ContextImp, ExecState, Interpreter, InterpreterImp, and JSRun.


All tests pass. Leaks test has not regressed from its baseline ~207 leaks
with ~3460 leaked nodes.

  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • bindings/NP_jsobject.cpp:
  • bindings/objc/WebScriptObject.mm: (+[WebScriptObject throwException:]):
  • bindings/runtime_root.cpp:
  • bindings/runtime_root.h:
  • kjs/Context.cpp: (KJS::Context::Context):
  • kjs/ExecState.cpp: Added. (KJS::ExecState::lexicalInterpreter):
  • kjs/ExecState.h: Added. (KJS::ExecState::dynamicInterpreter):
  • kjs/SavedBuiltins.h: Added.
  • kjs/bool_object.cpp: (BooleanPrototype::BooleanPrototype):
  • kjs/collector.cpp: (KJS::Collector::collect): (KJS::Collector::numInterpreters):
  • kjs/context.h:
  • kjs/debugger.cpp: (Debugger::attach): (Debugger::detach):
  • kjs/function.cpp: (KJS::FunctionImp::callAsFunction): (KJS::GlobalFuncImp::callAsFunction):
  • kjs/function_object.cpp: (FunctionObjectImp::construct):
  • kjs/internal.cpp:
  • kjs/internal.h:
  • kjs/interpreter.cpp: (KJS::interpreterMap): (KJS::Interpreter::Interpreter): (KJS::Interpreter::init): (KJS::Interpreter::~Interpreter): (KJS::Interpreter::globalObject): (KJS::Interpreter::initGlobalObject): (KJS::Interpreter::globalExec): (KJS::Interpreter::checkSyntax): (KJS::Interpreter::evaluate): (KJS::Interpreter::builtinObject): (KJS::Interpreter::builtinFunction): (KJS::Interpreter::builtinArray): (KJS::Interpreter::builtinBoolean): (KJS::Interpreter::builtinString): (KJS::Interpreter::builtinNumber): (KJS::Interpreter::builtinDate): (KJS::Interpreter::builtinRegExp): (KJS::Interpreter::builtinError): (KJS::Interpreter::builtinObjectPrototype): (KJS::Interpreter::builtinFunctionPrototype): (KJS::Interpreter::builtinArrayPrototype): (KJS::Interpreter::builtinBooleanPrototype): (KJS::Interpreter::builtinStringPrototype): (KJS::Interpreter::builtinNumberPrototype): (KJS::Interpreter::builtinDatePrototype): (KJS::Interpreter::builtinRegExpPrototype): (KJS::Interpreter::builtinErrorPrototype): (KJS::Interpreter::builtinEvalError): (KJS::Interpreter::builtinRangeError): (KJS::Interpreter::builtinReferenceError): (KJS::Interpreter::builtinSyntaxError): (KJS::Interpreter::builtinTypeError): (KJS::Interpreter::builtinURIError): (KJS::Interpreter::builtinEvalErrorPrototype): (KJS::Interpreter::builtinRangeErrorPrototype): (KJS::Interpreter::builtinReferenceErrorPrototype): (KJS::Interpreter::builtinSyntaxErrorPrototype): (KJS::Interpreter::builtinTypeErrorPrototype): (KJS::Interpreter::builtinURIErrorPrototype): (KJS::Interpreter::mark): (KJS::Interpreter::interpreterWithGlobalObject): (KJS::Interpreter::saveBuiltins): (KJS::Interpreter::restoreBuiltins):
  • kjs/interpreter.h: (KJS::Interpreter::setCompatMode): (KJS::Interpreter::compatMode): (KJS::Interpreter::firstInterpreter): (KJS::Interpreter::nextInterpreter): (KJS::Interpreter::prevInterpreter): (KJS::Interpreter::debugger): (KJS::Interpreter::setDebugger): (KJS::Interpreter::setContext): (KJS::Interpreter::context):
  • kjs/nodes.cpp: (StatementNode::hitStatement): (RegExpNode::evaluate):
  • kjs/protect.h:

JavaScriptGlue:

Reviewed by TimO, Maciej.


  • JSGlue part of merging InterpreterImp into Interpreter.


Since there's now a kjs forwarding header, I moved all forwarding
headers into a "ForwardingHeaders" directory, like in WebCore.

  • ForwardingHeaders: Added.
  • ForwardingHeaders/kjs: Added.
  • ForwardingHeaders/kjs/ExecState.h: Added.
  • ForwardingHeaders/wtf: Added.
  • JavaScriptGlue.xcodeproj/project.pbxproj:
  • config.h:
  • wtf: Removed.
  • wtf/AlwaysInline.h: Removed.
  • wtf/Assertions.h: Removed.
  • wtf/FastMalloc.h: Removed.
  • wtf/Forward.h: Removed.
  • wtf/HashCountedSet.h: Removed.
  • wtf/HashSet.h: Removed.
  • wtf/Noncopyable.h: Removed.
  • wtf/OwnArrayPtr.h: Removed.
  • wtf/OwnPtr.h: Removed.
  • wtf/PassRefPtr.h: Removed.
  • wtf/Platform.h: Removed.
  • wtf/RefPtr.h: Removed.
  • wtf/Vector.h: Removed.

WebCore:

Reviewed by TimO, Maciej.

  • WebCore part of merging InterpreterImp into Interpreter. No test because there's no behavior change.


A substantive change here is that ScriptInterpreter::mark must now chain to
Interpreter::mark, since Interpreter needs to mark the things that
InterpreterImp used to mark.


  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/kjs_binding.cpp:
  • bindings/js/kjs_window.cpp: (KJS::Window::put):
  • bridge/mac/WebCoreFrameBridge.mm:
  • bridge/mac/WebCoreScriptDebugger.mm: (-[WebCoreScriptCallFrame evaluateWebScript:]):
  • kwq/KWQPageState.mm:
File:
1 copied

Legend:

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

    r14827 r14834  
    2323 */
    2424
    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"
    3527#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 #endif
    4528
    4629namespace KJS {
    4730
    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
     31Interpreter* ExecState::lexicalInterpreter() const
    34032{
    34133  if (!m_context)
    34234    return dynamicInterpreter();
    34335
    344   InterpreterImp *result = InterpreterImp::interpreterWithGlobalObject(m_context->scopeChain().bottom());
     36  Interpreter* result = Interpreter::interpreterWithGlobalObject(m_context->scopeChain().bottom());
    34537
    34638  if (!result)
    34739    return dynamicInterpreter();
    34840
    349   return result->interpreter();
     41  return result;
    35042}
    35143
    352 }
     44} // namespace KJS
Note: See TracChangeset for help on using the changeset viewer.