-
Notifications
You must be signed in to change notification settings - Fork 5k
Format Temporal values in console.log, util.inspect, and test pretty-format #37043
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
Open
robobun
wants to merge
16
commits into
main
Choose a base branch
from
farm/8f01c0db/temporal-inspect
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+485
−14
Open
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3f48ea6
Format Temporal values in console.log, util.inspect, and test pretty-…
robobun 53c171c
[autofix.ci] apply automated fixes
autofix-ci[bot] d20fcc7
Tighten comments
robobun d3613cf
Fix clippy lints in print_temporal, strip ANSI in failure-message test
robobun 717a951
Cover sub-minute offset rounding and non-ISO YearMonth/MonthDay in tests
robobun 2828881
Temporal inspect: single C++ owner for classify+label+text, safe Rust…
dylan-conway 82e56ae
Merge remote-tracking branch 'origin/main' into farm/8f01c0db/tempora…
dylan-conway 26d5c51
Collapse Temporal helper comments to one line
dylan-conway 90724b6
Temporal: Bun::temporalObjectType(JSValue) with the extern as a thin …
dylan-conway 596e9ae
Temporal: typed TemporalType enum shared between C++ and Rust
dylan-conway 4351a73
Give bundler macros a deliberate Temporal arm
robobun 867820a
Temporal inspect: use JSC::temporalType and TemporalZonedDateTime::to…
dylan-conway 37519f4
Merge remote-tracking branch 'origin/main' into farm/8f01c0db/tempora…
dylan-conway 938dc69
macro Temporal arm: one-line comment; drain stdout in the test
dylan-conway edf96b1
macro Temporal test: don't assert empty stdout (debug builds print [m…
dylan-conway 6f38c05
Merge remote-tracking branch 'origin/main' into farm/8f01c0db/tempora…
dylan-conway File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| // Temporal value formatting shared by console.log/Bun.inspect, the test | ||
| // runner's pretty-format, and util.inspect: each type's default-options spec | ||
| // toString() text, built from internal slots, never from user-reachable code. | ||
|
robobun marked this conversation as resolved.
|
||
|
|
||
| #include "root.h" | ||
| #include "Temporal.h" | ||
| #include "headers-handwritten.h" | ||
|
|
||
| #include "JavaScriptCore/JSCJSValueInlines.h" | ||
| #include "JavaScriptCore/TemporalDuration.h" | ||
| #include "JavaScriptCore/TemporalInstant.h" | ||
| #include "JavaScriptCore/TemporalObject.h" | ||
| #include "JavaScriptCore/TemporalPlainDate.h" | ||
| #include "JavaScriptCore/TemporalPlainDateTime.h" | ||
| #include "JavaScriptCore/TemporalPlainMonthDay.h" | ||
| #include "JavaScriptCore/TemporalPlainTime.h" | ||
| #include "JavaScriptCore/TemporalPlainYearMonth.h" | ||
| #include "JavaScriptCore/TemporalZonedDateTime.h" | ||
|
|
||
| namespace Bun { | ||
|
|
||
| using JSC::TemporalType; | ||
|
|
||
| static ASCIILiteral temporalLabel(TemporalType type) | ||
| { | ||
| switch (type) { | ||
| case TemporalType::Instant: | ||
| return "Temporal.Instant"_s; | ||
| case TemporalType::PlainDateTime: | ||
| return "Temporal.PlainDateTime"_s; | ||
| case TemporalType::PlainDate: | ||
| return "Temporal.PlainDate"_s; | ||
| case TemporalType::PlainTime: | ||
| return "Temporal.PlainTime"_s; | ||
| case TemporalType::ZonedDateTime: | ||
| return "Temporal.ZonedDateTime"_s; | ||
| case TemporalType::PlainYearMonth: | ||
| return "Temporal.PlainYearMonth"_s; | ||
| case TemporalType::PlainMonthDay: | ||
| return "Temporal.PlainMonthDay"_s; | ||
| case TemporalType::Duration: | ||
| return "Temporal.Duration"_s; | ||
| case TemporalType::None: | ||
| RELEASE_ASSERT_NOT_REACHED(); | ||
| } | ||
| } | ||
|
|
||
| static WTF::String temporalDisplayString(JSC::JSGlobalObject* globalObject, JSC::JSCell* cell, TemporalType type) | ||
| { | ||
| switch (type) { | ||
| case TemporalType::Instant: | ||
| return uncheckedDowncast<JSC::TemporalInstant>(cell)->toString(); | ||
| case TemporalType::PlainDateTime: | ||
| return uncheckedDowncast<JSC::TemporalPlainDateTime>(cell)->toString(); | ||
| case TemporalType::PlainDate: | ||
| return uncheckedDowncast<JSC::TemporalPlainDate>(cell)->toString(); | ||
| case TemporalType::PlainTime: | ||
| return uncheckedDowncast<JSC::TemporalPlainTime>(cell)->toString(); | ||
| case TemporalType::ZonedDateTime: | ||
| return uncheckedDowncast<JSC::TemporalZonedDateTime>(cell)->toString(globalObject); | ||
| case TemporalType::PlainYearMonth: | ||
| return uncheckedDowncast<JSC::TemporalPlainYearMonth>(cell)->toString(); | ||
| case TemporalType::PlainMonthDay: | ||
| return uncheckedDowncast<JSC::TemporalPlainMonthDay>(cell)->toString(); | ||
| case TemporalType::Duration: | ||
| return uncheckedDowncast<JSC::TemporalDuration>(cell)->toString(globalObject); | ||
| case TemporalType::None: | ||
| RELEASE_ASSERT_NOT_REACHED(); | ||
| } | ||
| } | ||
|
|
||
| } // namespace Bun | ||
|
|
||
| extern "C" [[ZIG_EXPORT(nothrow)]] JSC::TemporalType Bun__JSValue__temporalType(JSC::EncodedJSValue encodedValue) | ||
| { | ||
| return JSC::temporalType(JSC::JSValue::decode(encodedValue)); | ||
| } | ||
|
|
||
| // Precondition: value is Temporal. Writes e.g. ("Temporal.PlainDate", "2020-01-02"). | ||
| extern "C" [[ZIG_EXPORT(check_slow)]] void Bun__Temporal__toDisplayString(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue encodedValue, BunString* label, BunString* text) | ||
| { | ||
| auto& vm = JSC::getVM(globalObject); | ||
| auto scope = DECLARE_THROW_SCOPE(vm); | ||
| JSC::JSValue value = JSC::JSValue::decode(encodedValue); | ||
| JSC::TemporalType type = JSC::temporalType(value); | ||
| WTF::String string = Bun::temporalDisplayString(globalObject, value.asCell(), type); | ||
| RETURN_IF_EXCEPTION(scope, ); | ||
| *label = Bun::toStringView(Bun::temporalLabel(type)); | ||
| *text = Bun::toStringRef(string); | ||
| } | ||
|
|
||
| JSC_DEFINE_HOST_FUNCTION(jsFunctionTemporalLabel, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) | ||
| { | ||
| JSC::TemporalType type = JSC::temporalType(callFrame->argument(0)); | ||
| if (type == JSC::TemporalType::None) | ||
| return JSC::JSValue::encode(JSC::jsUndefined()); | ||
| return JSC::JSValue::encode(JSC::jsNontrivialString(JSC::getVM(globalObject), Bun::temporalLabel(type))); | ||
| } | ||
|
|
||
| JSC_DEFINE_HOST_FUNCTION(jsFunctionTemporalToDisplayString, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) | ||
| { | ||
| auto& vm = JSC::getVM(globalObject); | ||
| auto scope = DECLARE_THROW_SCOPE(vm); | ||
|
|
||
| JSC::JSValue value = callFrame->argument(0); | ||
| JSC::TemporalType type = JSC::temporalType(value); | ||
| if (type == JSC::TemporalType::None) | ||
| return JSC::JSValue::encode(JSC::jsUndefined()); | ||
|
|
||
| WTF::String result = Bun::temporalDisplayString(globalObject, value.asCell(), type); | ||
| RETURN_IF_EXCEPTION(scope, {}); | ||
| return JSC::JSValue::encode(JSC::jsString(vm, WTF::move(result))); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #pragma once | ||
|
|
||
| #include "root.h" | ||
|
|
||
| // (value) -> "Temporal.PlainDate" etc., or undefined if not Temporal. | ||
| JSC_DECLARE_HOST_FUNCTION(jsFunctionTemporalLabel); | ||
| // (value) -> the slot-derived default-options toString() text, or undefined if not Temporal. | ||
| JSC_DECLARE_HOST_FUNCTION(jsFunctionTemporalToDisplayString); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.