Skip to content

Commit

Permalink
fix: property_attribute operator (denoland#1067)
Browse files Browse the repository at this point in the history
property_attribute previously had an addition operator overload which
doesn't make much sense in comparison to the corresponding V8
enumeration. This changes that to a bitor overload.

Signed-off-by: Darshan Sen <[email protected]>
  • Loading branch information
RaisinTen committed Sep 13, 2022
1 parent dbf19c8 commit 780eb79
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/property_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ impl Default for PropertyAttribute {
}
}

impl std::ops::Add for PropertyAttribute {
impl std::ops::BitOr for PropertyAttribute {
type Output = Self;

fn add(self, Self(rhs): Self) -> Self {
fn bitor(self, Self(rhs): Self) -> Self {
let Self(lhs) = self;
Self(lhs + rhs)
Self(lhs | rhs)
}
}

Expand All @@ -84,9 +84,15 @@ fn test_attr() {
assert!(DONT_DELETE.is_dont_delete());

assert_eq!(NONE, Default::default());
assert_eq!(READ_ONLY, NONE + READ_ONLY);
assert_eq!(READ_ONLY, NONE | READ_ONLY);

let attr = READ_ONLY + DONT_ENUM;
let attr = READ_ONLY | DONT_ENUM;
assert!(!attr.is_none());
assert!(attr.is_read_only());
assert!(attr.is_dont_enum());
assert!(!attr.is_dont_delete());

let attr = READ_ONLY | READ_ONLY | DONT_ENUM;
assert!(!attr.is_none());
assert!(attr.is_read_only());
assert!(attr.is_dont_enum());
Expand Down
2 changes: 1 addition & 1 deletion tests/test_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,7 @@ fn object_template() {
let object_templ = v8::ObjectTemplate::new(scope);
let function_templ = v8::FunctionTemplate::new(scope, fortytwo_callback);
let name = v8::String::new(scope, "f").unwrap();
let attr = v8::READ_ONLY + v8::DONT_ENUM + v8::DONT_DELETE;
let attr = v8::READ_ONLY | v8::DONT_ENUM | v8::DONT_DELETE;
object_templ.set_internal_field_count(1);
object_templ.set_with_attr(name.into(), function_templ.into(), attr);
let context = v8::Context::new(scope);
Expand Down

0 comments on commit 780eb79

Please sign in to comment.