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
#957 running cargo fmt
  • Loading branch information
Mike Mulchrone committed Nov 27, 2022
commit bcf9acb4e2139f441a843356080692e1a9f43df8
17 changes: 12 additions & 5 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ 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) -> *const String;
fn v8__Value__TypeOf(
this: *const Value,
isolate: *mut Isolate,
) -> *const String;
}

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

#[inline(always)]
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()
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()
}
}
3 changes: 1 addition & 2 deletions tests/test_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4438,7 +4438,7 @@ fn typeof_checker() {
let value_2 = eval(scope, "").unwrap();
let type_of_2 = value_2.type_of(scope);
assert_eq!(type_of, type_of_2);
let value_3 = eval(scope,"1").unwrap();
let value_3 = eval(scope, "1").unwrap();
let type_of_3 = value_3.type_of(scope);
assert_ne!(type_of_2, type_of_3);
}
Expand Down Expand Up @@ -4479,7 +4479,6 @@ fn value_checker() {
assert!(value.to_boolean(scope) == v8::Boolean::new(scope, false));
assert!(!value.boolean_value(scope));


let value = eval(scope, "true").unwrap();
assert!(value.is_boolean());
assert!(value.is_true());
Expand Down