分属不同的线程

//定义需要暴露给js的内容,这里我们只暴露personName和queryPersonName接口

@protocol PersonProtocol <JSExport>

@property(nonatomic,copy)NSString *personName;

-(NSString *)queryPersonName;

@end

//Person实现PersonProtocol协议,而自己定义的age和queryPersonAge接口不暴露给js

@interface Person : NSObject <PersonProtocol>

@property(nonatomic,assign)NSInteger age;

-(NSInteger)queryPersonAge;

@end

@implementation Person

@synthesize personName = _personName;

-(NSString *)queryPersonName{

return self.personName;

}

-(NSInteger)queryPersonAge{

return self.age;

}

@end

-(void)refreshXX

{

NSString *path = [[NSBundle mainBundle] pathForResource:@"info" ofType:@"html"];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]];

[self.webView loadRequest:request];

JSContext *jsContext = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];

Person *person=[Person new];

person.personName = @"Greg";

person.age = 27;

jsContext[@"person"]=person;

}

<div data-role="collapsible">

<h3 onclick="person.queryPersonName()">systemVersion</h3>

<p id="systemVersion"></p>

</div>

(lldb) bt

* thread #1: tid = 0x16b9e9, 0x000000010d5c1d40 jsTest`-[ViewController refreshXX](self=0x00007ff12a60ea30, _cmd="refreshXX") + 16 at ViewController.m:63, queue = 'com.apple.main-thread', stop reason = breakpoint 2.1

* frame #0: 0x000000010d5c1d40 jsTest`-[ViewController refreshXX](self=0x00007ff12a60ea30, _cmd="refreshXX") + 16 at ViewController.m:63

frame #1: 0x000000010eb4ea8d UIKit`-[UIApplication sendAction:to:from:forEvent:] + 92

frame #2: 0x000000010ecc1e67 UIKit`-[UIControl sendAction:to:forEvent:] + 67

frame #3: 0x000000010ecc2143 UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 327

frame #4: 0x000000010ecc1263 UIKit`-[UIControl touchesEnded:withEvent:] + 601

frame #5: 0x000000010ebc199f UIKit`-[UIWindow _sendTouchesForEvent:] + 835

frame #6: 0x000000010ebc26d4 UIKit`-[UIWindow sendEvent:] + 865

frame #7: 0x000000010eb6ddc6 UIKit`-[UIApplication sendEvent:] + 263

frame #8: 0x000000010eb47553 UIKit`_UIApplicationHandleEventQueue + 6660

frame #9: 0x000000010e6bb301 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17

frame #10: 0x000000010e6b122c CoreFoundation`__CFRunLoopDoSources0 + 556

frame #11: 0x000000010e6b06e3 CoreFoundation`__CFRunLoopRun + 867

frame #12: 0x000000010e6b00f8 CoreFoundation`CFRunLoopRunSpecific + 488

frame #13: 0x0000000112051ad2 GraphicsServices`GSEventRunModal + 161

frame #14: 0x000000010eb4cf09 UIKit`UIApplicationMain + 171

frame #15: 0x000000010d5c277f jsTest`main(argc=1, argv=0x00007fff5263e680) + 111 at main.m:14

frame #16: 0x00000001105b292d libdyld.dylib`start + 1

2017-04-07 14:50:16.620 jsTest[31840:1489385] /Users/zzf073/Library/Developer/CoreSimulator/Devices/96C38E7B-35FF-49AC-80A1-BCAA1E8E7873/data/Containers/Bundle/Application/AFCD9E1B-D5FD-498E-8AD5-AEDFC672314F/jsTest.app/info.html

(lldb) bt

* thread #8: tid = 0x16ba34, 0x000000010d5c1770 jsTest`-[Person queryPersonName](self=0x00007ff12a61ca20, _cmd="queryPersonName") + 16 at ViewController.m:28, name = 'WebThread', stop reason = breakpoint 1.1

* frame #0: 0x000000010d5c1770 jsTest`-[Person queryPersonName](self=0x00007ff12a61ca20, _cmd="queryPersonName") + 16 at ViewController.m:28

frame #1: 0x000000010e67e5cc CoreFoundation`__invoking___ + 140

frame #2: 0x000000010e67e41e CoreFoundation`-[NSInvocation invoke] + 286

frame #3: 0x000000010da38db3 JavaScriptCore`JSC::ObjCCallbackFunctionImpl::call(JSContext*, OpaqueJSValue*, unsigned long, OpaqueJSValue const* const*, OpaqueJSValue const**) + 451

frame #4: 0x000000010da38926 JavaScriptCore`JSC::objCCallbackFunctionCallAsFunction(OpaqueJSContext const*, OpaqueJSValue*, OpaqueJSValue*, unsigned long, OpaqueJSValue const* const*, OpaqueJSValue const**) + 262

