Skip to content

Commit c6a6ff7

Browse files
committed
Remove tree-walking legacy: Value::Object, JSObjectData, and related dead code
- Remove Value::Object variant and all match arms referencing it in vm.rs - Delete JSObjectData struct, JSObjectDataPtr alias, and new_js_object_data fn - Delete InternalSlot enum (~200 variants) and str_to_internal_slot function - Remove PropertyKey::Internal variant and its From/PartialEq/Hash/Display impls - Delete dead Value variants: Getter, Setter, Generator, AsyncGenerator, Promise, Map, Set, WeakMap, WeakSet, TypedArray - Delete tree-walking types: JSGenerator, JSAsyncGenerator, GeneratorState, AsyncGeneratorRequest, GeneratorForAwaitState, GeneratorForOfState, AsyncForAwaitState, GeneratorPendingCompletion - Delete tree-walking collection types: JSMap, JSSet, WeakKey, JSWeakMap, JSWeakSet - Delete JSPromise, PromiseState, generate_unique_id (replaced by VM promise handling) - Remove JSObjectData impl block (new, lookup_property, set_prototype, etc.) - Clean ClosureData: remove env, home_object, captured_envs fields and new() impl - Remove helper functions: object_get_key_value, object_set_key_value, env_set, slot_get, slot_get_chained, object_get_length - Remove is_error function from js_error.rs - Simplify EvalError-to-JSError conversion (drop Value::Object error mapping) - Clean lib.rs re-exports: remove JSObjectData, new_js_object_data, env_set, object_get/set_key_value - Remove stale commented-out InternalSlot usage in mod.rs - Remove unused pub use js_error::* re-export
1 parent 8150850 commit c6a6ff7

6 files changed

Lines changed: 124 additions & 1720 deletions

File tree

src/core/js_error.rs

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::{
22
JSError,
3-
core::{InternalSlot, PropertyKey, Value, value_to_string},
4-
object_get_key_value, utf16_to_utf8,
3+
core::{Value, value_to_string},
54
};
65

76
#[derive(Debug)]
@@ -22,36 +21,8 @@ impl<'gc> From<EvalError<'gc>> for JSError {
2221
EvalError::Js(j) => j,
2322
EvalError::Throw(v, line, column) => {
2423
let msg = value_to_string(&v);
25-
let mut mapped_kind = None;
26-
if let Value::Object(obj) = &v
27-
&& let Some(name_rc) = object_get_key_value(obj, "name")
28-
&& let Value::String(name_u16) = &*name_rc.borrow()
29-
{
30-
let name = utf16_to_utf8(name_u16);
31-
let message = if let Some(message_rc) = object_get_key_value(obj, "message") {
32-
match &*message_rc.borrow() {
33-
Value::String(m) => utf16_to_utf8(m),
34-
other => value_to_string(other),
35-
}
36-
} else {
37-
msg.clone()
38-
};
3924

40-
mapped_kind = match name.as_str() {
41-
"TypeError" => Some(crate::error::JSErrorKind::TypeError { message }),
42-
"RangeError" => Some(crate::error::JSErrorKind::RangeError { message }),
43-
"SyntaxError" => Some(crate::error::JSErrorKind::SyntaxError { message }),
44-
"ReferenceError" => Some(crate::error::JSErrorKind::ReferenceError { message }),
45-
"EvalError" | "URIError" => Some(crate::error::JSErrorKind::EvaluationError { message }),
46-
_ => None,
47-
};
48-
}
49-
50-
let mut e = if let Some(kind) = mapped_kind {
51-
crate::make_js_error!(kind)
52-
} else {
53-
crate::make_js_error!(crate::error::JSErrorKind::Throw(msg))
54-
};
25+
let mut e = crate::make_js_error!(crate::error::JSErrorKind::Throw(msg));
5526
e.inner.js_line = line;
5627
e.inner.js_column = column;
5728
e
@@ -68,13 +39,3 @@ impl<'gc> EvalError<'gc> {
6839
}
6940
}
7041
}
71-
72-
/// Check if a value is an Error object.
73-
pub fn is_error<'gc>(val: &Value<'gc>) -> bool {
74-
if let Value::Object(obj) = val
75-
&& let Ok(borrowed) = obj.try_borrow()
76-
{
77-
return borrowed.properties.contains_key(&PropertyKey::Internal(InternalSlot::IsError));
78-
}
79-
false
80-
}

src/core/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ mod parser;
3030
pub use parser::*;
3131

