From 1d625e01f3afc348bf016395700211b7f8d8175e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Wed, 24 Jan 2024 09:57:02 +0000 Subject: [PATCH] Bug 1874373 - Part 2: Call String.p.codePointAt in StringIteratorNext. r=jandem Directly call `String.p.codePointAt` instead of manually computing the code point in `StringIteratorNext`. Depends on D198360 Differential Revision: https://phabricator.services.mozilla.com/D199350 --- js/src/builtin/String.cpp | 2 +- js/src/builtin/String.h | 2 ++ js/src/builtin/String.js | 14 +++----------- js/src/vm/SelfHosting.cpp | 2 ++ 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/js/src/builtin/String.cpp b/js/src/builtin/String.cpp index 957c3f8d409cf..d815e6462f394 100644 --- a/js/src/builtin/String.cpp +++ b/js/src/builtin/String.cpp @@ -1893,7 +1893,7 @@ bool js::str_charCodeAt(JSContext* cx, unsigned argc, Value* vp) { * * ES2024 draft rev 7d2644968bd56d54d2886c012d18698ff3f72c35 */ -static bool str_codePointAt(JSContext* cx, unsigned argc, Value* vp) { +bool js::str_codePointAt(JSContext* cx, unsigned argc, Value* vp) { AutoJSMethodProfilerEntry pseudoFrame(cx, "String.prototype", "codePointAt"); CallArgs args = CallArgsFromVp(argc, vp); diff --git a/js/src/builtin/String.h b/js/src/builtin/String.h index 0262af36e0a37..556bc92488e30 100644 --- a/js/src/builtin/String.h +++ b/js/src/builtin/String.h @@ -36,6 +36,8 @@ extern bool str_toString(JSContext* cx, unsigned argc, Value* vp); extern bool str_charCodeAt(JSContext* cx, unsigned argc, Value* vp); +extern bool str_codePointAt(JSContext* cx, unsigned argc, Value* vp); + extern bool str_endsWith(JSContext* cx, unsigned argc, Value* vp); #if JS_HAS_INTL_API diff --git a/js/src/builtin/String.js b/js/src/builtin/String.js index 822b7f0741354..864c6ad588ec2 100644 --- a/js/src/builtin/String.js +++ b/js/src/builtin/String.js @@ -819,20 +819,12 @@ function StringIteratorNext() { return result; } - var charCount = 1; - var first = callFunction(std_String_charCodeAt, S, index); - if (first >= 0xd800 && first <= 0xdbff && index + 1 < size) { - var second = callFunction(std_String_charCodeAt, S, index + 1); - if (second >= 0xdc00 && second <= 0xdfff) { - first = (first - 0xd800) * 0x400 + (second - 0xdc00) + 0x10000; - charCount = 2; - } - } + var codePoint = callFunction(std_String_codePointAt, S, index); + var charCount = 1 + (codePoint > 0xffff); UnsafeSetReservedSlot(obj, ITERATOR_SLOT_NEXT_INDEX, index + charCount); - // Communicate |first|'s possible range to the compiler. - result.value = callFunction(std_String_fromCodePoint, null, first & 0x1fffff); + result.value = callFunction(std_String_fromCodePoint, null, codePoint); return result; } diff --git a/js/src/vm/SelfHosting.cpp b/js/src/vm/SelfHosting.cpp index ccba11f65bef7..4fcb6f5ae2708 100644 --- a/js/src/vm/SelfHosting.cpp +++ b/js/src/vm/SelfHosting.cpp @@ -2299,6 +2299,8 @@ static const JSFunctionSpec intrinsic_functions[] = { JS_FN("std_Set_values", SetObject::values, 0, 0), JS_INLINABLE_FN("std_String_charCodeAt", str_charCodeAt, 1, 0, StringCharCodeAt), + JS_INLINABLE_FN("std_String_codePointAt", str_codePointAt, 1, 0, + StringCodePointAt), JS_INLINABLE_FN("std_String_endsWith", str_endsWith, 1, 0, StringEndsWith), JS_INLINABLE_FN("std_String_fromCharCode", str_fromCharCode, 1, 0, StringFromCharCode),