Skip to content

Commit d713b50

Browse files
Merge branch 'main' into temporal_intrinsic
2 parents 0a93de6 + b47a71c commit d713b50

File tree

16 files changed

+313
-158
lines changed

16 files changed

+313
-158
lines changed

.cargo/config.toml

Lines changed: 0 additions & 2 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ jobs:
3939
with:
4040
shared-key: warm
4141
- name: Install Dylint
42-
if: false
4342
uses: taiki-e/install-action@v2
4443
with:
4544
tool: cargo-dylint,dylint-link
@@ -50,11 +49,9 @@ jobs:
5049
cargo +stable clippy --all-targets -- -D warnings
5150
cargo +nightly-2025-05-14 clippy --all-targets --all-features -- -D warnings
5251
- name: Dylint tests
53-
if: false
5452
working-directory: nova_lint
5553
run: cargo test
5654
- name: Dylint
57-
if: false
5855
run: cargo dylint --all
5956

6057
build:

.well-known/funding-manifest-urls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/aapoalas/aapoalas/blob/main/funding.json

Cargo.toml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ cliclack = "0.3.6"
2121
console = "0.15.11"
2222
ctrlc = "3.4.5"
2323
fast-float = "0.2.0"
24-
fast_float = "0.2.0"
2524
hashbrown = "0.16.0"
2625
lexical = { version = "7.0.4", default-features = false, features = [
2726
"std",
@@ -31,16 +30,16 @@ lexical = { version = "7.0.4", default-features = false, features = [
3130
] }
3231
num-bigint = "0.4.6"
3332
num-traits = "0.2.19"
34-
oxc-miette = { version = "2.4.0", features = ["fancy"] }
35-
oxc_allocator = "0.89.0"
36-
oxc_ast = "0.89.0"
37-
oxc_diagnostics = "0.89.0"
38-
oxc_ecmascript = "0.89.0"
39-
oxc_parser = "0.89.0"
40-
oxc_regular_expression = "0.89.0"
41-
oxc_semantic = "0.89.0"
42-
oxc_span = "0.89.0"
43-
oxc_syntax = "0.89.0"
33+
oxc-miette = { version = "2.5.0", features = ["fancy"] }
34+
oxc_allocator = "0.90.0"
35+
oxc_ast = "0.90.0"
36+
oxc_diagnostics = "0.90.0"
37+
oxc_ecmascript = "0.90.0"
38+
oxc_parser = "0.90.0"
39+
oxc_regular_expression = "0.90.0"
40+
oxc_semantic = "0.90.0"
41+
oxc_span = "0.90.0"
42+
oxc_syntax = "0.90.0"
4443
rand = "0.9.2"
4544
regex = "1.11.2"
4645
ryu-js = "1.0.2"
@@ -55,8 +54,14 @@ temporal_rs = "0.0.16"
5554
[workspace.metadata.dylint]
5655
libraries = [{ path = "nova_lint" }]
5756

57+
# The release profile, used for `cargo build --release`.
5858
[profile.release]
59-
lto = true
59+
# Enables "fat" LTO, for faster release builds
60+
lto = "fat"
61+
# Makes sure that all code is compiled together, for LTO
62+
codegen-units = 1
63+
# Strips debug information and symbols from the binary, reducing its size
64+
strip = "symbols"
6065

6166
# This profile has all the same safety checks as dev builds. It trades slightly
6267
# longer compile times for faster runs, which is worth it when running test262.

nova_lint/.cargo/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[target.'cfg(all())']
2-
rustflags = ["-C", "linker=dylint-link"]
2+
linker = "dylint-link"

nova_lint/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ name = "gc_scope_is_only_passed_by_value"
2525
path = "ui/gc_scope_is_only_passed_by_value.rs"
2626

2727
[dependencies]
28-
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "ff4a26d442bead94a4c96fb1de967374bc4fbd8e" }
29-
dylint_linting = { version = "4.0.0", features = ["constituent"] }
28+
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "0450db33a5d8587f7c1d4b6d233dac963605766b" }
29+
dylint_linting = { version = "4.1.0", features = ["constituent"] }
3030

3131
[dev-dependencies]
32-
dylint_testing = "4.0.0"
32+
dylint_testing = "4.1.0"
3333
nova_vm = { path = "../nova_vm" }
3434

3535
[package.metadata.rust-analyzer]

nova_lint/src/utils.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1-
use clippy_utils::match_def_path;
1+
use rustc_hir::def_id::DefId;
22
use rustc_lint::LateContext;
33
use rustc_middle::ty::{Ty, TyKind};
4+
use rustc_span::symbol::Symbol;
5+
6+
// Copyright (c) 2014-2025 The Rust Project Developers
7+
//
8+
// Originally copied from `dylint` which in turn copied it from `clippy_utils`:
9+
// - https://github.com/trailofbits/dylint/blob/a2dd5c60d53d66fc791fa8184bed27a4cb142e74/internal/src/match_def_path.rs
10+
// - https://github.com/rust-lang/rust-clippy/blob/f62f26965817f2573c2649288faa489a03ed1665/clippy_utils/src/lib.rs
11+
// It was removed from `clippy_utils` by the following PR:
12+
// - https://github.com/rust-lang/rust-clippy/pull/14705
13+
/// Checks if the given `DefId` matches the path.
14+
pub fn match_def_path(cx: &LateContext<'_>, did: DefId, syms: &[&str]) -> bool {
15+
// We should probably move to Symbols in Clippy as well rather than interning every time.
16+
let path = cx.get_def_path(did);
17+
syms.iter()
18+
.map(|x| Symbol::intern(x))
19+
.eq(path.iter().copied())
20+
}
421

522
pub fn is_param_ty(ty: &Ty) -> bool {
623
matches!(ty.kind(), TyKind::Param(_))

nova_vm/src/ecmascript/builtins/fundamental_objects/symbol_objects/symbol_constructor.rs

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use crate::{
99
builtins::{ArgumentsList, Behaviour, Builtin, BuiltinIntrinsicConstructor},
1010
execution::{Agent, JsResult, Realm, agent::ExceptionType},
1111
types::{
12-
BUILTIN_STRING_MEMORY, IntoObject, IntoValue, Object, String, SymbolHeapData, Value,
12+
BUILTIN_STRING_MEMORY, IntoObject, IntoValue, Object, String, Symbol, SymbolHeapData,
13+
Value,
1314
},
1415
},
1516
engine::context::{Bindable, GcScope},
@@ -89,29 +90,59 @@ impl SymbolConstructor {
8990
fn r#for<'gc>(
9091
agent: &mut Agent,
9192
_this_value: Value,
92-
_arguments: ArgumentsList,
93-
gc: GcScope<'gc, '_>,
93+
arguments: ArgumentsList,
94+
mut gc: GcScope<'gc, '_>,
9495
) -> JsResult<'gc, Value<'gc>> {
96+
let key = arguments.get(0).bind(gc.nogc());
9597
// 1. Let stringKey be ? ToString(key).
98+
let string_key = to_string(agent, key.unbind(), gc.reborrow())
99+
.unbind()?
100+
.bind(gc.nogc());
101+
96102
// 2. For each element e of the GlobalSymbolRegistry List, do
97103
// a. If e.[[Key]] is stringKey, return e.[[Symbol]].
104+
if let Some(&symbol) = agent.global_symbol_registry.get(&string_key.unbind()) {
105+
return Ok(symbol.into_value());
106+
}
107+
98108
// 3. Assert: The GlobalSymbolRegistry List does not currently contain an entry for stringKey.
99109
// 4. Let newSymbol be a new Symbol whose [[Description]] is stringKey.
110+
let new_symbol = agent.heap.create(SymbolHeapData {
111+
descriptor: Some(string_key.unbind()),
112+
});
113+
100114
// 5. Append the GlobalSymbolRegistry Record { [[Key]]: stringKey, [[Symbol]]: newSymbol } to the GlobalSymbolRegistry List.
115+
agent
116+
.global_symbol_registry
117+
.insert(string_key.unbind(), new_symbol);
118+
101119
// 6. Return newSymbol.
102-
Err(agent.todo("Symbol.for", gc.into_nogc()))
120+
Ok(new_symbol.into_value())
103121
}
104122

105123
/// ### [20.4.2.6 Symbol.keyFor ( sym )](https://tc39.es/ecma262/#sec-symbol.keyfor)
106124
fn key_for<'gc>(
107125
agent: &mut Agent,
108126
_this_value: Value,
109-
_arguments: ArgumentsList,
127+
arguments: ArgumentsList,
110128
gc: GcScope<'gc, '_>,
111129
) -> JsResult<'gc, Value<'gc>> {
130+
let sym = arguments.get(0).bind(gc.nogc());
131+
112132
// 1. If sym is not a Symbol, throw a TypeError exception.
133+
let symbol = match sym.unbind().try_into() {
134+
Ok(symbol) => symbol,
135+
Err(_) => {
136+
return Err(agent.throw_exception_with_static_message(
137+
ExceptionType::TypeError,
138+
"Symbol.keyFor argument is not a symbol",
139+
gc.into_nogc(),
140+
));
141+
}
142+
};
143+
113144
// 2. Return KeyForSymbol(sym).
114-
Err(agent.todo("Symbol.keyFor", gc.into_nogc()))
145+
Ok(key_for_symbol(agent, symbol).map_or(Value::Undefined, |key| key.into_value()))
115146
}
116147

117148
pub(crate) fn create_intrinsic(agent: &mut Agent, realm: Realm<'static>) {
@@ -237,3 +268,19 @@ impl SymbolConstructor {
237268
.build();
238269
}
239270
}
271+
272+
/// ### [20.4.5.1 KeyForSymbol ( sym )](https://tc39.es/ecma262/#sec-keyforsymbol)
273+
///
274+
/// The abstract operation KeyForSymbol takes argument sym (a Symbol) and returns a String or undefined.
275+
pub(crate) fn key_for_symbol<'a>(agent: &Agent, sym: Symbol<'a>) -> Option<String<'a>> {
276+
// 1. For each element e of the GlobalSymbolRegistry List, do
277+
// a. If SameValue(e.[[Symbol]], sym) is true, return e.[[Key]].
278+
for (key, &symbol) in &agent.global_symbol_registry {
279+
if symbol == sym {
280+
return Some(*key);
281+
}
282+
}
283+
// 2. Assert: The GlobalSymbolRegistry List does not currently contain an entry for sym.
284+
// 3. Return undefined.
285+
None
286+
}

nova_vm/src/ecmascript/builtins/keyed_collections/weak_set_objects/weak_set_constructor.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::{
2727
context::{Bindable, GcScope, NoGcScope},
2828
rootable::Scopable,
2929
},
30-
heap::{Heap, IntrinsicConstructorIndexes},
30+
heap::IntrinsicConstructorIndexes,
3131
};
3232

3333
pub(crate) struct WeakSetConstructor;
@@ -196,22 +196,22 @@ fn weak_set_add_trivially_iterable_array_elements<'a>(
196196
iterable: Array,
197197
gc: NoGcScope<'a, '_>,
198198
) -> JsResult<'a, ()> {
199-
let Heap {
200-
arrays,
201-
elements,
202-
weak_sets,
203-
..
204-
} = &mut agent.heap;
205-
let array_heap = ArrayHeap::new(elements, arrays);
199+
let array_heap = ArrayHeap::new(&agent.heap.elements, &agent.heap.arrays);
206200
let slice = iterable.as_slice(&array_heap);
207-
let weak_set_data = &mut weak_sets[set];
201+
202+
let mut weak_keys = Vec::new();
208203
for value in slice {
209204
let value = value.unwrap_or(Value::Undefined);
210205
// 3. If CanBeHeldWeakly(value) is false, throw a TypeError exception.
211-
let Some(value) = can_be_held_weakly(value) else {
206+
let Some(weak_key) = can_be_held_weakly(agent, value) else {
212207
return Err(throw_not_weak_key_error(agent, value, gc));
213208
};
214-
weak_set_data.add(value);
209+
weak_keys.push(weak_key);
210+
}
211+
212+
let weak_set_data = &mut agent.heap.weak_sets[set];
213+
for weak_key in weak_keys {
214+
weak_set_data.add(weak_key);
215215
}
216216
Ok(())
217217
}

nova_vm/src/ecmascript/builtins/keyed_collections/weak_set_objects/weak_set_prototype.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl WeakSetPrototype {
5454
// 2. Perform ? RequireInternalSlot(S, [[WeakSetData]]).
5555
let s = require_internal_slot_weak_set(agent, s, gc)?;
5656
// 3. If CanBeHeldWeakly(value) is false, throw a TypeError exception.
57-
let Some(value) = can_be_held_weakly(value) else {
57+
let Some(value) = can_be_held_weakly(agent, value) else {
5858
return Err(throw_not_weak_key_error(agent, value.unbind(), gc));
5959
};
6060
// 4. For each element e of S.[[WeakSetData]], do
@@ -87,7 +87,7 @@ impl WeakSetPrototype {
8787
// 2. Perform ? RequireInternalSlot(S, [[WeakSetData]]).
8888
let s = require_internal_slot_weak_set(agent, s, gc)?;
8989
// 3. If CanBeHeldWeakly(value) is false, return false.
90-
let Some(value) = can_be_held_weakly(value) else {
90+
let Some(value) = can_be_held_weakly(agent, value) else {
9191
return Ok(false.into_value());
9292
};
9393
// 4. For each element e of S.[[WeakSetData]], do
@@ -116,7 +116,7 @@ impl WeakSetPrototype {
116116
// 2. Perform ? RequireInternalSlot(S, [[WeakSetData]]).
117117
let s = require_internal_slot_weak_set(agent, s, gc)?;
118118
// 3. If CanBeHeldWeakly(value) is false, return false.
119-
let Some(value) = can_be_held_weakly(value) else {
119+
let Some(value) = can_be_held_weakly(agent, value) else {
120120
return Ok(false.into_value());
121121
};
122122
// 4. For each element e of S.[[WeakSetData]], do

0 commit comments

Comments
 (0)