Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require('NSNumber').alloc().initWithInt(0) 导致的崩溃 #125

Closed
chieryw opened this issue Oct 21, 2015 · 4 comments
Closed

require('NSNumber').alloc().initWithInt(0) 导致的崩溃 #125

chieryw opened this issue Oct 21, 2015 · 4 comments

Comments

@chieryw
Copy link
Contributor

chieryw commented Oct 21, 2015

崩溃描述:Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -objCType only defined for abstract class. Define -[NSPlaceholderNumber objCType]!

将之换成了require('NSNumber').numberWithInt(0) 则可以避免这样的错误

崩溃产生在JPEngine.m 532行 jsval = [fun callWithArguments:params];

@bang590
Copy link
Owner

bang590 commented Oct 24, 2015

实际上崩溃产生在 formatOCToJS() 里。

所有的 NSNumber 对象在返回给JS时都会转成相应的数值类型。
又因为 NSNumber 是一个类簇,require('NSNumber').alloc() 这句产生一个 NSPlaceholderNumber 对象,只是个临时的壳,想把它转为数值类型时会crash。

如果要解决这个问题,就需要判断返回的对象是 NSPlaceholderNumber 时不转为数值类型,但这个对象不是公开的,会涉及私有 API 调用,所以这个问题先不改,请避免调用 require('NSNumber').alloc()

@chieryw
Copy link
Contributor Author

chieryw commented Oct 25, 2015

所以对于NSString、NSArray、NSDictionary......这样的类簇,避免使用require('类簇').alloc()。对应的使用类方法创建需要的变量,避开对应的.alloc()方法产生的NSPlaceholderXXXX对象。

@bang590
Copy link
Owner

bang590 commented Nov 6, 2015

@chieryw 不是的,只有 NSNumber 例外,其他的没问题

@bang590
Copy link
Owner

bang590 commented Nov 6, 2015

已写入 wiki

@bang590 bang590 closed this as completed Nov 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants