-
-
Save jeromegn/40727cf0eaa8e18734b0822b5ffd14bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct AppRunner<'a> { | |
iso: &'a v8::Isolate, | |
ctx: &'a v8::Context, | |
script: &'a v8::Script, | |
fetch_fn: &'a v8::value::Function, | |
} | |
impl<'a> AppRunner<'a> { | |
fn bootstrap(&self) { | |
bootstrap_context(&self.iso, &self.ctx); | |
let global = self.ctx.global(); | |
let fi = self.iso.clone(); | |
let fc = self.ctx.clone(); | |
global.set( | |
self.ctx, | |
&value::String::from_str(self.iso, "addEventListener"), | |
&value::Function::new( | |
self.iso, | |
self.ctx, | |
2, | |
Box::new(move |info: value::FunctionCallbackInfo| { | |
let event_name = &info.args[0]; | |
if !event_name.is_string() { | |
return Err(value::Exception::type_error( | |
&fi, | |
&value::String::from_str( | |
&fi, | |
"First argument of 'addEventListener' should be a string", | |
), | |
)); | |
} | |
let event_name = event_name.to_string(&fc).value(); | |
let func_arg = &info.args[1]; | |
if !func_arg.is_function() { | |
return Err(value::Exception::type_error( | |
&fi, | |
&value::String::from_str( | |
&fi, | |
"Second argument of 'addEventListener' should be a function", | |
), | |
)); | |
} | |
let func = &func_arg.clone().into_function().unwrap(); | |
if event_name == "fetch" { | |
self.fetch_fn = func; | |
} | |
Ok(value::undefined(&fi).into()) | |
}), | |
), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cargo build | |
Compiling rustproxy v0.1.0 (file:///Users/jerome/projects/github.com/superfly/rustproxy) | |
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements | |
--> src/main.rs:137:17 | |
| | |
137 | / Box::new(|info: value::FunctionCallbackInfo| { | |
138 | | let event_name = &info.args[0]; | |
139 | | if !event_name.is_string() { | |
140 | | return Err(value::Exception::type_error( | |
... | | |
169 | | Ok(value::undefined(&fi).into()) | |
170 | | }), | |
| |__________________^ | |
| | |
note: first, the lifetime cannot outlive the lifetime 'a as defined on the impl at 123:1... | |
--> src/main.rs:123:1 | |
| | |
123 | / impl<'a> AppRunner<'a> { | |
124 | | fn bootstrap(&self) { | |
125 | | bootstrap_context(&self.iso, &self.ctx); | |
126 | | | |
... | | |
173 | | } | |
174 | | } | |
| |_^ | |
note: ...so that the type `[closure@src/main.rs:137:26: 170:18 fi:&v8::Isolate, fc:&v8::Context, self:&mut &AppRunner<'a>]` will meet its required lifetime bounds | |
--> src/main.rs:137:17 | |
| | |
137 | / Box::new(|info: value::FunctionCallbackInfo| { | |
138 | | let event_name = &info.args[0]; | |
139 | | if !event_name.is_string() { | |
140 | | return Err(value::Exception::type_error( | |
... | | |
169 | | Ok(value::undefined(&fi).into()) | |
170 | | }), | |
| |__________________^ | |
= note: but, the lifetime must be valid for the static lifetime... | |
note: ...so that expression is assignable (expected std::boxed::Box<std::ops::Fn(v8::value::FunctionCallbackInfo) -> std::result::Result<v8::Value, v8::Value> + 'static>, found std::boxed::Box<std::ops::Fn(v8::value::FunctionCallbackInfo) -> std::result::Result<v8::Value, v8::Value>>) | |
--> src/main.rs:137:17 | |
| | |
137 | / Box::new(|info: value::FunctionCallbackInfo| { | |
138 | | let event_name = &info.args[0]; | |
139 | | if !event_name.is_string() { | |
140 | | return Err(value::Exception::type_error( | |
... | | |
169 | | Ok(value::undefined(&fi).into()) | |
170 | | }), | |
| |__________________^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct AppRunner<'a> { | |
iso: &'a v8::Isolate, | |
ctx: &'a v8::Context, | |
script: &'a v8::Script, | |
fetch_fn: &'a v8::value::Function, | |
} | |
impl<'a> AppRunner<'a> { | |
fn bootstrap(&self) { | |
bootstrap_context(&self.iso, &self.ctx); | |
let global = self.ctx.global(); | |
let fi = self.iso.clone(); | |
let fc = self.ctx.clone(); | |
global.set( | |
self.ctx, | |
&value::String::from_str(self.iso, "addEventListener"), | |
&value::Function::new( | |
self.iso, | |
self.ctx, | |
2, | |
Box::new(|info: value::FunctionCallbackInfo| { | |
Ok(value::undefined(self.iso).into()) | |
}), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment