Changeset 27022 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Oct 24, 2007, 11:38:35 PM (18 years ago)
Author:
eseidel
Message:

2007-10-24 Eric Seidel <[email protected]>

Reviewed by Maciej.


Add a JSGlobalObject class and remove the InterpreterMap
http://bugs.webkit.org/show_bug.cgi?id=15681


This required making JSCallbackObject a template class to allow for
JSGlobalObjects with JSCallbackObject functionality.


SunSpider claims this was a 0.5% speedup.

  • API/JSCallbackObject.cpp: (KJS::):
  • API/JSCallbackObject.h:
  • API/JSCallbackObjectFunctions.h: Copied from API/JSCallbackObject.cpp. (KJS::::JSCallbackObject): (KJS::::init): (KJS::::~JSCallbackObject): (KJS::::initializeIfNeeded): (KJS::::className): (KJS::::getOwnPropertySlot): (KJS::::put): (KJS::::deleteProperty): (KJS::::implementsConstruct): (KJS::::construct): (KJS::::implementsHasInstance): (KJS::::hasInstance): (KJS::::implementsCall): (KJS::::callAsFunction): (KJS::::getPropertyNames): (KJS::::toNumber): (KJS::::toString): (KJS::::setPrivate): (KJS::::getPrivate): (KJS::::inherits): (KJS::::cachedValueGetter): (KJS::::staticValueGetter): (KJS::::staticFunctionGetter): (KJS::::callbackGetter):
  • API/JSClassRef.cpp: (OpaqueJSClass::prototype):
  • API/JSContextRef.cpp: (JSGlobalContextCreate):
  • API/JSObjectRef.cpp: (JSObjectMake): (JSObjectGetPrivate): (JSObjectSetPrivate):
  • API/JSValueRef.cpp: (JSValueIsObjectOfClass):
  • JavaScriptCore.exp:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • bindings/c/c_utility.cpp: (KJS::Bindings::convertValueToNPVariant):
  • bindings/jni/jni_jsobject.cpp:
  • bindings/objc/objc_utility.mm: (KJS::Bindings::convertValueToObjcValue):
  • kjs/Context.cpp: (KJS::Context::Context):
  • kjs/ExecState.cpp: (KJS::ExecState::lexicalInterpreter):
  • kjs/JSGlobalObject.h: Added. (KJS::JSGlobalObject::JSGlobalObject): (KJS::JSGlobalObject::isGlobalObject): (KJS::JSGlobalObject::interpreter): (KJS::JSGlobalObject::setInterpreter):
  • kjs/array_instance.cpp:
  • kjs/context.h:
  • kjs/function.cpp: (KJS::FunctionImp::callAsFunction): (KJS::GlobalFuncImp::callAsFunction):
  • kjs/interpreter.cpp: (KJS::Interpreter::Interpreter): (KJS::Interpreter::init): (KJS::Interpreter::~Interpreter): (KJS::Interpreter::globalObject): (KJS::Interpreter::initGlobalObject): (KJS::Interpreter::evaluate):
  • kjs/interpreter.h:
  • kjs/lookup.h: (KJS::cacheGlobalObject):
  • kjs/object.h: (KJS::JSObject::isGlobalObject):
  • kjs/testkjs.cpp:
Location:
trunk/JavaScriptCore/kjs
Files:
1 added
10 edited

Legend:

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

    r26620 r27022  
    2828
    2929// ECMA 10.2
    30 Context::Context(JSObject* glob, Interpreter* interpreter, JSObject* thisV,
     30Context::Context(JSGlobalObject* glob, Interpreter* interpreter, JSObject* thisV,
    3131                 FunctionBodyNode* currentBody, CodeType type, Context* callingCon,
    3232                 FunctionImp* func, const List* args)
  • trunk/JavaScriptCore/kjs/ExecState.cpp

    r15118 r27022  
    3131Interpreter* ExecState::lexicalInterpreter() const
    3232{
    33   if (!m_context)
     33    if (!m_context)
     34        return dynamicInterpreter();
     35   
     36    JSObject* object = m_context->scopeChain().bottom();
     37    if (object && object->isGlobalObject())
     38        return static_cast<JSGlobalObject*>(object)->interpreter();
     39
    3440    return dynamicInterpreter();
    35 
    36   Interpreter* result = Interpreter::interpreterWithGlobalObject(m_context->scopeChain().bottom());
    37 
    38   if (!result)
    39     return dynamicInterpreter();
    40 
    41   return result;
    4241}
    4342
  • trunk/JavaScriptCore/kjs/array_instance.cpp

    r26897 r27022  
    492492    JSObject *compareFunction;
    493493    List arguments;
    494     JSObject *globalObject;
     494    JSGlobalObject* globalObject;
    495495};
    496496
  • trunk/JavaScriptCore/kjs/context.h

    r25534 r27022  
    5151  class Context {
    5252  public:
    53     Context(JSObject* global, Interpreter*, JSObject* thisV,
     53    Context(JSGlobalObject*, Interpreter*, JSObject* thisV,
    5454            FunctionBodyNode* currentBody, CodeType type = GlobalCode,
    5555            Context* callingContext = 0, FunctionImp* function = 0, const List* args = 0);
  • trunk/JavaScriptCore/kjs/function.cpp

    r26808 r27022  
    3131#include "function_object.h"
    3232#include "internal.h"
     33#include "JSGlobalObject.h"
    3334#include "lexer.h"
    3435#include "nodes.h"
     
    6667JSValue* FunctionImp::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
    6768{
    68   JSObject* globalObj = exec->dynamicInterpreter()->globalObject();
     69  JSGlobalObject* globalObj = exec->dynamicInterpreter()->globalObject();
    6970
    7071  // enter a new execution context
     
    755756          return throwError(exec, SyntaxError, errMsg, errLine, sid, NULL);
    756757
    757         bool switchGlobal = thisObj && exec->dynamicInterpreter()->isGlobalObject(thisObj) && thisObj != exec->dynamicInterpreter()->globalObject();
     758        bool switchGlobal = thisObj && thisObj != exec->dynamicInterpreter()->globalObject();
    758759         
    759760        // enter a new execution context
    760         Interpreter* interpreter = switchGlobal ? exec->dynamicInterpreter()->interpreterForGlobalObject(thisObj) : exec->dynamicInterpreter();
     761        Interpreter* interpreter = switchGlobal ? static_cast<JSGlobalObject*>(thisObj)->interpreter() : exec->dynamicInterpreter();
    761762        JSObject* thisVal = static_cast<JSObject*>(exec->context()->thisValue());
    762763        Context ctx(interpreter->globalObject(),
  • trunk/JavaScriptCore/kjs/interpreter.cpp

    r26808 r27022  
    8080    return* map;
    8181}
    82    
    83 Interpreter::Interpreter(JSObject* globalObject)
     82
     83Interpreter::Interpreter(JSGlobalObject* globalObject)
    8484    : m_globalExec(this, 0)
    8585    , m_globalObject(globalObject)
     
    9090Interpreter::Interpreter()
    9191    : m_globalExec(this, 0)
    92     , m_globalObject(new JSObject())
     92    , m_globalObject(new JSGlobalObject())
    9393{
    9494    init();
     
    119119        s_hook = next = prev = this;
    120120    }
    121     interpreterMap().set(m_globalObject, this);
    122121
    123122    initGlobalObject();
     
    138137        s_hook = 0;
    139138    }
    140     interpreterMap().remove(m_globalObject);
    141 }
    142 
    143 JSObject* Interpreter::globalObject() const
    144 {
    145   return m_globalObject;
     139}
     140
     141JSGlobalObject* Interpreter::globalObject() const
     142{
     143    return m_globalObject;
    146144}
    147145
    148146void Interpreter::initGlobalObject()
    149147{
     148    m_globalObject->setInterpreter(this);
     149
    150150    // Clear before inititalizing, to avoid marking uninitialized (dangerous) or
    151151    // stale (wasteful) pointers during initialization.
    152 
     152   
    153153    // Prototypes
    154154    m_FunctionPrototype = 0;
     
    348348    m_recursion++;
    349349   
    350     JSObject* globalObj = m_globalObject;
     350    JSGlobalObject* globalObj = m_globalObject;
    351351    JSObject* thisObj = globalObj;
    352352   
     
    611611}
    612612
    613 Interpreter* Interpreter::interpreterWithGlobalObject(JSObject* globalObject)
    614 {
    615     return interpreterMap().get(globalObject);
    616 }
    617 
    618613#ifdef KJS_DEBUG_MEM
    619614#include "lexer.h"
  • trunk/JavaScriptCore/kjs/interpreter.h

    r20310 r27022  
    4646  class FunctionObjectImp;
    4747  class FunctionPrototype;
     48  class JSGlobalObject;
    4849  class NativeErrorImp;
    4950  class NativeErrorPrototype;
     
    9596     * @param global The object to use as the global object for this interpreter
    9697     */
    97     Interpreter(JSObject* globalObject);
     98    Interpreter(JSGlobalObject*);
    9899    /**
    99100     * Creates a new interpreter. A global object will be created and
     
    112113     * execution performed by this interpreter
    113114     */
    114     JSObject* globalObject() const;
     115    JSGlobalObject* globalObject() const;
    115116
    116117    /**
     
    301302    void saveBuiltins (SavedBuiltins&) const;
    302303    void restoreBuiltins (const SavedBuiltins&);
    303 
    304     /**
    305      * Determine if the value is a global object (for any interpreter).  This may
    306      * be difficult to determine for multiple uses of JSC in a process that are
    307      * logically independent of each other.  In the case of WebCore, this method
    308      * is used to determine if an object is the Window object so we can perform
    309      * security checks.
    310      */
    311     virtual bool isGlobalObject(JSValue*) { return false; }
    312    
    313     /**
    314      * Find the interpreter for a particular global object.  This should really
    315      * be a static method, but we can't do that is C++.  Again, as with isGlobalObject()
    316      * implementation really need to know about all instances of Interpreter
    317      * created in an application to correctly implement this method.  The only
    318      * override of this method is currently in WebCore.
    319      */
    320     virtual Interpreter* interpreterForGlobalObject(const JSValue*) { return 0; }
    321304   
    322305    /**
     
    338321    void setContext(Context* c) { m_context = c; }
    339322    Context* context() const { return m_context; }
    340    
    341     static Interpreter* interpreterWithGlobalObject(JSObject*);
    342    
     323       
    343324    void setTimeoutTime(unsigned timeoutTime) { m_timeoutTime = timeoutTime; }
    344325
     
    389370    unsigned m_ticksUntilNextTimeoutCheck;
    390371
    391     JSObject* m_globalObject;
     372    JSGlobalObject* m_globalObject;
    392373
    393374    ObjectObjectImp* m_Object;
  • trunk/JavaScriptCore/kjs/lookup.h

    r26956 r27022  
    2020 */
    2121
    22 #ifndef _KJSLOOKUP_H_
    23 #define _KJSLOOKUP_H_
     22#ifndef KJS_lookup_h
     23#define KJS_lookup_h
    2424
    2525#include "context.h"
    2626#include "identifier.h"
    2727#include "interpreter.h"
     28#include "JSGlobalObject.h"
    2829#include "object.h"
    2930#include <stdio.h>
     
    270271  inline JSObject* cacheGlobalObject(ExecState* exec, const Identifier& propertyName)
    271272  {
    272     JSObject* globalObject = static_cast<JSObject*>(exec->lexicalInterpreter()->globalObject());
     273    JSGlobalObject* globalObject = exec->lexicalInterpreter()->globalObject();
    273274    JSValue* obj = globalObject->getDirect(propertyName);
    274275    if (obj) {
     
    352353  };
    353354
    354 #endif
     355#endif // KJS_lookup_h
  • trunk/JavaScriptCore/kjs/object.h

    r26688 r27022  
    458458
    459459    virtual bool isActivation() { return false; }
     460    virtual bool isGlobalObject() const { return false; }
    460461  protected:
    461462    PropertyMap _prop;
  • trunk/JavaScriptCore/kjs/testkjs.cpp

    r26783 r27022  
    2727#include "Parser.h"
    2828#include "collector.h"
     29#include "JSGlobalObject.h"
    2930#include "object.h"
    3031#include "protect.h"
     
    111112}
    112113
    113 class GlobalImp : public JSObject {
     114class GlobalImp : public JSGlobalObject {
    114115public:
    115116  virtual UString className() const { return "global"; }
Note: See TracChangeset for help on using the changeset viewer.