-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
N-API should allow setting the 'length' property of functions #28196
Comments
We discussed this a bit in the last N-API call. Our guess/understanding is that the main motivation is to allow the JavaScript engine to better optimize as today the length property is not set? The advantage to providing signatures with the length value is to avoid a second round trip to set it using a napi_set_property? Is this correct or is there something else that motivates this. |
Right now the length is always zero. Providing a length seems reasonable to me because it can be abstracted. In a v8 napi, we can just pass the int to FunctionTemplate::New or Function::New. In a jerryscript napi, an additional property set call can be added. |
@devsnek the assumption was that the only downside of the length being zero is potentially performance right? If we added a new method with the length it could be documented as a 'hint' to the JavaScript engine that may be ignored. |
I'm not entirely sure about the optimization aspect, I just think this is important for consistency with functions written in js. |
@devsnek to make sure I understand your concern. It's that functions created in JavaScript will always have the value set to the right number, but that those created on the native side will have it set to 0? |
@mhdawson correct |
Hi everyone, |
@mhdawson I report the v8 reference link here: Like you can see in both cases |
I found the similar API in other JavaScript engines: ChackraCoreJsCallFunction(
_In_ JsValueRef function,
_In_reads_(argumentCount) JsValueRef *arguments,
_In_ unsigned short argumentCount,
_Out_ JsValueRef *result);
JsConstructObject(
_In_ JsValueRef function,
_In_reads_(argumentCount) JsValueRef *arguments,
_In_ unsigned short argumentCount,
_Out_ JsValueRef *result);
SpiderMonkey
JavaScriptCoretypedef JSValueRef
(*JSObjectCallAsFunctionCallback)
(JSContextRef ctx,
JSObjectRef function,
JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef* exception); The callback invoked when an object is called as a function. typedef JSObjectRef
(*JSObjectCallAsConstructorCallback)
(JSContextRef ctx,
JSObjectRef constructor,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef* exception); The callback invoked when an object is used as a constructor in a |
@NickNaso can you add the link to the PR you were working on? Just wondering what the status is in respect to this issue. |
I see it was closed as stalled, @NickNaso if you have cycles to pick it back up I'll reopen the PR. |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment. For more information on how the project manages feature requests, please consult the feature request management document. |
Currently,
napi_create_function()
andnapi_define_class()
only accept name, native callback, and an opaque data pointer.node/src/js_native_api.h
Lines 87 to 92 in c1f0cbe
node/src/js_native_api.h
Lines 269 to 277 in c1f0cbe
In particular, it does not accept a parameter for the
length
property for JavaScript functions.While it's possible to redefine the
length
property after the function/class has been created, doing so could be slow and error-prone. It would be nice if N-API could directly support this use case.The text was updated successfully, but these errors were encountered: