mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
test-js: Add a test helper to override the current time zone
This commit is contained in:
parent
ee7ab5d053
commit
99233776e6
Notes:
sideshowbarker
2024-07-17 08:25:15 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/99233776e6 Pull-request: https://github.com/SerenityOS/serenity/pull/21833
1 changed files with 23 additions and 0 deletions
|
@ -5,8 +5,11 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibCore/System.h>
|
||||
#include <LibJS/Runtime/ArrayBuffer.h>
|
||||
#include <LibTest/JavaScriptTestRunner.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
TEST_ROOT("Userland/Libraries/LibJS/Tests");
|
||||
|
||||
|
@ -88,6 +91,26 @@ TESTJS_GLOBAL_FUNCTION(detach_array_buffer, detachArrayBuffer)
|
|||
return JS::js_null();
|
||||
}
|
||||
|
||||
TESTJS_GLOBAL_FUNCTION(set_time_zone, setTimeZone)
|
||||
{
|
||||
auto current_time_zone = JS::js_null();
|
||||
|
||||
if (auto const* time_zone = getenv("TZ"))
|
||||
current_time_zone = JS::PrimitiveString::create(vm, StringView { time_zone, strlen(time_zone) });
|
||||
|
||||
if (auto time_zone = vm.argument(0); time_zone.is_null()) {
|
||||
if (auto result = Core::System::unsetenv("TZ"sv); result.is_error())
|
||||
return vm.throw_completion<JS::InternalError>(MUST(String::formatted("Could not unset time zone: {}", result.error())));
|
||||
} else {
|
||||
if (auto result = Core::System::setenv("TZ"sv, TRY(time_zone.to_string(vm)), true); result.is_error())
|
||||
return vm.throw_completion<JS::InternalError>(MUST(String::formatted("Could not set time zone: {}", result.error())));
|
||||
}
|
||||
|
||||
tzset();
|
||||
|
||||
return current_time_zone;
|
||||
}
|
||||
|
||||
TESTJS_RUN_FILE_FUNCTION(DeprecatedString const& test_file, JS::Realm& realm, JS::ExecutionContext&)
|
||||
{
|
||||
if (!test262_parser_tests)
|
||||
|
|
Loading…
Reference in a new issue