Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #[repr(C)]
  2. pub struct FunctionKernel<T: Value>(fn(Call) -> JsResult<T>);
  3.  
  4. impl<T: Value> Kernel<()> for FunctionKernel<T> {
  5. extern "C" fn callback(info: &CallbackInfo) {
  6. info.scope().exec(info, |call| {
  7. let data = info.data();
  8. let FunctionKernel(kernel) = unsafe { Self::from_wrapper(data.to_raw()) };
  9. // error: the parameter type `T` might not live long enough
  10. // note: the parameter type `T` must be valid for the anonymous lifetime #1 defined on the block at 6:39...
  11. if let Ok(value) = kernel(call) {
  12. // ~~~~~~~~~~~~
  13. info.set_return(value);
  14. }
  15. })
  16. }
  17. // ...
  18. }
  19.  
  20. impl<'a> RootScopeInternal<'a> for RootScope<'a> {
  21. fn exec<T: 'a, U: This, F: FnOnce(FunctionCall<U>) -> T>(&'a mut self, info: &'a CallbackInfo, f: F) -> T {
  22. let mut v8_scope = raw::HandleScope::new();
  23. unsafe {
  24. neon_sys::scope::enter(&mut v8_scope, self.isolate().to_raw());
  25. }
  26. let call = info.as_call(self);
  27. let result = f(call);
  28. unsafe {
  29. neon_sys::scope::exit(&mut v8_scope);
  30. }
  31. result
  32.  
  33. }
  34. // ...
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement