Skip to content

Commit 17c27b0

Browse files
committed
tmp
1 parent 1983890 commit 17c27b0

4 files changed

Lines changed: 5 additions & 159 deletions

File tree

src/core/value.rs

Lines changed: 3 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
use crate::core::{ClassDefinition, DestructuringElement, Statement};
21
use crate::core::{Collect, FunctionID, Gc, GcPtr, GcTrace};
32
use crate::unicode::utf16_to_utf8;
43
use indexmap::IndexMap;
54
use num_bigint::BigInt;
5+
66
/// VM Map storage (simple Vec of key-value pairs).
77
#[derive(Clone, Collect)]
88
#[collect(no_drop)]
99
pub struct VmMapData<'gc> {
1010
pub entries: Vec<(Value<'gc>, Value<'gc>)>,
1111
pub is_weak: bool,
1212
}
13+
1314
/// VM Set storage (simple Vec of values).
1415
#[derive(Clone, Collect)]
1516
#[collect(no_drop)]
1617
pub struct VmSetData<'gc> {
1718
pub values: Vec<Value<'gc>>,
1819
pub is_weak: bool,
1920
}
21+
2022
/// Array storage with optional named properties (e.g. `arr.foo = "bar"`).
2123
#[derive(Clone, Collect)]
2224
#[collect(no_drop)]
@@ -43,53 +45,6 @@ impl<'gc> std::ops::DerefMut for VmArrayData<'gc> {
4345
&mut self.elements
4446
}
4547
}
46-
use std::sync::{Arc, Mutex};
47-
48-
#[derive(Clone, Debug, Collect, Default)]
49-
#[collect(require_static)]
50-
pub struct JSArrayBuffer {
51-
pub data: Arc<Mutex<Vec<u8>>>,
52-
pub detached: bool,
53-
pub shared: bool,
54-
pub max_byte_length: Option<usize>,
55-
/// Whether this ArrayBuffer is immutable (frozen data, cannot be written to or transferred)
56-
pub immutable: bool,
57-
}
58-
#[derive(Clone, Collect)]
59-
#[collect(no_drop)]
60-
pub struct JSDataView<'gc> {
61-
pub buffer: GcPtr<'gc, JSArrayBuffer>,
62-
pub byte_offset: usize,
63-
pub byte_length: usize,
64-
/// Whether this DataView was constructed without an explicit byteLength
65-
/// (i.e. it tracks the buffer's current size minus offset).
66-
pub length_tracking: bool,
67-
}
68-
#[derive(Clone, Debug, PartialEq, Collect)]
69-
#[collect(require_static)]
70-
pub enum TypedArrayKind {
71-
Int8,
72-
Uint8,
73-
Uint8Clamped,
74-
Int16,
75-
Uint16,
76-
Int32,
77-
Uint32,
78-
Float16,
79-
Float32,
80-
Float64,
81-
BigInt64,
82-
BigUint64,
83-
}
84-
#[derive(Clone, Collect)]
85-
#[collect(no_drop)]
86-
pub struct JSTypedArray<'gc> {
87-
pub kind: TypedArrayKind,
88-
pub buffer: GcPtr<'gc, JSArrayBuffer>,
89-
pub byte_offset: usize,
90-
pub length: usize,
91-
pub length_tracking: bool,
92-
}
9348

9449
#[derive(Clone, Debug, Collect)]
9550
#[collect(require_static)]
@@ -116,17 +71,6 @@ impl SymbolData {
11671
self.description.as_deref()
11772
}
11873
}
119-
#[derive(Clone, Collect)]
120-
#[collect(no_drop)]
121-
pub struct ClosureData<'gc> {
122-
pub params: Vec<DestructuringElement>,
123-
pub body: Vec<Statement>,
124-
pub bound_this: Option<Value<'gc>>,
125-
pub is_arrow: bool,
126-
pub is_strict: bool,
127-
pub native_target: Option<String>,
128-
pub enforce_strictness_inheritance: bool,
129-
}
13074

13175
#[derive(Clone)]
13276
pub enum Value<'gc> {
@@ -144,13 +88,6 @@ pub enum Value<'gc> {
14488
VmNativeFunction(FunctionID),
14589
VmMap(crate::core::VmMapHandle<'gc>),
14690
VmSet(crate::core::VmSetHandle<'gc>),
147-
AsyncClosure(Gc<'gc, ClosureData<'gc>>),
148-
GeneratorFunction(Option<String>, Gc<'gc, ClosureData<'gc>>),
149-
AsyncGeneratorFunction(Option<String>, Gc<'gc, ClosureData<'gc>>),
150-
ClassDefinition(Gc<'gc, ClassDefinition>),
151-
ArrayBuffer(GcPtr<'gc, JSArrayBuffer>),
152-
DataView(Gc<'gc, JSDataView<'gc>>),
153-
PrivateName(String, u32),
15491
/// Internal property representation stored in an object's `properties` map.
15592
/// Contains either a concrete `value` or accessor `getter`/`setter` functions.
15693
/// Note: a `Value::Property` is not the same as a JS descriptor object
@@ -207,12 +144,6 @@ impl From<&String> for Value<'_> {
207144
unsafe impl<'gc> Collect<'gc> for Value<'gc> {
208145
fn trace<T: GcTrace<'gc>>(&self, cc: &mut T) {
209146
match self {
210-
Value::AsyncClosure(cl) => cl.trace(cc),
211-
Value::GeneratorFunction(_, cl) => cl.trace(cc),
212-
Value::AsyncGeneratorFunction(_, cl) => cl.trace(cc),
213-
Value::ClassDefinition(cl) => cl.trace(cc),
214-
Value::ArrayBuffer(b) => b.trace(cc),
215-
Value::DataView(d) => d.trace(cc),
216147
Value::Property { value, getter, setter } => {
217148
if let Some(v) = value {
218149
v.trace(cc);
@@ -295,17 +226,6 @@ pub fn value_to_string<'gc>(val: &Value<'gc>) -> String {
295226
format!("function [{name}]() {{ [native code] }}")
296227
}
297228
}
298-
Value::AsyncClosure(..) => "async function".to_string(),
299-
Value::GeneratorFunction(name, ..) => {
300-
format!("function* {}", name.as_deref().unwrap_or(""))
301-
}
302-
Value::AsyncGeneratorFunction(name, ..) => {
303-
format!("async function* {}", name.as_deref().unwrap_or(""))
304-
}
305-
Value::ClassDefinition(..) => "class".to_string(),
306-
Value::PrivateName(n, _) => format!("#{n}"),
307-
Value::ArrayBuffer(_) => "[object ArrayBuffer]".to_string(),
308-
Value::DataView(_) => "[object DataView]".to_string(),
309229
Value::Property { .. } => "[Property]".to_string(),
310230
Value::Symbol(sym) => {
311231
if let Some(desc) = &sym.description {

src/core/vm.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24113,9 +24113,7 @@ impl<'gc> VM<'gc> {
2411324113

2411424114
fn is_value_callable(&self, value: &Value<'gc>) -> bool {
2411524115
match value {
24116-
Value::VmFunction(..) | Value::VmClosure(..) | Value::VmNativeFunction(..) | Value::Function(..) | Value::AsyncClosure(..) => {
24117-
true
24118-
}
24116+
Value::VmFunction(..) | Value::VmClosure(..) | Value::VmNativeFunction(..) | Value::Function(..) => true,
2411924117
Value::VmObject(map) => {
2412024118
let b = map.borrow();
2412124119
if let Some(target) = b.get("__proxy_target__") {

src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ pub(crate) mod repl;
1313
pub(crate) mod unicode;
1414

1515
pub use crate::core::{Token, TokenData};
16-
pub use core::{
17-
JSArrayBuffer, JSDataView, JSTypedArray, TypedArrayKind, parse_object_destructuring_pattern, parse_simple_expression, parse_statement,
18-
parse_statements, read_script_file,
19-
};
2016
pub use core::{PropertyKey, Value, evaluate_script_with_vm, format_js_number, tokenize};
17+
pub use core::{parse_object_destructuring_pattern, parse_simple_expression, parse_statement, parse_statements, read_script_file};
2118
pub use error::{JSError, JSErrorKind};
2219
// pub use js_promise::set_short_timer_threshold_ms;
2320
// pub use js_promise::set_wait_for_active_handles;

tests/typedarray_tests.rs

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,10 @@
11
use javascript::*;
2-
use std::cell::RefCell;
3-
use std::rc::Rc;
4-
use std::sync::{Arc, Mutex};
52

63
#[ctor::ctor]
74
fn __init_test_logger() {
85
let _ = env_logger::Builder::from_env(env_logger::Env::default()).is_test(true).try_init();
96
}
107

11-
#[test]
12-
fn test_jsarraybuffer_creation_and_access() {
13-
// Test creating a new ArrayBuffer
14-
let mut buffer = JSArrayBuffer {
15-
data: Arc::new(Mutex::new(vec![0; 16])),
16-
..JSArrayBuffer::default()
17-
};
18-
19-
assert_eq!(buffer.data.lock().unwrap().len(), 16);
20-
assert!(!buffer.detached);
21-
22-
// Test data access and modification
23-
buffer.data.lock().unwrap()[0] = 42;
24-
buffer.data.lock().unwrap()[15] = 255;
25-
assert_eq!(buffer.data.lock().unwrap()[0], 42);
26-
assert_eq!(buffer.data.lock().unwrap()[15], 255);
27-
28-
// Test detachment
29-
buffer.detached = true;
30-
assert!(buffer.detached);
31-
}
32-
33-
#[test]
34-
fn test_arraybuffer_detachment() {
35-
// Create an ArrayBuffer
36-
let buffer = Rc::new(RefCell::new(JSArrayBuffer {
37-
data: Arc::new(Mutex::new(vec![1, 2, 3, 4])),
38-
..JSArrayBuffer::default()
39-
}));
40-
41-
assert!(!buffer.borrow().detached);
42-
assert_eq!(buffer.borrow().data.lock().unwrap().len(), 4);
43-
44-
// Detach the buffer
45-
buffer.borrow_mut().detached = true;
46-
47-
assert!(buffer.borrow().detached);
48-
// Note: In a real implementation, detached buffers might clear their data
49-
// For this test, we just check the flag
50-
}
51-
52-
#[test]
53-
fn test_typedarray_kind_properties() {
54-
// Test that all TypedArray kinds are properly defined
55-
let all_kinds = vec![
56-
TypedArrayKind::Int8,
57-
TypedArrayKind::Uint8,
58-
TypedArrayKind::Uint8Clamped,
59-
TypedArrayKind::Int16,
60-
TypedArrayKind::Uint16,
61-
TypedArrayKind::Int32,
62-
TypedArrayKind::Uint32,
63-
TypedArrayKind::Float32,
64-
TypedArrayKind::Float64,
65-
TypedArrayKind::BigInt64,
66-
TypedArrayKind::BigUint64,
67-
];
68-
69-
assert_eq!(all_kinds.len(), 11);
70-
71-
// Test Debug formatting
72-
assert_eq!(format!("{:?}", TypedArrayKind::Int8), "Int8");
73-
assert_eq!(format!("{:?}", TypedArrayKind::Float64), "Float64");
74-
assert_eq!(format!("{:?}", TypedArrayKind::BigInt64), "BigInt64");
75-
}
76-
778
#[test]
789
fn test_js_arraybuffer_constructor_via_script() {
7910
// Test ArrayBuffer constructor through JavaScript

0 commit comments

Comments
 (0)