Skip to content

Commit

Permalink
chore: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
yossydev committed Jan 31, 2025
1 parent 883114d commit 147cb9b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use crate::ecmascript::abstract_operations::testing_and_comparison::is_integral_number;
use crate::ecmascript::abstract_operations::type_conversion::to_number;
use crate::ecmascript::abstract_operations::type_conversion::to_string;
use crate::ecmascript::builders::builtin_function_builder::BuiltinFunctionBuilder;
use crate::ecmascript::builtins::ordinary::get_prototype_from_constructor;
Expand Down Expand Up @@ -170,9 +172,8 @@ impl StringConstructor {
agent: &mut Agent,
_this_value: Value,
code_points: ArgumentsList,
gc: GcScope,
mut gc: GcScope,
) -> JsResult<Value> {
let gc = gc.nogc();
// 3. Assert: If codePoints is empty, then result is the empty String.
if code_points.is_empty() {
return Ok(String::EMPTY_STRING.into_value());
Expand All @@ -190,7 +191,7 @@ impl StringConstructor {
return Err(agent.throw_exception(
ExceptionType::RangeError,
format!("{:?} is not a valid code point", next_cp),
gc,
gc.nogc(),
));
}
// d. Set result to the string-concatenation of result and UTF16EncodeCodePoint(ℝ(nextCP)).
Expand All @@ -204,24 +205,29 @@ impl StringConstructor {
// 2. For each element next of codePoints, do
for next in code_points.iter() {
// a. Let nextCP be ? ToNumber(next).
let next_cp = to_number(agent, next.into_value(), gc.reborrow())?.unbind();
// b. If IsIntegralNumber(nextCP) is false, throw a RangeError exception.
if !is_integral_number(agent, next_cp, gc.reborrow()) {
return Err(agent.throw_exception(
ExceptionType::RangeError,
format!("{:?} is not a valid code point", next_cp.to_real(agent)),
gc.nogc(),
));
}
// c. If ℝ(nextCP) < 0 or ℝ(nextCP) > 0x10FFFF, throw a RangeError exception.
let Value::Integer(next_cp) = next else {
unreachable!();
};
let next_cp = next_cp.into_i64();
let next_cp = next_cp.into_i64(agent);
if !(0..=0x10FFFF).contains(&next_cp) {
return Err(agent.throw_exception(
ExceptionType::RangeError,
format!("{:?} is not a valid code point", next_cp),
gc,
gc.nogc(),
));
}
// d. Set result to the string-concatenation of result and UTF16EncodeCodePoint(ℝ(nextCP)).
result.push(char::from_u32(next_cp as u32).unwrap());
}
// 4. Return result.
Ok(String::from_string(agent, result, gc).into())
Ok(String::from_string(agent, result, gc.nogc()).into())
}

fn raw(
Expand Down
14 changes: 9 additions & 5 deletions tests/expectations.json
Original file line number Diff line number Diff line change
Expand Up @@ -5195,11 +5195,6 @@
"built-ins/SharedArrayBuffer/zero-length.js": "CRASH",
"built-ins/String/S15.5.5.1_A4_T1.js": "CRASH",
"built-ins/String/S9.8_A5_T1.js": "FAIL",
"built-ins/String/fromCodePoint/argument-is-Symbol.js": "CRASH",
"built-ins/String/fromCodePoint/argument-is-not-integer.js": "CRASH",
"built-ins/String/fromCodePoint/argument-not-coercible.js": "CRASH",
"built-ins/String/fromCodePoint/number-is-out-of-range.js": "CRASH",
"built-ins/String/fromCodePoint/to-number-conversions.js": "CRASH",
"built-ins/String/proto-from-ctor-realm.js": "FAIL",
"built-ins/String/prototype/Symbol.iterator/this-val-non-obj-coercible.js": "CRASH",
"built-ins/String/prototype/Symbol.iterator/this-val-to-str-err.js": "CRASH",
Expand Down Expand Up @@ -11361,7 +11356,12 @@
"built-ins/isFinite/tonumber-operations.js": "FAIL",
"built-ins/isNaN/tonumber-operations.js": "FAIL",
"built-ins/parseFloat/S15.1.2.3_A6.js": "TIMEOUT",
"harness/assert-notsamevalue-tostring.js": "CRASH",
"harness/assert-obj.js": "CRASH",
"harness/assert-samevalue-objects.js": "CRASH",
"harness/assert-samevalue-tostring.js": "CRASH",
"harness/assert-throws-same-realm.js": "FAIL",
"harness/assert-tostring.js": "CRASH",
"harness/assertRelativeDateMs.js": "CRASH",
"harness/asyncHelpers-throwsAsync-custom-typeerror.js": "CRASH",
"harness/asyncHelpers-throwsAsync-func-throws-sync.js": "CRASH",
Expand All @@ -11375,11 +11375,15 @@
"harness/asyncHelpers-throwsAsync-same-realm.js": "CRASH",
"harness/asyncHelpers-throwsAsync-single-arg.js": "CRASH",
"harness/deepEqual-array.js": "CRASH",
"harness/deepEqual-deep.js": "CRASH",
"harness/deepEqual-mapset.js": "CRASH",
"harness/deepEqual-object.js": "CRASH",
"harness/deepEqual-primitives-bigint.js": "CRASH",
"harness/deepEqual-primitives.js": "FAIL",
"harness/nativeFunctionMatcher.js": "CRASH",
"harness/testTypedArray-conversions.js": "CRASH",
"harness/verifyProperty-desc-is-not-object.js": "CRASH",
"harness/verifyProperty-undefined-desc.js": "CRASH",
"language/arguments-object/10.6-10-c-ii-1.js": "FAIL",
"language/arguments-object/10.6-10-c-ii-2.js": "FAIL",
"language/arguments-object/10.6-12-1.js": "FAIL",
Expand Down
8 changes: 4 additions & 4 deletions tests/metrics.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"results": {
"crash": 14950,
"fail": 7662,
"pass": 24122,
"crash": 14931,
"fail": 7665,
"pass": 24138,
"skip": 55,
"timeout": 12,
"unresolved": 0
},
"total": 45299
"total": 46801
}

0 comments on commit 147cb9b

Please sign in to comment.