Changeset 38148 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Nov 5, 2008, 7:26:30 PM (17 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

2008-11-05 Gavin Barraclough <[email protected]>

Reviewed by Maciej Stachowiak.

https://bugs.webkit.org/show_bug.cgi?id=22094

Fix for bug where the callee incorrectly recieves the caller's lexical
global object as this, rather than its own. Implementation closely
follows the spec, passing jsNull, checking in the callee and replacing
with the global object where necessary.

  • VM/CTI.cpp: (JSC::CTI::compileOpCall):
  • VM/Machine.cpp: (JSC::Machine::cti_op_call_NotJSFunction): (JSC::Machine::cti_op_call_eval):
  • runtime/JSCell.h: (JSC::JSValue::toThisObject):
  • runtime/JSImmediate.cpp: (JSC::JSImmediate::toThisObject):
  • runtime/JSImmediate.h:

LayoutTests:

2008-11-05 Gavin Barraclough <[email protected]>

Reviewed by Maciej Stachowiak.

Previosly the test 'cross-site-this' checked that the second level deep method called
across frames recieved the correct this pointer, when no base object is provided.


Test updated so that it check that the code in the child frame, and both the first
and second functions called in the parent frame recieve the correct this values.

  • fast/frames/cross-site-this.html:
  • fast/frames/resources/cross-site-this-helper.html:
Location:
trunk/JavaScriptCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r38146 r38148  
     12008-11-05  Gavin Barraclough  <[email protected]>
     2
     3        Reviewed by Maciej Stachowiak.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=22094
     6
     7        Fix for bug where the callee incorrectly recieves the caller's lexical
     8        global object as this, rather than its own.  Implementation closely
     9        follows the spec, passing jsNull, checking in the callee and replacing
     10        with the global object where necessary.
     11
     12        * VM/CTI.cpp:
     13        (JSC::CTI::compileOpCall):
     14        * VM/Machine.cpp:
     15        (JSC::Machine::cti_op_call_NotJSFunction):
     16        (JSC::Machine::cti_op_call_eval):
     17        * runtime/JSCell.h:
     18        (JSC::JSValue::toThisObject):
     19        * runtime/JSImmediate.cpp:
     20        (JSC::JSImmediate::toThisObject):
     21        * runtime/JSImmediate.h:
     22
    1232008-11-05  Kevin Ollivier  <[email protected]>
    224
  • trunk/JavaScriptCore/VM/CTI.cpp

    r38012 r38148  
    629629    if (opcodeID != op_construct) {
    630630        int thisVal = instruction[3].u.operand;
    631         if (thisVal == missingThisObjectMarker()) {
    632             // FIXME: should this be loaded dynamically off m_callFrame?
    633             m_jit.movl_i32m(asInteger(m_callFrame->globalThisValue()), firstArg * sizeof(Register), X86::edi);
    634         } else {
     631        if (thisVal == missingThisObjectMarker())
     632            m_jit.movl_i32m(asInteger(jsNull()), firstArg * sizeof(Register), X86::edi);
     633        else {
    635634            emitGetArg(thisVal, X86::eax);
    636635            emitPutResult(firstArg);
  • trunk/JavaScriptCore/VM/Machine.cpp

    r38137 r38148  
    48194819        {
    48204820            SamplingTool::HostCallRecord callRecord(CTI_SAMPLER);
    4821             returnValue = callData.native.function(callFrame, asObject(funcVal), argv[0].jsValue(callFrame), argList);
     4821
     4822            // All host methods should be calling toThisObject, but this is not presently the case.
     4823            JSValue* thisValue = argv[0].jsValue(callFrame);
     4824            if (thisValue == jsNull())
     4825                thisValue = callFrame->globalThisValue();
     4826
     4827            returnValue = callData.native.function(callFrame, asObject(funcVal), thisValue, argList);
    48224828        }
    48234829        ARG_setCallFrame(previousCallFrame);
     
    56455651
    56465652    if (baseVal == scopeChain->globalObject() && funcVal == scopeChain->globalObject()->evalFunction()) {
    5647         JSObject* thisObject = asObject(callFrame[codeBlock->thisRegister].jsValue(callFrame));
     5653        JSObject* thisObject = callFrame[codeBlock->thisRegister].jsValue(callFrame)->toThisObject(callFrame);
    56485654        JSValue* exceptionValue = noValue();
    56495655        JSValue* result = machine->callEval(callFrame, thisObject, scopeChain, registerFile, registerOffset - RegisterFile::CallFrameHeaderSize - argCount, argCount, exceptionValue);
  • trunk/JavaScriptCore/runtime/JSCell.h

    r38137 r38148  
    285285    {
    286286        if (UNLIKELY(JSImmediate::isImmediate(asValue())))
    287             return JSImmediate::toObject(asValue(), exec);
     287            return JSImmediate::toThisObject(asValue(), exec);
    288288        return asCell()->toThisObject(exec);
    289289    }
  • trunk/JavaScriptCore/runtime/JSImmediate.cpp

    r37938 r38148  
    3232
    3333namespace JSC {
     34
     35JSObject* JSImmediate::toThisObject(JSValue* v, ExecState* exec)
     36{
     37    ASSERT(isImmediate(v));
     38    if (isNumber(v))
     39        return constructNumberFromImmediateNumber(exec, v);
     40    if (isBoolean(v))
     41        return constructBooleanFromImmediateBoolean(exec, v);
     42    if (v == jsNull())
     43        return exec->globalThisValue();
     44   
     45    JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, v->isNull());
     46    exec->setException(exception);
     47    return new (exec) JSNotAnObject(exec, exception);
     48}
    3449
    3550JSObject* JSImmediate::toObject(JSValue* v, ExecState* exec)
  • trunk/JavaScriptCore/runtime/JSImmediate.h

    r37938 r38148  
    234234        static bool toBoolean(JSValue*);
    235235        static JSObject* toObject(JSValue*, ExecState*);
     236        static JSObject* toThisObject(JSValue*, ExecState*);
    236237        static UString toString(JSValue*);
    237238
Note: See TracChangeset for help on using the changeset viewer.