Changeset 30395 in webkit


Ignore:
Timestamp:
Feb 18, 2008 9:19:04 PM (16 years ago)
Author:
beidson@apple.com
Message:

WebCore:

Reviewed by Darin

Fix for <rdar://5747529> - ObjC Exception can cause JSLock to never be released

Test: platform/mac/plugins/webScriptObject-exception-deadlock.html

  • bindings/objc/WebScriptObject.mm: (-[WebScriptObject valueForKey:]): The line resultObj = [super valueForKey:key]; // defaults to throwing an exception says it all - it throws an exception. This method also happens to hold the JSLock. Problematically, when the exeception is thrown and the method exited, the JSLock is never released. Fix that without otherwise changing behavior by holding the JSLock in two individual scopes - Right before the exception and right after.

WebKitTools:

Changes by Geoff Garen, Reviewed by Darin

Fix for <rdar://5747529> - ObjC Exception can cause JSLock to never be released

DRT changes for test: platform/mac/plugins/webScriptObject-exception-deadlock.html

[WebScriptObject valueForKey:] might throw an exception, and previously might have "leaked" the global JSLock
This test calls valueForKey, then runs some arbitrary Javascript on a 2ndary thread. If the lock has leaked,
this series of method calls will deadlock. If things are good, it will complete successfully.

  • DumpRenderTree/mac/ObjCController.m: (runJavaScriptThread): (+[ObjCController isSelectorExcludedFromWebScript:]): (+[ObjCController webScriptNameForSelector:]): (-[ObjCController testValueForKey]):

LayoutTests:

Reviewed by Darin