frame #5: 0x000000010da39bad JavaScriptCore`long long JSC::APICallbackFunction::call<JSC::ObjCCallbackFunction>(JSC::ExecState*) + 573

frame #6: 0x000000010da03340 JavaScriptCore`JSC::LLInt::setUpCall(JSC::ExecState*, JSC::Instruction*, JSC::CodeSpecializationKind, JSC::JSValue, JSC::LLIntCallLinkInfo*) + 528

frame #7: 0x000000010da0a35d JavaScriptCore`llint_entry + 22900

frame #8: 0x000000010da047d9 JavaScriptCore`vmEntryToJavaScript + 326

frame #9: 0x000000010d8d6959 JavaScriptCore`JSC::JITCode::execute(JSC::VM*, JSC::ProtoCallFrame*) + 169

frame #10: 0x000000010d8bd5ad JavaScriptCore`JSC::Interpreter::executeCall(JSC::ExecState*, JSC::JSObject*, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) + 493

frame #11: 0x000000010d691bd7 JavaScriptCore`JSC::call(JSC::ExecState*, JSC::JSValue, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&, WTF::NakedPtr<JSC::Exception>&) + 71

frame #12: 0x000000011395fc1a WebCore`WebCore::JSEventListener::handleEvent(WebCore::ScriptExecutionContext*, WebCore::Event*) + 1002

frame #13: 0x00000001135ac630 WebCore`WebCore::EventTarget::fireEventListeners(WebCore::Event*, WebCore::EventTargetData*, WTF::Vector<WebCore::RegisteredEventListener, 1ul, WTF::CrashOnOverflow, 16ul>&) + 752

frame #14: 0x00000001135ac267 WebCore`WebCore::EventTarget::fireEventListeners(WebCore::Event*) + 311

frame #15: 0x000000011359550e WebCore`WebCore::MouseOrFocusEventContext::handleLocalEvents(WebCore::Event&) const + 174

frame #16: 0x00000001135960b8 WebCore`WebCore::EventDispatcher::dispatchEvent(WebCore::Node*, WTF::PassRefPtr<WebCore::Event>) + 920

frame #17: 0x0000000113c97c5d WebCore`WebCore::Node::dispatchEvent(WTF::PassRefPtr<WebCore::Event>) + 29

frame #18: 0x000000011357f61e WebCore`WebCore::Element::dispatchMouseEvent(WebCore::PlatformMouseEvent const&, WTF::AtomicString const&, int, WebCore::Element*) + 318

frame #19: 0x000000011359c8df WebCore`WebCore::EventHandler::dispatchMouseEvent(WTF::AtomicString const&, WebCore::Node*, bool, int, WebCore::PlatformMouseEvent const&, bool) + 111

frame #20: 0x000000011359e108 WebCore`WebCore::EventHandler::handleMouseReleaseEvent(WebCore::PlatformMouseEvent const&) + 1192

frame #21: 0x00000001135a550d WebCore`WebCore::EventHandler::mouseUp(WebEvent*) + 237

frame #22: 0x000000011310cbe3 WebKitLegacy`-[WebHTMLView mouseUp:] + 115

frame #23: 0x000000011414c30d WebCore`-[WAKView _selfHandleEvent:] + 125

frame #24: 0x000000011414c26f WebCore`-[WAKView handleEvent:] + 63

frame #25: 0x000000011414f46d WebCore`-[WAKWindow sendEventSynchronously:] + 269

frame #26: 0x000000010ee6ce81 UIKit`__47-[UIWebDocumentView(Interaction) performClick:]_block_invoke + 740

frame #27: 0x000000010ee6cb97 UIKit`-[UIWebDocumentView(Interaction) performClick:] + 68

frame #28: 0x000000010ee6d49f UIKit`__64-[UIWebDocumentView(Interaction) _sendMouseMoveAndAttemptClick:]_block_invoke + 345

frame #29: 0x0000000114167996 WebCore`HandleRunSource(void*) + 390

frame #30: 0x000000010e6bb301 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17

frame #31: 0x000000010e6b11a7 CoreFoundation`__CFRunLoopDoSources0 + 423

frame #32: 0x000000010e6b06e3 CoreFoundation`__CFRunLoopRun + 867

frame #33: 0x000000010e6b00f8 CoreFoundation`CFRunLoopRunSpecific + 488

frame #34: 0x0000000114167325 WebCore`RunWebThread(void*) + 469

frame #35: 0x00000001108d199d libsystem_pthread.dylib`_pthread_body + 131

frame #36: 0x00000001108d191a libsystem_pthread.dylib`_pthread_start + 168

frame #37: 0x00000001108cf351 libsystem_pthread.dylib`thread_start + 13

js oc与线程的更多相关文章

  1. iOS js oc相互调用JavaScriptCore(一)

    原址:http://blog.csdn.net/lwjok2007/article/details/47058101 1.普通调用 从iOS7开始 苹果公布了JavaScriptCore.framew ...

  2. 转载 OS js oc相互调用(JavaScriptCore) ---js调用iOS ---js里面直接调用方法

    OS js oc相互调用(JavaScriptCore)   接着上节我们讲到的iOS调用js 下来我们使用js调用iOS js调用iOS分两种情况 一,js里面直接调用方法 二,js里面通过对象调用 ...

  3. 转载 iOS js oc相互调用(JavaScriptCore) --iOS调用js

    iOS js oc相互调用(JavaScriptCore)   从iOS7开始 苹果公布了JavaScriptCore.framework 它使得JS与OC的交互更加方便了. 下面我们就简单了解一下这 ...

  4. js运行机制(线程)

    浏览器线程 js运作在浏览器中,是单线程的,即js代码始终在一个线程上执行,这个线程称为js引擎线程. 浏览器是多线程的,除了js引擎线程,它还有:  UI渲染线程 浏览器事件触发线程 http请求线 ...

  5. 深入理解 Node.js 进程与线程

    原文链接: https://mp.weixin.qq.com/s?__biz=MzAxODE2MjM1MA==&mid=2651557398&idx=1&sn=1fb991da ...

  6. WKWebView与Js (OC版)

    OC如何给JS注入对象及JS如何给IOS发送数据 JS调用alert.confirm.prompt时,不采用JS原生提示,而是使用iOS原生来实现 如何监听web内容加载进度.是否加载完成 如何处理去 ...

  7. iOS js oc相互调用(JavaScriptCore)(二)

    下来我们使用js调用iOS js调用iOS分两种情况 一,js里面直接调用方法 二,js里面通过对象调用方法 首先我们看第一种,直接调用方法. 其中用到了iOS的block 上代码 -(void)we ...

  8. UIWebView 获取当前的javascript上下文,并js,oc互调

    OC调用UIWebView 中的js,网上例子很多,最常用的是UIWebView自带的一个方法: - (NSString *)stringByEvaluatingJavaScriptFromStrin ...

  9. iOS js oc相互调用(JavaScriptCore 下)

    下来我们使用js调用iOS js调用iOS分两种情况 一,js里面直接调用方法 二,js里面通过对象调用方法 首先我们看第一种,直接调用方法. 其中用到了iOS的block 上代码 -(void)we ...

随机推荐

  1. js控制div样式显示与隐藏,JS通过点击超链接右边(指定位置)显示一个图标

    原文出自:https://blog.csdn.net/seesun2012 javascript基础篇,老土的方法解决js控制div样式,便于新手理解,粗暴的不能再粗暴,如果你是高手,请忽略! 思路: ...

  2. [PHP] 从PHP 5.6.x 移植到 PHP 7.0.x不兼容点

    1.错误和异常处理 1.1 set_exception_handler()函数申明的类型 function handler($e){ var_dump($e); } set_exception_han ...

  3. ZOJ 1049 判断坐标点

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=49 水题 #include<iostream> #include&l ...

  4. 多线程拷贝备份文件方法(Windows)

    D:\bat\robocopy.exe D:\backupdata  \\192.168.36.45\BData\  db_20170716.dmp 解释: 微软提供的robocopy.exe命令,默 ...

  5. thinkphp I() 方法

    I() 方法用于获取前台提交的表单的value值. <form id="complai_form" method="post" action=" ...

  6. js实现队列结构

    创建队列 let items function Queue { this.enqueue = function(element){ items.push(element) } this.dequeue ...

  7. [POI2005]AUT-The Bus

    树状数组维护前缀最大值+扫描线DP #include"cstdio" #include"cstring" #include"iostream" ...

  8. [转]运用@media实现网页自适应中的几个关键分辨率

    转自百度经验:http://jingyan.baidu.com/article/6f2f55a1ab36c3b5b83e6c46.html 经常为不同分辨率设备或不同窗口大小下布局错位而头疼,可以利用 ...

  9. PHP中使用Jpgraph生成统计图

    Jpgraph是PHP图表类库,可以生成折线图.柱状图.大饼图等等统计图.如果你想使用PHP生成统计图来统计数据,使用它再方便不过啦. 如果说你要亲自使用GD库来写的话,那我只能膜拜大神啦(我不会哈哈 ...

  10. Web开发须知的浏览器内幕 缓存与存储篇(1)

    本文禁止转载,由UC浏览器内部出品. 0.前言 大纲 浏览器缓存和存储相关的功能分为四类: 加载流程 Memory Cache Application Cache(简称AppCache) HTTP C ...