Skip to content
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

Merged
merged 6 commits into from Nov 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
#957 adjusting return type and adding binding.cc
  • Loading branch information
Mike Mulchrone committed Nov 26, 2022
commit 37be5852db119fff7520d12720526e67087a82ae
4 changes: 4 additions & 0 deletions src/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,10 @@ bool v8__Value__BooleanValue(const v8::Value& self, v8::Isolate* isolate) {
return self.BooleanValue(isolate);
}

const v8::String* v8__Value__TypeOf(v8::Value& self, v8::Isolate* isolate) {
return local_to_ptr(self.TypeOf(isolate));
}

const v8::Primitive* v8__Null(v8::Isolate* isolate) {
return local_to_ptr(v8::Null(isolate));
}
Expand Down
8 changes: 5 additions & 3 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +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;
fn v8__Value__TypeOf(this: *const Value, isolate: *mut Isolate) -> *const String;
}

impl Value {
Expand Down Expand Up @@ -705,7 +705,9 @@ impl Value {
}

#[inline(always)]
pub fn type_of<'s>(&self, scope: &mut HandleScope<'s, ()>) -> String {
unsafe { v8__Value__TypeOf(self, scope.get_isolate_ptr()) }
pub fn type_of<'s>(&self, scope: &mut HandleScope<'s, ()>) -> Local<'s, String> {
unsafe {
scope.cast_local(|sd| v8__Value__TypeOf(self, sd.get_isolate_ptr()))
}.unwrap()
}
}