Bug 135446 - REGRESSION: Exception causing crash in UIWebView iOS 8 Beta
Summary: REGRESSION: Exception causing crash in UIWebView iOS 8 Beta
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: iPhone / iPad Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-07-30 18:18 PDT by zack.ulrich
Modified: 2014-07-31 10:04 PDT (History)
2 users (show)

See Also:


Attachments
Stack trace from crash (1.79 KB, application/octet-stream)
2014-07-30 18:18 PDT, zack.ulrich
no flags Details
JS function (451 bytes, application/x-javascript)
2014-07-30 18:19 PDT, zack.ulrich
no flags Details
Objc code (1.61 KB, application/octet-stream)
2014-07-30 18:20 PDT, zack.ulrich
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description zack.ulrich 2014-07-30 18:18:50 PDT
Created attachment 235789 [details]
Stack trace from crash

I was testing out calling some Javascript with my iOS app and noticed that I could crash the app by causing an exception. The JS that I'm calling is attached below as well as the objective c code that I'm using to call it. 

I'm calling a named autoexecuting function which just has a generic try catch inside. The second time the function executes and the exception is caused the app crashes. 

I tested this same function using the new WKWebView and it doesn't crash the app but it seems to crash my the webview, I can't execute anything on it the second time the function runs.

I've run this code on iOS 7 and it doesn't cause a crash.

	


function ActivateDemo() {

		this.testFunction = function()
		{
			if (document.body.style.backgroundColor == "red") 
			{
				document.body.style.backgroundColor="blue";
			}
			else
			{
				document.body.style.backgroundColor="red";
			}
			 
			(function namedFunc() {
			try{
				eval("console.log('hey from function'aa')")
			}
			catch(e)
			{
				console.log('exception ' + e)
			}
			})();
		}
	}
	var AD = window.AD = new ActivateDemo();



////objc code //////////////

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    NSString *fullURL = @"http://10.20.11.166/testWeb.html";
    NSURL *url = [NSURL URLWithString:fullURL];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    
    self.wkTest = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];
    [self.view addSubview:self.wkTest];
    [self.wkTest loadRequest:requestObj];
    
    self.testButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 350, 50, 50)];
    
    [self.testButton setBackgroundColor:[UIColor blueColor]];
    
    [self.testButton setTitle:@"Test" forState:UIControlStateNormal];
    
    [self.testButton addTarget:self action:@selector(testBut) forControlEvents:UIControlEventTouchUpInside];
    
    self.testWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 400, 100, 300)];
    
    [self.view addSubview:self.testWebView];
    
    [self.testWebView loadRequest:requestObj];
    
    [self.view addSubview:self.testButton];
}

-(void)testBut
{
    [self.wkTest evaluateJavaScript:@"AD.testFunction()" completionHandler:nil];
    
    [self.testWebView stringByEvaluatingJavaScriptFromString:@"AD.testFunction();"];

}

//
Comment 1 zack.ulrich 2014-07-30 18:19:47 PDT
Created attachment 235791 [details]
JS function
Comment 2 zack.ulrich 2014-07-30 18:20:31 PDT
Created attachment 235792 [details]
Objc code