From b97fabb1758e6feb8f39fb7eb651f839dbd045c1 Mon Sep 17 00:00:00 2001
From: Dan Ehrenberg
Date: Thu, 24 Mar 2016 20:29:07 -0700
Subject: [PATCH 1/2] ECMA-402 v1 legacy constructor semantics compromise for
NumberFormat
This patch addresses #57 by allowing certain legacy constructor
patterns to coexist with the new guarantees in ECMA-402 v2, which
allows for a pattern where all internal slots exist from the
beginning of the object's lifetime. The compromise is based on
storing a "real" object inside of a symbol-named property to allow
for object initialization in cases of the
Intl..call(Object.create(Intl.) pattern.
Legacy methods have to forward their calls to this "real" object.
This patch specifies the change for Intl.NumberFormat, and a follow-on
patch makes the same change for Intl.DateTimeFormat.
This patch, together with changes for Intl.DateTimeFormat,
has been demonstrated to fix old versions of Intl.js on a deployed
website.
A sample implementation in V8 can be found at
https://codereview.chromium.org/1828543007
---
spec/conventions.html | 4 ++++
spec/index.html | 14 ++++++++++++++
spec/intl.html | 4 ++++
spec/numberformat.html | 37 ++++++++++++++++++++++++++++++++++---
4 files changed, 56 insertions(+), 3 deletions(-)
diff --git a/spec/conventions.html b/spec/conventions.html
index 787dd319..6420561b 100644
--- a/spec/conventions.html
+++ b/spec/conventions.html
@@ -24,6 +24,10 @@ Notational Conventions
For ECMAScript objects, this standard may use variable-named internal slots: The notation "[[<_name_>]]" denotes an internal slot whose name is given by the variable name, which must have a String value. For example, if a variable _s_ has the value *"a"*, then [[<_s_>]] denotes the [[<_a_>]] internal slot.
+
Well-Known Intrinsic Objects
diff --git a/spec/index.html b/spec/index.html
index 9dd67989..09219f00 100644
--- a/spec/index.html
+++ b/spec/index.html
@@ -25,6 +25,20 @@
margin-bottom: 10px;
padding-left: 10px;
}
+
+emu-normative-optional {
+ margin: 1em 0;
+ border-left: 5px solid #ff6600;
+ display: block;
+ background: #ffeedd;
+}
+
+span.normative-optional {
+ padding-left: 5px;
+ text-transform: uppercase;
+ color: #884400;
+}
+
diff --git a/spec/intl.html b/spec/intl.html
index 82648599..6ddcf0f9 100644
--- a/spec/intl.html
+++ b/spec/intl.html
@@ -12,6 +12,10 @@ The Intl Object
The Intl object is not a function object. It does not have a [[Construct]] internal method; it is not possible to use the Intl object as a constructor with the *new* operator. The Intl object does not have a [[Call]] internal method; it is not possible to invoke the Intl object as a function.
+
+ The Intl object has an internal slot, [[FallbackSymbol]], which is a new %Symbol% in the current realm.
+
+
Constructor Properties of the Intl Object
diff --git a/spec/numberformat.html b/spec/numberformat.html
index 46c24ec2..7238ee7c 100644
--- a/spec/numberformat.html
+++ b/spec/numberformat.html
@@ -448,6 +448,26 @@ ToRawFixed( _x_, _minInteger_, _minFraction_, _maxFraction_ )
1. Return _m_.
+
+
+ UnwrapNumberFormat(nf)
+
+ The UnwrapNumberFormat abstract operation gets the underlying NumberFormat operation
+ for various methods which implement ECMA-402 v1 semantics for supporting initializing
+ existing Intl objects.
+
+ Normative Optional
+
+ 1. If _nf_ does not have an [[initializedNumberFormat]] internal slot and ? InstanceofOperator(_nf_, %NumberFormat%),
+ 1. Let _nf_ be ? RequireObjectCoercible(Get(_nf_, Intl.[[FallbackSymbol]])).
+
+
+
+ 2. If _nf_ does not have an [[initializedNumberFormat]] internal slot,
+ 1. Throw a *TypeError* exception.
+ 1. Return _nf_.
+
+
1. Let _nf_ be *this* value.
1. If Type(_nf_) is not Object, throw a *TypeError* exception.
- 1. If _nf_.[[initializedNumberFormat]] is *true*, throw a *TypeError* exception.
+ 1. Let _nf_ be ? UnwrapNumberFormat(_nf_);
1. If _nf_.[[boundFormat]] is *undefined*, then
1. Let _F_ be a new built-in function object as defined in Number Format Functions ().
1. Let _bf_ be BoundFunctionCreate(_F_, _nf_, « »).
@@ -591,7 +622,7 @@ get Intl.NumberFormat.prototype.format
Intl.NumberFormat.prototype.resolvedOptions ()
- This function provides access to the locale and formatting options computed during initialization of the object.
+ This function provides access to the locale and formatting options computed during initialization of the object. This function initially invokes the internal algorithm UnwrapNumberFormat to get the %NumberFormat% object on which to operate.
The function returns a new object whose properties and attributes are set as if constructed by an object literal assigning to each of the following properties the value of the corresponding internal slot of this NumberFormat object (see ): locale, numberingSystem, style, currency, currencyDisplay, minimumIntegerDigits, minimumFractionDigits, maximumFractionDigits, minimumSignificantDigits, maximumSignificantDigits, and useGrouping. Properties whose corresponding internal slots have the value *undefined* are not assigned.
From 8775fdc117f93cb6ba14f9608183d552eebf4d83 Mon Sep 17 00:00:00 2001
From: Dan Ehrenberg
Date: Mon, 28 Mar 2016 13:35:34 -0700
Subject: [PATCH 2/2] ECMA-402 v1 constructor compatibility semantics for
DateTimeFormat
---
spec/datetimeformat.html | 38 +++++++++++++++++++++++++++++++++++---
1 file changed, 35 insertions(+), 3 deletions(-)
diff --git a/spec/datetimeformat.html b/spec/datetimeformat.html
index 62c6911a..2090fd7e 100644
--- a/spec/datetimeformat.html
+++ b/spec/datetimeformat.html
@@ -360,6 +360,27 @@ ToLocalTime ( _date_, _calendar_, _timeZone_ )
It is recommended that implementations use the time zone information of the IANA Time Zone Database.
+
+
+ UnwrapDateTimeFormat( dtf )
+
+ The UnwrapDateTimeFormat abstract operation gets the underlying DateTimeFormat operation
+ for various methods which implement ECMA-402 v1 semantics for supporting initializing
+ existing Intl objects.
+
+ Normative Optional
+
+ 1. If _dtf_ does not have an [[initializedDateTimeFormat]] internal slot and ? InstanceofOperator(_dtf_, %DateTimeFormat%),
+ 1. Let _dtf_ be ? RequireObjectCoercible(Get(_dtf_, Intl.[[FallbackSymbol]])).
+
+
+
+ 2. If _dtf_ does not have an [[initializedDateTimeFormat]] internal slot,
+ 1. Throw a *TypeError* exception.
+ 1. Return _dtf_.
+
+
+
@@ -379,7 +400,18 @@ Intl.DateTimeFormat ( [ _locales_ [ , _options_ ] ] )
1. If NewTarget is *undefined*, let _newTarget_ be the active function object, else let _newTarget_ be NewTarget.
1. Let _dateTimeFormat_ be ? OrdinaryCreateFromConstructor(_newTarget_, `"%DateTimeFormatPrototype%"`, « [[initializedIntlObject]], [[initializedDateTimeFormat]], [[locale]], [[calendar]], [[numberingSystem]], [[timeZone]], [[weekday]], [[era]], [[year]], [[month]], [[day]], [[hour]], [[minute]], [[second]], [[timeZoneName]], [[hour12]], [[hourNo0]], [[pattern]], [[boundFormat]] »).
- 1. Return ? InitializeDateTimeFormat(_dateTimeFormat_, _locales_, _options_).
+ 1. Perform ? InitializeDateTimeFormat(_dateTimeFormat_, _locales_, _options_).
+
+ Normative Optional
+
+ 4. Let _this_ be the *this* value.
+ 1. If NewTarget is *undefined* and ? InstanceofOperator(_this_, %NumberFormat%),
+ 1. Perform ? DefineOwnPropertyOrThrow(_this_, Intl.[[FallbackSymbol]], { [[Value]]: _dateTimeFormat_, [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *false* }).
+ 1. Return _this_.
+
+
+
+ 1. Return _dateTimeFormat_.
@@ -512,7 +544,7 @@ get Intl.DateTimeFormat.prototype.format
1. Let _dtf_ be *this* value.
1. If Type(_dtf_) is not Object, throw a *TypeError* exception.
- 1. If _dtf_ does not have an [[initializedDateTimeFormat]] internal slot, throw a *TypeError* exception.
+ 1. Let _dtf_ be ? UnwrapDateTimeFormat(_dtf_).
1. If _dtf_.[[boundFormat]] is *undefined*, then
1. Let _F_ be a new built-in function object as defined in DateTime Format Functions ().
1. Let _bf_ be BoundFunctionCreate(_F_, _dft_, « »).
@@ -545,7 +577,7 @@ Intl.DateTimeFormat.prototype.formatToParts ( [ _date_ ] )
Intl.DateTimeFormat.prototype.resolvedOptions ()
- This function provides access to the locale and formatting options computed during initialization of the object.
+ This function provides access to the locale and formatting options computed during initialization of the object. This function initially invokes the internal algorithm UnwrapDateTimeFormat to get the %DateTimeFormat% object on which to operate.