bang
bang
试试self.context()也改成用performSelectorInOC,里面那个也是
哪一步开始不行呢?调试下
`setObject:forKeyedSubscript:`传非block有效吗
JSPatch is support both `block` and `pointer` types. How is the `executeBlockPointer` define in OC?
知道你的意思了,还是说中文吧:( `executeBlockPointer`是在JS新增的方法,默认JS里新增的方法参数类型都是id,所以这里参数block是被识别成`id`类型的,不是函数。 如果`executeBlockPointer`在OC有定义并指明它的参数类型是block,这样写是没问题的。 若新增方法参数需要是别的类型,可以用defineProtocol,详见文档,不过也不支持block类型。 这种在OC调用JS新增的方法似乎除了debug外不会有场景遇到。
喔对,不好意思没仔细看第二条回复,确实不支持参数类型是指针的block。要通过box/unbox支持的话……相当麻烦,再看看能不能通过扩展的方式支持
1. 基于string建索引能解决的问题似乎只有这个特殊block问题和延迟释放,但可能会带来其他问题,待研究。 2. 有个私有API `JSSynchronousGarbageCollectForDebugging` 可以强制垃圾回收,AppStore不通过。
看堆栈跟webview有关,试试用performSelectorInOC调用这个方法 https://github.com/bang590/JSPatch/wiki/performSelectorInOC-%E4%BD%BF%E7%94%A8%E6%96%87%E6%A1%A3
要return才行的,对照下文档
``` js var attrStr = require('NSMutableAttributedString').alloc().init() return attrStr.performSelectorInOC('readFromData_options_documentAttributes_error', [recordModel.match().dataUsingEncoding(10), { 'DocumentType': 'NSHTML' }, null, pError], function(ret) { attrStr = ret; console.log(attrStr); }); ```