Changeset 31267 in webkit


Ignore:
Timestamp:
Mar 24, 2008 7:26:24 PM (16 years ago)
Author:
weinig@apple.com
Message:

JavaScriptCore:

2008-03-23 Sam Weinig <sam@webkit.org>

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 <sam@webkit.org>

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
Files:
6 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  <sam@webkit.org>
     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  <jruderman@gmail.com>
    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);
  • trunk/WebCore/ChangeLog

    r31258 r31267  
     12008-03-24  Sam Weinig  <sam@webkit.org>
     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        * bindings/js/kjs_proxy.cpp:
     9        (WebCore::KJSProxy::evaluate): No need to pass a thisObject since we want the global object to be used.
     10        * bridge/jni/jni_jsobject.mm:
     11        (JavaJSObject::eval): To avoid any change to this function, don't pass a thisObject to keep the same
     12        behavior.
     13
    1142008-03-24  Brady Eidson  <beidson@apple.com>
    215
  • trunk/WebCore/bindings/js/kjs_proxy.cpp

    r31197 r31267  
    8383    m_frame->keepAlive();
    8484
    85     // FIXME: Can this call to toJSDOMWindow be replaced by using m_globalObject.
    86     JSValue* thisNode = toJSDOMWindow(m_frame);
    87 
    8885    m_globalObject->startTimeoutCheck();
    89     Completion comp = Interpreter::evaluate(exec, filename, baseLine, str.characters(), str.length(), thisNode);
     86    Completion comp = Interpreter::evaluate(exec, filename, baseLine, str.characters(), str.length());
    9087    m_globalObject->stopTimeoutCheck();
    9188 
  • trunk/WebCore/bridge/jni/jni_jsobject.mm

    r31076 r31267  
    311311    JS_LOG ("script = %s\n", JavaString(script).UTF8String());
    312312   
    313     JSObject *thisObj = const_cast<JSObject*>(_imp);
    314     JSValue *result;
    315    
     313    JSValue* result;
     314
    316315    JSLock lock;
    317316   
     
    321320
    322321    rootObject->globalObject()->startTimeoutCheck();
    323     Completion completion = Interpreter::evaluate(rootObject->globalObject()->globalExec(), UString(), 0, JavaString(script).ustring(),thisObj);
     322    Completion completion = Interpreter::evaluate(rootObject->globalObject()->globalExec(), UString(), 0, JavaString(script).ustring());
    324323    rootObject->globalObject()->stopTimeoutCheck();
    325324    ComplType type = completion.complType();
Note: See TracChangeset for help on using the changeset viewer.