[INTL] Implement Date.prototype.toLocaleString in ECMA-402
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Jan 2016 19:30:45 +0000 (19:30 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Jan 2016 19:30:45 +0000 (19:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=147611

Patch by Andy VanWagoner <thetalecrafter@gmail.com> on 2016-01-15
Reviewed by Benjamin Poulain.

Source/JavaScriptCore:

Expose dateProtoFuncGetTime as thisTimeValue for builtins.
Remove unused code in DateTimeFormat toDateTimeOptions, and make the
function specific to the call in initializeDateTimeFormat. Properly
throw when the options parameter is null.
Add toLocaleString in builtin JavaScript, with it's own specific branch
of toDateTimeOptions.

* CMakeLists.txt:
* DerivedSources.make:
* JavaScriptCore.xcodeproj/project.pbxproj:
* builtins/DatePrototype.js: Added.
(toLocaleString.toDateTimeOptionsAnyAll):
(toLocaleString):
* runtime/CommonIdentifiers.h:
* runtime/DatePrototype.cpp:
(JSC::DatePrototype::finishCreation):
* runtime/DatePrototype.h:
* runtime/IntlDateTimeFormat.cpp:
(JSC::toDateTimeOptionsAnyDate):
(JSC::IntlDateTimeFormat::initializeDateTimeFormat):
(JSC::toDateTimeOptions): Deleted.
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):

LayoutTests:

* js/intl-datetimeformat-expected.txt: Added test for null options.
* js/date-toLocaleString-expected.txt: Added.
* js/date-toLocaleString.html: Added.
* js/script-tests/intl-datetimeformat.js: Added test for null options.
* js/script-tests/date-toLocaleString.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@195138 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
LayoutTests/ChangeLog
LayoutTests/js/date-toLocaleString-expected.txt [new file with mode: 0644]
LayoutTests/js/date-toLocaleString.html [new file with mode: 0644]
LayoutTests/js/intl-datetimeformat-expected.txt
LayoutTests/js/script-tests/date-toLocaleString.js [new file with mode: 0644]
LayoutTests/js/script-tests/intl-datetimeformat.js
Source/JavaScriptCore/CMakeLists.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/DerivedSources.make
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/builtins/DatePrototype.js [new file with mode: 0644]
Source/JavaScriptCore/runtime/CommonIdentifiers.h
Source/JavaScriptCore/runtime/DatePrototype.cpp
Source/JavaScriptCore/runtime/DatePrototype.h
Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp
Source/JavaScriptCore/runtime/JSGlobalObject.cpp

index 9cc99bd..b30e774 100644 (file)
@@ -1,3 +1,16 @@
+2016-01-15  Andy VanWagoner  <thetalecrafter@gmail.com>
+
+        [INTL] Implement Date.prototype.toLocaleString in ECMA-402
+        https://bugs.webkit.org/show_bug.cgi?id=147611
+
+        Reviewed by Benjamin Poulain.
+
+        * js/intl-datetimeformat-expected.txt: Added test for null options.
+        * js/date-toLocaleString-expected.txt: Added.
+        * js/date-toLocaleString.html: Added.
+        * js/script-tests/intl-datetimeformat.js: Added test for null options.
+        * js/script-tests/date-toLocaleString.js: Added.
+
 2016-01-15  Antti Koivisto  <antti@apple.com>
 
         Switch out from ES6 arrow function syntax to allow the test to work with an older WebKit.
diff --git a/LayoutTests/js/date-toLocaleString-expected.txt b/LayoutTests/js/date-toLocaleString-expected.txt
new file mode 100644 (file)
index 0000000..02ccf80
--- /dev/null
@@ -0,0 +1,32 @@
+This test checks the behavior of Date.prototype.toLocaleString as described in the ECMAScript Internationalization API Specification (ECMA-402 2.0).
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Date.prototype.toLocaleString.length is 0
+PASS Object.getOwnPropertyDescriptor(Date.prototype, 'toLocaleString').enumerable is false
+PASS Object.getOwnPropertyDescriptor(Date.prototype, 'toLocaleString').configurable is true
+PASS Object.getOwnPropertyDescriptor(Date.prototype, 'toLocaleString').writable is true
+PASS Date.prototype.toLocaleString.call(new Date) did not throw exception.
+PASS Date.prototype.toLocaleString.call() threw exception TypeError: Type error.
+PASS Date.prototype.toLocaleString.call(undefined) threw exception TypeError: Type error.
+PASS Date.prototype.toLocaleString.call(null) threw exception TypeError: Type error.
+PASS Date.prototype.toLocaleString.call(0) threw exception TypeError: Type error.
+PASS Date.prototype.toLocaleString.call(NaN) threw exception TypeError: Type error.
+PASS Date.prototype.toLocaleString.call(Infinity) threw exception TypeError: Type error.
+PASS Date.prototype.toLocaleString.call('1') threw exception TypeError: Type error.
+PASS Date.prototype.toLocaleString.call({}) threw exception TypeError: Type error.
+PASS Date.prototype.toLocaleString.call([]) threw exception TypeError: Type error.
+PASS Date.prototype.toLocaleString.call(Symbol()) threw exception TypeError: Type error.
+PASS typeof new Date().toLocaleString() === 'string' is true
+PASS new Date(NaN).toLocaleString() is "Invalid Date"
+PASS new Date().toLocaleString('i') threw exception RangeError: invalid language tag: i.
+PASS new Date(0).toLocaleString('zh-Hans-CN-u-nu-hanidec', { timeZone: 'UTC' }) is "一九七〇/一/一 上午一二:〇〇:〇〇"
+PASS new Date(0).toLocaleString('en', { timeZone: 'UTC' }) is "1/1/1970, 12:00:00 AM"
+PASS new Date(0).toLocaleString('en', null) threw exception TypeError: null is not an object.
+PASS new Date(0).toLocaleString('en', { timeZone: 'UTC', hour:'numeric', minute:'2-digit' }) is "12:00 AM"
+PASS new Date(0).toLocaleString('en', { timeZone: 'UTC', year:'numeric', month:'long' }) is "January 1970"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/js/date-toLocaleString.html b/LayoutTests/js/date-toLocaleString.html
new file mode 100644 (file)
index 0000000..c14a03c
--- /dev/null
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<meta charset="utf-8">
+<script src="../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="script-tests/date-toLocaleString.js"></script>
+<script src="../resources/js-test-post.js"></script>
+</body>
+</html>
index 80fef1c..a584e84 100644 (file)
@@ -82,7 +82,7 @@ PASS Intl.DateTimeFormat.prototype.resolvedOptions().timeZoneName is new Intl.Da
 PASS Intl.DateTimeFormat.prototype.resolvedOptions() === Intl.DateTimeFormat.prototype.resolvedOptions() is false
 PASS Intl.DateTimeFormat.prototype.resolvedOptions.call(5) threw exception TypeError: Intl.DateTimeFormat.prototype.resolvedOptions called on value that's not an object initialized as a DateTimeFormat.
 PASS Intl.DateTimeFormat('$') threw exception RangeError: invalid language tag: $.
-PASS Intl.DateTimeFormat('en', null) did not throw exception.
+PASS Intl.DateTimeFormat('en', null) threw exception TypeError: null is not an object (evaluating 'Intl.DateTimeFormat('en', null)').
 PASS Intl.DateTimeFormat('en').resolvedOptions().weekday is undefined
 PASS Intl.DateTimeFormat('en').resolvedOptions().era is undefined
 PASS Intl.DateTimeFormat('en').resolvedOptions().month is 'numeric'
diff --git a/LayoutTests/js/script-tests/date-toLocaleString.js b/LayoutTests/js/script-tests/date-toLocaleString.js
new file mode 100644 (file)
index 0000000..bc4f1e7
--- /dev/null
@@ -0,0 +1,37 @@
+description("This test checks the behavior of Date.prototype.toLocaleString as described in the ECMAScript Internationalization API Specification (ECMA-402 2.0).");
+
+shouldBe("Date.prototype.toLocaleString.length", "0");
+shouldBeFalse("Object.getOwnPropertyDescriptor(Date.prototype, 'toLocaleString').enumerable");
+shouldBeTrue("Object.getOwnPropertyDescriptor(Date.prototype, 'toLocaleString').configurable");
+shouldBeTrue("Object.getOwnPropertyDescriptor(Date.prototype, 'toLocaleString').writable");
+
+// Test thisTimeValue abrupt completion.
+shouldNotThrow("Date.prototype.toLocaleString.call(new Date)");
+shouldThrow("Date.prototype.toLocaleString.call()");
+shouldThrow("Date.prototype.toLocaleString.call(undefined)");
+shouldThrow("Date.prototype.toLocaleString.call(null)");
+shouldThrow("Date.prototype.toLocaleString.call(0)");
+shouldThrow("Date.prototype.toLocaleString.call(NaN)");
+shouldThrow("Date.prototype.toLocaleString.call(Infinity)");
+shouldThrow("Date.prototype.toLocaleString.call('1')");
+shouldThrow("Date.prototype.toLocaleString.call({})");
+shouldThrow("Date.prototype.toLocaleString.call([])");
+shouldThrow("Date.prototype.toLocaleString.call(Symbol())");
+
+shouldBeTrue("typeof new Date().toLocaleString() === 'string'");
+
+shouldBeEqualToString("new Date(NaN).toLocaleString()", "Invalid Date");
+
+// Test for DateTimeFormat behavior.
+// Test that locale parameter is passed through properly.
+shouldThrow("new Date().toLocaleString('i')");
+shouldBeEqualToString("new Date(0).toLocaleString('zh-Hans-CN-u-nu-hanidec', { timeZone: 'UTC' })", "一九七〇/一/一 上午一二:〇〇:〇〇");
+
+// Defaults to mdy, hms
+shouldBeEqualToString("new Date(0).toLocaleString('en', { timeZone: 'UTC' })", "1/1/1970, 12:00:00 AM");
+
+// Test that options parameter is passed through properly.
+shouldThrow("new Date(0).toLocaleString('en', null)", "'TypeError: null is not an object'");
+shouldBeEqualToString("new Date(0).toLocaleString('en', { timeZone: 'UTC', hour:'numeric', minute:'2-digit' })", "12:00 AM");
+shouldBeEqualToString("new Date(0).toLocaleString('en', { timeZone: 'UTC', year:'numeric', month:'long' })", "January 1970");
+
index 85a1c65..5fcb587 100644 (file)
@@ -162,7 +162,7 @@ shouldBeFalse("Intl.DateTimeFormat.prototype.resolvedOptions() === Intl.DateTime
 shouldThrow("Intl.DateTimeFormat.prototype.resolvedOptions.call(5)", "'TypeError: Intl.DateTimeFormat.prototype.resolvedOptions called on value that\\'s not an object initialized as a DateTimeFormat'");
 
 shouldThrow("Intl.DateTimeFormat('$')", "'RangeError: invalid language tag: $'");
-shouldNotThrow("Intl.DateTimeFormat('en', null)");
+shouldThrow("Intl.DateTimeFormat('en', null)", '"TypeError: null is not an object (evaluating \'Intl.DateTimeFormat(\'en\', null)\')"');
 
 // Defaults to month, day, year.
 shouldBe("Intl.DateTimeFormat('en').resolvedOptions().weekday", "undefined");
index 6d46ff7..8cca47f 100644 (file)
@@ -1222,6 +1222,7 @@ set(JavaScriptCore_BUILTINS_SOURCES
     ${JAVASCRIPTCORE_DIR}/builtins/ArrayConstructor.js
     ${JAVASCRIPTCORE_DIR}/builtins/ArrayIteratorPrototype.js
     ${JAVASCRIPTCORE_DIR}/builtins/ArrayPrototype.js
+    ${JAVASCRIPTCORE_DIR}/builtins/DatePrototype.js
     ${JAVASCRIPTCORE_DIR}/builtins/FunctionPrototype.js
     ${JAVASCRIPTCORE_DIR}/builtins/GeneratorPrototype.js
     ${JAVASCRIPTCORE_DIR}/builtins/GlobalObject.js
index aa53e99..86567b2 100644 (file)
@@ -1,3 +1,34 @@
+2016-01-15  Andy VanWagoner  <thetalecrafter@gmail.com>
+
+        [INTL] Implement Date.prototype.toLocaleString in ECMA-402
+        https://bugs.webkit.org/show_bug.cgi?id=147611
+
+        Reviewed by Benjamin Poulain.
+
+        Expose dateProtoFuncGetTime as thisTimeValue for builtins.
+        Remove unused code in DateTimeFormat toDateTimeOptions, and make the
+        function specific to the call in initializeDateTimeFormat. Properly
+        throw when the options parameter is null.
+        Add toLocaleString in builtin JavaScript, with it's own specific branch
+        of toDateTimeOptions.
+
+        * CMakeLists.txt:
+        * DerivedSources.make:
+        * JavaScriptCore.xcodeproj/project.pbxproj:
+        * builtins/DatePrototype.js: Added.
+        (toLocaleString.toDateTimeOptionsAnyAll):
+        (toLocaleString):
+        * runtime/CommonIdentifiers.h:
+        * runtime/DatePrototype.cpp:
+        (JSC::DatePrototype::finishCreation):
+        * runtime/DatePrototype.h:
+        * runtime/IntlDateTimeFormat.cpp:
+        (JSC::toDateTimeOptionsAnyDate):
+        (JSC::IntlDateTimeFormat::initializeDateTimeFormat):
+        (JSC::toDateTimeOptions): Deleted.
+        * runtime/JSGlobalObject.cpp:
+        (JSC::JSGlobalObject::init):
+
 2016-01-15  Konstantin Tokarev  <annulen@yandex.ru>
 
         [mips] Implemented emitFunctionPrologue/Epilogue
index 55016fb..69d7529 100644 (file)
@@ -83,6 +83,7 @@ JavaScriptCore_BUILTINS_SOURCES = \
     $(JavaScriptCore)/builtins/ArrayConstructor.js \
     $(JavaScriptCore)/builtins/ArrayIteratorPrototype.js \
     $(JavaScriptCore)/builtins/ArrayPrototype.js \
+    $(JavaScriptCore)/builtins/DatePrototype.js \
     $(JavaScriptCore)/builtins/FunctionPrototype.js \
     $(JavaScriptCore)/builtins/GeneratorPrototype.js \
     $(JavaScriptCore)/builtins/GlobalObject.js \
index 2c5f38b..cef1895 100644 (file)
                A1D792FA1B43864B004516F5 /* IntlNumberFormatPrototype.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntlNumberFormatPrototype.cpp; sourceTree = "<group>"; };
                A1D792FB1B43864B004516F5 /* IntlNumberFormatPrototype.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntlNumberFormatPrototype.h; sourceTree = "<group>"; };
                A1E0451B1C25B4B100BB663C /* StringPrototype.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = StringPrototype.js; sourceTree = "<group>"; };
+               A1FE1EB01C2C537E00A289FF /* DatePrototype.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = DatePrototype.js; sourceTree = "<group>"; };
                A503FA13188E0FAF00110F14 /* JavaScriptCallFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JavaScriptCallFrame.cpp; sourceTree = "<group>"; };
                A503FA14188E0FAF00110F14 /* JavaScriptCallFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JavaScriptCallFrame.h; sourceTree = "<group>"; };
                A503FA15188E0FB000110F14 /* JSJavaScriptCallFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSJavaScriptCallFrame.cpp; sourceTree = "<group>"; };
                                A7D801A21880D66E0026C39B /* BuiltinExecutables.h */,
                                A75EE9B018AAB7E200AAD043 /* BuiltinNames.h */,
                                41DEA1311B9F3154006D65DD /* BuiltinUtils.h */,
+                               A1FE1EB01C2C537E00A289FF /* DatePrototype.js */,
                                A7A979C418BE8D9E002C3733 /* FunctionPrototype.js */,
                                70B7918F1C0244EC002481E2 /* GeneratorPrototype.js */,
                                7CF9BC5A1B65D9A3009DB1EF /* GlobalObject.js */,
diff --git a/Source/JavaScriptCore/builtins/DatePrototype.js b/Source/JavaScriptCore/builtins/DatePrototype.js
new file mode 100644 (file)
index 0000000..6601a23
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2015 Andy VanWagoner <thetalecrafter@gmail.com>.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// @conditional=ENABLE(INTL)
+
+function toLocaleString(/* locales, options */)
+{
+    "use strict";
+
+    function toDateTimeOptionsAnyAll(opts)
+    {
+        // ToDateTimeOptions abstract operation (ECMA-402 2.0)
+        // http://ecma-international.org/publications/standards/Ecma-402.htm
+
+        // 1. If options is undefined, then let options be null, else let options be ToObject(options).
+        // 2. ReturnIfAbrupt(options).
+        var optObj;
+        if (opts === undefined)
+            optObj = null;
+        else if (opts === null)
+            throw new @TypeError("null is not an object");
+        else
+            optObj = @Object(opts);
+
+        // 3. Let options be ObjectCreate(options).
+        var options = @Object.create(optObj);
+
+        // 4. Let needDefaults be true.
+        // 5. If required is "date" or "any",
+        // a. For each of the property names "weekday", "year", "month", "day":
+        // i. Let prop be the property name.
+        // ii. Let value be Get(options, prop).
+        // iii. ReturnIfAbrupt(value).
+        // iv. If value is not undefined, then let needDefaults be false.
+        // 6. If required is "time" or "any",
+        // a. For each of the property names "hour", "minute", "second":
+        // i. Let prop be the property name.
+        // ii. Let value be Get(options, prop).
+        // iii. ReturnIfAbrupt(value).
+        // iv. If value is not undefined, then let needDefaults be false.
+        // Check optObj instead of options to reduce lookups up the prototype chain.
+        var needsDefaults = !optObj || (
+            optObj.weekday === undefined &&
+            optObj.year === undefined &&
+            optObj.month === undefined &&
+            optObj.day === undefined &&
+            optObj.hour === undefined &&
+            optObj.minute === undefined &&
+            optObj.second === undefined
+        );
+
+        // 7. If needDefaults is true and defaults is either "date" or "all", then a. For each of the property names "year", "month", "day":
+        // i. Let status be CreateDatePropertyOrThrow(options, prop, "numeric").
+        // ii. ReturnIfAbrupt(status).
+        // 8. If needDefaults is true and defaults is either "time" or "all", then
+        // a. For each of the property names "hour", "minute", "second":
+        // i. Let status be CreateDatePropertyOrThrow(options, prop, "numeric").
+        // ii. ReturnIfAbrupt(status).
+        if (needsDefaults) {
+            options.year = "numeric";
+            options.month = "numeric";
+            options.day = "numeric";
+            options.hour = "numeric";
+            options.minute = "numeric";
+            options.second = "numeric";
+        }
+
+        // 9. Return options.
+        return options;
+    }
+
+    // 13.3.1 Date.prototype.toLocaleString ([locales [, options ]]) (ECMA-402 2.0)
+    // http://ecma-international.org/publications/standards/Ecma-402.htm
+
+    // 1. Let x be thisTimeValue(this value).
+    // 2. ReturnIfAbrupt(x).
+    var value = @thisTimeValue.@call(this);
+
+    // 3. If x is NaN, return "Invalid Date".
+    if (@isNaN(value))
+        return "Invalid Date";
+
+    // 4. Let options be ToDateTimeOptions(options, "any", "all").
+    // 5. ReturnIfAbrupt(options).
+    var options = toDateTimeOptionsAnyAll(arguments[1]);
+
+    // 6. Let dateFormat be Construct(%DateTimeFormat%, «locales, options»).
+    // 7. ReturnIfAbrupt(dateFormat).
+    var locales = arguments[0];
+    var dateFormat = new @DateTimeFormat(locales, options);
+
+    // 8. Return FormatDateTime(dateFormat, x).
+    return dateFormat.format(value);
+}
index 0c5a8a0..f66533b 100644 (file)
     macro(Collator) \
     macro(DateTimeFormat) \
     macro(NumberFormat) \
+    macro(thisTimeValue) \
     macro(newTargetLocal) \
     macro(derivedConstructor) \
     macro(isBoundFunction) \
index 53f7ea3..f5e8684 100644 (file)
 #include "DateConversion.h"
 #include "DateInstance.h"
 #include "Error.h"
+#include "JSCBuiltins.h"
 #include "JSDateMath.h"
 #include "JSGlobalObject.h"
+#include "JSObject.h"
 #include "JSString.h"
 #include "Lookup.h"
 #include "ObjectPrototype.h"
@@ -78,7 +80,6 @@ EncodedJSValue JSC_HOST_CALL dateProtoFuncGetMilliSeconds(ExecState*);
 EncodedJSValue JSC_HOST_CALL dateProtoFuncGetMinutes(ExecState*);
 EncodedJSValue JSC_HOST_CALL dateProtoFuncGetMonth(ExecState*);
 EncodedJSValue JSC_HOST_CALL dateProtoFuncGetSeconds(ExecState*);
-EncodedJSValue JSC_HOST_CALL dateProtoFuncGetTime(ExecState*);
 EncodedJSValue JSC_HOST_CALL dateProtoFuncGetTimezoneOffset(ExecState*);
 EncodedJSValue JSC_HOST_CALL dateProtoFuncGetUTCDate(ExecState*);
 EncodedJSValue JSC_HOST_CALL dateProtoFuncGetUTCDay(ExecState*);
@@ -485,11 +486,17 @@ DatePrototype::DatePrototype(VM& vm, Structure* structure)
 {
 }
 
-void DatePrototype::finishCreation(VM& vm, JSGlobalObject*)
+void DatePrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
 {
     Base::finishCreation(vm);
     ASSERT(inherits(info()));
 
+#if ENABLE(INTL)
+    JSC_BUILTIN_FUNCTION("toLocaleString", datePrototypeToLocaleStringCodeGenerator, DontEnum);
+#else
+    UNUSED_PARAM(globalObject);
+#endif // ENABLE(INTL)
+
     // The constructor will be added later, after DateConstructor has been built.
 }
 
index 7225ac5..cda4c1a 100644 (file)
@@ -54,6 +54,8 @@ protected:
     void finishCreation(VM&, JSGlobalObject*);
 };
 
+EncodedJSValue JSC_HOST_CALL dateProtoFuncGetTime(ExecState*);
+
 } // namespace JSC
 
 #endif // DatePrototype_h
index ca0675f..495f15e 100644 (file)
@@ -51,9 +51,6 @@ static const char* const relevantExtensionKeys[2] = { "ca", "nu" };
 static const size_t indexOfExtensionKeyCa = 0;
 static const size_t indexOfExtensionKeyNu = 1;
 
-enum class DateTimeOptionRequired { Date, Time, Any };
-enum class DateTimeOptionDefaults { Date, Time, All };
-
 IntlDateTimeFormat* IntlDateTimeFormat::create(VM& vm, IntlDateTimeFormatConstructor* constructor)
 {
     IntlDateTimeFormat* format = new (NotNull, allocateCell<IntlDateTimeFormat>(vm.heap)) IntlDateTimeFormat(vm, constructor->dateTimeFormatStructure());
@@ -221,7 +218,7 @@ static Vector<String> localeData(const String& locale, size_t keyIndex)
     return keyLocaleData;
 }
 
-static JSObject* toDateTimeOptions(ExecState& exec, JSValue originalOptions, const DateTimeOptionRequired required, const DateTimeOptionDefaults defaults)
+static JSObject* toDateTimeOptionsAnyDate(ExecState& exec, JSValue originalOptions)
 {
     // 12.1.1 ToDateTimeOptions abstract operation (ECMA-402 2.0)
     VM& vm = exec.vm();
@@ -230,7 +227,7 @@ static JSObject* toDateTimeOptions(ExecState& exec, JSValue originalOptions, con
     // 2. ReturnIfAbrupt(options).
     // 3. Let options be ObjectCreate(options).
     JSObject* options;
-    if (originalOptions.isUndefinedOrNull())
+    if (originalOptions.isUndefined())
         options = constructEmptyObject(&exec, exec.lexicalGlobalObject()->nullPrototypeObjectStructure());
     else {
         JSObject* originalToObject = originalOptions.toObject(&exec);
@@ -243,98 +240,84 @@ static JSObject* toDateTimeOptions(ExecState& exec, JSValue originalOptions, con
     bool needDefaults = true;
 
     // 5. If required is "date" or "any",
-    if (required == DateTimeOptionRequired::Date || required == DateTimeOptionRequired::Any) {
-        // a. For each of the property names "weekday", "year", "month", "day":
-        // i. Let prop be the property name.
-        // ii. Let value be Get(options, prop).
-        // iii. ReturnIfAbrupt(value).
-        // iv. If value is not undefined, then let needDefaults be false.
-        JSValue weekday = options->get(&exec, vm.propertyNames->weekday);
-        if (exec.hadException())
-            return nullptr;
-        if (!weekday.isUndefined())
-            needDefaults = false;
+    // Always "any".
+
+    // a. For each of the property names "weekday", "year", "month", "day":
+    // i. Let prop be the property name.
+    // ii. Let value be Get(options, prop).
+    // iii. ReturnIfAbrupt(value).
+    // iv. If value is not undefined, then let needDefaults be false.
+    JSValue weekday = options->get(&exec, vm.propertyNames->weekday);
+    if (exec.hadException())
+        return nullptr;
+    if (!weekday.isUndefined())
+        needDefaults = false;
 
-        JSValue year = options->get(&exec, vm.propertyNames->year);
-        if (exec.hadException())
-            return nullptr;
-        if (!year.isUndefined())
-            needDefaults = false;
+    JSValue year = options->get(&exec, vm.propertyNames->year);
+    if (exec.hadException())
+        return nullptr;
+    if (!year.isUndefined())
+        needDefaults = false;
 
-        JSValue month = options->get(&exec, vm.propertyNames->month);
-        if (exec.hadException())
-            return nullptr;
-        if (!month.isUndefined())
-            needDefaults = false;
+    JSValue month = options->get(&exec, vm.propertyNames->month);
+    if (exec.hadException())
+        return nullptr;
+    if (!month.isUndefined())
+        needDefaults = false;
 
-        JSValue day = options->get(&exec, vm.propertyNames->day);
-        if (exec.hadException())
-            return nullptr;
-        if (!day.isUndefined())
-            needDefaults = false;
-    }
+    JSValue day = options->get(&exec, vm.propertyNames->day);
+    if (exec.hadException())
+        return nullptr;
+    if (!day.isUndefined())
+        needDefaults = false;
 
     // 6. If required is "time" or "any",
-    if (required == DateTimeOptionRequired::Time || required == DateTimeOptionRequired::Any) {
-        // a. For each of the property names "hour", "minute", "second":
-        // i. Let prop be the property name.
-        // ii. Let value be Get(options, prop).
-        // iii. ReturnIfAbrupt(value).
-        // iv. If value is not undefined, then let needDefaults be false.
-        JSValue hour = options->get(&exec, vm.propertyNames->hour);
-        if (exec.hadException())
-            return nullptr;
-        if (!hour.isUndefined())
-            needDefaults = false;
+    // Always "any".
+
+    // a. For each of the property names "hour", "minute", "second":
+    // i. Let prop be the property name.
+    // ii. Let value be Get(options, prop).
+    // iii. ReturnIfAbrupt(value).
+    // iv. If value is not undefined, then let needDefaults be false.
+    JSValue hour = options->get(&exec, vm.propertyNames->hour);
+    if (exec.hadException())
+        return nullptr;
+    if (!hour.isUndefined())
+        needDefaults = false;
 
-        JSValue minute = options->get(&exec, vm.propertyNames->minute);
-        if (exec.hadException())
-            return nullptr;
-        if (!minute.isUndefined())
-            needDefaults = false;
+    JSValue minute = options->get(&exec, vm.propertyNames->minute);
+    if (exec.hadException())
+        return nullptr;
+    if (!minute.isUndefined())
+        needDefaults = false;
 
-        JSValue second = options->get(&exec, vm.propertyNames->second);
-        if (exec.hadException())
-            return nullptr;
-        if (!second.isUndefined())
-            needDefaults = false;
-    }
+    JSValue second = options->get(&exec, vm.propertyNames->second);
+    if (exec.hadException())
+        return nullptr;
+    if (!second.isUndefined())
+        needDefaults = false;
 
     // 7. If needDefaults is true and defaults is either "date" or "all", then
-    if (needDefaults && (defaults == DateTimeOptionDefaults::Date || defaults == DateTimeOptionDefaults::All)) {
+    // Defaults is always "date".
+    if (needDefaults) {
         // a. For each of the property names "year", "month", "day":
         // i. Let status be CreateDatePropertyOrThrow(options, prop, "numeric").
         // ii. ReturnIfAbrupt(status).
-        options->putDirect(vm, vm.propertyNames->year, jsString(&exec, "numeric"));
+        options->putDirect(vm, vm.propertyNames->year, jsNontrivialString(&exec, ASCIILiteral("numeric")));
         if (exec.hadException())
             return nullptr;
 
-        options->putDirect(vm, vm.propertyNames->month, jsString(&exec, "numeric"));
+        options->putDirect(vm, vm.propertyNames->month, jsNontrivialString(&exec, ASCIILiteral("numeric")));
         if (exec.hadException())
             return nullptr;
 
-        options->putDirect(vm, vm.propertyNames->day, jsString(&exec, "numeric"));
+        options->putDirect(vm, vm.propertyNames->day, jsNontrivialString(&exec, ASCIILiteral("numeric")));
         if (exec.hadException())
             return nullptr;
     }
 
     // 8. If needDefaults is true and defaults is either "time" or "all", then
-    if (needDefaults && (defaults == DateTimeOptionDefaults::Time || defaults == DateTimeOptionDefaults::All)) {
-        // a. For each of the property names "hour", "minute", "second":
-        // i. Let status be CreateDatePropertyOrThrow(options, prop, "numeric").
-        // ii. ReturnIfAbrupt(status).
-        options->putDirect(vm, vm.propertyNames->hour, jsString(&exec, "numeric"));
-        if (exec.hadException())
-            return nullptr;
-
-        options->putDirect(vm, vm.propertyNames->minute, jsString(&exec, "numeric"));
-        if (exec.hadException())
-            return nullptr;
-
-        options->putDirect(vm, vm.propertyNames->second, jsString(&exec, "numeric"));
-        if (exec.hadException())
-            return nullptr;
-    }
+    // Defaults is always "date". Ignore this branch.
 
     // 9. Return options.
     return options;
@@ -451,7 +434,7 @@ void IntlDateTimeFormat::initializeDateTimeFormat(ExecState& exec, JSValue local
         return;
 
     // 5. Let options be ToDateTimeOptions(options, "any", "date").
-    JSObject* options = toDateTimeOptions(exec, originalOptions, DateTimeOptionRequired::Any, DateTimeOptionDefaults::Date);
+    JSObject* options = toDateTimeOptionsAnyDate(exec, originalOptions);
     // 6. ReturnIfAbrupt(options).
     if (exec.hadException())
         return;
index 769a3ef..b6ba27c 100644 (file)
@@ -519,6 +519,7 @@ putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Construct
     JSFunction* privateFuncIsBoundFunction = JSFunction::create(vm, this, 0, String(), isBoundFunction);
     JSFunction* privateFuncHasInstanceBoundFunction = JSFunction::create(vm, this, 0, String(), hasInstanceBoundFunction);
     JSFunction* privateFuncInstanceOf = JSFunction::create(vm, this, 0, String(), objectPrivateFuncInstanceOf);
+    JSFunction* privateFuncThisTimeValue = JSFunction::create(vm, this, 0, String(), dateProtoFuncGetTime);
 
     GlobalPropertyInfo staticGlobals[] = {
         GlobalPropertyInfo(vm.propertyNames->NaN, jsNaN(), DontEnum | DontDelete | ReadOnly),
@@ -577,6 +578,7 @@ putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Construct
         GlobalPropertyInfo(vm.propertyNames->builtinNames().InspectorInstrumentationPrivateName(), InspectorInstrumentationObject::create(vm, this, InspectorInstrumentationObject::createStructure(vm, this, m_objectPrototype.get())), DontEnum | DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->MapPrivateName, mapConstructor, DontEnum | DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->builtinNames().generatorResumePrivateName(), JSFunction::createBuiltinFunction(vm, generatorPrototypeGeneratorResumeCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
+        GlobalPropertyInfo(vm.propertyNames->builtinNames().thisTimeValuePrivateName(), privateFuncThisTimeValue, DontEnum | DontDelete | ReadOnly),
 #if ENABLE(INTL)
         GlobalPropertyInfo(vm.propertyNames->builtinNames().CollatorPrivateName(), intl->getDirect(vm, vm.propertyNames->Collator), DontEnum | DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->builtinNames().DateTimeFormatPrivateName(), intl->getDirect(vm, vm.propertyNames->DateTimeFormat), DontEnum | DontDelete | ReadOnly),