Title: [195138] trunk
Revision
195138
Author
[email protected]
Date
2016-01-15 11:30:45 -0800 (Fri, 15 Jan 2016)

Log Message

[INTL] Implement Date.prototype.toLocaleString in ECMA-402
https://bugs.webkit.org/show_bug.cgi?id=147611

Patch by Andy VanWagoner <[email protected]> on 2016-01-15
Reviewed by Benjamin Poulain.

Source/_javascript_Core:

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:
* _javascript_Core.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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (195137 => 195138)


--- trunk/LayoutTests/ChangeLog	2016-01-15 18:59:50 UTC (rev 195137)
+++ trunk/LayoutTests/ChangeLog	2016-01-15 19:30:45 UTC (rev 195138)
@@ -1,3 +1,16 @@
+2016-01-15  Andy VanWagoner  <[email protected]>
+
+        [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  <[email protected]>
 
         Switch out from ES6 arrow function syntax to allow the test to work with an older WebKit.

Added: trunk/LayoutTests/js/date-toLocaleString-expected.txt (0 => 195138)


--- trunk/LayoutTests/js/date-toLocaleString-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/js/date-toLocaleString-expected.txt	2016-01-15 19:30:45 UTC (rev 195138)
@@ -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
+

Added: trunk/LayoutTests/js/date-toLocaleString.html (0 => 195138)


--- trunk/LayoutTests/js/date-toLocaleString.html	                        (rev 0)
+++ trunk/LayoutTests/js/date-toLocaleString.html	2016-01-15 19:30:45 UTC (rev 195138)
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<meta charset="utf-8">
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+</body>
+</html>

Modified: trunk/LayoutTests/js/intl-datetimeformat-expected.txt (195137 => 195138)


--- trunk/LayoutTests/js/intl-datetimeformat-expected.txt	2016-01-15 18:59:50 UTC (rev 195137)
+++ trunk/LayoutTests/js/intl-datetimeformat-expected.txt	2016-01-15 19:30:45 UTC (rev 195138)
@@ -82,7 +82,7 @@
 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'

Added: trunk/LayoutTests/js/script-tests/date-toLocaleString.js (0 => 195138)


--- trunk/LayoutTests/js/script-tests/date-toLocaleString.js	                        (rev 0)
+++ trunk/LayoutTests/js/script-tests/date-toLocaleString.js	2016-01-15 19:30:45 UTC (rev 195138)
@@ -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");
+

Modified: trunk/LayoutTests/js/script-tests/intl-datetimeformat.js (195137 => 195138)


--- trunk/LayoutTests/js/script-tests/intl-datetimeformat.js	2016-01-15 18:59:50 UTC (rev 195137)
+++ trunk/LayoutTests/js/script-tests/intl-datetimeformat.js	2016-01-15 19:30:45 UTC (rev 195138)
@@ -162,7 +162,7 @@
 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");

Modified: trunk/Source/_javascript_Core/CMakeLists.txt (195137 => 195138)


--- trunk/Source/_javascript_Core/CMakeLists.txt	2016-01-15 18:59:50 UTC (rev 195137)
+++ trunk/Source/_javascript_Core/CMakeLists.txt	2016-01-15 19:30:45 UTC (rev 195138)
@@ -1222,6 +1222,7 @@
     ${_javascript_CORE_DIR}/builtins/ArrayConstructor.js
     ${_javascript_CORE_DIR}/builtins/ArrayIteratorPrototype.js
     ${_javascript_CORE_DIR}/builtins/ArrayPrototype.js
+    ${_javascript_CORE_DIR}/builtins/DatePrototype.js
     ${_javascript_CORE_DIR}/builtins/FunctionPrototype.js
     ${_javascript_CORE_DIR}/builtins/GeneratorPrototype.js
     ${_javascript_CORE_DIR}/builtins/GlobalObject.js

Modified: trunk/Source/_javascript_Core/ChangeLog (195137 => 195138)


--- trunk/Source/_javascript_Core/ChangeLog	2016-01-15 18:59:50 UTC (rev 195137)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-01-15 19:30:45 UTC (rev 195138)
@@ -1,3 +1,34 @@
+2016-01-15  Andy VanWagoner  <[email protected]>
+
+        [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:
+        * _javascript_Core.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  <[email protected]>
 
         [mips] Implemented emitFunctionPrologue/Epilogue

Modified: trunk/Source/_javascript_Core/DerivedSources.make (195137 => 195138)


--- trunk/Source/_javascript_Core/DerivedSources.make	2016-01-15 18:59:50 UTC (rev 195137)
+++ trunk/Source/_javascript_Core/DerivedSources.make	2016-01-15 19:30:45 UTC (rev 195138)
@@ -83,6 +83,7 @@
     $(_javascript_Core)/builtins/ArrayConstructor.js \
     $(_javascript_Core)/builtins/ArrayIteratorPrototype.js \
     $(_javascript_Core)/builtins/ArrayPrototype.js \
+    $(_javascript_Core)/builtins/DatePrototype.js \
     $(_javascript_Core)/builtins/FunctionPrototype.js \
     $(_javascript_Core)/builtins/GeneratorPrototype.js \
     $(_javascript_Core)/builtins/GlobalObject.js \

Modified: trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj (195137 => 195138)


--- trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2016-01-15 18:59:50 UTC (rev 195137)
+++ trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2016-01-15 19:30:45 UTC (rev 195138)
@@ -3702,6 +3702,7 @@
 		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 /* _javascript_CallFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = _javascript_CallFrame.cpp; sourceTree = "<group>"; };
 		A503FA14188E0FAF00110F14 /* _javascript_CallFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _javascript_CallFrame.h; sourceTree = "<group>"; };
 		A503FA15188E0FB000110F14 /* JSJavaScriptCallFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSJavaScriptCallFrame.cpp; sourceTree = "<group>"; };
@@ -6797,6 +6798,7 @@
 				A7D801A21880D66E0026C39B /* BuiltinExecutables.h */,
 				A75EE9B018AAB7E200AAD043 /* BuiltinNames.h */,
 				41DEA1311B9F3154006D65DD /* BuiltinUtils.h */,
+				A1FE1EB01C2C537E00A289FF /* DatePrototype.js */,
 				A7A979C418BE8D9E002C3733 /* FunctionPrototype.js */,
 				70B7918F1C0244EC002481E2 /* GeneratorPrototype.js */,
 				7CF9BC5A1B65D9A3009DB1EF /* GlobalObject.js */,

Added: trunk/Source/_javascript_Core/builtins/DatePrototype.js (0 => 195138)


--- trunk/Source/_javascript_Core/builtins/DatePrototype.js	                        (rev 0)
+++ trunk/Source/_javascript_Core/builtins/DatePrototype.js	2016-01-15 19:30:45 UTC (rev 195138)
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2015 Andy VanWagoner <[email protected]>.
+ *
+ * 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);
+}

