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

Fix internal methods #1076

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
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
5 changes: 3 additions & 2 deletions boa/examples/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct Person {
// or any function that matches that signature.
impl Person {
/// This function says hello
fn say_hello(this: &Value, _: &[Value], context: &mut Context) -> Result<Value> {
fn say_hello(this: &Value, _: &[Value], context: &Context) -> Result<Value> {
// We check if this is an object.
if let Some(object) = this.as_object() {
// If it is we downcast the type to type `Person`.
Expand Down Expand Up @@ -57,7 +57,8 @@ impl Class for Person {
const LENGTH: usize = 2;

// This is what is called when we do `new Person()`
fn constructor(_this: &Value, args: &[Value], context: &mut Context) -> Result<Self> {

fn constructor(_this: &Value, args: &[Value], context: &Context) -> Result<Self> {
// We get the first argument. If it is unavailable we get `undefined`. And, then call `to_string()`.
//
// This is equivalent to `String(arg)`.
Expand Down
4 changes: 2 additions & 2 deletions boa/src/builtins/array/array_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl ArrayIterator {
/// - [ECMA reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-%arrayiteratorprototype%.next
pub(crate) fn next(this: &Value, _: &[Value], context: &mut Context) -> Result<Value> {
pub(crate) fn next(this: &Value, _: &[Value], context: &Context) -> Result<Value> {
if let Value::Object(ref object) = this {
let mut object = object.borrow_mut();
if let Some(array_iterator) = object.as_array_iterator_mut() {
Expand Down Expand Up @@ -118,7 +118,7 @@ impl ArrayIterator {
/// - [ECMA reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-%arrayiteratorprototype%-object
pub(crate) fn create_prototype(context: &mut Context, iterator_prototype: Value) -> GcObject {
pub(crate) fn create_prototype(context: &Context, iterator_prototype: Value) -> GcObject {
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

// Create prototype
Expand Down
100 changes: 42 additions & 58 deletions boa/src/builtins/array/mod.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion boa/src/builtins/array/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,6 @@ fn array_length_is_not_enumerable() {
let context = Context::new();

let array = Array::new_array(&context).unwrap();
let desc = array.get_property("length").unwrap();
let desc = array.get_property("length", &context).unwrap().unwrap();
assert!(!desc.enumerable());
}
2 changes: 1 addition & 1 deletion boa/src/builtins/bigint/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl BigInt {
///
/// [spec]: https://tc39.es/ecma262/#sec-stringtobigint
#[inline]
pub(crate) fn from_string(string: &str, context: &mut Context) -> Result<Self, Value> {
pub(crate) fn from_string(string: &str, context: &Context) -> Result<Self, Value> {
if string.trim().is_empty() {
return Ok(BigInt::from(0));
}
Expand Down
16 changes: 8 additions & 8 deletions boa/src/builtins/bigint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl BuiltIn for BigInt {
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE
}

fn init(context: &mut Context) -> (&'static str, Value, Attribute) {
fn init(context: &Context) -> (&'static str, Value, Attribute) {
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

let bigint_object = ConstructorBuilder::with_standard_object(
Expand Down Expand Up @@ -83,7 +83,7 @@ impl BigInt {
///
/// [spec]: https://tc39.es/ecma262/#sec-bigint-objects
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt
fn constructor(_: &Value, args: &[Value], context: &mut Context) -> Result<Value> {
fn constructor(_: &Value, args: &[Value], context: &Context) -> Result<Value> {
let data = match args.get(0) {
Some(ref value) => value.to_bigint(context)?,
None => RcBigInt::from(Self::from(0)),
Expand All @@ -102,7 +102,7 @@ impl BigInt {
///
/// [spec]: https://tc39.es/ecma262/#sec-thisbigintvalue
#[inline]
fn this_bigint_value(value: &Value, context: &mut Context) -> Result<RcBigInt> {
fn this_bigint_value(value: &Value, context: &Context) -> Result<RcBigInt> {
match value {
// 1. If Type(value) is BigInt, return value.
Value::BigInt(ref bigint) => return Ok(bigint.clone()),
Expand Down Expand Up @@ -133,7 +133,7 @@ impl BigInt {
/// [spec]: https://tc39.es/ecma262/#sec-bigint.prototype.tostring
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString
#[allow(clippy::wrong_self_convention)]
pub(crate) fn to_string(this: &Value, args: &[Value], context: &mut Context) -> Result<Value> {
pub(crate) fn to_string(this: &Value, args: &[Value], context: &Context) -> Result<Value> {
let radix = if !args.is_empty() {
args[0].to_integer(context)? as i32
} else {
Expand All @@ -158,7 +158,7 @@ impl BigInt {
///
/// [spec]: https://tc39.es/ecma262/#sec-bigint.prototype.valueof
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/valueOf
pub(crate) fn value_of(this: &Value, _: &[Value], context: &mut Context) -> Result<Value> {
pub(crate) fn value_of(this: &Value, _: &[Value], context: &Context) -> Result<Value> {
Ok(Value::from(Self::this_bigint_value(this, context)?))
}

Expand All @@ -169,7 +169,7 @@ impl BigInt {
/// [spec]: https://tc39.es/ecma262/#sec-bigint.asintn
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asIntN
#[allow(clippy::wrong_self_convention)]
pub(crate) fn as_int_n(_: &Value, args: &[Value], context: &mut Context) -> Result<Value> {
pub(crate) fn as_int_n(_: &Value, args: &[Value], context: &Context) -> Result<Value> {
let (modulo, bits) = Self::calculate_as_uint_n(args, context)?;

if bits > 0
Expand All @@ -196,7 +196,7 @@ impl BigInt {
/// [spec]: https://tc39.es/ecma262/#sec-bigint.asuintn
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asUintN
#[allow(clippy::wrong_self_convention)]
pub(crate) fn as_uint_n(_: &Value, args: &[Value], context: &mut Context) -> Result<Value> {
pub(crate) fn as_uint_n(_: &Value, args: &[Value], context: &Context) -> Result<Value> {
let (modulo, _) = Self::calculate_as_uint_n(args, context)?;

Ok(Value::from(modulo))
Expand All @@ -207,7 +207,7 @@ impl BigInt {
/// This function expects the same arguments as `as_uint_n` and wraps the value of a `BigInt`.
/// Additionally to the wrapped unsigned value it returns the converted `bits` argument, so it
/// can be reused from the `as_int_n` method.
fn calculate_as_uint_n(args: &[Value], context: &mut Context) -> Result<(BigInt, u32)> {
fn calculate_as_uint_n(args: &[Value], context: &Context) -> Result<(BigInt, u32)> {
use std::convert::TryFrom;

let undefined_value = Value::undefined();
Expand Down
2 changes: 1 addition & 1 deletion boa/src/builtins/bigint/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ fn as_uint_n_errors() {
assert_throws(&mut context, "BigInt.asUintN(0n, 0n)", "TypeError");
}

fn assert_throws(context: &mut Context, src: &str, error_type: &str) {
fn assert_throws(context: &Context, src: &str, error_type: &str) {
let result = forward(context, src);
assert!(result.contains(error_type));
}
Expand Down
10 changes: 5 additions & 5 deletions boa/src/builtins/boolean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl BuiltIn for Boolean {
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE
}

fn init(context: &mut Context) -> (&'static str, Value, Attribute) {
fn init(context: &Context) -> (&'static str, Value, Attribute) {
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

let boolean_object = ConstructorBuilder::with_standard_object(
Expand Down Expand Up @@ -59,7 +59,7 @@ impl Boolean {
pub(crate) fn constructor(
new_target: &Value,
args: &[Value],
context: &mut Context,
context: &Context,
) -> Result<Value> {
// Get the argument, if any
let data = args.get(0).map(|x| x.to_boolean()).unwrap_or(false);
Expand Down Expand Up @@ -92,7 +92,7 @@ impl Boolean {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-thisbooleanvalue
fn this_boolean_value(value: &Value, context: &mut Context) -> Result<bool> {
fn this_boolean_value(value: &Value, context: &Context) -> Result<bool> {
match value {
Value::Boolean(boolean) => return Ok(*boolean),
Value::Object(ref object) => {
Expand All @@ -116,7 +116,7 @@ impl Boolean {
/// [spec]: https://tc39.es/ecma262/#sec-boolean-object
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/toString
#[allow(clippy::wrong_self_convention)]
pub(crate) fn to_string(this: &Value, _: &[Value], context: &mut Context) -> Result<Value> {
pub(crate) fn to_string(this: &Value, _: &[Value], context: &Context) -> Result<Value> {
let boolean = Self::this_boolean_value(this, context)?;
Ok(Value::from(boolean.to_string()))
}
Expand All @@ -130,7 +130,7 @@ impl Boolean {
/// [spec]: https://tc39.es/ecma262/#sec-boolean.prototype.valueof
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/valueOf
#[inline]
pub(crate) fn value_of(this: &Value, _: &[Value], context: &mut Context) -> Result<Value> {
pub(crate) fn value_of(this: &Value, _: &[Value], context: &Context) -> Result<Value> {
Ok(Value::from(Self::this_boolean_value(this, context)?))
}
}
Loading