Skip to content

Commit

Permalink
Implement resolve_expect for the Interner
Browse files Browse the repository at this point in the history
  • Loading branch information
raskad committed Jan 18, 2022
1 parent b2409cd commit 2ff513e
Show file tree
Hide file tree
Showing 42 changed files with 156 additions and 428 deletions.
3 changes: 1 addition & 2 deletions boa/src/builtins/console/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ impl Console {
stack_trace.push(
context
.interner()
.resolve(frame.code.name)
.expect("string disappeared")
.resolve_expect(frame.code.name)
.to_owned(),
);
prev_frame = frame.prev.as_ref();
Expand Down
192 changes: 44 additions & 148 deletions boa/src/bytecompiler.rs

Large diffs are not rendered by default.

45 changes: 9 additions & 36 deletions boa/src/environment/declarative_environment_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ impl EnvironmentRecordTrait for DeclarativeEnvironmentRecord {
assert!(
!self.env_rec.borrow().contains_key(&name),
"Identifier {} has already been declared",
context
.interner()
.resolve(name)
.expect("string disappeared")
context.interner().resolve_expect(name)
);
}

Expand Down Expand Up @@ -118,10 +115,7 @@ impl EnvironmentRecordTrait for DeclarativeEnvironmentRecord {
assert!(
!self.env_rec.borrow().contains_key(&name),
"Identifier {} has already been declared",
context
.interner()
.resolve(name)
.expect("string disappeared")
context.interner().resolve_expect(name)
);

// 2. Create an immutable binding in envRec for N and record that it is uninitialized.
Expand Down Expand Up @@ -161,10 +155,7 @@ impl EnvironmentRecordTrait for DeclarativeEnvironmentRecord {
// 1. Assert: envRec must have an uninitialized binding for N.
panic!(
"record must have binding for {}",
context
.interner()
.resolve(name)
.expect("string disappeared")
context.interner().resolve_expect(name)
);
}

Expand All @@ -188,10 +179,7 @@ impl EnvironmentRecordTrait for DeclarativeEnvironmentRecord {
if strict {
return context.throw_reference_error(format!(
"{} not found",
context
.interner()
.resolve(name)
.expect("string disappeared")
context.interner().resolve_expect(name)
));
}

Expand Down Expand Up @@ -219,10 +207,7 @@ impl EnvironmentRecordTrait for DeclarativeEnvironmentRecord {
if binding_value_is_none {
return context.throw_reference_error(format!(
"{} has not been initialized",
context
.interner()
.resolve(name)
.expect("string disappeared")
context.interner().resolve_expect(name)
));
// 4. Else if the binding for N in envRec is a mutable binding, change its bound value to V.
} else if binding_mutable {
Expand All @@ -235,10 +220,7 @@ impl EnvironmentRecordTrait for DeclarativeEnvironmentRecord {
} else if strict {
return context.throw_type_error(format!(
"Cannot mutate an immutable binding {}",
context
.interner()
.resolve(name)
.expect("string disappeared")
context.interner().resolve_expect(name)
));
}

Expand Down Expand Up @@ -267,19 +249,13 @@ impl EnvironmentRecordTrait for DeclarativeEnvironmentRecord {
} else {
context.throw_reference_error(format!(
"{} is an uninitialized binding",
context
.interner()
.resolve(name)
.expect("string disappeared")
context.interner().resolve_expect(name)
))
}
} else {
panic!(
"Cannot get binding value for {}",
context
.interner()
.resolve(name)
.expect("string disappeared")
context.interner().resolve_expect(name)
);
}
}
Expand All @@ -306,10 +282,7 @@ impl EnvironmentRecordTrait for DeclarativeEnvironmentRecord {
}
None => panic!(
"env_rec has no binding for {}",
context
.interner()
.resolve(name)
.expect("string disappeared")
context.interner().resolve_expect(name)
),
}
}
Expand Down
5 changes: 1 addition & 4 deletions boa/src/environment/environment_record_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,7 @@ pub trait EnvironmentRecordTrait: Debug + Trace + Finalize {
Some(outer) => outer.recursive_get_binding_value(name, context),
None => context.throw_reference_error(format!(
"{} is not defined",
context
.interner()
.resolve(name)
.expect("string disappeared")
context.interner().resolve_expect(name)
)),
}
}
Expand Down
73 changes: 15 additions & 58 deletions boa/src/environment/global_environment_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,8 @@ impl GlobalEnvironmentRecord {
let global_object = &self.object_record.bindings;

// 3. Let existingProp be ? globalObject.[[GetOwnProperty]](N).
let existing_prop = global_object.__get_own_property__(
&context
.interner()
.resolve(name)
.expect("string disappeared")
.into(),
context,
)?;
let existing_prop = global_object
.__get_own_property__(&context.interner().resolve_expect(name).into(), context)?;

if let Some(existing_prop) = existing_prop {
// 5. If existingProp.[[Configurable]] is true, return false.
Expand All @@ -125,11 +119,7 @@ impl GlobalEnvironmentRecord {
let global_object = &self.object_record.bindings;

// 3. Let hasProperty be ? HasOwnProperty(globalObject, N).
let key = context
.interner()
.resolve(name)
.expect("string disappeared")
.to_owned();
let key = context.interner().resolve_expect(name).to_owned();
let has_property = global_object.has_own_property(key, context)?;

// 4. If hasProperty is true, return true.
Expand All @@ -153,14 +143,8 @@ impl GlobalEnvironmentRecord {
let global_object = &self.object_record.bindings;

// 3. Let existingProp be ? globalObject.[[GetOwnProperty]](N).
let existing_prop = global_object.__get_own_property__(
&context
.interner()
.resolve(name)
.expect("string disappeared")
.into(),
context,
)?;
let existing_prop = global_object
.__get_own_property__(&context.interner().resolve_expect(name).into(), context)?;

if let Some(existing_prop) = existing_prop {
// 5. If existingProp.[[Configurable]] is true, return true.
Expand Down Expand Up @@ -203,14 +187,8 @@ impl GlobalEnvironmentRecord {
let global_object = &self.object_record.bindings;

// 3. Let hasProperty be ? HasOwnProperty(globalObject, N).
let has_property = global_object.has_own_property(
context
.interner()
.resolve(name)
.expect("string disappeared")
.to_owned(),
context,
)?;
let has_property = global_object
.has_own_property(context.interner().resolve_expect(name).to_owned(), context)?;
// 4. Let extensible be ? IsExtensible(globalObject).
let extensible = global_object.is_extensible(context)?;

Expand Down Expand Up @@ -254,14 +232,8 @@ impl GlobalEnvironmentRecord {
let global_object = &self.object_record.bindings;

// 3. Let existingProp be ? globalObject.[[GetOwnProperty]](N).
let existing_prop = global_object.__get_own_property__(
&context
.interner()
.resolve(name)
.expect("string disappeared")
.into(),
context,
)?;
let existing_prop = global_object
.__get_own_property__(&context.interner().resolve_expect(name).into(), context)?;

// 4. If existingProp is undefined or existingProp.[[Configurable]] is true, then
let desc = if existing_prop
Expand All @@ -281,11 +253,7 @@ impl GlobalEnvironmentRecord {
PropertyDescriptor::builder().value(value.clone()).build()
};

let name_str = context
.interner()
.resolve(name)
.expect("string disappeared")
.to_owned();
let name_str = context.interner().resolve_expect(name).to_owned();

// 6. Perform ? DefinePropertyOrThrow(globalObject, N, desc).
global_object.define_property_or_throw(name_str.as_str(), desc, context)?;
Expand Down Expand Up @@ -341,10 +309,7 @@ impl EnvironmentRecordTrait for GlobalEnvironmentRecord {
if !allow_name_reuse && self.declarative_record.has_binding(name, context)? {
return context.throw_type_error(format!(
"Binding already exists for {}",
context
.interner()
.resolve(name)
.expect("string disappeared")
context.interner().resolve_expect(name)
));
}

Expand All @@ -370,10 +335,7 @@ impl EnvironmentRecordTrait for GlobalEnvironmentRecord {
if self.declarative_record.has_binding(name, context)? {
return context.throw_type_error(format!(
"Binding already exists for {}",
context
.interner()
.resolve(name)
.expect("string disappeared")
context.interner().resolve_expect(name)
));
}

Expand Down Expand Up @@ -483,14 +445,9 @@ impl EnvironmentRecordTrait for GlobalEnvironmentRecord {

// 5. Let existingProp be ? HasOwnProperty(globalObject, N).
// 6. If existingProp is true, then
if global_object.has_own_property(
context
.interner()
.resolve(name)
.expect("string disappeared")
.to_owned(),
context,
)? {
if global_object
.has_own_property(context.interner().resolve_expect(name).to_owned(), context)?
{
// a. Let status be ? ObjRec.DeleteBinding(N).
let status = self.object_record.delete_binding(name, context)?;

Expand Down

0 comments on commit 2ff513e

Please sign in to comment.