-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exposing Value::TypeOf #1133
Exposing Value::TypeOf #1133
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, can you add a test somewhere in test_api.rs
comparing types of two strings (to assert that it matches) and then a string and a number?
I can have a go at it. |
Excuse terminology or if my understanding is incorrect. As I would like to work through this. What I just realized this morning is that I did not bind const v8::String v8__Value__TypeOf(const v8::Value& self, v8::Isolate* isolate) {
return self.TypeOf(isolate);
} note: /usr/bin/ld: /root/Deno/rusty_v8/target/debug/deps/test_api-f7990818cf20050a.4svfdgqfs3t2c6tr.rcgu.o: in function `v8::value::<impl v8::data::Value>::type_of':
/root/Deno/rusty_v8/src/value.rs:709: undefined reference to `v8__Value__TypeOf'
collect2: error: ld returned 1 exit status
= help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
} |
To build with changes in
|
I will continue troubleshooting later today there are tons of examples on how to test. I suppose that makes sense how can I pass an independent copy of V8 as a parameter and or expect to use to the newly implemented function if the source hasn't been compiled locally on my machine instead of using the prebuilt version using |
src/value.rs
Outdated
@@ -142,6 +142,7 @@ extern "C" { | |||
fn v8__Value__BooleanValue(this: *const Value, isolate: *mut Isolate) | |||
-> bool; | |||
fn v8__Value__GetHash(this: *const Value) -> int; | |||
fn v8__Value__TypeOf(this: *const Value, isolate: *mut Isolate) -> String; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*const String
- V8 String
is a reference not an owned String
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So my original commit was correct in passing the Isolate as a mutable reference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No - this is correct you need to pass raw pointers between Rust and C++
I was having some memory issues with WSL2 on Ubuntu 22.04 and 20.04 on Windows 11 while compiling on this tiny laptop. So Powershell for everything is it these days. I can atleast compile this with sccache installed within 15-20 seconds. If I was reading the docs correctly v8::Local<v8::String> v8__Value__TypeOf(v8::Value& self, v8::Isolate* isolate) {
return self.TypeOf(isolate);
} ../../../src/binding.cc(762,23): error: 'v8__Value__TypeOf' has C-linkage specified, but returns user-defined type 'v8::Local<v8::String>' which is incompatible with C [-Werror,-Wreturn-type-c-linkage]
v8::Local<v8::String> v8__Value__TypeOf(v8::Value& self, v8::Isolate* isolate) { |
@WingZer0o take a look at other APIs that return the same type - eg. |
Included my test case for this PR. Please let know if anything needs to be changed if I messed up. This was a good issue for me to work on to solidify some knowledge I had from Node.js conceptually not practically. I've always wanted to get involved in either project considering all this browser work that I do and my old TypeScript projects, have to dive in I guess. |
@WingZer0o this is a great first contribution! It looks good to me, please make sure to run |
Looks like the fixed a few formatting errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @WingZer0o!
#957