Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ecmascript): Implement Float16Array proposal #551

Merged
merged 21 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9e148bd
fix(ecmascript): `trimLeft` and `trimRight` property descriptors
eliassjogreen Jan 30, 2025
a3bbec1
feat(ecmascript): Add `Float16Array` proposal
eliassjogreen Jan 30, 2025
6423f49
feat(ecmascript): Implement `Float16Array` proposal
eliassjogreen Jan 30, 2025
857df94
chore: Update expectations
eliassjogreen Jan 30, 2025
adcade5
Merge branch 'main' into feat/proposal-float16array
eliassjogreen Jan 30, 2025
59238d0
fix: Merge
eliassjogreen Jan 30, 2025
7adb69c
chore: Correct metrics.json
eliassjogreen Jan 30, 2025
2217348
fix: Remove `proposals` from default features
eliassjogreen Jan 30, 2025
b8053b5
Discard changes to tests/expectations.json
eliassjogreen Jan 30, 2025
2f3295d
Discard changes to tests/metrics.json
eliassjogreen Jan 30, 2025
6a9aa7e
Merge branch 'main' into feat/proposal-float16array
eliassjogreen Jan 30, 2025
74d959d
feat(ecmascript): %TypedArray%.prototype.at (#550)
yossydev Jan 30, 2025
27e3979
chore(ecmascript): Use ValidateTypedArray return value's Object data …
aapoalas Feb 1, 2025
582017b
feat(ecmascript): String fromCodePoints (#543)
yossydev Feb 1, 2025
ba5eb5f
feat(ecmascript): AsyncGenerator (#520)
aapoalas Feb 2, 2025
57e1e0f
chore: Update expectations
eliassjogreen Jan 30, 2025
2222e78
chore: Update expectations
eliassjogreen Feb 3, 2025
3caba43
Merge branch 'main' into feat/proposal-float16array
eliassjogreen Feb 3, 2025
cf1b873
fix: Merge
eliassjogreen Feb 3, 2025
aadb145
fix: Wrong featue flag in lib.rs
eliassjogreen Feb 3, 2025
78f1b67
fix: Workflow
eliassjogreen Feb 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ jobs:
- name: Check formatting
run: cargo fmt --check
- name: Clippy
run: cargo clippy --all-targets --all-features -- -D warnings
run: >
cargo clippy --all-targets
--features math,json,date,array-buffer,shared-array-buffer,weak-refs,atomics,regexp,set,annex-b,interleaved-gc,typescript
-- -D warnings
- name: Spell check
uses: crate-ci/typos@master
- name: Build
Expand Down
12 changes: 9 additions & 3 deletions nova_vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,21 @@ default = [
"weak-refs",
"atomics",
"regexp",
"annex-b",
"set"
"set",
"annex-b"
]
array-buffer = []
atomics = ["array-buffer", "shared-array-buffer"]
date = []
interleaved-gc = []
json = ["sonic-rs"]
json = ["dep:sonic-rs"]
math = []
regexp = []
shared-array-buffer = []
weak-refs = []
set = []
typescript = []

# Enables features defined by [Annex B](https://tc39.es/ecma262/#sec-additional-ecmascript-features-for-web-browsers)
annex-b = ["annex-b-string", "annex-b-global", "annex-b-date", "annex-b-regexp"]
# Adds the additional properties to the global object as defined by Annex B section [B.2.1](https://tc39.es/ecma262/#sec-additional-properties-of-the-global-object)
Expand All @@ -68,5 +69,10 @@ annex-b-date = ["date"]
# - [B.2.4](https://tc39.es/ecma262/#sec-additional-properties-of-the-regexp.prototype-object)
annex-b-regexp = ["regexp"]

# Enables all currently supported proposals
proposals = ["proposal-float16array"]
# Enables the [Float16Array proposal](https://tc39.es/proposal-float16array/)
proposal-float16array = ["array-buffer"]

[build-dependencies]
small_string = { path = "../small_string" }
4 changes: 4 additions & 0 deletions nova_vm/src/builtin_strings
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ exchange
exec
exp
expm1
f16round
false
fill
filter
Expand All @@ -133,6 +134,7 @@ fixed
flags
flat
flatMap
Float16Array
Float32Array
Float64Array
floor
Expand Down Expand Up @@ -177,6 +179,7 @@ getBigInt64
getBigUint64
getDate
getDay
getFloat16
getFloat32
getFloat64
getFullYear
Expand Down Expand Up @@ -335,6 +338,7 @@ Set Iterator
setBigInt64
setBigUint64
setDate
setFloat16
setFloat32
setFloat64
setFullYear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,7 @@ pub(crate) fn canonical_numeric_index_string<'gc>(
) -> Option<Number<'gc>> {
// 1. If argument is "-0", return -0𝔽.
if argument == BUILTIN_STRING_MEMORY.__0 {
return Some((-0.0).into());
return Some(Number::neg_zero());
}

// 2. Let n be ! ToNumber(argument).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,10 @@ impl ArrayIteratorPrototype {
);
};

let len: i64 = match array {
// i. If array has a [[TypedArrayName]] internal slot, then
#[cfg(feature = "array-buffer")]
Object::Int8Array(array)
| Object::Uint8Array(array)
| Object::Uint8ClampedArray(array)
| Object::Int16Array(array)
| Object::Uint16Array(array)
| Object::Int32Array(array)
| Object::Uint32Array(array)
| Object::BigInt64Array(array)
| Object::BigUint64Array(array)
| Object::Float32Array(array)
| Object::Float64Array(array) => {
let array = array.into();
#[cfg(feature = "array-buffer")]
macro_rules! handle_typed_array {
($array:expr) => {{
let array = $array;
// 1. Let taRecord be MakeTypedArrayWithBufferWitnessRecord(array, seq-cst).
let ta_record = make_typed_array_with_buffer_witness_record(
agent,
Expand Down Expand Up @@ -122,6 +111,10 @@ impl ArrayIteratorPrototype {
TypedArray::BigUint64Array(_) => {
is_typed_array_out_of_bounds::<u64>(agent, &ta_record, gc.nogc())
}
#[cfg(feature = "proposal-float16array")]
TypedArray::Float16Array(_) => {
is_typed_array_out_of_bounds::<f16>(agent, &ta_record, gc.nogc())
}
TypedArray::Float32Array(_) => {
is_typed_array_out_of_bounds::<f32>(agent, &ta_record, gc.nogc())
}
Expand Down Expand Up @@ -165,14 +158,36 @@ impl ArrayIteratorPrototype {
TypedArray::BigUint64Array(_) => {
typed_array_length::<u64>(agent, &ta_record, gc.nogc())
}
#[cfg(feature = "proposal-float16array")]
TypedArray::Float16Array(_) => {
typed_array_length::<f16>(agent, &ta_record, gc.nogc())
}
TypedArray::Float32Array(_) => {
typed_array_length::<f32>(agent, &ta_record, gc.nogc())
}
TypedArray::Float64Array(_) => {
typed_array_length::<f64>(agent, &ta_record, gc.nogc())
}
}) as i64
}
}};
}

let len: i64 = match array {
// i. If array has a [[TypedArrayName]] internal slot, then
#[cfg(feature = "array-buffer")]
Object::Int8Array(array)
| Object::Uint8Array(array)
| Object::Uint8ClampedArray(array)
| Object::Int16Array(array)
| Object::Uint16Array(array)
| Object::Int32Array(array)
| Object::Uint32Array(array)
| Object::BigInt64Array(array)
| Object::BigUint64Array(array)
| Object::Float32Array(array)
| Object::Float64Array(array) => handle_typed_array!(array.into()),
#[cfg(feature = "proposal-float16array")]
Object::Float16Array(array) => handle_typed_array!(array.into()),
// ii. Else,
// 1. Let len be ? LengthOfArrayLike(array).
Object::Array(array) => array.len(agent).into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ pub(crate) fn validate_typed_array<'a>(
TypedArray::Uint32Array(_) => is_typed_array_out_of_bounds::<u32>(agent, &ta_record, gc),
TypedArray::BigInt64Array(_) => is_typed_array_out_of_bounds::<i64>(agent, &ta_record, gc),
TypedArray::BigUint64Array(_) => is_typed_array_out_of_bounds::<u64>(agent, &ta_record, gc),
#[cfg(feature = "proposal-float16array")]
TypedArray::Float16Array(_) => is_typed_array_out_of_bounds::<f16>(agent, &ta_record, gc),
TypedArray::Float32Array(_) => is_typed_array_out_of_bounds::<f32>(agent, &ta_record, gc),
TypedArray::Float64Array(_) => is_typed_array_out_of_bounds::<f64>(agent, &ta_record, gc),
} {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,21 @@ impl Builtin for BigUint64ArrayConstructor {
impl BuiltinIntrinsicConstructor for BigUint64ArrayConstructor {
const INDEX: IntrinsicConstructorIndexes = IntrinsicConstructorIndexes::BigUint64Array;
}
#[cfg(feature = "proposal-float16array")]
struct Float16ArrayConstructor;
#[cfg(feature = "proposal-float16array")]
impl Builtin for Float16ArrayConstructor {
const NAME: String<'static> = BUILTIN_STRING_MEMORY.Float16Array;

const LENGTH: u8 = 3;

const BEHAVIOUR: Behaviour =
Behaviour::Constructor(TypedArrayConstructors::float16_array_constructor);
}
#[cfg(feature = "proposal-float16array")]
impl BuiltinIntrinsicConstructor for Float16ArrayConstructor {
const INDEX: IntrinsicConstructorIndexes = IntrinsicConstructorIndexes::Float16Array;
}
struct Float32ArrayConstructor;
impl Builtin for Float32ArrayConstructor {
const NAME: String<'static> = BUILTIN_STRING_MEMORY.Float32Array;
Expand Down Expand Up @@ -257,6 +272,17 @@ impl TypedArrayConstructors {
typed_array_constructor::<u64>(agent, arguments, new_target, gc)
}

#[cfg(feature = "proposal-float16array")]
fn float16_array_constructor(
agent: &mut Agent,
_this_value: Value,
arguments: ArgumentsList,
new_target: Option<Object>,
gc: GcScope,
) -> JsResult<Value> {
typed_array_constructor::<f16>(agent, arguments, new_target, gc)
}

fn float32_array_constructor(
agent: &mut Agent,
_this_value: Value,
Expand Down Expand Up @@ -290,6 +316,8 @@ impl TypedArrayConstructors {
let uint32_array_prototype = intrinsics.uint32_array_prototype();
let big_int64_array_prototype = intrinsics.big_int64_array_prototype();
let big_uint64_array_prototype = intrinsics.big_uint64_array_prototype();
#[cfg(feature = "proposal-float16array")]
let float16_array_prototype = intrinsics.float16_array_prototype();
let float32_array_prototype = intrinsics.float32_array_prototype();
let float64_array_prototype = intrinsics.float64_array_prototype();

Expand Down Expand Up @@ -423,6 +451,21 @@ impl TypedArrayConstructors {
.with_prototype_property(big_uint64_array_prototype.into_object())
.build();

#[cfg(feature = "proposal-float16array")]
BuiltinFunctionBuilder::new_intrinsic_constructor::<Float16ArrayConstructor>(agent, realm)
.with_property_capacity(2)
.with_prototype(typed_array_constructor)
.with_property(|builder| {
builder
.with_key(BUILTIN_STRING_MEMORY.BYTES_PER_ELEMENT.into())
.with_value_readonly(4.into())
.with_enumerable(false)
.with_configurable(false)
.build()
})
.with_prototype_property(float16_array_prototype.into_object())
.build();

BuiltinFunctionBuilder::new_intrinsic_constructor::<Float32ArrayConstructor>(agent, realm)
.with_property_capacity(2)
.with_prototype(typed_array_constructor)
Expand Down Expand Up @@ -477,6 +520,10 @@ impl TypedArrayPrototypes {
let big_int64_array_prototype = intrinsics.big_int64_array_prototype();
let big_uint64_array_constructor = intrinsics.big_uint64_array();
let big_uint64_array_prototype = intrinsics.big_uint64_array_prototype();
#[cfg(feature = "proposal-float16array")]
let float16_array_constructor = intrinsics.float16_array();
#[cfg(feature = "proposal-float16array")]
let float16_array_prototype = intrinsics.float16_array_prototype();
let float32_array_constructor = intrinsics.float32_array();
let float32_array_prototype = intrinsics.float32_array_prototype();
let float64_array_constructor = intrinsics.float64_array();
Expand Down Expand Up @@ -608,6 +655,21 @@ impl TypedArrayPrototypes {
.with_constructor_property(big_uint64_array_constructor)
.build();

#[cfg(feature = "proposal-float16array")]
OrdinaryObjectBuilder::new_intrinsic_object(agent, realm, float16_array_prototype)
.with_property_capacity(2)
.with_prototype(typed_array_prototype)
.with_property(|builder| {
builder
.with_key(BUILTIN_STRING_MEMORY.BYTES_PER_ELEMENT.into())
.with_value_readonly(4.into())
.with_enumerable(false)
.with_configurable(false)
.build()
})
.with_constructor_property(float16_array_constructor)
.build();

OrdinaryObjectBuilder::new_intrinsic_object(agent, realm, float32_array_prototype)
.with_property_capacity(2)
.with_prototype(typed_array_prototype)
Expand Down Expand Up @@ -739,6 +801,13 @@ fn typed_array_constructor<T: Viewable>(
first_argument,
gc.nogc(),
)?,
#[cfg(feature = "proposal-float16array")]
TypedArray::Float16Array(_) => initialize_typed_array_from_typed_array::<T, f16>(
agent,
o,
first_argument,
gc.nogc(),
)?,
TypedArray::Float32Array(_) => initialize_typed_array_from_typed_array::<T, f32>(
agent,
o,
Expand Down
Loading