Fix for <rdar://5747529> - ObjC Exception can cause JSLock to never be released

  • platform/mac-tiger/Skipped: Removed 2 hanging tests that now don't hang
  • platform/mac/plugins/webScriptObject-exception-deadlock-expected.txt: Added.
  • platform/mac/plugins/webScriptObject-exception-deadlock.html: Added.
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r30393 r30395  
     12008-02-18  Brady Eidson  <beidson@apple.com>
     2
     3        Reviewed by Darin
     4
     5        Fix for <rdar://5747529> - ObjC Exception can cause JSLock to never be released
     6
     7        * platform/mac-tiger/Skipped: Removed 2 hanging tests that now don't hang
     8        * platform/mac/plugins/webScriptObject-exception-deadlock-expected.txt: Added.
     9        * platform/mac/plugins/webScriptObject-exception-deadlock.html: Added.
     10
    1112008-02-18  Darin Adler  <darin@apple.com>
    212
  • trunk/LayoutTests/platform/mac-tiger/Skipped

    r30335 r30395  
    55http/tests/xmlhttprequest/small-chunks-response-text.html
    66
    7 # Storage tests failing only on Tiger - <rdar://problem/5747529>
    8 storage/quota-tracking.html
    9 storage/success-callback.html
    10 
    117# On Tiger, WebKit does not override the MIME type returned by NSHTTPURLResponse
    128http/tests/loading/text-content-type-with-binary-extension.html
  • trunk/WebCore/ChangeLog

    r30393 r30395  
     12008-02-18  Brady Eidson  <beidson@apple.com>
     2
     3        Reviewed by Darin
     4
     5        Fix for <rdar://5747529> - ObjC Exception can cause JSLock to never be released
     6
     7        Test: platform/mac/plugins/webScriptObject-exception-deadlock.html
     8
     9        * bindings/objc/WebScriptObject.mm:
     10        (-[WebScriptObject valueForKey:]): The line `resultObj = [super valueForKey:key];    // defaults to throwing an exception`
     11          says it all - it throws an exception.  This method also happens to hold the JSLock.  Problematically, when the exeception
     12          is thrown and the method exited, the JSLock is never released.  Fix that without otherwise changing behavior by holding the
     13          JSLock in two individual scopes - Right before the exception and right after. 
     14
    1152008-02-18  Darin Adler  <darin@apple.com>
    216
  • trunk/WebCore/bindings/objc/WebScriptObject.mm

    r29710 r30395  
    383383    ASSERT(!exec->hadException());
    384384
    385     JSLock lock;
    386     JSValue *result = [self _imp]->get(exec, String(key));
    387    
    388     if (exec->hadException()) {
    389         LOG_EXCEPTION(exec);
    390         result = jsUndefined();
    391         exec->clearException();
    392     }
    393 
    394     id resultObj = [WebScriptObject _convertValueToObjcValue:result originRootObject:[self _originRootObject] rootObject:[self _rootObject]];
     385    id resultObj;
     386    {
     387        // Need to scope this lock to ensure that we release the lock before calling
     388        // [super valueForKey:key] which might throw an exception and bypass the JSLock destructor,
     389        // leaving the lock permanently held
     390        JSLock lock;
     391       
     392        JSValue *result = [self _imp]->get(exec, String(key));
     393       
     394        if (exec->hadException()) {
     395            LOG_EXCEPTION(exec);
     396            result = jsUndefined();
     397            exec->clearException();
     398        }
     399
     400        resultObj = [WebScriptObject _convertValueToObjcValue:result originRootObject:[self _originRootObject] rootObject:[self _rootObject]];
     401    }
     402   
    395403    if ([resultObj isKindOfClass:[WebUndefined class]])
    396404        resultObj = [super valueForKey:key];    // defaults to throwing an exception
    397405
     406    JSLock lock;
    398407    _didExecute(self);
    399408   
  • trunk/WebKitTools/ChangeLog

    r30394 r30395  
     12008-02-18  Brady Eidson  <beidson@apple.com>
     2
     3        Changes by Geoff Garen, Reviewed by Darin
     4
     5        Fix for <rdar://5747529> - ObjC Exception can cause JSLock to never be released
     6
     7        DRT changes for test: platform/mac/plugins/webScriptObject-exception-deadlock.html
     8
     9        [WebScriptObject valueForKey:] might throw an exception, and previously might have "leaked" the global JSLock
     10        This test calls valueForKey, then runs some arbitrary Javascript on a 2ndary thread.  If the lock has leaked,
     11        this series of method calls will deadlock.  If things are good, it will complete successfully.
     12
     13        * DumpRenderTree/mac/ObjCController.m:
     14        (runJavaScriptThread):
     15        (+[ObjCController isSelectorExcludedFromWebScript:]):
     16        (+[ObjCController webScriptNameForSelector:]):
     17        (-[ObjCController testValueForKey]):
     18
    1192008-02-18  Matt Lilek  <webkit@mattlilek.com>
    220
  • trunk/WebKitTools/DumpRenderTree/mac/ObjCController.m

    r29663 r30395  
    2929#import "ObjCController.h"
    3030
     31#import <JavaScriptCore/JavaScriptCore.h>
    3132#import <WebKit/DOMAbstractView.h>
    3233#import <WebKit/WebScriptObject.h>
    3334#import <WebKit/WebView.h>
     35#import <pthread.h>
    3436#import <wtf/Assertions.h>
     37
     38static void* runJavaScriptThread(void* arg)
     39{
     40    JSGlobalContextRef ctx = JSGlobalContextCreate(0);
     41    JSStringRef scriptRef = JSStringCreateWithUTF8CString("'Hello World!'");
     42
     43    JSValueRef exception = 0;
     44    JSEvaluateScript(ctx, scriptRef, 0, 0, 0, &exception);
     45    ASSERT(!exception);
     46
     47    JSGlobalContextRelease(ctx);
     48    JSStringRelease(scriptRef);
     49   
     50    return 0;
     51}
    3552
    3653@implementation ObjCController
     
    4764            || aSelector == @selector(accessStoredWebScriptObject)
    4865            || aSelector == @selector(storeWebScriptObject:)
     66            || aSelector == @selector(testValueForKey)
    4967        )
    5068        return NO;
     
    6886    if (aSelector == @selector(storeWebScriptObject:))
    6987        return @"storeWebScriptObject";
     88    if (aSelector == @selector(testValueForKey))
     89        return @"testValueForKey";
    7090
    7191    return nil;
     
    116136}
    117137
     138- (void)testValueForKey
     139{
     140    ASSERT(storedWebScriptObject);
     141   
     142    @try {
     143        [storedWebScriptObject valueForKey:@"ThisKeyDoesNotExist"];
     144    } @catch (NSException *e) {
     145    }
     146
     147    pthread_t pthread;
     148    pthread_create(&pthread, 0, &runJavaScriptThread, 0);
     149    pthread_join(pthread, 0);
     150}
     151
    118152- (BOOL)testWrapperRoundTripping:(WebScriptObject *)webScriptObject
    119153{
Note: See TracChangeset for help on using the changeset viewer.