Skip to content

Commit

Permalink
update fuzzer/inputgen with new features
Browse files Browse the repository at this point in the history
  • Loading branch information
addisoncrump committed Jul 6, 2022
1 parent df2956a commit 0e6cbf2
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions boa_engine/src/syntax/ast/node/declaration/class_decl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use serde::{Deserialize, Serialize};
/// [spec]: https://tc39.es/ecma262/#sec-class-definitions
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function
#[cfg_attr(feature = "deser", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "fuzzer", derive(arbitrary::Arbitrary))]
#[derive(Clone, Debug, PartialEq)]
pub struct Class {
pub(crate) name: Sym,
Expand Down Expand Up @@ -352,6 +353,7 @@ impl ToInternedString for Class {

/// Class element types.
#[cfg_attr(feature = "deser", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "fuzzer", derive(arbitrary::Arbitrary))]
#[derive(Clone, Debug, PartialEq)]
pub enum ClassElement {
MethodDefinition(PropertyName, MethodDefinition),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use serde::{Deserialize, Serialize};
/// [spec]: https://tc39.es/ecma262/#prod-MemberExpression
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields
#[cfg_attr(feature = "deser", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "fuzzer", derive(arbitrary::Arbitrary))]
#[derive(Clone, Debug, PartialEq)]
pub struct GetPrivateField {
pub(crate) obj: Box<Node>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use serde::{Deserialize, Serialize};
/// [spec]: https://tc39.es/ecma262/#prod-SuperProperty
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/super
#[cfg_attr(feature = "deser", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "fuzzer", derive(arbitrary::Arbitrary))]
#[derive(Clone, Debug, PartialEq)]
pub enum GetSuperField {
Const(Sym),
Expand Down
1 change: 1 addition & 0 deletions boa_engine/src/syntax/ast/node/super_call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use serde::{Deserialize, Serialize};
/// [spec]: https://tc39.es/ecma262/#prod-SuperCall
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/super
#[cfg_attr(feature = "deser", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "fuzzer", derive(arbitrary::Arbitrary))]
#[derive(Clone, Debug, PartialEq)]
pub struct SuperCall {
pub(crate) args: Box<[Node]>,
Expand Down
2 changes: 1 addition & 1 deletion boa_inputgen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "boa_inputgen"
version = "0.14.0"
version = "0.15.0"
edition = "2021"
rust-version = "1.58"
authors = ["Addison Crump <[email protected]>"]
Expand Down
9 changes: 8 additions & 1 deletion boa_inputgen/src/data.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Fuzz data generation.
use std::collections::HashSet;
use std::fmt::{Debug, Formatter};

use arbitrary::{size_hint, Arbitrary, Unstructured};
use spin::lazy::Lazy;
Expand Down Expand Up @@ -62,11 +63,17 @@ impl Arbitrary<'_> for Name {
}

/// Fuzz data which can be arbitrarily generated and used to test boa's parser, compiler, and vm.
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct FuzzData {
source: String,
}

impl Debug for FuzzData {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.source)
}
}

impl<'a> Arbitrary<'a> for FuzzData {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
// we need at least one name or we'll mod by zero when trying to get a name
Expand Down
2 changes: 1 addition & 1 deletion boa_inputgen/src/ident_walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct SymReplacer<'a> {

impl<'a, 'ast> Visitor<'ast> for SymReplacer<'a> {
fn visit_sym_mut(&mut self, sym: &'ast mut Sym) {
*sym = self.syms[sym.as_raw().get() % self.syms.len()];
*sym = self.syms[sym.get() % self.syms.len()];
}
}

Expand Down
2 changes: 1 addition & 1 deletion boa_interner/src/sym.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl Sym {

/// Returns the internal value of the [`Sym`]
#[inline]
pub(super) const fn get(self) -> usize {
pub const fn get(self) -> usize {
self.value.get()
}
}
Expand Down
143 changes: 109 additions & 34 deletions fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0e6cbf2

Please sign in to comment.