Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Oct 2, 2020
1 parent 0bea202 commit 58c0a5a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 18 deletions.
4 changes: 2 additions & 2 deletions boa/src/builtins/error/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl BuiltIn for ReferenceError {

let error_prototype = context.standard_objects().error_object().prototype();
let attribute = Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE;
let range_error_object = ConstructorBuilder::with_standard_object(
let reference_error_object = ConstructorBuilder::with_standard_object(
context,
Self::constructor,
context.standard_objects().reference_error_object().clone(),
Expand All @@ -44,7 +44,7 @@ impl BuiltIn for ReferenceError {
.property("message", "", attribute)
.build();

(Self::NAME, range_error_object.into(), Self::attribute())
(Self::NAME, reference_error_object.into(), Self::attribute())
}
}

Expand Down
4 changes: 2 additions & 2 deletions boa/src/builtins/error/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl BuiltIn for SyntaxError {

let error_prototype = context.standard_objects().error_object().prototype();
let attribute = Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE;
let range_error_object = ConstructorBuilder::with_standard_object(
let syntax_error_object = ConstructorBuilder::with_standard_object(
context,
Self::constructor,
context.standard_objects().syntax_error_object().clone(),
Expand All @@ -47,7 +47,7 @@ impl BuiltIn for SyntaxError {
.property("message", "", attribute)
.build();

(Self::NAME, range_error_object.into(), Self::attribute())
(Self::NAME, syntax_error_object.into(), Self::attribute())
}
}

Expand Down
4 changes: 2 additions & 2 deletions boa/src/builtins/error/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl BuiltIn for TypeError {

let error_prototype = context.standard_objects().error_object().prototype();
let attribute = Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE;
let range_error_object = ConstructorBuilder::with_standard_object(
let type_error_object = ConstructorBuilder::with_standard_object(
context,
Self::constructor,
context.standard_objects().type_error_object().clone(),
Expand All @@ -50,7 +50,7 @@ impl BuiltIn for TypeError {
.property("message", "", attribute)
.build();

(Self::NAME, range_error_object.into(), Self::attribute())
(Self::NAME, type_error_object.into(), Self::attribute())
}
}

Expand Down
5 changes: 1 addition & 4 deletions boa/src/builtins/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,11 @@ impl Map {

/// Create a new map
pub(crate) fn constructor(this: &Value, args: &[Value], ctx: &mut Context) -> Result<Value> {
// Make a new Object which will internally represent the Array (mapping
// between indices and values): this creates an Object with no prototype

// Set Prototype
let prototype = ctx.global_object().get_field("Map").get_field(PROTOTYPE);

this.as_object_mut()
.expect("this is array object")
.expect("this is map object")
.set_prototype_instance(prototype);
// This value is used by console.log and other routines to match Object type
// to its Javascript Identifier (global constructor method name)
Expand Down
4 changes: 2 additions & 2 deletions boa/src/builtins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub(crate) trait BuiltIn {
/// Initializes builtin objects and functions
#[inline]
pub fn init(context: &mut Context) {
let globals2 = [
let globals = [
// Global properties.
Undefined::init,
Infinity::init,
Expand Down Expand Up @@ -90,7 +90,7 @@ pub fn init(context: &mut Context) {
unreachable!("global object should always be an object")
};

for init in &globals2 {
for init in &globals {
let (name, value, attribute) = init(context);
let property = Property::data_descriptor(value, attribute);
global_object.borrow_mut().insert(name, property);
Expand Down
9 changes: 4 additions & 5 deletions boa/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,9 @@ impl<'context> ClassBuilder<'context> {
/// It is added to `prototype`.
pub fn method<N>(&mut self, name: N, length: usize, function: NativeFunction) -> &mut Self
where
N: Into<String>,
N: AsRef<str>,
{
// TODO: \/
self.builder.method(function, &name.into(), length);
self.builder.method(function, name.as_ref(), length);
self
}

Expand All @@ -147,9 +146,9 @@ impl<'context> ClassBuilder<'context> {
function: NativeFunction,
) -> &mut Self
where
N: Into<String>,
N: AsRef<str>,
{
self.builder.static_method(function, &name.into(), length);
self.builder.static_method(function, name.as_ref(), length);
self
}

Expand Down
8 changes: 7 additions & 1 deletion boa/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ impl Default for StandardConstructor {
}

impl StandardConstructor {
/// Return the constructor object.
///
/// This is the same as `Object`, `Array`, etc.
#[inline]
pub fn constructor(&self) -> GcObject {
self.constructor.clone()
}

/// Return the prototype of the constructor object.
///
/// This is the same as `Object.prototype`, `Array.prototype`, etc
#[inline]
pub fn prototype(&self) -> GcObject {
self.prototype.clone()
Expand Down Expand Up @@ -150,7 +156,7 @@ impl StandardObjects {
///
/// `Context`s constructed in a thread share the same runtime, therefore it
/// is possible to share objects from one context to another context, but they
/// have to in the same thread.
/// have to be in the same thread.
#[derive(Debug)]
pub struct Context {
/// realm holds both the global object and the environment
Expand Down

0 comments on commit 58c0a5a

Please sign in to comment.