Advertisement
robertbira

Italian Translation Report: Node.js [Part 6 - 1003 words]

Jul 16th, 2018
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.78 KB | None | 0 0
  1. The environment that the API is invoked under.
  2. representing the new scope.
  3. Returns if the API succeeded
  4. This API open a new scope.
  5. representing the scope to be closed.
  6. This API closes the scope passed in.
  7. Scopes must be closed in the
  8. reverse order from which they were created.
  9. This API can be called even if there is a pending JavaScript exception.
  10. This API open a new scope from which one object can be promoted
  11. to the outer scope.
  12. representing the current scope.
  13. representing the JavaScript to be
  14. escaped.
  15. representing the handle to the escaped
  16. in the outer scope.
  17. This API promotes the handle to the JavaScript object so that it is valid
  18. for the lifetime of the outer scope.
  19. It can only be called once per scope.
  20. If it is called more than once an error will be returned.
  21. References to objects with a lifespan longer than that of the native method
  22.  
  23. In some cases an addon will need to be able to create and reference objects with a lifespan longer than that of a single native method invocation. For example, to create a constructor and later use that constructor in a request to creates instances, it must be possible to reference the constructor object across many different instance creation requests. This would not be possible with a normal handle returned as a as described in the earlier section. The lifespan of a normal handle is managed by scopes and all scopes must be closed before the end of a native method.
  24. N-API provides methods to create persistent references to an object. Each persistent reference has an associated count with a value of 0 or higher. The count determines if the reference will keep the corresponding object live. References with a count of 0 do not prevent the object from being collected and are often called 'weak' references. Any count greater than 0 will prevent the object from being collected.
  25. References can be created with an initial reference count. The count can then be modified through and. If an object is collected while the count for a reference is 0, all subsequent calls to get the object associated with the reference will return NULL for the returned napi_value. An attempt to call for a reference whose object has been collected will result in an error.
  26. References must be deleted once they are no longer required by the addon. When a reference is deleted it will no longer prevent the corresponding object from being collected. Failure to delete a persistent reference will result in a 'memory leak' with both the native memory for the persistent reference and the corresponding object on the heap being retained forever.
  27. There can be multiple persistent references created which refer to the same object, each of which will either keep the object live or not based on its individual count.
  28.  
  29. representing the to which we want
  30. a reference.
  31. Initial reference count for the new reference.
  32. pointing to the new reference.
  33. This API create a new reference with the specified reference count
  34. to the passed in.
  35. to be deleted.
  36. This API deletes the reference passed in.
  37. for which the reference count will be incremented.
  38. The new reference count.
  39. This API increments the reference count for the reference
  40. passed in and returns the resulting reference count.
  41. for which the reference count will be decremented.
  42. This API decrements the reference count for the reference
  43. passed in and returns the resulting reference count.
  44. the in or out of these methods is a handle to the
  45. object to which the reference is related.
  46. for which we requesting the corresponding
  47. The for the referenced by the
  48. If still valid, this API returns the representing the
  49. JavaScript associated with the
  50. Otherwise, result will be NULL.
  51.  
  52. Module registration
  53. N-API modules are registered in a manner similar to other modules
  54. except that instead of using the macro the following
  55. is used:
  56. The next difference is the signature for the method.
  57. For a N-API
  58. module it is as follows:
  59. The return value from is treated as the object for the module.
  60. The method is passed an empty object via the parameter as a
  61. convenience.
  62. If returns NULL, the parameter passed as is
  63. exported by the module.
  64. N-API modules cannot modify the object but can
  65. specify anything as the property of the module.
  66. To add the method as a function so that it can be called as a method
  67. provided by the addon:
  68. To set a function to be returned by the for the addon:
  69. To define a class so that new instances can be created (often used with):
  70. NOTE: partial example, not all referenced code is included
  71. If you expect that your module will be loaded multiple times during the lifetime
  72. of the Node.js process, you can use the macro to initialize
  73. your module:
  74. This macro includes, and declares an function with a
  75. special name and with visibility beyond the addon.
  76. This will allow Node.js to
  77. initialize the module even if it is loaded multiple times.
  78. The variables and will be available inside the function body
  79. following the macro invocation.
  80. For more details on setting properties on objects, see the section on Working with JavaScript Properties.
  81. For more details on building addon modules in general, refer to the existing
  82. API.
  83.  
  84. Working with JavaScript Values
  85. N-API exposes a set of APIs to create all types of JavaScript values. Some of these types are documented under Section 6 of the ECMAScript Language Specification.
  86. Fundamentally, these APIs are used to do one of the following:
  87. Create a new JavaScript object
  88. Convert from a primitive C type to an N-API value
  89. Convert from N-API value to a primitive C type
  90. Get global instances including undefined and null
  91. N-API values are represented by the type. Any N-API call that requires a JavaScript value takes in a. In some cases, the API does check the type of the. up-front. However, for better performance, it's better for the caller to make sure that the in question is of the JavaScript type expected by the API.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement