Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions core/engine/src/builtins/intl/date_time_format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,18 @@ impl BuiltInConstructor for DateTimeFormat {
let options = args.get_or_undefined(1);

// 2. Let dateTimeFormat be ? CreateDateTimeFormat(newTarget, locales, options, any, date).
let prototype = get_prototype_from_constructor(
new_target_inner,
StandardConstructors::date_time_format,
context,
)?;
let dtf = create_date_time_format(
locales,
options,
FormatType::Any,
FormatDefaults::Date,
context,
)?;
let prototype = get_prototype_from_constructor(
new_target_inner,
StandardConstructors::date_time_format,
context,
)?;
let date_time_format = JsObject::from_proto_and_data(prototype, dtf);

// 3. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then
Expand Down Expand Up @@ -534,6 +534,11 @@ pub(crate) fn create_date_time_format(
defaults: FormatDefaults,
context: &mut Context,
) -> JsResult<DateTimeFormat> {
// NOTE: The below step's code was moved out into constructor to prevent unnecessary JsObject allocation when we create dtf internally
// (e.g. toLocaleString methods of Date and Temporal objects)
// 1. Let dateTimeFormat be ? OrdinaryCreateFromConstructor(newTarget, "%Intl.DateTimeFormat.prototype%",
// « [[InitializedDateTimeFormat]], [[Locale]], [[Calendar]], [[NumberingSystem]], [[TimeZone]],
// [[HourCycle]], [[DateStyle]], [[TimeStyle]], [[DateTimeFormat]], [[BoundFormat]] »).
// 2. Let hour12 be undefined. <- TODO
// 3. Let modifyResolutionOptions be a new Abstract Closure with parameters (options) that captures hour12 and performs the following steps when called:
// a. Set hour12 to options.[[hour12]].
Expand Down
28 changes: 28 additions & 0 deletions core/engine/src/builtins/intl/date_time_format/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,31 @@ fn date_to_locale_string() {
TestAction::assert_eq("result === '6:07\u{202f}AM'", true),
]);
}

#[cfg(feature = "intl_bundled")]
#[test]
fn dtf_ctor_observable_behavior() {
run_test_actions([
TestAction::run(indoc! {"
const expected = [];

const proxyConstructor = new Proxy(Intl.DateTimeFormat, {
get(target, prop) {
if (prop === 'prototype') {
expected.push('prototype-access');
}
return target[prop];
}
});

try {
new proxyConstructor('en', { timeZone: 'Invalid/Zone' });
} catch (e) {
expected.push('error-thrown');
}
"}),
TestAction::assert_eq("expected.length === 2", true),
TestAction::assert_eq("expected[0] === 'prototype-access'", true),
TestAction::assert_eq("expected[1] === 'error-thrown'", true),
]);
}