Skip to content

Commit

Permalink
Merge f917c7f into b8d0b3c
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Aug 15, 2020
2 parents b8d0b3c + f917c7f commit eca45f4
Show file tree
Hide file tree
Showing 9 changed files with 281 additions and 232 deletions.
6 changes: 3 additions & 3 deletions boa/src/builtins/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ unsafe impl Trace for FunctionBody {

bitflags! {
#[derive(Finalize, Default)]
struct FunctionFlags: u8 {
pub(crate) struct FunctionFlags: u8 {
const CALLABLE = 0b0000_0001;
const CONSTRUCTABLE = 0b0000_0010;
}
}

impl FunctionFlags {
fn from_parameters(callable: bool, constructable: bool) -> Self {
pub(crate) fn from_parameters(callable: bool, constructable: bool) -> Self {
let mut flags = Self::default();

if callable {
Expand Down Expand Up @@ -142,7 +142,7 @@ pub struct Function {
// Environment, built-in functions don't need Environments
pub environment: Option<Environment>,
/// Is it constructable or
flags: FunctionFlags,
pub(crate) flags: FunctionFlags,
}

impl Function {
Expand Down
11 changes: 6 additions & 5 deletions boa/src/builtins/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ impl Json {
///
/// [polyfill]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
fn walk(reviver: &Value, ctx: &mut Interpreter, holder: &mut Value, key: Value) -> ResultValue {
let mut value = holder.get_field(key.clone());
let value = holder.get_field(key.clone());

let obj = value.as_object().as_deref().cloned();
if let Some(obj) = obj {
for key in obj.properties().keys() {
let v = Self::walk(reviver, ctx, &mut value, Value::from(key.as_str()));
if let Value::Object(ref object) = value {
let keys: Vec<_> = object.borrow().properties().keys().cloned().collect();

for key in keys {
let v = Self::walk(reviver, ctx, &mut value.clone(), Value::from(key.as_str()));
match v {
Ok(v) if !v.is_undefined() => {
value.set_field(key.as_str(), v);
Expand Down
82 changes: 40 additions & 42 deletions boa/src/builtins/object/internal_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ impl Object {
return Value::undefined();
}

let parent_obj = Object::from(&parent).expect("Failed to get object");

return parent_obj.get(property_key);
return parent.get_field(property_key);
}

if desc.is_data_descriptor() {
Expand Down Expand Up @@ -298,45 +296,45 @@ impl Object {
}
}

/// `Object.setPropertyOf(obj, prototype)`
///
/// This method sets the prototype (i.e., the internal `[[Prototype]]` property)
/// of a specified object to another object or `null`.
///
/// More information:
/// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn]
///
/// [spec]: https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-setprototypeof-v
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf
pub fn set_prototype_of(&mut self, val: Value) -> bool {
debug_assert!(val.is_object() || val.is_null());
let current = self.prototype.clone();
if same_value(&current, &val) {
return true;
}
if !self.is_extensible() {
return false;
}
let mut p = val.clone();
let mut done = false;
while !done {
if p.is_null() {
done = true
} else if same_value(&Value::from(self.clone()), &p) {
return false;
} else {
let prototype = p
.as_object()
.expect("prototype should be null or object")
.prototype
.clone();
p = prototype;
}
}
self.prototype = val;
true
}
// /// `Object.setPropertyOf(obj, prototype)`
// ///
// /// This method sets the prototype (i.e., the internal `[[Prototype]]` property)
// /// of a specified object to another object or `null`.
// ///
// /// More information:
// /// - [ECMAScript reference][spec]
// /// - [MDN documentation][mdn]
// ///
// /// [spec]: https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-setprototypeof-v
// /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf
// pub fn set_prototype_of(&mut self, val: Value) -> bool {
// debug_assert!(val.is_object() || val.is_null());
// let current = self.prototype.clone();
// if same_value(&current, &val) {
// return true;
// }
// if !self.is_extensible() {
// return false;
// }
// let mut p = val.clone();
// let mut done = false;
// while !done {
// if p.is_null() {
// done = true
// } else if same_value(&Value::from(self.clone()), &p) {
// return false;
// } else {
// let prototype = p
// .as_object()
// .expect("prototype should be null or object")
// .prototype
// .clone();
// p = prototype;
// }
// }
// self.prototype = val;
// true
// }

/// Returns either the prototype or null
///
Expand Down
64 changes: 0 additions & 64 deletions boa/src/builtins/object/internal_state.rs

This file was deleted.

0 comments on commit eca45f4

Please sign in to comment.