Modified: trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h (195137 => 195138)


--- trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h	2016-01-15 18:59:50 UTC (rev 195137)
+++ trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h	2016-01-15 19:30:45 UTC (rev 195138)
@@ -357,6 +357,7 @@
     macro(Collator) \
     macro(DateTimeFormat) \
     macro(NumberFormat) \
+    macro(thisTimeValue) \
     macro(newTargetLocal) \
     macro(derivedConstructor) \
     macro(isBoundFunction) \

Modified: trunk/Source/_javascript_Core/runtime/DatePrototype.cpp (195137 => 195138)


--- trunk/Source/_javascript_Core/runtime/DatePrototype.cpp	2016-01-15 18:59:50 UTC (rev 195137)
+++ trunk/Source/_javascript_Core/runtime/DatePrototype.cpp	2016-01-15 19:30:45 UTC (rev 195138)
@@ -27,8 +27,10 @@
 #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 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 @@
 {
 }
 
-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.
 }
 

Modified: trunk/Source/_javascript_Core/runtime/DatePrototype.h (195137 => 195138)


--- trunk/Source/_javascript_Core/runtime/DatePrototype.h	2016-01-15 18:59:50 UTC (rev 195137)
+++ trunk/Source/_javascript_Core/runtime/DatePrototype.h	2016-01-15 19:30:45 UTC (rev 195138)
@@ -54,6 +54,8 @@
     void finishCreation(VM&, JSGlobalObject*);
 };
 
+EncodedJSValue JSC_HOST_CALL dateProtoFuncGetTime(ExecState*);
+
 } // namespace JSC
 
 #endif // DatePrototype_h

Modified: trunk/Source/_javascript_Core/runtime/IntlDateTimeFormat.cpp (195137 => 195138)


--- trunk/Source/_javascript_Core/runtime/IntlDateTimeFormat.cpp	2016-01-15 18:59:50 UTC (rev 195137)
+++ trunk/Source/_javascript_Core/runtime/IntlDateTimeFormat.cpp	2016-01-15 19:30:45 UTC (rev 195138)
@@ -51,9 +51,6 @@
 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 @@
     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 @@
     // 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,99 +240,85 @@
     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".
 
-        JSValue year = options->get(&exec, vm.propertyNames->year);
-        if (exec.hadException())
-            return nullptr;
-        if (!year.isUndefined())
-            needDefaults = false;
+    // 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 month = options->get(&exec, vm.propertyNames->month);
-        if (exec.hadException())
-            return nullptr;
-        if (!month.isUndefined())
-            needDefaults = false;
+    JSValue year = options->get(&exec, vm.propertyNames->year);
+    if (exec.hadException())
+        return nullptr;
+    if (!year.isUndefined())
+        needDefaults = false;
 
-        JSValue day = options->get(&exec, vm.propertyNames->day);
-        if (exec.hadException())
-            return nullptr;
-        if (!day.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;
+
     // 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".
 
-        JSValue minute = options->get(&exec, vm.propertyNames->minute);
-        if (exec.hadException())
-            return nullptr;
-        if (!minute.isUndefined())
-            needDefaults = false;
+    // 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 second = options->get(&exec, vm.propertyNames->second);
-        if (exec.hadException())
-            return nullptr;
-        if (!second.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;
+
     // 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;
+    // Defaults is always "date". Ignore this branch.
 
-        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;
-    }
-
     // 9. Return options.
     return options;
 }
@@ -451,7 +434,7 @@
         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;

Modified: trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp (195137 => 195138)


--- trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp	2016-01-15 18:59:50 UTC (rev 195137)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp	2016-01-15 19:30:45 UTC (rev 195138)
@@ -519,6 +519,7 @@
     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 @@
         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),
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to