Skip to content

Commit

Permalink
Rename Value => JsValue
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Aug 6, 2021
1 parent fff3974 commit f41572e
Show file tree
Hide file tree
Showing 108 changed files with 2,124 additions and 1,819 deletions.
8 changes: 4 additions & 4 deletions boa/examples/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use boa::{
class::{Class, ClassBuilder},
gc::{Finalize, Trace},
property::Attribute,
Context, Result, Value,
Context, JsValue, Result,
};

// We create a new struct that is going to represent a person.
Expand All @@ -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: &JsValue, _: &[JsValue], context: &mut Context) -> Result<JsValue> {
// 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 All @@ -37,7 +37,7 @@ impl Person {
person.name,
person.age // Here we can access the native rust fields of Person struct.
);
return Ok(Value::undefined());
return Ok(JsValue::undefined());
}
}
// If `this` was not an object or the type was not an native object `Person`,
Expand All @@ -57,7 +57,7 @@ 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: &JsValue, args: &[JsValue], context: &mut 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/examples/closures.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use boa::{Context, JsString, Value};
use boa::{Context, JsString, JsValue};

fn main() -> Result<(), Value> {
fn main() -> Result<(), JsValue> {
let mut context = Context::new();

let variable = JsString::new("I am a captured variable");
Expand Down
8 changes: 4 additions & 4 deletions boa/src/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::{
builtins::Number,
gc::{empty_trace, Finalize, Trace},
Context, Value,
Context, JsValue,
};

use std::{
Expand Down Expand Up @@ -162,7 +162,7 @@ impl JsBigInt {
}

#[inline]
pub fn pow(x: &Self, y: &Self, context: &mut Context) -> Result<Self, Value> {
pub fn pow(x: &Self, y: &Self, context: &mut Context) -> Result<Self, JsValue> {
let y = if let Some(y) = y.inner.to_biguint() {
y
} else {
Expand All @@ -173,7 +173,7 @@ impl JsBigInt {
}

#[inline]
pub fn shift_right(x: &Self, y: &Self, context: &mut Context) -> Result<Self, Value> {
pub fn shift_right(x: &Self, y: &Self, context: &mut Context) -> Result<Self, JsValue> {
if let Some(n) = y.inner.to_i32() {
let inner = if n > 0 {
x.inner.as_ref().clone().shr(n as usize)
Expand All @@ -188,7 +188,7 @@ impl JsBigInt {
}

#[inline]
pub fn shift_left(x: &Self, y: &Self, context: &mut Context) -> Result<Self, Value> {
pub fn shift_left(x: &Self, y: &Self, context: &mut Context) -> Result<Self, JsValue> {
if let Some(n) = y.inner.to_i32() {
let inner = if n > 0 {
x.inner.as_ref().clone().shl(n as usize)
Expand Down
34 changes: 21 additions & 13 deletions boa/src/builtins/array/array_iterator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
builtins::{function::make_builtin_fn, iterable::create_iter_result_object, Array, Value},
builtins::{function::make_builtin_fn, iterable::create_iter_result_object, Array, JsValue},
gc::{Finalize, Trace},
object::{GcObject, ObjectData},
property::PropertyDescriptor,
Expand All @@ -22,15 +22,15 @@ pub enum ArrayIterationKind {
/// [spec]: https://tc39.es/ecma262/#sec-array-iterator-objects
#[derive(Debug, Clone, Finalize, Trace)]
pub struct ArrayIterator {
array: Value,
array: JsValue,
next_index: u32,
kind: ArrayIterationKind,
}

impl ArrayIterator {
pub(crate) const NAME: &'static str = "ArrayIterator";

fn new(array: Value, kind: ArrayIterationKind) -> Self {
fn new(array: JsValue, kind: ArrayIterationKind) -> Self {
ArrayIterator {
array,
kind,
Expand All @@ -48,10 +48,10 @@ impl ArrayIterator {
/// [spec]: https://tc39.es/ecma262/#sec-createarrayiterator
pub(crate) fn create_array_iterator(
context: &Context,
array: Value,
array: JsValue,
kind: ArrayIterationKind,
) -> Value {
let array_iterator = Value::new_object(context);
) -> JsValue {
let array_iterator = JsValue::new_object(context);
array_iterator.set_data(ObjectData::ArrayIterator(Self::new(array, kind)));
array_iterator
.as_object()
Expand All @@ -68,13 +68,17 @@ 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> {
if let Value::Object(ref object) = this {
pub(crate) fn next(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result<JsValue> {
if let JsValue::Object(ref object) = this {
let mut object = object.borrow_mut();
if let Some(array_iterator) = object.as_array_iterator_mut() {
let index = array_iterator.next_index;
if array_iterator.array.is_undefined() {
return Ok(create_iter_result_object(context, Value::undefined(), true));
return Ok(create_iter_result_object(
context,
JsValue::undefined(),
true,
));
}
let len = array_iterator
.array
Expand All @@ -83,8 +87,12 @@ impl ArrayIterator {
.ok_or_else(|| context.construct_type_error("Not an array"))?
as u32;
if array_iterator.next_index >= len {
array_iterator.array = Value::undefined();
return Ok(create_iter_result_object(context, Value::undefined(), true));
array_iterator.array = JsValue::undefined();
return Ok(create_iter_result_object(
context,
JsValue::undefined(),
true,
));
}
array_iterator.next_index = index + 1;
match array_iterator.kind {
Expand All @@ -98,7 +106,7 @@ impl ArrayIterator {
ArrayIterationKind::KeyAndValue => {
let element_value = array_iterator.array.get_field(index, context)?;
let result = Array::constructor(
&Value::new_object(context),
&JsValue::new_object(context),
&[index.into(), element_value],
context,
)?;
Expand All @@ -119,7 +127,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: &mut Context, iterator_prototype: JsValue) -> GcObject {
let _timer = BoaProfiler::global().start_event(Self::NAME, "init");

// Create prototype
Expand Down
Loading

0 comments on commit f41572e

Please sign in to comment.