Comments (7)
I was under the impression that eliding the lifetimes would mean they'd all be inferred to the same lifetime. But I guess I was wrong about that...
Can you share a snippet of code that compiles but shouldn't? Then I can add a trybuild test for that.
from rusty_v8.
@piscisaureus I added a test in theory that should be affected, basically anything that interacts between scope, arguments, and return_value without some implicit cast happening (i.e. like with ReturnValue::set
).
The example included in my commit actually doesn't quite cover it now that I look, see below:
fn fn_callback_lifetimes_proxy<'sc>(scope: &mut impl v8::ToLocal<'sc>, arg: v8::Local<'sc, v8::Value>) -> v8::Local<'sc, v8::Value> {
v8::String::new(scope, "Hello lifetimed callback!").unwrap().into()
}
fn fn_callback_lifetimes(
scope: v8::FunctionCallbackScope,
args: v8::FunctionCallbackArguments,
mut rv: v8::ReturnValue,
) {
rv.set(fn_callback_lifetimes_proxy(scope, args.get(0)));
}
That should fail to compile because args.get(0)
will have a lifetime equal to the lifetime of this callback, but not equivalent to that of the callback scope, which is asserted by fn_callback_lifetimes_proxy
.
By the way, I pushed up another commit to my fork that fixes this issue further by keeping scope lifetimes fully attached to FunctionCallbackArguments
and ReturnValue
. This is a greatly breaking change though, as it more or less breaks using closures as a callback.
A more elegant way forward might be to not track lifetimes explicitly with FunctionCallbackArguments
and ReturnValue
, but to require a scope to be passed in like other places to provide that lifetime. At this point I'm just hacking stuff together to get my own project working, so I didn't drop that in my fork.
from rusty_v8.
I have confirmed that my own fix has solved this issue for the project I'm working on. Previously I had been transmuting the lifetimes to avoid the issue...
from rusty_v8.
@piscisaureus See https://doc.rust-lang.org/nomicon/lifetime-elision.html
from rusty_v8.
The example included in my commit actually doesn't quite cover it now that I look, see below:
fn fn_callback_lifetimes_proxy<'sc>(scope: &mut impl v8::ToLocal<'sc>, arg: v8::Local<'sc, v8::Value>) -> v8::Local<'sc, v8::Value> { v8::String::new(scope, "Hello lifetimed callback!").unwrap().into() } fn fn_callback_lifetimes( scope: v8::FunctionCallbackScope, args: v8::FunctionCallbackArguments, mut rv: v8::ReturnValue, ) { rv.set(fn_callback_lifetimes_proxy(scope, args.get(0))); }
That should fail to compile because
args.get(0)
will have a lifetime equal to the lifetime of this callback, but not equivalent to that of the callback scope, which is asserted byfn_callback_lifetimes_proxy
.
So, with all due respect, I think the above example is perfectly safe and therefore it should compile.
What am I missing?
from rusty_v8.
@piscisaureus See https://doc.rust-lang.org/nomicon/lifetime-elision.html
Thanks. "Each elided lifetime in input position becomes a distinct lifetime parameter." 🤦🏻♂️
from rusty_v8.
Seems like these types all have explicit lifetimes on them now.
from rusty_v8.
Related Issues (20)
- Missing v8::Context::new() options
- ICU Error in DateTimePatternGeneratorCache::CreateGenerator HOT 1
- [Feature request] Support for Linux PowerPC64 Little Endian
- V8 Sandbox feature HOT 8
- ASAN failure: context_from_object_template HOT 2
- API to create and re-use StartupData HOT 4
- [Bug Report]: Static assertion failed while compiling to target_arch = arm
- [question] How do scopes work? HOT 3
- Unsoundness when starting an isolate per thread HOT 6
- ci: x86_64 build failed on macos-latest image HOT 2
- `v8::String::new_from_onebyte_const` crash on Android aarch64 HOT 6
- Failed to build V8 on riscv64
- Use of deprecated APIs in binding.cc
- `clear_kept_objects` is flaky when run in parallel HOT 1
- Property setter and definer should not return "non-hole" values HOT 2
- Catch Reached heap limit crashes? HOT 1
- feature: wasm32 target HOT 1
- `ExternalOneByteStringResource::as_str` is unsound
- Question: Global context and callbacks HOT 3
- rust_v8 0.98.0,0.99.0 build failure HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rusty_v8.