分属不同的线程

//定义需要暴露给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. TypeScript 乱糟笔记

    数组头上插一个值. var arr: Array<String> = ['a', 'b', 'c'];arr.unshift('d'); object删除元素. var obj: Obje ...

  2. php中的字符串常用函数(二) substr() 截取字符串

    //substr($str, startIndex, length) //截取方向都是从左向右的. //length不写默认截取到最后一个. //length为正是个数(包括开头的个数),为负是索引( ...

  3. DataGridView 绑定数据方法

    DataGridView控件用于显示来自多种外部数据源中的数据,用户可以在此控件添加行和列,并可以填充数据.   如要让DataGridView显示数据库中的数据,只需要将此控件绑定到挑用数据库的数据 ...

  4. Bundle传递数据,Handler更新UI

    Bundle主要用于传递数据:它保存的数据,是以key-value(键值对)的形式存在的. Bundle经常使用在Activity之间或者线程间传递数据,传递的数据可以是boolean.byte.in ...

  5. LeetCode刷题第一天

    1 . 两数之和 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,你不能重复利用 ...

  6. 撩课-Java每天10道面试题第5天

    41.Iterator.ListIterator 和 Enumeration的区别? 迭代器是一种设计模式, 它是一个对象, 它可以遍历并选择序列中的对象, 而开发人员不需要了解 该序列的底层结构. ...

  7. mysql随机查询符合条件的几条记录

    随机查询,方法可以有很多种.比如,查询出所有记录,然后随机从列表中取n条记录.使用程序便可实现.可是程序实现必须查询出所有符合条件的记录(至少是所有符合条件的记录id),然后再随机取出n个id,查询数 ...

  8. Map 模板

    #include<stdio.h> #include<iostream> #include<map> using namespace std; typedef pa ...

  9. Spring的自动装配Bean

    spring的自动装配功能的定义:无须在Spring配置文件中描述javaBean之间的依赖关系(如配置<property>.<constructor-arg>).IOC容器会 ...

  10. 简单Json序列化和反序列化

    序列化是什么: 序列化就是将一个对象的状态(各个属性量)保存起来,然后在适当的时候再获得.序列化分为两大部分:序列化和反序列化.序列化是这个过程的第一部分,将数据分解成字节流,以便存储在文件中或在网络 ...