Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The environment that the API is invoked under.
- representing the being queried.
- The underlying data buffer of the
- Length in bytes of the underlying data buffer.
- Returns if the API succeeded.
- This API is used to retrieve the underlying data buffer of an and
- its length.
- Use caution while using this API.
- The lifetime of the underlying data
- buffer is managed by the even after it's returned.
- A
- possible safe way to use this API is in conjunction with
- which can be used to guarantee control over the
- lifetime of the
- It's also safe to use the returned data buffer
- within the same callback as long as there are no calls to other APIs that might
- trigger a GC.
- Use caution while using this API since the underlying data buffer's
- lifetime is not guaranteed if it's managed by the VM.
- representing JavaScript whose prototype to return.
- This returns the equivalent of (which is not the same as the function's property).
- representing prototype of the given object.
- representing the whose properties to query.
- Scalar datatype of the elements within the
- of elements in the
- The data buffer underlying the typed array.
- The byte offset within the data buffer from which
- to start projecting the
- This API returns various properties of a typed array.
- of bytes in the
- C boolean primitive equivalent of the given JavaScript
- If a non-boolean is passed in it returns
- representing JavaScript external value.
- Pointer to the data wrapped by the JavaScript external value.
- This API retrieves the external data pointer that was previously passed to
- If the number exceeds the range of the 32 bit integer, then the result is
- truncated to the equivalent of the bottom 32 bits.
- This can result in a large positive number becoming a negative number if the value is > 2^31 -1.
- Non-finite number values set the result to zero.
- values outside the range of
- -(2^53 - 1) - (2^53 - 1) will lose precision.
- Buffer to write the ISO-8859-1-encoded string into.
- If NULL is passed in, the length of the string (in bytes) is returned.
- Size of the destination buffer.
- When this value is
- insufficient, the returned string will be truncated.
- Number of bytes copied into the buffer, excluding the null terminator.
- This API returns the ISO-8859-1-encoded string corresponding the value passed in.
- in 2-byte code units
- Functions to get global instances
- The value of the boolean to retrieve.
- This API is used to return the JavaScript singleton object that is used to represent the given boolean value.
- Working with JavaScript Values - Abstract Operations
- N-API exposes a set of APIs to perform some abstract operations on JavaScript
- values.
- Some of these operations are documented under Section 7 of the ECMAScript Language Specification
- These APIs support doing one of the following:
- Coerce JavaScript values to specific JavaScript types (such as or)
- Check the type of a JavaScript value.
- Check for equality between two JavaScript values.
- The JavaScript value to coerce.
- This API implements the abstract operation as defined in Section 7.1.2 of the ECMAScript Language Specification.
- This API can be re-entrant if getters are defined on the passed-in
- The JavaScript value whose type to query.
- The type of the JavaScript value.
- if the type of is not a known ECMAScript type and is not an External value.
- This API represents behavior similar to invoking the Operator on the object as defined in Section 12.5.5 of the ECMAScript Language Specification.
- However, it has support for detecting an External value.
- If has a type that is invalid, an error is returned.
- The JavaScript value to check.
- The JavaScript function object of the constructor function to check against.
- Boolean that is set to true if is true.
- Whether the given object is an array.
- This API checks if the passed in is an array buffer.
- Whether the two objects are equal.
- This API represents the invocation of the Strict Equality algorithm as defined in Section 7.2.14 of the ECMAScript Language Specification.
- Working with JavaScript Properties
- N-API exposes a set of APIs to get and set properties on JavaScript objects.
- Some of these types are documented under Section 7 of the ECMAScript Language Specification
- Properties in JavaScript are represented as a tuple of a key and a value.
- Fundamentally, all property keys in N-API can be represented in one of the following forms:
- Named: a simple UTF8-encoded string
- Integer-Indexed: an index value represented by
- JavaScript value: these are represented in N-API by
- This can be a representing a or
- N-API values are represented by the type
- Any N-API call that requires a JavaScript value takes in a
- However, it's the caller's responsibility to make sure that the in question is of the JavaScript type expected by the API.
- The APIs documented in this section provide a simple interface to
- get and set properties on arbitrary JavaScript objects represented by
- For instance, consider the following JavaScript code snippet:
- The equivalent can be done using N-API values with the following snippet:
- Create a napi_value for 123
- Indexed properties can be set in a similar manner.
- Create a napi_value for 'hello'
- Properties can be retrieved using the APIs described in this section.
- The following is the approximate equivalent of the N-API counterpart:
- Finally, multiple properties can also be defined on an object for performance
- reasons.
- Create napi_values for 123 and 456
- Set the properties
- Structures
- Used with napi_define_class to distinguish static properties from instance properties.
- Ignored by napi_define_properties.
- are flags used to control the behavior of properties set on a JavaScript object.
- Other than they correspond to the attributes listed in Section 6.1.7.1 of the ECMAScript Language Specification.
- They can be one or more of the following bitflags:
- Used to indicate that no explicit attributes are set on the
- given property.
- By default, a property is read only, not enumerable and not
- configurable.
- Used to indicate that a given property is writable.
- Used to indicate that the property will be defined as a static property on a class as opposed to an instance property, which is the default. This is used only by
- One of utf8name or name should be NULL.
- Optional describing the key for the property, encoded as UTF8.
- One of or must be provided for the property.
- Optional that points to a JavaScript string or symbol to be used as the key for the property.
- The value that's retrieved by a get access of the property if the
- property is a data property.
- If this is passed in, set and to (since these members won't be used).
- A function to call when a get access of the property is performed.
- The given function is called implicitly by the runtime when the
- property is accessed from JavaScript code (or if a get on the property is
- performed using a N-API call).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement