如何测试UIWebView的10MB限制的JavaScript? [英] How to test UIWebView's 10MB limit on JavaScript?

查看:103
本文介绍了如何测试UIWebView的10MB限制的JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图测试UIWebView的10MB限制对Javascript内存分配。这里是我的代码到目前为止,我在模拟器上运行(iOS 5.1)。

I'm trying to test UIWebView's 10MB limit on Javascript memory allocation. Here is my code so far which I'm running on the simulator (iOS 5.1).

int size = 10485760+1024000*10; 
int i = 13;
char *cStr = (char *) malloc(size); // 20MB buffer
char *lcStr = cStr;
lcStr+=i;
strcpy(cStr, "window._x = \'");
for ( ; i < size-4; i++){
    if(i%2){
        *lcStr = ' ';
    }else{
        *lcStr = 'c';
    }
    lcStr++;
}
strcpy(lcStr, "c\';\0");

NSString *longStr = [NSString stringWithCString:cStr encoding:NSASCIIStringEncoding];
// by now 40MB used

//memory usage spikes to 60MB
NSString *result = [self.webView stringByEvaluatingJavaScriptFromString: longStr];

free(cStr);

HTML / JS:

HTML/JS:

<script type="text/javascript">
    setTimeout(function(){document.getElementById("one").innerText = window._x;},3000);
</script>

我的问题是上面的代码不会导致任何异常抛出的UIWebView即使显然JS分配在一点大于10MB。我使用仪器来验证内存使用情况。

My problem is that the code above doesn't result in any exception being thrown by the UIWebView even though clearly the JS allocation at one point is greater than 10MB. I've used instruments to verify the memory usage.

整个程序的最终结果是我看到一堆'c'在网络视图中打印在屏幕上,但是没有崩溃。

The end result of the entire program is that I see bunch of 'c ' are printed on the screen in a webview but no crash.

我做错了什么?如何测试此JS限制?

Am I doing something wrong? How can I test this JS limit?

推荐答案

限制因设备而异。模拟器不会对实际设备施加相同的限制。如果你在iPhone上测试,你应该会看到异常。

The limits vary by device. The Simulator does not impose the same limits as actual devices. If you test this on an iPhone, you should see an exception.

这篇关于如何测试UIWebView的10MB限制的JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