Skip to content

Commit

Permalink
juno_eval: fix warnings
Browse files Browse the repository at this point in the history
Summary: .

Reviewed By: neildhar

Differential Revision: D34805684

fbshipit-source-id: 621e6d73d0cabbbac5fe930794fd3ed04fce5ee4
  • Loading branch information
tmikov authored and facebook-github-bot committed Mar 11, 2022
1 parent c4d45aa commit 6261417
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 54 deletions.
16 changes: 7 additions & 9 deletions unsupported/juno/crates/juno_eval/src/eval/environment_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

use super::addr::*;
use super::completion_record::*;
use super::jsvalue::*;
use super::runtime::*;
Expand Down Expand Up @@ -130,7 +129,7 @@ impl EnvironmentRecord {
}
}

fn unreachable_get_this_binding(run: &mut Runtime, eaddr: EnvRecordAddr) -> CompletionRecord {
fn unreachable_get_this_binding(_run: &mut Runtime, _eaddr: EnvRecordAddr) -> CompletionRecord {
unimplemented!()
}

Expand Down Expand Up @@ -363,7 +362,7 @@ impl DeclarativeEnv {
}

/// https://262.ecma-international.org/11.0/#sec-declarative-environment-records-withbaseobject
fn with_base_object(run: &Runtime, eaddr: EnvRecordAddr) -> Option<ObjectAddr> {
fn with_base_object(_run: &Runtime, _eaddr: EnvRecordAddr) -> Option<ObjectAddr> {
None
}
}
Expand Down Expand Up @@ -446,19 +445,18 @@ impl FunctionEnv {
impl ObjectEnv {
/// https://262.ecma-international.org/11.0/#sec-object-environment-records-hasbinding-n
fn has_binding(run: &mut Runtime, eaddr: EnvRecordAddr, n: &Rc<JSString>) -> CompletionRecord {
let env_rec = &run.env_record(eaddr);
let env_rec = run.env_record(eaddr);
let nv = JSValue::String(n.clone());
if !run.has_property(env_rec.obj.binding_object.unwrap(), &nv) {
return Ok(NormalCompletion::Value(JSValue::Boolean(false)));
}
if !env_rec.obj.with_environment {
return Ok(NormalCompletion::Value(JSValue::Boolean(true)));
}
let unscopables_sym = run.well_known_symbol(WellKnownSymbol::Unscopables);
let binding_object_addr = env_rec.obj.binding_object.unwrap();
let unscopables = run
.get(
env_rec.obj.binding_object.unwrap(),
&run.well_known_symbol(WellKnownSymbol::Unscopables),
)?
.get(binding_object_addr, &unscopables_sym)?
.unwrap_value();
if let JSValue::Object(unsc_addr) = unscopables {
let blocked = to_boolean(&run.get(unsc_addr, &nv)?.unwrap_value());
Expand Down Expand Up @@ -910,7 +908,7 @@ impl GlobalEnv {
}

/// https://262.ecma-international.org/11.0/#sec-global-environment-records-withbaseobject
fn with_base_object(run: &Runtime, eaddr: EnvRecordAddr) -> Option<ObjectAddr> {
fn with_base_object(_run: &Runtime, _eaddr: EnvRecordAddr) -> Option<ObjectAddr> {
None
}
}
20 changes: 10 additions & 10 deletions unsupported/juno/crates/juno_eval/src/eval/execution_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

use super::jsvalue::*;
use super::runtime::*;

/// https://262.ecma-international.org/11.0/#table-22
Expand All @@ -21,15 +20,16 @@ pub struct ExecutionContext {
}

impl ExecutionContext {
pub fn new_script(script_or_module: ScriptOrModule) -> Self {
ExecutionContext {
function: None,
realm: (),
script_or_module: Some(script_or_module),

lex_env: todo!(),
var_env: todo!(),
}
pub fn new_script(_script_or_module: ScriptOrModule) -> Self {
unimplemented!();
// ExecutionContext {
// function: None,
// realm: (),
// script_or_module: Some(script_or_module),
//
// lex_env: todo!(),
// var_env: todo!(),
// }
}
}

Expand Down
1 change: 0 additions & 1 deletion unsupported/juno/crates/juno_eval/src/eval/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

use super::addr::*;
use super::completion_record::*;
use super::jsobject::*;
use super::runtime::*;
Expand Down
30 changes: 10 additions & 20 deletions unsupported/juno/crates/juno_eval/src/eval/jsobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
* LICENSE file in the root directory of this source tree.
*/

use super::addr::*;
use super::completion_record::*;
use super::function::*;
use super::jsvalue::*;
use super::operations::*;
use super::runtime::*;
use crate::eval::jsvalue::JSValue;
use std::cmp::Ordering;
use std::collections::HashMap;
use std::num::FpCategory::Normal;
use std::rc::Rc;

declare_opaque_id!(PropertyIndex);

Expand Down Expand Up @@ -91,7 +87,7 @@ pub struct ObjectMethods {
pub get: fn(&mut Runtime, ObjectAddr, &JSValue, &JSValue) -> CompletionRecord,
pub set: fn(&mut Runtime, ObjectAddr, &JSValue, JSValue, &JSValue) -> CompletionRecord,
pub delete: fn(&mut Runtime, ObjectAddr, &JSValue) -> bool,
pub own_property_keys: fn(&Runtime, ObjectAddr, JSValue) -> Vec<JSValue>,
pub own_property_keys: fn(&Runtime, ObjectAddr) -> Vec<JSValue>,
}

pub struct JSObject {
Expand Down Expand Up @@ -502,7 +498,7 @@ impl JSObject {
return true;
}
let parent = (methods.get_prototype_of)(run, oaddr);
if let (JSValue::Object(pa)) = parent {
if let JSValue::Object(pa) = parent {
(methods.has_property)(run, *pa, p)
} else {
false
Expand All @@ -520,7 +516,9 @@ impl JSObject {
match (run.object(oaddr).methods.get_own_property)(run, oaddr, p) {
None => match (run.object(oaddr).methods.get_prototype_of)(run, oaddr) {
JSValue::Object(paddr) => {
(run.object(*paddr).methods.get)(run, *paddr, p, receiver)
// Copy to avoid the borrows checker.
let paddr = *paddr;
(run.object(paddr).methods.get)(run, paddr, p, receiver)
}
_ => Ok(NormalCompletion::Value(JSValue::Undefined)),
},
Expand Down Expand Up @@ -566,13 +564,9 @@ impl JSObject {
if let JSValue::Object(parent_addr) =
(run.object(oaddr).methods.get_prototype_of)(run, oaddr)
{
return (run.object(*parent_addr).methods.set)(
run,
*parent_addr,
p,
v,
receiver,
);
// Avoid the borrows checker.
let parent_addr = *parent_addr;
return (run.object(parent_addr).methods.set)(run, parent_addr, p, v, receiver);
}
PropertyDescriptor {
value: Some(JSValue::Undefined),
Expand Down Expand Up @@ -633,11 +627,7 @@ impl JSObject {
}

/// https://262.ecma-international.org/11.0/#sec-ordinaryownpropertykeys
pub fn ordinary_own_property_keys(
run: &Runtime,
oaddr: ObjectAddr,
p: JSValue,
) -> Vec<JSValue> {
pub fn ordinary_own_property_keys(run: &Runtime, oaddr: ObjectAddr) -> Vec<JSValue> {
let mut res = run.object(oaddr).keys.clone();

// Sort: indexes first, strings next, symbols last.
Expand Down Expand Up @@ -679,7 +669,7 @@ impl JSObject {
if let Some(additional) = additional_internal_slots_list {
internal_slots_list.extend(additional);
}
let mut o = run.make_basic_object(&internal_slots_list);
let o = run.make_basic_object(&internal_slots_list);
run.object_mut(o)
.internal_slots
.insert(InternalSlotName::Prototype, proto.into());
Expand Down
3 changes: 1 addition & 2 deletions unsupported/juno/crates/juno_eval/src/eval/jsvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

use super::addr::*;
use super::runtime::*;
use std::cmp::Ordering;
use std::fmt::{Debug, Display, Formatter, Pointer};
use std::fmt::{Debug, Display, Formatter};
use std::hash::{Hash, Hasher};
use std::rc::Rc;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl LexicalEnvironment {
}

/// https://262.ecma-international.org/11.0/#sec-newfunctionenvironment
pub fn new_function_environment(run: &mut Runtime, f: &JSValue) -> LexicalEnvAddr {
pub fn new_function_environment(_run: &mut Runtime, _f: &JSValue) -> LexicalEnvAddr {
// 1. Assert: F is an ECMAScript function.
// 2. Assert: Type(newTarget) is Undefined or Object.
// 3. Let env be a new Lexical Environment.
Expand Down
6 changes: 2 additions & 4 deletions unsupported/juno/crates/juno_eval/src/eval/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
* LICENSE file in the root directory of this source tree.
*/

use super::addr::*;
use super::completion_record::CompletionRecord;
use super::completion_record::NormalCompletion;
use super::environment_record::EnvironmentRecord;
use super::execution_context::ExecutionContext;
use super::jsvalue::JSValue;
use super::operations::{to_boolean, to_object};
use super::operations::to_object;
use super::runtime::EnvRecordAddr;
use super::runtime::Runtime;

#[derive(Clone, Debug, PartialEq)]
enum ReferenceBase {
pub enum ReferenceBase {
Value(JSValue),
EnvRec(EnvRecordAddr),
}
Expand Down
9 changes: 4 additions & 5 deletions unsupported/juno/crates/juno_eval/src/eval/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

use super::addr::*;
use super::completion_record::*;
use super::environment_record::*;
use super::execution_context::*;
Expand Down Expand Up @@ -83,9 +82,9 @@ impl Runtime {
&mut self.objects[addr.as_usize()]
}
pub fn new_env_record(&mut self, kind: EnvironmentRecordKind) -> EnvRecordAddr {
let newAddr = EnvRecordAddr::new(self.env_records.len());
let new_addr = EnvRecordAddr::new(self.env_records.len());
self.env_records.push(EnvironmentRecord::new(kind));
newAddr
new_addr
}
pub fn env_record(&self, addr: EnvRecordAddr) -> &EnvironmentRecord {
&self.env_records[addr.as_usize()]
Expand Down Expand Up @@ -209,11 +208,11 @@ impl Runtime {
}

/// https://262.ecma-international.org/11.0/#sec-call
pub fn call(&mut self, f: &JSValue, v: &JSValue, args: &[JSValue]) -> CompletionRecord {
pub fn call(&mut self, _f: &JSValue, _v: &JSValue, _args: &[JSValue]) -> CompletionRecord {
unimplemented!()
}
}

pub fn evaluate_program(run: &mut Runtime, ast: &NodeRc) -> CompletionRecord {
pub fn evaluate_program(_run: &mut Runtime, _ast: &NodeRc) -> CompletionRecord {
todo!()
}
2 changes: 1 addition & 1 deletion unsupported/juno/crates/juno_eval/src/eval/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl ScriptRecord {
}

/// https://262.ecma-international.org/11.0/#sec-globaldeclarationinstantiation
pub fn global_declaration_instantiation(run: &mut Runtime, ast: &NodeRc) -> CompletionRecord {
pub fn global_declaration_instantiation(_run: &mut Runtime, _ast: &NodeRc) -> CompletionRecord {
todo!();
}

Expand Down
3 changes: 2 additions & 1 deletion unsupported/juno/crates/juno_eval/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
use crate::eval::*;
use juno_ast::NodeRc;

#[allow(dead_code)]
mod eval;

pub fn run(ast: &NodeRc) {
eval::script::script_evaluation(&mut runtime::Runtime::new(), ast);
let _ = eval::script::script_evaluation(&mut runtime::Runtime::new(), ast);
}

0 comments on commit 6261417

Please sign in to comment.