-
Notifications
You must be signed in to change notification settings - Fork 679
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
Add C API for Promise #1794
Comments
sure, like |
Yeah and API to reject / fullfill, for example: |
@martijnthe, |
@jprestwo, can you help me understand why you have the |
@martijnthe, no that is not needed. I have a pending PR for ZJS that uses JerryScript promises and I took out that parameter: Of course this PR is irrelevant once JerryScript has C API's. |
On second thought, I don't think the promise api in intel/zephyr.js#1058 is suitable for jerry C api. Because it saves the resolve/reject handler inside the native pointer of promise object, however, the ideal I suggest the the signature should be
the resolve_p and reject_p are function object, and are OUT arguments, so that users get the handler, and should maintain them (including free them). When they want to resolve a promise, they just jerry_call_function(*resolve_p, ......). And we don't need the explicit api like fullfill/resolve/reject. What do you think? @martijnthe @jprestwo |
@jiangzidong I'm not sure if I like that signature.
See below for usage example.
|
Yes, I know what you mean, I can put these 2 function in the internal prop of the promise object (like the LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER, but not just in the native pointer). |
Yeah, that makes sense to me. Need to take care of breaking the "retain cycle" there: both resolve and reject function objects retain the promise object (through Idea 3: stick with @jiangzidong 's proposal + add a utility to
|
It should not be a problem. Though the promise object and the handler are marked by each other during gc, but that doesn't affect their ref count. As long as the promise object's ref == 0 and it cannot be visited by other visited object, both the promise and the handler will be GCed. It's like |
OK, if there's no problem there w.r.t. memory mgmt, I think it would be nice if the jerryscript.h API is easy to use directly. Something like this?
|
see #1796 Why do we need the api like |
I don't have a good concrete example at hand, but I feel that because the JS Promise API semantics hand the user 2 function objects ( |
#1796 merged. |
Now we've got ES6
Promise
support from within .js, I think it's a good time to add the C API as well :)The text was updated successfully, but these errors were encountered: