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

js生成block失败 #846

Open
gopep9 opened this issue Apr 4, 2019 · 2 comments
Open

js生成block失败 #846

gopep9 opened this issue Apr 4, 2019 · 2 comments

Comments

@gopep9
Copy link

gopep9 commented Apr 4, 2019

按照demo中的写法,在js中的以下代码
require('JPObject').request(block("NSString *, BOOL", function(ctn, succ) {
if (succ) log(ctn) //output: I'm content
}))
中的succ是false,没有能够打印出I'm content

@gopep9 gopep9 changed the title js js生成block失败 Apr 4, 2019
@gopep9
Copy link
Author

gopep9 commented Apr 4, 2019

在genCallbackBlock中

void (^block)(void) = ^(void){};
uint8_t *p = (uint8_t *)((__bridge void *)block);
p += sizeof(void *) + sizeof(int32_t) *2;
void(**invoke)(void) = (void (**)(void))p;

p += sizeof(void *) + sizeof(uintptr_t) * 2;
const char **signature = (const char **)p;

这里的signature应该是指向了下一个oc对象了
当前的内存状态如下
6C4FABCE-139F-4080-AA96-98E78FA5BE9B
其中100CE07F8是block指向的地址,经过上面的运算后signature会指向0x0000000100ce0820,这个值是对应下一个block的__flags,值和上一个block一样都是1342177280,最终生成的类型会修改这里的内存,没看懂为什么这样做

@gopep9
Copy link
Author

gopep9 commented Apr 4, 2019

这里正确的写法是

p += sizeof(void *) + sizeof(int32_t) *2;
void(**invoke)(void) = (void (**)(void))p;
p += sizeof(void*);
void *p2 = *(void **)p;
p = p2;
p += sizeof(uintptr_t) * 2;
const char **signature = (const char **)p;

能够获取block当前的签名
Untitled

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

1 participant