3232
pub mod js_error;
33-
pub use js_error::*;
3433

3534
pub mod opcode;
3635
pub use opcode::*;
@@ -148,7 +147,7 @@ pub fn evaluate_script_with_vm<T: AsRef<str>, P: AsRef<std::path::Path>>(
148147
if run_as_module && let Some(injected_path) = extract_injected_module_filepath(script_str) {
149148
p_str = injected_path;
150149
}
151-
// slot_set(ctx, &root.global_env, InternalSlot::Filepath, &Value::String(utf8_to_utf16(&p_str)));
150+
152151
Some(std::path::PathBuf::from(p_str))
153152
} else {
154153
None

src/core/property_key.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
use crate::core::{Collect, Gc};
2-
use crate::core::{InternalSlot, SymbolData, Value};
2+
use crate::core::{SymbolData, Value};
33
#[derive(Clone, Debug, Collect)]
44
#[collect(no_drop)]
55
pub enum PropertyKey<'gc> {
66
String(String),
77
Symbol(Gc<'gc, SymbolData>),
88
Private(String, u32),
9-
/// Engine-internal slot key. JS code can never produce this variant,
10-
/// guaranteeing zero collision with user-defined properties.
11-
Internal(InternalSlot),
129
}
1310
impl<'gc> From<&Gc<'gc, SymbolData>> for PropertyKey<'gc> {
1411
fn from(s: &Gc<'gc, SymbolData>) -> Self {
@@ -31,7 +28,6 @@ impl<'gc> From<&PropertyKey<'gc>> for PropertyKey<'gc> {
3128
PropertyKey::String(s) => PropertyKey::String(s.clone()),
3229
PropertyKey::Symbol(sym) => PropertyKey::Symbol(*sym),
3330
PropertyKey::Private(s, id) => PropertyKey::Private(s.clone(), *id),
34-
PropertyKey::Internal(slot) => PropertyKey::Internal(slot.clone()),
3531
}
3632
}
3733
}
@@ -45,11 +41,6 @@ impl<'gc> From<String> for PropertyKey<'gc> {
4541
PropertyKey::String(s)
4642
}
4743
}
48-
impl<'gc> From<InternalSlot> for PropertyKey<'gc> {
49-
fn from(slot: InternalSlot) -> Self {
50-
PropertyKey::Internal(slot)
51-
}
52-
}
5344
impl<'gc> From<&String> for PropertyKey<'gc> {
5445
fn from(s: &String) -> Self {
5546
PropertyKey::String(s.clone())
@@ -74,7 +65,6 @@ impl<'gc> PartialEq for PropertyKey<'gc> {
7465
(PropertyKey::String(s1), PropertyKey::String(s2)) => s1 == s2,
7566
(PropertyKey::Symbol(sym1), PropertyKey::Symbol(sym2)) => Gc::ptr_eq(*sym1, *sym2),
7667
(PropertyKey::Private(s1, id1), PropertyKey::Private(s2, id2)) => s1 == s2 && id1 == id2,
77-
(PropertyKey::Internal(a), PropertyKey::Internal(b)) => a == b,
7868
_ => false,
7969
}
8070
}
@@ -96,10 +86,6 @@ impl<'gc> std::hash::Hash for PropertyKey<'gc> {
9686
s.hash(state);
9787
id.hash(state);
9888
}
99-
PropertyKey::Internal(slot) => {
100-
3u8.hash(state);
101-
slot.hash(state);
102-
}
10389
}
10490
}
10591
}
@@ -109,7 +95,6 @@ impl<'gc> std::fmt::Display for PropertyKey<'gc> {
10995
PropertyKey::String(s) => write!(f, "{s}"),
11096
PropertyKey::Symbol(sym) => write!(f, "[symbol {:p}]", Gc::as_ptr(*sym)),
11197
PropertyKey::Private(s, _) => write!(f, "#{s}"),
112-
PropertyKey::Internal(slot) => write!(f, "[internal {slot:?}]"),
11398
}
11499
}
115100
}
@@ -119,7 +104,6 @@ impl<'gc> AsRef<str> for PropertyKey<'gc> {
119104
PropertyKey::String(s) => s,
120105
PropertyKey::Symbol(_sym) => todo!("Cannot convert Symbol to &str"),
121106
PropertyKey::Private(s, _) => s,
122-
PropertyKey::Internal(_) => todo!("Cannot convert Internal slot to &str"),
123107
}
124108
}
125109
}

0 commit comments

Comments
 (0)