Changeset 51329 in webkit for trunk/JavaScriptCore/API


Ignore:
Timestamp:
Nov 23, 2009, 4:54:27 PM (16 years ago)
Author:
[email protected]
Message:

Part 1/3 of <rdar://problem/7377477> REGRESSION: Many web pages fail to render after interesting script runs in isolated world

Reviewed by Geoff Garen.

Some clients of the JavaScriptCore API expect to be able to make callbacks over the JSC API,
and for this to automagically cause execution to take place in the world associated with the
global object associated with the ExecState (JSContextRef) passed. However this is not how
things work - the world must be explicitly set within WebCore.

Making this work just for API calls to evaluate & call will be a far from perfect solution,
since direct (non-API) use of JSC still relies on WebCore setting the current world correctly.
A better solution would be to make this all work automagically all throughout WebCore, but this
will require more refactoring.

Since the API is in JSC but worlds only exist in WebCore, add callbacks on the JSGlobalData::ClientData
to allow it to update the current world on entry/exit via the JSC API. This is temporary duck
tape, and should be removed once the current world no longer needs to be explicitly tracked.

  • API/JSBase.cpp:

(JSEvaluateScript):

  • API/JSObjectRef.cpp:

(JSObjectCallAsFunction):

(JSC::JSGlobalData::ClientData::beginningExecution):
(JSC::JSGlobalData::ClientData::completedExecution):

  • runtime/JSGlobalData.h:
Location:
trunk/JavaScriptCore/API
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSBase.cpp

    r46431 r51329  
    4747    JSLock lock(exec);
    4848
     49    exec->globalData().clientData->willExecute(exec);
     50
    4951    JSObject* jsThisObject = toJS(thisObject);
    5052
     
    5456    Completion completion = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), source, jsThisObject);
    5557
     58    JSValueRef result = 0;
    5659    if (completion.complType() == Throw) {
    5760        if (exception)
    5861            *exception = toRef(exec, completion.value());
    59         return 0;
    60     }
     62    } else if (completion.value())
     63        result = toRef(exec, completion.value());
     64    else // happens, for example, when the only statement is an empty (';') statement
     65        result = toRef(exec, jsUndefined());
    6166
    62     if (completion.value())
    63         return toRef(exec, completion.value());
    64    
    65     // happens, for example, when the only statement is an empty (';') statement
    66     return toRef(exec, jsUndefined());
     67    exec->globalData().clientData->didExecute(exec);
     68    return result;
    6769}
    6870
  • trunk/JavaScriptCore/API/JSObjectRef.cpp

    r47412 r51329  
    393393    JSLock lock(exec);
    394394
     395    exec->globalData().clientData->willExecute(exec);
     396
    395397    JSObject* jsObject = toJS(object);
    396398    JSObject* jsThisObject = toJS(thisObject);
     
    403405        argList.append(toJS(exec, arguments[i]));
    404406
     407    JSValueRef result = 0;
     408
    405409    CallData callData;
    406410    CallType callType = jsObject->getCallData(callData);
    407     if (callType == CallTypeNone)
    408         return 0;
    409 
    410     JSValueRef result = toRef(exec, call(exec, jsObject, callType, callData, jsThisObject, argList));
    411     if (exec->hadException()) {
    412         if (exception)
    413             *exception = toRef(exec, exec->exception());
    414         exec->clearException();
    415         result = 0;
    416     }
     411    if (callType != CallTypeNone) {
     412        result = toRef(exec, call(exec, jsObject, callType, callData, jsThisObject, argList));
     413        if (exec->hadException()) {
     414            if (exception)
     415                *exception = toRef(exec, exec->exception());
     416            exec->clearException();
     417            result = 0;
     418        }
     419    }
     420
     421    exec->globalData().clientData->didExecute(exec);
    417422    return result;
    418423}
Note: See TracChangeset for help on using the changeset viewer.