Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The object to query.
- The name of the property to delete.
- Whether the property deletion succeeded or not.
- result can optionally be ignored by passing
- This API attempts to delete the own property from
- The name of the own property whose existence to check.
- Whether the own property exists on the object or not.
- This API checks if the passed in has the named own property. must be a string or a, or an error will be thrown.
- N-API will not perform any conversion between data types.
- The object on which to set the property.
- The name of the property to set.
- The property value.
- This method is equivalent to calling with a created from the string passed in as
- The object from which to retrieve the property.
- The name of the property to get.
- The object from which to set the properties.
- The index of the property to set.
- This API sets and element on the passed in.
- This API gets the element at the requested index.
- This API returns if the passed in has an element at the requested index.
- Whether the element deletion succeeded or not.
- This API attempts to delete the specified from
- The number of elements in the array.
- The array of property descriptors.
- This method allows the efficient definition of multiple properties on a given object.
- The properties are defined using property descriptors (see
- Given an array of such property descriptors, this API will set the properties on the object one at a time, as defined by (described in Section 9.1.6 of the ECMA262 specification).
- The object passed to the called function.
- representing the JavaScript function to be invoked.
- The count of elements in the array.
- Array of representing JavaScript values passed in as arguments to the function.
- representing the JavaScript object returned.
- This method allows a JavaScript function object to be called from a native add-on.
- This is the primary mechanism of calling back from the add-on's native code into JavaScript.
- For the special case of calling into JavaScript after an async operation, see
- A sample use case might look as follows.
- Consider the following JavaScript snippet:
- Then, the above function can be invoked from a native add-on using the following code:
- Get the function named "AddTwo" on the global object
- Convert the result back to a native type
- The name of the function encoded as UTF8.
- This is visible within JavaScript as the new function object's property.
- The native function which should be called when this function object is invoked.
- User-provided data context.This will be passed back into the function when invoked later.
- representing the JavaScript function object for the newly created function.
- This API allows an add-on author to create a function object in native code. This is the primary mechanism to allow calling into the add-on's native code from JavaScript.
- The newly created function is not automatically visible from script after this call. Instead, a property must be explicitly set on any object that is visible to JavaScript, in order for the function to be accessible from script.
- In order to expose a function as part of the add-on's module exports, set the newly created function on the exports object. A sample module might look as follows:
- Given the above code, the add-on can be used from JavaScript as follows:
- The string passed to require is not necessarily the name passed into in the earlier snippet but the name of the target in responsible for creating the file
- The callback info passed into the callback function.
- Specifies the size of the provided array and receives the actual count of arguments.
- Buffer to which the representing the arguments are copied.
- If there are more arguments than the provided count, only the requested number of arguments are copied.
- If there are fewer arguments provided than claimed, the rest of is filled with values that represent
- Receives the JavaScript argument for the call.
- Receives the data pointer for the callback.
- This method is used within a callback function to retrieve details about the call like the arguments and the pointer from a given callback info.
- The of the constructor call.
- This API returns the of the constructor call.If the current callback is not a constructor call, the result is
- representing the JavaScript function to be invoked as a constructor.
- Array of JavaScript values as representing the arguments to the constructor.
- representing the JavaScript object returned, which in this case is the constructed object.
- This method is used to instantiate a new JavaScript value using a given that represents the constructor for the object.
- The following can be approximated in N-API using the following snippet:
- Get the constructor function MyObject
- Object Wrap
- N-API offers a way to "wrap" C++ classes and instances so that the class constructor and methods can be called from JavaScript.
- The API defines a JavaScript class with constructor, static properties and methods, and instance properties and methods that correspond to the C++ class.
- When JavaScript code invokes the constructor, the constructor callback uses to wrap a new C++ instance in a JavaScript object, then returns the wrapper object.
- When JavaScript code invokes a method or property accessor on the class, the corresponding C++ function is invoked.
- For an instance callback, obtains the C++ instance that is the target of the call.
- For wrapped objects it may be difficult to distinguish between a function called on a class prototype and a function called on an instance of a class.
- A common pattern used to address this problem is to save a persistent reference to the class constructor for later checks.
- otherwise
- The reference must be freed once it is no longer needed.
- Name of the JavaScript constructor function; this is not required to be the same as the C++ class name, though it is recommended for clarity.
- The length of the in bytes, or if it is null-terminated.
- Callback function that handles constructing instances of the class. (This should be a static method on the class, not an actual C++ constructor function.)
- Optional data to be passed to the constructor callback as the property of the callback info.
- Number of items in the array argument.
- Array of property descriptors describing static and instance data properties, accessors, and methods on the class See
- A representing the constructor function for the class.
- Defines a JavaScript class that corresponds to a C++ class, including:
- A JavaScript constructor function that has the class name and invokes the provided C++ constructor callback.
- Properties on the constructor function corresponding to static data properties, accessors, and methods of the C++ class (defined by property descriptors with the attribute).
- Properties on the constructor function's object corresponding to <1>non-static</1> data properties, accessors, and methods of the C++ class (defined by property descriptors without the attribute).
- The C++ constructor callback should be a static method on the class that calls the actual class constructor, then wraps the new C++ instance in a JavaScript object, and returns the wrapper object. See for details.
- The JavaScript constructor function returned from is often saved and used later, to construct new instances of the class from native code, and/or check whether provided values are instances of the class.
- In that case, to prevent the function value from being garbage-collected, create a persistent reference to it using and ensure the reference count is kept >= 1.
- The JavaScript object that will be the wrapper for the native object.
- This object must have been created from the of a constructor that was created using
- The native instance that will be wrapped in the JavaScript object.
- Optional native callback that can be used to free the native instance when the JavaScript object is ready for garbage-collection.
- Optional contextual hint that is passed to the finalize callback.
- Optional reference to the wrapped object
Advertisement
Add Comment
Please, Sign In to add comment