Changeset 31746 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Apr 8, 2008, 7:17:49 PM (17 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

2008-04-04 Sam Weinig <[email protected]>

Reviewed by Geoffrey Garen.

First step in implementing the "split window"

  • Add a GlobalThisValue to ExecState which should be used in places that used to implement the "use the global object as this if null" rule.
  • Factor out lookupGetter/lookupSetter into virtual methods on JSObject so that they can be forwarded.
  • Make defineGetter/defineSetter virtual methods for the same reason.
  • Have PrototypeReflexiveFunction store the globalObject used to create it so that it can be used to get the correct thisObject for eval.
  • API/JSObjectRef.cpp: (JSObjectCallAsFunction):
  • JavaScriptCore.exp:
  • kjs/Activation.h:
  • kjs/ExecState.cpp: (KJS::ExecState::ExecState): (KJS::GlobalExecState::GlobalExecState):
  • kjs/ExecState.h: (KJS::ExecState::globalThisValue):
  • kjs/ExecStateInlines.h: (KJS::ExecState::ExecState): (KJS::FunctionExecState::FunctionExecState):
  • kjs/JSGlobalObject.cpp: (KJS::JSGlobalObject::reset): (KJS::JSGlobalObject::toGlobalObject):
  • kjs/JSGlobalObject.h: (KJS::JSGlobalObject::JSGlobalObjectData::JSGlobalObjectData): (KJS::JSGlobalObject::JSGlobalObject):
  • kjs/array_instance.cpp: (KJS::CompareWithCompareFunctionArguments::CompareWithCompareFunctionArguments): (KJS::compareWithCompareFunctionForQSort):
  • kjs/array_object.cpp: (KJS::arrayProtoFuncSort): (KJS::arrayProtoFuncFilter): (KJS::arrayProtoFuncMap): (KJS::arrayProtoFuncEvery): (KJS::arrayProtoFuncForEach): (KJS::arrayProtoFuncSome):
  • kjs/function.cpp: (KJS::FunctionImp::callAsFunction): (KJS::ActivationImp::toThisObject): (KJS::globalFuncEval): (KJS::PrototypeReflexiveFunction::PrototypeReflexiveFunction): (KJS::PrototypeReflexiveFunction::mark):
  • kjs/function.h: (KJS::PrototypeReflexiveFunction::cachedGlobalObject):
  • kjs/function_object.cpp: (KJS::functionProtoFuncApply): (KJS::functionProtoFuncCall):
  • kjs/nodes.cpp: (KJS::ExpressionNode::resolveAndCall): (KJS::FunctionCallValueNode::evaluate): (KJS::LocalVarFunctionCallNode::inlineEvaluate): (KJS::ScopedVarFunctionCallNode::inlineEvaluate): (KJS::FunctionCallBracketNode::evaluate): (KJS::FunctionCallDotNode::inlineEvaluate):
  • kjs/object.cpp: (KJS::JSObject::call): (KJS::JSObject::put): (KJS::tryGetAndCallProperty): (KJS::JSObject::lookupGetter): (KJS::JSObject::lookupSetter): (KJS::JSObject::toThisObject): (KJS::JSObject::toGlobalObject): (KJS::JSObject::fillGetterPropertySlot):
  • kjs/object.h:
  • kjs/object_object.cpp: (KJS::objectProtoFuncLookupGetter): (KJS::objectProtoFuncLookupSetter):
  • kjs/string_object.cpp: (KJS::replace):

WebCore:

2008-04-04 Sam Weinig <[email protected]>

Reviewed by Geoffrey Garen.

First step in implementing the "split window"

  • This patch takes the first step in changing the window navigation model from clearing the window properties on navigation, to replacing an inner window. This is necessary to safely perform security checks using the lexical global object.

This first step adds a new class called JSDOMWindowWrapper, which wraps
the real window object. All JS calls that would go to the window object
now go to it, which it forwards to the current inner window. To accomplish
this, the wrapper window is used as the ThisValue wherever the window was used
before.

  • WebCore.base.exp:
  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/JSDOMWindowBase.cpp: (WebCore::JSDOMWindowBase::JSDOMWindowBase): (WebCore::JSDOMWindowBase::clear): Reset the wrapper windows prototype too. (WebCore::JSDOMWindowBase::toThisObject): (WebCore::JSDOMWindowBase::wrapper): (WebCore::windowProtoFuncAToB): (WebCore::windowProtoFuncBToA): (WebCore::windowProtoFuncOpen): (WebCore::windowProtoFuncSetTimeout): (WebCore::windowProtoFuncClearTimeout): (WebCore::windowProtoFuncSetInterval): (WebCore::windowProtoFuncAddEventListener): (WebCore::windowProtoFuncRemoveEventListener): (WebCore::windowProtoFuncShowModalDialog): (WebCore::windowProtoFuncNotImplemented): (WebCore::toJS):
  • bindings/js/JSDOMWindowBase.h: Fix to expect the wrapper as the thisObj.
  • bindings/js/JSDOMWindowCustom.cpp: (WebCore::JSDOMWindow::postMessage): (WebCore::toDOMWindow):
  • bindings/js/JSDOMWindowWrapper.cpp: Added. (WebCore::): (WebCore::JSDOMWindowWrapper::JSDOMWindowWrapper): (WebCore::JSDOMWindowWrapper::~JSDOMWindowWrapper): (WebCore::JSDOMWindowWrapper::mark): (WebCore::JSDOMWindowWrapper::className): (WebCore::JSDOMWindowWrapper::getOwnPropertySlot): (WebCore::JSDOMWindowWrapper::put): (WebCore::JSDOMWindowWrapper::deleteProperty): (WebCore::JSDOMWindowWrapper::getPropertyNames): (WebCore::JSDOMWindowWrapper::getPropertyAttributes): (WebCore::JSDOMWindowWrapper::defineGetter): (WebCore::JSDOMWindowWrapper::defineSetter): (WebCore::JSDOMWindowWrapper::lookupGetter): (WebCore::JSDOMWindowWrapper::lookupSetter): (WebCore::JSDOMWindowWrapper::toGlobalObject): (WebCore::JSDOMWindowWrapper::impl): (WebCore::JSDOMWindowWrapper::disconnectFrame): (WebCore::JSDOMWindowWrapper::clear): (WebCore::toJS):
  • bindings/js/JSDOMWindowWrapper.h: Added. (WebCore::JSDOMWindowWrapper::innerWindow): (WebCore::JSDOMWindowWrapper::setInnerWindow): (WebCore::JSDOMWindowWrapper::classInfo): Forward methods to the innerWindow.
  • bindings/js/JSHTMLDocumentCustom.cpp: (WebCore::JSHTMLDocument::open):
  • bindings/js/ScheduledAction.cpp: (WebCore::ScheduledAction::execute):
  • bindings/js/kjs_events.cpp: (WebCore::JSAbstractEventListener::handleEvent):
  • bindings/js/kjs_proxy.cpp: (WebCore::KJSProxy::~KJSProxy): (WebCore::KJSProxy::evaluate): (WebCore::KJSProxy::clear): (WebCore::KJSProxy::initScript): (WebCore::KJSProxy::clearDocumentWrapper): (WebCore::KJSProxy::processingUserGesture): (WebCore::KJSProxy::attachDebugger):
  • bindings/js/kjs_proxy.h: (WebCore::KJSProxy::haveWindowWrapper): (WebCore::KJSProxy::windowWrapper): (WebCore::KJSProxy::globalObject): (WebCore::KJSProxy::initScriptIfNeeded): Hold onto the wrapper window instead of global object. As a convenience, keep the globalObject() as a forward to the inner window.
  • bindings/objc/DOMUtility.mm: (KJS::createDOMWrapper):
  • bindings/scripts/CodeGeneratorJS.pm:
  • dom/Document.cpp: (WebCore::Document::domWindow):
  • dom/Document.h: (WebCore::Document::defaultView):
  • loader/FrameLoader.cpp: (WebCore::FrameLoader::dispatchWindowObjectAvailable):
  • page/DOMWindow.idl:
  • page/Frame.cpp: (WebCore::Frame::~Frame): (WebCore::Frame::pageDestroyed):
Location:
trunk/JavaScriptCore/kjs
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/Activation.h

    r31136 r31746  
    6767        static const ClassInfo info;
    6868
     69        virtual JSObject* toThisObject(ExecState*) const;
     70
    6971        virtual void mark();
    7072        void markChildren();
  • trunk/JavaScriptCore/kjs/ExecState.cpp

    r31267 r31746  
    4343
    4444// The constructor for the globalExec pseudo-ExecState
    45 inline ExecState::ExecState(JSGlobalObject* globalObject)
     45inline ExecState::ExecState(JSGlobalObject* globalObject, JSObject* thisObject)
    4646    : m_globalObject(globalObject)
    4747    , m_exception(0)
     
    5656    , m_inlineScopeChainNode(0, 0)
    5757    , m_variableObject(globalObject)
    58     , m_thisValue(globalObject)
     58    , m_thisValue(thisObject)
     59    , m_globalThisValue(thisObject)
    5960    , m_iterationDepth(0)
    6061    , m_switchDepth(0)
     
    7879    , m_variableObject(globalObject)
    7980    , m_thisValue(thisObject)
     81    , m_globalThisValue(thisObject)
    8082    , m_iterationDepth(0)
    8183    , m_switchDepth(0)
     
    101103    , m_variableObject(variableObject)
    102104    , m_thisValue(thisObject)
     105    , m_globalThisValue(thisObject)
    103106    , m_iterationDepth(0)
    104107    , m_switchDepth(0)
     
    116119}
    117120
    118 GlobalExecState::GlobalExecState(JSGlobalObject* globalObject)
    119     : ExecState(globalObject)
     121GlobalExecState::GlobalExecState(JSGlobalObject* globalObject, JSObject* thisObject)
     122    : ExecState(globalObject, thisObject)
    120123{
    121124}
  • trunk/JavaScriptCore/kjs/ExecState.h

    r31172 r31746  
    7474       
    7575        JSObject* thisValue() const { return m_thisValue; }
     76        JSObject* globalThisValue() const { return m_globalThisValue; }
    7677       
    7778        ExecState* callingExecState() { return m_callingExec; }
     
    165166
    166167    protected:
    167         ExecState(JSGlobalObject*);
     168        ExecState(JSGlobalObject*, JSObject* thisObject);
    168169        ExecState(JSGlobalObject*, JSObject* thisObject, ProgramNode*);
    169170        ExecState(JSGlobalObject*, JSObject* thisObject, EvalNode*, ExecState* callingExecState, const ScopeChain&, JSVariableObject*);
    170         ExecState(JSGlobalObject*, JSObject* thisObject, FunctionBodyNode*, ExecState* callingExecState, FunctionImp*, const List& args);
     171        ExecState(JSGlobalObject*, JSObject* thisObject, JSObject* globalThisValue, FunctionBodyNode*, ExecState* callingExecState, FunctionImp*, const List& args);
    171172        ~ExecState();
    172173
     
    191192        ScopeChainNode m_inlineScopeChainNode;
    192193        JSVariableObject* m_variableObject;
     194
    193195        JSObject* m_thisValue;
     196        JSObject* m_globalThisValue;
    194197       
    195198        LabelStack m_labelStack;
     
    204207    class GlobalExecState : public ExecState {
    205208    public:
    206         GlobalExecState(JSGlobalObject*);
     209        GlobalExecState(JSGlobalObject*, JSObject* thisObject);
    207210        ~GlobalExecState();
    208211    };
     
    222225    class FunctionExecState : public ExecState {
    223226    public:
    224         FunctionExecState(JSGlobalObject*, JSObject* thisObject, FunctionBodyNode*,
     227        FunctionExecState(JSGlobalObject*, JSObject* thisObject, JSObject* globalThisValue, FunctionBodyNode*,
    225228            ExecState* callingExecState, FunctionImp*, const List& args);
    226229        ~FunctionExecState();
  • trunk/JavaScriptCore/kjs/ExecStateInlines.h

    r31205 r31746  
    3131namespace KJS  {
    3232
    33     inline ExecState::ExecState(JSGlobalObject* globalObject, JSObject* thisObject,
     33    inline ExecState::ExecState(JSGlobalObject* globalObject, JSObject* thisObject, JSObject* globalThisValue,
    3434                                FunctionBodyNode* functionBodyNode, ExecState* callingExec,
    3535                                FunctionImp* func, const List& args)
     
    4545        , m_inlineScopeChainNode(0, 0)
    4646        , m_thisValue(thisObject)
     47        , m_globalThisValue(globalThisValue)
    4748        , m_iterationDepth(0)
    4849        , m_switchDepth(0)
     
    6970    }
    7071
    71     inline FunctionExecState::FunctionExecState(JSGlobalObject* globalObject, JSObject* thisObject,
     72    inline FunctionExecState::FunctionExecState(JSGlobalObject* globalObject, JSObject* thisObject, JSObject* globalThisValue,
    7273                                                FunctionBodyNode* functionBodyNode, ExecState* callingExec,
    7374                                                FunctionImp* func, const List& args)
    74         : ExecState(globalObject, thisObject, functionBodyNode, callingExec, func, args)
     75        : ExecState(globalObject, thisObject, globalThisValue, functionBodyNode, callingExec, func, args)
    7576    {
    7677        m_globalObject->activeExecStates().append(this);
  • trunk/JavaScriptCore/kjs/JSGlobalObject.cpp

    r31226 r31746  
    328328    // Set global functions.
    329329
    330     d()->evalFunction = new PrototypeReflexiveFunction(exec, d()->functionPrototype, 1, exec->propertyNames().eval, globalFuncEval);
     330    d()->evalFunction = new PrototypeReflexiveFunction(exec, d()->functionPrototype, 1, exec->propertyNames().eval, globalFuncEval, this);
    331331    putDirectFunction(d()->evalFunction, DontEnum);
    332332    putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 2, "parseInt", globalFuncParseInt), DontEnum);
     
    535535}
    536536
     537JSGlobalObject* JSGlobalObject::toGlobalObject(ExecState*) const
     538{
     539    return const_cast<JSGlobalObject*>(this);
     540}
     541
    537542ExecState* JSGlobalObject::globalExec()
    538543{
  • trunk/JavaScriptCore/kjs/JSGlobalObject.h

    r31173 r31746  
    7777
    7878        struct JSGlobalObjectData : public JSVariableObjectData {
    79             JSGlobalObjectData(JSGlobalObject* globalObject)
     79            JSGlobalObjectData(JSGlobalObject* globalObject, JSObject* thisValue)
    8080                : JSVariableObjectData(&inlineSymbolTable)
    81                 , globalExec(globalObject)
     81                , globalExec(globalObject, thisValue)
    8282            {
    8383            }
     
    142142    public:
    143143        JSGlobalObject()
    144             : JSVariableObject(new JSGlobalObjectData(this))
     144            : JSVariableObject(new JSGlobalObjectData(this, this))
    145145        {
    146146            init();
     
    148148
    149149    protected:
    150         JSGlobalObject(JSValue* proto)
    151             : JSVariableObject(proto, new JSGlobalObjectData(this))
     150        JSGlobalObject(JSValue* proto, JSObject* globalThisValue)
     151            : JSVariableObject(proto, new JSGlobalObjectData(this, globalThisValue))
    152152        {
    153153            init();
     
    226226
    227227        virtual bool isGlobalObject() const { return true; }
     228        virtual JSGlobalObject* toGlobalObject(ExecState*) const;
    228229
    229230        virtual ExecState* globalExec();
  • trunk/JavaScriptCore/kjs/array_instance.cpp

    r31343 r31746  
    2424#include "array_instance.h"
    2525
    26 #include "JSGlobalObject.h"
    2726#include "PropertyNameArray.h"
    2827#include <wtf/Assertions.h>
     
    490489        : exec(e)
    491490        , compareFunction(cf)
    492         , globalObject(e->dynamicGlobalObject())
     491        , globalThisValue(e->globalThisValue())
    493492    {
    494493    }
     
    497496    JSObject *compareFunction;
    498497    List arguments;
    499     JSGlobalObject* globalObject;
     498    JSObject* globalThisValue;
    500499};
    501500
     
    514513    args->arguments.append(va);
    515514    args->arguments.append(vb);
    516     double compareResult = args->compareFunction->call
    517         (args->exec, args->globalObject, args->arguments)->toNumber(args->exec);
     515    double compareResult = args->compareFunction->call(args->exec, args->globalThisValue, args->arguments)->toNumber(args->exec);
    518516    return compareResult < 0 ? -1 : compareResult > 0 ? 1 : 0;
    519517}
  • trunk/JavaScriptCore/kjs/array_object.cpp

    r30041 r31746  
    405405                l.append(jObj);
    406406                l.append(minObj);
    407                 compareResult = sortFunction->call(exec, exec->dynamicGlobalObject(), l)->toNumber(exec);
     407                compareResult = sortFunction->call(exec, exec->globalThisValue(), l)->toNumber(exec);
    408408            } else
    409409                compareResult = (jObj->toString(exec) < minObj->toString(exec)) ? -1 : 1;
     
    503503        return throwError(exec, TypeError);
    504504
    505     JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicGlobalObject() :  args[1]->toObject(exec);
     505    JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->globalThisValue() :  args[1]->toObject(exec);
    506506    JSObject* resultArray = static_cast<JSObject*>(exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, exec->emptyList()));
    507507
     
    536536        return throwError(exec, TypeError);
    537537
    538     JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicGlobalObject() :  args[1]->toObject(exec);
     538    JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->globalThisValue() :  args[1]->toObject(exec);
    539539
    540540    unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);
     
    576576        return throwError(exec, TypeError);
    577577
    578     JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicGlobalObject() :  args[1]->toObject(exec);
     578    JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->globalThisValue() :  args[1]->toObject(exec);
    579579
    580580    JSValue* result = jsBoolean(true);
     
    611611        return throwError(exec, TypeError);
    612612
    613     JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicGlobalObject() :  args[1]->toObject(exec);
     613    JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->globalThisValue() :  args[1]->toObject(exec);
    614614
    615615    unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);
     
    636636        return throwError(exec, TypeError);
    637637
    638     JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicGlobalObject() :  args[1]->toObject(exec);
     638    JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->globalThisValue() :  args[1]->toObject(exec);
    639639
    640640    JSValue* result = jsBoolean(false);
  • trunk/JavaScriptCore/kjs/function.cpp

    r31173 r31746  
    7474JSValue* FunctionImp::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
    7575{
    76     FunctionExecState newExec(exec->dynamicGlobalObject(), thisObj, body.get(), exec, this, args);
     76    FunctionExecState newExec(exec->dynamicGlobalObject(), thisObj, exec->globalThisValue(), body.get(), exec, this, args);
    7777    JSValue* result = body->execute(&newExec);
    7878    if (newExec.completionType() == ReturnValue)
     
    465465    // call instead of storing the list ourselves.
    466466    d()->argumentsObject = new Arguments(exec, d()->exec->function(), *d()->exec->arguments(), this);
     467}
     468
     469JSObject* ActivationImp::toThisObject(ExecState* exec) const
     470{
     471    return exec->globalThisValue();
    467472}
    468473
     
    739744JSValue* globalFuncEval(ExecState* exec, PrototypeReflexiveFunction* function, JSObject* thisObj, const List& args)
    740745{
    741     JSGlobalObject* globalObject = thisObj->isGlobalObject() ? static_cast<JSGlobalObject*>(thisObj) : 0;
     746    JSGlobalObject* globalObject = thisObj->toGlobalObject(exec);
    742747
    743748    if (!globalObject || globalObject->evalFunction() != function)
     
    745750
    746751    ScopeChain scopeChain(globalObject);
    747     return eval(exec, scopeChain, globalObject, globalObject, globalObject, args);
     752    return eval(exec, scopeChain, globalObject, globalObject, function->cachedGlobalObject()->toThisObject(exec), args);
    748753}
    749754
     
    891896// ------------------------------ PrototypeReflexiveFunction -------------------------------
    892897
    893 PrototypeReflexiveFunction::PrototypeReflexiveFunction(ExecState* exec, FunctionPrototype* functionPrototype, int len, const Identifier& name, JSMemberFunction function)
     898PrototypeReflexiveFunction::PrototypeReflexiveFunction(ExecState* exec, FunctionPrototype* functionPrototype, int len, const Identifier& name, JSMemberFunction function, JSGlobalObject* cachedGlobalObject)
    894899    : InternalFunctionImp(functionPrototype, name)
    895900    , m_function(function)
     901    , m_cachedGlobalObject(cachedGlobalObject)
    896902{
    897903    ASSERT_ARG(function, function);
     904    ASSERT_ARG(cachedGlobalObject, cachedGlobalObject);
    898905    putDirect(exec->propertyNames().length, jsNumber(len), DontDelete | ReadOnly | DontEnum);
    899906}
     
    904911}
    905912
     913void PrototypeReflexiveFunction::mark()
     914{
     915    InternalFunctionImp::mark();
     916    if (!m_cachedGlobalObject->marked())
     917        m_cachedGlobalObject->mark();
     918}
     919
    906920} // namespace KJS
  • trunk/JavaScriptCore/kjs/function.h

    r30871 r31746  
    143143    typedef JSValue* (*JSMemberFunction)(ExecState*, PrototypeReflexiveFunction*, JSObject* thisObj, const List&);
    144144
    145     PrototypeReflexiveFunction(ExecState*, FunctionPrototype*, int len, const Identifier&, JSMemberFunction);
     145    PrototypeReflexiveFunction(ExecState*, FunctionPrototype*, int len, const Identifier&, JSMemberFunction, JSGlobalObject* expectedThisObject);
    146146
     147    virtual void mark();
    147148    virtual JSValue* callAsFunction(ExecState* exec, JSObject* thisObj, const List&);
     149
     150    JSGlobalObject* cachedGlobalObject() const { return m_cachedGlobalObject; }
    148151
    149152  private:
    150153    const JSMemberFunction m_function;
     154    JSGlobalObject* m_cachedGlobalObject;
    151155  };
    152156
  • trunk/JavaScriptCore/kjs/function_object.cpp

    r31208 r31746  
    8787    JSObject* applyThis;
    8888    if (thisArg->isUndefinedOrNull())
    89         applyThis = exec->dynamicGlobalObject();
     89        applyThis = exec->globalThisValue();
    9090    else
    9191        applyThis = thisArg->toObject(exec);
     
    117117    JSObject* callThis;
    118118    if (thisArg->isUndefinedOrNull())
    119         callThis = exec->dynamicGlobalObject();
     119        callThis = exec->globalThisValue();
    120120    else
    121121        callThis = thisArg->toObject(exec);
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r31431 r31746  
    11231123            KJS_CHECKEXCEPTIONVALUE
    11241124
    1125             JSObject* thisObj = base;
    1126             // ECMA 11.2.3 says that in this situation the this value should be null.
    1127             // However, section 10.2.3 says that in the case where the value provided
    1128             // by the caller is null, the global object should be used. It also says
    1129             // that the section does not apply to internal functions, but for simplicity
    1130             // of implementation we use the global object anyway here. This guarantees
    1131             // that in host objects you always get a valid object for this.
    1132             if (thisObj->isActivationObject())
    1133                 thisObj = exec->dynamicGlobalObject();
    1134 
    11351125            if (callerType == EvalOperator) {
    11361126                if (base == exec->lexicalGlobalObject() && func == exec->lexicalGlobalObject()->evalFunction()) {
     
    11391129                }
    11401130            }
     1131
     1132            JSObject* thisObj = base->toThisObject(exec);
    11411133            return func->call(exec, thisObj, argList);
    11421134        }
     
    11831175    KJS_CHECKEXCEPTIONVALUE
    11841176
    1185     JSObject* thisObj =  exec->dynamicGlobalObject();
    1186 
     1177    JSObject* thisObj = exec->globalThisValue();
    11871178    return func->call(exec, thisObj, argList);
    11881179}
     
    12671258    KJS_CHECKEXCEPTIONVALUE
    12681259
    1269     return func->call(exec, exec->dynamicGlobalObject(), argList);
     1260    JSObject* thisObj = exec->globalThisValue();
     1261    return func->call(exec, thisObj, argList);
    12701262}
    12711263
     
    13191311    m_args->evaluateList(exec, argList);
    13201312    KJS_CHECKEXCEPTIONVALUE
    1321    
    1322     return func->call(exec, exec->dynamicGlobalObject(), argList);
     1313
     1314    JSObject* thisObj = exec->globalThisValue();
     1315    return func->call(exec, thisObj, argList);
    13231316}
    13241317
     
    14491442    ASSERT(!thisObj->isActivationObject());
    14501443
     1444    // No need to call toThisObject() on the thisObj as it is known not to be the GlobalObject or ActivationObject
    14511445    return func->call(exec, thisObj, argList);
    14521446}
     
    14981492    ASSERT(!thisObj->isActivationObject());
    14991493
     1494    // No need to call toThisObject() on the thisObj as it is known not to be the GlobalObject or ActivationObject
    15001495    return func->call(exec, thisObj, argList);
    15011496}
  • trunk/JavaScriptCore/kjs/object.cpp

    r31147 r31746  
    9494#endif
    9595
    96   JSValue *ret = callAsFunction(exec,thisObj,args);
     96  JSValue* ret = callAsFunction(exec, thisObj, args);
    9797
    9898#if KJS_MAX_STACK > 0
     
    262262          args.append(value);
    263263       
    264           setterFunc->call(exec, this, args);
     264          setterFunc->call(exec, this->toThisObject(exec), args);
    265265          return;
    266266        } else {
     
    338338    if (o->implementsCall()) { // spec says "not primitive type" but ...
    339339      JSObject *thisObj = const_cast<JSObject*>(object);
    340       JSValue* def = o->call(exec, thisObj, exec->emptyList());
     340      JSValue* def = o->call(exec, thisObj->toThisObject(exec), exec->emptyList());
    341341      JSType defType = def->type();
    342342      ASSERT(defType != GetterSetterType);
     
    418418    _prop.setHasGetterSetterProperties(true);
    419419    gs->setSetter(setterFunc);
     420}
     421
     422JSValue* JSObject::lookupGetter(ExecState*, const Identifier& propertyName)
     423{
     424    JSObject* obj = this;
     425    while (true) {
     426        JSValue* v = obj->getDirect(propertyName);
     427        if (v) {
     428            if (v->type() != GetterSetterType)
     429                return jsUndefined();
     430            JSObject* funcObj = static_cast<GetterSetterImp*>(v)->getGetter();
     431            if (!funcObj)
     432                return jsUndefined();
     433            return funcObj;
     434        }
     435
     436        if (!obj->prototype() || !obj->prototype()->isObject())
     437            return jsUndefined();
     438        obj = static_cast<JSObject*>(obj->prototype());
     439    }
     440}
     441
     442JSValue* JSObject::lookupSetter(ExecState*, const Identifier& propertyName)
     443{
     444    JSObject* obj = this;
     445    while (true) {
     446        JSValue* v = obj->getDirect(propertyName);
     447        if (v) {
     448            if (v->type() != GetterSetterType)
     449                return jsUndefined();
     450            JSObject* funcObj = static_cast<GetterSetterImp*>(v)->getSetter();
     451            if (!funcObj)
     452                return jsUndefined();
     453            return funcObj;
     454        }
     455
     456        if (!obj->prototype() || !obj->prototype()->isObject())
     457            return jsUndefined();
     458        obj = static_cast<JSObject*>(obj->prototype());
     459    }
    420460}
    421461
     
    546586}
    547587
     588JSObject* JSObject::toThisObject(ExecState*) const
     589{
     590    return const_cast<JSObject*>(this);
     591}
     592
     593JSGlobalObject* JSObject::toGlobalObject(ExecState*) const
     594{
     595    return 0;
     596}
     597
    548598void JSObject::putDirect(const Identifier &propertyName, JSValue *value, int attr)
    549599{
     
    571621    JSObject *getterFunc = gs->getGetter();
    572622    if (getterFunc)
    573         slot.setGetterSlot(this, getterFunc);
     623        slot.setGetterSlot(this->toThisObject(0), getterFunc);
    574624    else
    575625        slot.setUndefined(this);
  • trunk/JavaScriptCore/kjs/object.h

    r31225 r31746  
    403403    virtual UString toString(ExecState *exec) const;
    404404    virtual JSObject *toObject(ExecState *exec) const;
    405    
     405
     406    virtual JSObject* toThisObject(ExecState*) const;
     407    virtual JSGlobalObject* toGlobalObject(ExecState*) const;
     408
    406409    virtual bool getPropertyAttributes(const Identifier& propertyName, unsigned& attributes) const;
    407410   
     
    425428    void fillGetterPropertySlot(PropertySlot& slot, JSValue **location);
    426429
    427     void defineGetter(ExecState *exec, const Identifier& propertyName, JSObject *getterFunc);
    428     void defineSetter(ExecState *exec, const Identifier& propertyName, JSObject *setterFunc);
     430    virtual void defineGetter(ExecState*, const Identifier& propertyName, JSObject* getterFunction);
     431    virtual void defineSetter(ExecState*, const Identifier& propertyName, JSObject* setterFunction);
     432    virtual JSValue* lookupGetter(ExecState*, const Identifier& propertyName);
     433    virtual JSValue* lookupSetter(ExecState*, const Identifier& propertyName);
    429434
    430435    void saveProperties(SavedProperties &p) const { _prop.save(p); }
  • trunk/JavaScriptCore/kjs/object_object.cpp

    r31208 r31746  
    110110JSValue* objectProtoFuncLookupGetter(ExecState* exec, JSObject* thisObj, const List& args)
    111111{
    112     Identifier propertyName = Identifier(args[0]->toString(exec));
    113     JSObject* obj = thisObj;
    114     while (true) {
    115         JSValue* v = obj->getDirect(propertyName);
    116         if (v) {
    117             if (v->type() != GetterSetterType)
    118                 return jsUndefined();
    119             JSObject* funcObj = static_cast<GetterSetterImp*>(v)->getGetter();
    120             if (!funcObj)
    121                 return jsUndefined();
    122             return funcObj;
    123         }
    124 
    125         if (!obj->prototype() || !obj->prototype()->isObject())
    126             return jsUndefined();
    127         obj = static_cast<JSObject*>(obj->prototype());
    128     }
     112    return thisObj->lookupGetter(exec, Identifier(args[0]->toString(exec)));
    129113}
    130114
    131115JSValue* objectProtoFuncLookupSetter(ExecState* exec, JSObject* thisObj, const List& args)
    132116{
    133     Identifier propertyName = Identifier(args[0]->toString(exec));
    134     JSObject* obj = thisObj;
    135     while (true) {
    136         JSValue* v = obj->getDirect(propertyName);
    137         if (v) {
    138             if (v->type() != GetterSetterType)
    139                 return jsUndefined();
    140             JSObject* funcObj = static_cast<GetterSetterImp*>(v)->getSetter();
    141             if (!funcObj)
    142                 return jsUndefined();
    143             return funcObj;
    144         }
    145 
    146         if (!obj->prototype() || !obj->prototype()->isObject())
    147             return jsUndefined();
    148         obj = static_cast<JSObject*>(obj->prototype());
    149     }
     117    return thisObj->lookupSetter(exec, Identifier(args[0]->toString(exec)));
    150118}
    151119
  • trunk/JavaScriptCore/kjs/string_object.cpp

    r30942 r31746  
    351351          args.append(sourceVal);
    352352
    353           substitutedReplacement = replacementFunction->call(exec, exec->dynamicGlobalObject(),
    354                                                              args)->toString(exec);
     353          substitutedReplacement = replacementFunction->call(exec, exec->globalThisValue(), args)->toString(exec);
    355354      } else
    356355          substitutedReplacement = substituteBackreferences(replacementString, source, ovector, reg);
     
    401400      args.append(sourceVal);
    402401     
    403       replacementString = replacementFunction->call(exec, exec->dynamicGlobalObject(),
    404                                                     args)->toString(exec);
     402      replacementString = replacementFunction->call(exec, exec->globalThisValue(), args)->toString(exec);
    405403  }
    406404
Note: See TracChangeset for help on using the changeset viewer.