Changeset 31267 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Mar 24, 2008, 7:26:24 PM (17 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

2008-03-23 Sam Weinig <[email protected]>

Reviewed by Darin Adler.

Fix http://bugs.webkit.org/show_bug.cgi?id=18048
The "thisObject" parameter to JSEvaluateScript is not used properly

Making passing a thisObject to JSEvaluateScript actually set the thisObject of the created
ExecState.

  • API/testapi.c: (main): Add tests for setting the thisObject when calling JSEvaluateScript.
  • kjs/ExecState.cpp: (KJS::ExecState::ExecState): Assign the thisObject to m_thisValue and remove the comment.

WebCore:

2008-03-24 Sam Weinig <[email protected]>

Reviewed by Darin Adler.

Fix http://bugs.webkit.org/show_bug.cgi?id=18048
The "thisObject" parameter to JSEvaluateScript is not used properly

  • bindings/js/kjs_proxy.cpp: (WebCore::KJSProxy::evaluate): No need to pass a thisObject since we want the global object to be used.
  • bridge/jni/jni_jsobject.mm: (JavaJSObject::eval): To avoid any change to this function, don't pass a thisObject to keep the same behavior.
Location:
trunk/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/testapi.c

    r30795 r31267  
    870870    v = JSObjectCallAsFunction(context, function, o, 0, NULL, NULL);
    871871    ASSERT(JSValueIsEqual(context, v, o, NULL));
    872    
     872
     873    functionBody = JSStringCreateWithUTF8CString("return eval(\"this\");");
     874    function = JSObjectMakeFunction(context, NULL, 0, NULL, functionBody, NULL, 1, NULL);
     875    JSStringRelease(functionBody);
     876    v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL);
     877    ASSERT(JSValueIsEqual(context, v, globalObject, NULL));
     878    v = JSObjectCallAsFunction(context, function, o, 0, NULL, NULL);
     879    ASSERT(JSValueIsEqual(context, v, o, NULL));
     880
     881    JSStringRef script = JSStringCreateWithUTF8CString("this;");
     882    v = JSEvaluateScript(context, script, NULL, NULL, 0, NULL);
     883    ASSERT(JSValueIsEqual(context, v, globalObject, NULL));
     884    v = JSEvaluateScript(context, script, o, NULL, 0, NULL);
     885    ASSERT(JSValueIsEqual(context, v, o, NULL));
     886    JSStringRelease(script);
     887
     888    script = JSStringCreateWithUTF8CString("eval(this);");
     889    v = JSEvaluateScript(context, script, NULL, NULL, 0, NULL);
     890    ASSERT(JSValueIsEqual(context, v, globalObject, NULL));
     891    v = JSEvaluateScript(context, script, o, NULL, 0, NULL);
     892    ASSERT(JSValueIsEqual(context, v, o, NULL));
     893    JSStringRelease(script);
     894
    873895    char* scriptUTF8 = createStringWithContentsOfFile(scriptPath);
    874896    if (!scriptUTF8)
    875897        printf("FAIL: Test script could not be loaded.\n");
    876898    else {
    877         JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8);
     899        script = JSStringCreateWithUTF8CString(scriptUTF8);
    878900        result = JSEvaluateScript(context, script, NULL, NULL, 1, &exception);
    879901        if (JSValueIsUndefined(context, result))
  • trunk/JavaScriptCore/ChangeLog

    r31229 r31267  
     12008-03-23  Sam Weinig  <[email protected]>
     2
     3        Reviewed by Darin Adler.
     4
     5        Fix http://bugs.webkit.org/show_bug.cgi?id=18048
     6        The "thisObject" parameter to JSEvaluateScript is not used properly
     7
     8        Making passing a thisObject to JSEvaluateScript actually set the thisObject of the created
     9        ExecState.
     10
     11        * API/testapi.c:
     12        (main): Add tests for setting the thisObject when calling JSEvaluateScript.
     13
     14        * kjs/ExecState.cpp:
     15        (KJS::ExecState::ExecState): Assign the thisObject to m_thisValue and remove the comment.
     16
    1172008-03-22  Jesse Ruderman  <[email protected]>
    218
  • trunk/JavaScriptCore/kjs/ExecState.cpp

    r31173 r31267  
    6464}
    6565
    66 inline ExecState::ExecState(JSGlobalObject* globalObject, JSObject* /*thisObject*/, ProgramNode* programNode)
     66inline ExecState::ExecState(JSGlobalObject* globalObject, JSObject* thisObject, ProgramNode* programNode)
    6767    : m_globalObject(globalObject)
    6868    , m_exception(0)
     
    7777    , m_inlineScopeChainNode(0, 0)
    7878    , m_variableObject(globalObject)
    79     , m_thisValue(globalObject)
     79    , m_thisValue(thisObject)
    8080    , m_iterationDepth(0)
    8181    , m_switchDepth(0)
    8282    , m_codeType(GlobalCode)
    8383{
    84     // FIXME: This function ignores the "thisObject" parameter, which means that the API for evaluating
    85     // a script with a this object that's not the same as the global object is broken, and probably
    86     // has been for some time.
    8784    ASSERT(m_scopeNode);
    8885    m_scopeChain.push(globalObject);
Note: See TracChangeset for help on using the changeset viewer.