Changeset 35159 in webkit for trunk/JavaScriptCore/API/JSBase.cpp


Ignore:
Timestamp:
Jul 14, 2008, 4:28:57 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Geoff Garen.

Eliminate per-thread JavaScript global data instance support and make arbitrary
global data/global object combinations possible.

File:
1 edited

Legend:

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

    r34977 r35159  
    4242{
    4343    ExecState* exec = toJS(ctx);
     44    exec->globalData().heap->registerThread();
    4445    JSLock lock(exec);
     46
    4547    JSObject* jsThisObject = toJS(thisObject);
    4648    UString::Rep* scriptRep = toJS(script);
     
    6769{
    6870    ExecState* exec = toJS(ctx);
     71    exec->globalData().heap->registerThread();
    6972    JSLock lock(exec);
     73
    7074    UString::Rep* scriptRep = toJS(script);
    7175    UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null;
     
    8690        initializeThreading();
    8791
    88     // It might seem that we have a context passed to this function, and can use toJS(ctx)->heap(), but the parameter is likely to be NULL,
    89     // and it may actually be garbage for some clients (most likely, because of JSGarbageCollect being called after releasing the context).
     92    // When using a shared heap, clients need to call JSGarbageCollect(0) after releasing the last reference to the context to avoid
     93    // leaking protected objects. Because the function arguments were originally ignored, some clients may pass their released context here,
     94    // in which case there is a risk of crashing if another thread performs GC on the same heap in between.
     95    if (ctx) {
     96        ExecState* exec = toJS(ctx);
     97        JSGlobalData& globalData = exec->globalData();
     98        Heap* heap = globalData.heap;
    9099
    91     if (JSGlobalData::threadInstanceExists()) {
    92         Heap* heap = JSGlobalData::threadInstance().heap;
     100        JSLock lock(globalData.isSharedInstance);
     101
    93102        if (!heap->isBusy())
    94103            heap->collect();
    95     }
     104    } else {
     105        JSLock lock(true);
    96106
    97     JSLock lock(true);
    98 
    99     if (JSGlobalData::sharedInstanceExists()) {
    100         Heap* heap = JSGlobalData::sharedInstance().heap;
    101         if (!heap->isBusy())
    102             heap->collect();
     107        if (JSGlobalData::sharedInstanceExists()) {
     108            Heap* heap = JSGlobalData::sharedInstance().heap;
     109            if (!heap->isBusy())
     110                heap->collect();
     111        }
    103112    }
    104113
Note: See TracChangeset for help on using the changeset viewer.