I use javaScriptCore in my swift project, there has two images on the webview, I want click the image to present my swift viewController, in html, the function of click image named "scanImgs", this is my code
func webViewDidFinishLoad(webView: UIWebView) {
guard let context = webView.valueForKeyPath("documentView.webView.mainFrame.javaScriptContext") as? JSContext else {
return
}
let scanImgs: @convention(block) (String, String, Int) -> Void = { (image1: String, image2: String, index: Int) in
let photosVC: UIViewController = SpursPhotoBrowserViewController.getPhotoBrowser(image1, secondImageURL: image2, selectIndex: UInt(index))
dispatch_async(dispatch_get_main_queue(), {
self.presentViewController(photosVC, animated: true, completion: nil)
})
}
context.setObject(unsafeBitCast(scanImgs, AnyObject.self), forKeyedSubscript: "scanImgs")
}
this code can running right most of time, but sometimes i get crash in JavaScriptCore, this is crash log
0 JavaScriptCore bmalloc::VMHeap::grow() + 132
1 JavaScriptCore bmalloc::VMHeap::grow() + 56
2 JavaScriptCore bmalloc::Heap::allocateSmallPage(std::__1::lock_guard<bmalloc::StaticMutex>&, unsigned long) + 244
3 JavaScriptCore bmalloc::Heap::refillSmallBumpRangeCache(std::__1::lock_guard<bmalloc::StaticMutex>&, unsigned long, bmalloc::FixedVector<bmalloc::BumpRange, 32ul>&) + 36
4 JavaScriptCore bmalloc::Allocator::allocateBumpRangeSlowCase(unsigned long) + 128
5 JavaScriptCore bmalloc::Allocator::allocateSlowCase(unsigned long) + 180
6 WebCore cssyyparse(WebCore::CSSParser*) + 1232
7 WebCore WebCore::CSSParser::parseSheet(WebCore::StyleSheetContents*, WTF::String const&, WTF::TextPosition const&, WTF::Vector<WTF::RefPtr<WebCore::CSSRuleSourceData>, 0ul, WTF::CrashOnOverflow, 16ul>*, bool) + 488
8 WebCore WebCore::StyleSheetContents::parseAuthorStyleSheet(WebCore::CachedCSSStyleSheet const*, WebCore::SecurityOrigin const*) + 164
9 WebCore WebCore::HTMLLinkElement::setCSSStyleSheet(WTF::String const&, WebCore::URL const&, WTF::String const&, WebCore::CachedCSSStyleSheet const*) + 996
10 WebCore WebCore::CachedCSSStyleSheet::didAddClient(WebCore::CachedResourceClient*) + 116
11 WebCore WebCore::HTMLLinkElement::process() + 2064
12 WebCore WebCore::HTMLLinkElement::insertedInto(WebCore::ContainerNode&) + 80
13 WebCore WebCore::ChildNodeInsertionNotifier::notify(WebCore::Node&, WTF::Vector<WTF::Ref<WebCore::Node>, 11ul, WTF::CrashOnOverflow, 16ul>&) + 164
14 WebCore WebCore::ContainerNode::notifyChildInserted(WebCore::Node&, WebCore::ContainerNode::ChildChangeSource) + 172
15 WebCore WebCore::ContainerNode::parserAppendChild(WTF::PassRefPtr<WebCore::Node>) + 240
16 WebCore WebCore::insert(WebCore::HTMLConstructionSiteTask&) + 228
17 WebCore WebCore::HTMLConstructionSite::executeQueuedTasks() + 148
18 WebCore WebCore::HTMLDocumentParser::constructTreeFromHTMLToken(WebCore::HTMLTokenizer::TokenPtr&) + 156
19 WebCore WebCore::HTMLDocumentParser::pumpTokenizer(WebCore::HTMLDocumentParser::SynchronousMode) + 352
20 WebCore WebCore::HTMLDocumentParser::append(WTF::PassRefPtr<WTF::StringImpl>) + 608
21 WebCore WebCore::DecodedDataDocumentParser::appendBytes(WebCore::DocumentWriter&, char const*, unsigned long) + 116
22 WebCore WebCore::DocumentLoader::commitData(char const*, unsigned long) + 596
23 WebKitLegacy -[WebHTMLRepresentation receivedData:withDataSource:] + 112
24 WebKitLegacy -[WebDataSource(WebInternal) _receivedData:] + 68
25 WebKitLegacy WebFrameLoaderClient::committedLoad(WebCore::DocumentLoader*, char const*, int) + 112
26 WebCore WebCore::DocumentLoader::commitLoad(char const*, int) + 172
27 WebCore WebCore::CachedRawResource::didAddClient(WebCore::CachedResourceClient*) + 828
28 WebCore WebCore::ThreadTimers::sharedTimerFiredInternal() + 148
29 WebCore WebCore::timerFired(__CFRunLoopTimer*, void*) + 36
30 CoreFoundation ___CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 28
31 CoreFoundation ___CFRunLoopDoTimer + 884
32 CoreFoundation ___CFRunLoopRun + 1520
33 CoreFoundation CFRunLoopRunSpecific + 384
34 WebCore RunWebThread(void*) + 456
35 libsystem_pthread.dylib __pthread_body + 156
36 libsystem_pthread.dylib __pthread_body
what's wrong with this bug...
I meet the same issue recently, it may be a webkit's bug
You could try [webview stopLoading] when viewWillDisappear. It would be helpful to fix this crash
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With