From 211c2d1ed52664c47acb6100110e50a39a66d392 Mon Sep 17 00:00:00 2001 From: Neil Dhar Date: Fri, 15 Jul 2022 22:25:39 -0700 Subject: [PATCH] Fix TypedArray.prototype.toLocaleString when Intl is available Summary: Similar to Array, TypedArray should use the Intl NumberFormatter when it is available. Reviewed By: jpporto Differential Revision: D37894492 fbshipit-source-id: 4ce02e5cb3b72d20e70243ddc0353d5a273018ac --- android/intltest/build.gradle | 1 + .../java/com/facebook/hermes/test/HermesIntlTest262.java | 1 + lib/VM/JSLib/TypedArray.cpp | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/android/intltest/build.gradle b/android/intltest/build.gradle index 45bc9fa14..8d9da90b5 100644 --- a/android/intltest/build.gradle +++ b/android/intltest/build.gradle @@ -34,6 +34,7 @@ task prepareTests() { include("test/intl402/String/**/*.js") include("test/intl402/Number/**/*.js") include("test/intl402/Array/**/*.js") + include("test/intl402/TypedArray/**/*.js") include("test/intl402/Date/**/*.js") include("test/intl402/Intl/**/*.js") include("test/built-ins/String/prototype/toLocale**/*.js") diff --git a/android/intltest/java/com/facebook/hermes/test/HermesIntlTest262.java b/android/intltest/java/com/facebook/hermes/test/HermesIntlTest262.java index 640637864..a83c34f16 100644 --- a/android/intltest/java/com/facebook/hermes/test/HermesIntlTest262.java +++ b/android/intltest/java/com/facebook/hermes/test/HermesIntlTest262.java @@ -53,6 +53,7 @@ public class HermesIntlTest262 extends InstrumentationTestCase { evalScriptFromAsset(rt, "test262/harness/compareArray.js"); evalScriptFromAsset(rt, "test262/harness/dateConstants.js"); evalScriptFromAsset(rt, "test262/harness/isConstructor.js"); + evalScriptFromAsset(rt, "test262/harness/testTypedArray.js"); } public void test262Intl() throws IOException { diff --git a/lib/VM/JSLib/TypedArray.cpp b/lib/VM/JSLib/TypedArray.cpp index 08755729a..8c60f7929 100644 --- a/lib/VM/JSLib/TypedArray.cpp +++ b/lib/VM/JSLib/TypedArray.cpp @@ -1632,7 +1632,12 @@ typedArrayPrototypeToLocaleString(void *, Runtime &runtime, NativeArgs args) { } if (auto func = Handle::dyn_vmcast( runtime.makeHandle(std::move(*propRes)))) { +#ifdef HERMES_ENABLE_INTL + auto callRes = Callable::executeCall2( + func, runtime, elementObj, args.getArg(0), args.getArg(1)); +#else auto callRes = Callable::executeCall0(func, runtime, elementObj); +#endif if (LLVM_UNLIKELY(callRes == ExecutionStatus::EXCEPTION)) { return ExecutionStatus::EXCEPTION; }