Print this page
enable v8plus_call to be used in any thread


  95  */
  96 extern nvlist_t *v8plus_void(void);
  97 
  98 /*
  99  * Find the named V8 function in the nvlist.  Analogous to other lookup
 100  * routines; see libnvpair(3lib), with an important exception: the
 101  * nvlist_lookup_v8plus_jsfunc() and nvpair_value_v8plus_jsfunc() functions
 102  * place a hold on the underlying function object, which must be released by C
 103  * code when it is no longer needed.  See the documentation to understand how
 104  * this works.  The add routine is of very limited utility because there is no
 105  * mechanism for creating a JS function from C.  It can however be used to
 106  * return a function (or object containing one, etc.) from a deferred
 107  * completion routine in which a JS function has been invoked that returned
 108  * such a thing to us.
 109  */
 110 extern int nvlist_lookup_v8plus_jsfunc(const nvlist_t *, const char *,
 111     v8plus_jsfunc_t *);
 112 extern int nvpair_value_v8plus_jsfunc(const nvpair_t *, v8plus_jsfunc_t *);
 113 extern void v8plus_jsfunc_hold(v8plus_jsfunc_t);
 114 extern void v8plus_jsfunc_rele(v8plus_jsfunc_t);

 115 
 116 /*
 117  * Place or release a hold on the V8 representation of the specified C object.
 118  * This is rarely necessary; v8plus_defer() performs this action for you, but
 119  * other asynchronous mechanisms may require it.  If you are returning from
 120  * a method call but have stashed a reference to the object somewhere and are
 121  * not calling v8plus_defer(), you must call this first.  Holds and releases
 122  * must be balanced.  Use of the object within a thread after releasing is a
 123  * bug.
 124  */
 125 extern void v8plus_obj_hold(const void *);
 126 extern void v8plus_obj_rele(const void *);

 127 
 128 /*
 129  * Convenience functions for dealing with JS arguments.
 130  */
 131 extern v8plus_type_t v8plus_typeof(const nvpair_t *);
 132 extern int v8plus_args(const nvlist_t *, uint_t, v8plus_type_t t, ...);
 133 extern nvlist_t *v8plus_obj(v8plus_type_t, ...);
 134 extern int v8plus_obj_setprops(nvlist_t *, v8plus_type_t, ...);
 135 
 136 /*
 137  * Perform a background, possibly blocking and/or expensive, task.  First,
 138  * the worker function will be enqueued for execution on another thread; its
 139  * first argument is a pointer to the C object on which to operate, and the
 140  * second is arbitrary per-call context, arguments, etc. defined by the caller.
 141  * When that worker function has completed execution, the completion function
 142  * will be invoked in the main thread.  Its arguments are the C object, the
 143  * original context pointer, and the return value from the worker function.
 144  * See the documentation for a typical use case.
 145  */
 146 typedef void *(*v8plus_worker_f)(void *, void *);
 147 typedef void (*v8plus_completion_f)(void *, void *, void *);
 148 
 149 extern void v8plus_defer(void *, void *, v8plus_worker_f, v8plus_completion_f);
 150 
 151 /*
 152  * Call an opaque JavaScript function from C.  The caller is responsible for
 153  * freeing the returned list.  The first argument is not const because it is
 154  * possible for the JS code to modify the function represented by the cookie.
 155  */
 156 extern nvlist_t *v8plus_call(v8plus_jsfunc_t, const nvlist_t *);

 157 
 158 /*
 159  * Call the named JavaScript function in the context of the JS object
 160  * represented by the native object.  Calling and return conventions are the
 161  * same as for the C interfaces; i.e., the nvlist will be converted into JS
 162  * objects and the return value or exception will be in the "res" or "err"
 163  * members of the nvlist that is returned, respectively.  If an internal
 164  * error occurs, NULL is returned and _v8plus_errno set accordingly.  The
 165  * results of calling a method implemented in C via this interface are
 166  * undefined.
 167  *
 168  * These methods can be used in concert with JS code to emit events
 169  * asynchronously; see the documentation.
 170  *
 171  * Note: As JavaScript functions must be called from the event loop thread,
 172  * v8plus_method_call() contains logic to determine whether we are in the
 173  * correct context or not.  If we are running on some other thread we will
 174  * queue the request and sleep, waiting for the event loop thread to make the
 175  * call.  In the simple case, where we are already in the correct thread,
 176  * we make the call directly.  v8plus_method_call_direct() assumes we are




  95  */
  96 extern nvlist_t *v8plus_void(void);
  97 
  98 /*
  99  * Find the named V8 function in the nvlist.  Analogous to other lookup
 100  * routines; see libnvpair(3lib), with an important exception: the
 101  * nvlist_lookup_v8plus_jsfunc() and nvpair_value_v8plus_jsfunc() functions
 102  * place a hold on the underlying function object, which must be released by C
 103  * code when it is no longer needed.  See the documentation to understand how
 104  * this works.  The add routine is of very limited utility because there is no
 105  * mechanism for creating a JS function from C.  It can however be used to
 106  * return a function (or object containing one, etc.) from a deferred
 107  * completion routine in which a JS function has been invoked that returned
 108  * such a thing to us.
 109  */
 110 extern int nvlist_lookup_v8plus_jsfunc(const nvlist_t *, const char *,
 111     v8plus_jsfunc_t *);
 112 extern int nvpair_value_v8plus_jsfunc(const nvpair_t *, v8plus_jsfunc_t *);
 113 extern void v8plus_jsfunc_hold(v8plus_jsfunc_t);
 114 extern void v8plus_jsfunc_rele(v8plus_jsfunc_t);
 115 extern void v8plus_jsfunc_rele_direct(v8plus_jsfunc_t);
 116 
 117 /*
 118  * Place or release a hold on the V8 representation of the specified C object.
 119  * This is rarely necessary; v8plus_defer() performs this action for you, but
 120  * other asynchronous mechanisms may require it.  If you are returning from
 121  * a method call but have stashed a reference to the object somewhere and are
 122  * not calling v8plus_defer(), you must call this first.  Holds and releases
 123  * must be balanced.  Use of the object within a thread after releasing is a
 124  * bug.
 125  */
 126 extern void v8plus_obj_hold(const void *);
 127 extern void v8plus_obj_rele(const void *);
 128 extern void v8plus_obj_rele_direct(const void *);
 129 
 130 /*
 131  * Convenience functions for dealing with JS arguments.
 132  */
 133 extern v8plus_type_t v8plus_typeof(const nvpair_t *);
 134 extern int v8plus_args(const nvlist_t *, uint_t, v8plus_type_t t, ...);
 135 extern nvlist_t *v8plus_obj(v8plus_type_t, ...);
 136 extern int v8plus_obj_setprops(nvlist_t *, v8plus_type_t, ...);
 137 
 138 /*
 139  * Perform a background, possibly blocking and/or expensive, task.  First,
 140  * the worker function will be enqueued for execution on another thread; its
 141  * first argument is a pointer to the C object on which to operate, and the
 142  * second is arbitrary per-call context, arguments, etc. defined by the caller.
 143  * When that worker function has completed execution, the completion function
 144  * will be invoked in the main thread.  Its arguments are the C object, the
 145  * original context pointer, and the return value from the worker function.
 146  * See the documentation for a typical use case.
 147  */
 148 typedef void *(*v8plus_worker_f)(void *, void *);
 149 typedef void (*v8plus_completion_f)(void *, void *, void *);
 150 
 151 extern void v8plus_defer(void *, void *, v8plus_worker_f, v8plus_completion_f);
 152 
 153 /*
 154  * Call an opaque JavaScript function from C.  The caller is responsible for
 155  * freeing the returned list.  The first argument is not const because it is
 156  * possible for the JS code to modify the function represented by the cookie.
 157  */
 158 extern nvlist_t *v8plus_call(v8plus_jsfunc_t, const nvlist_t *);
 159 extern nvlist_t *v8plus_call_direct(v8plus_jsfunc_t, const nvlist_t *);
 160 
 161 /*
 162  * Call the named JavaScript function in the context of the JS object
 163  * represented by the native object.  Calling and return conventions are the
 164  * same as for the C interfaces; i.e., the nvlist will be converted into JS
 165  * objects and the return value or exception will be in the "res" or "err"
 166  * members of the nvlist that is returned, respectively.  If an internal
 167  * error occurs, NULL is returned and _v8plus_errno set accordingly.  The
 168  * results of calling a method implemented in C via this interface are
 169  * undefined.
 170  *
 171  * These methods can be used in concert with JS code to emit events
 172  * asynchronously; see the documentation.
 173  *
 174  * Note: As JavaScript functions must be called from the event loop thread,
 175  * v8plus_method_call() contains logic to determine whether we are in the
 176  * correct context or not.  If we are running on some other thread we will
 177  * queue the request and sleep, waiting for the event loop thread to make the
 178  * call.  In the simple case, where we are already in the correct thread,
 179  * we make the call directly.  v8plus_method_call_direct() assumes we are