js/src/builtin/Date.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 /*global intl_DateTimeFormat: false, */
michael@0 6
michael@0 7
michael@0 8 var dateTimeFormatCache = new Record();
michael@0 9
michael@0 10
michael@0 11 /**
michael@0 12 * Format this Date object into a date and time string, using the locale and
michael@0 13 * formatting options provided.
michael@0 14 *
michael@0 15 * Spec: ECMAScript Language Specification, 5.1 edition, 15.9.5.5.
michael@0 16 * Spec: ECMAScript Internationalization API Specification, 13.3.1.
michael@0 17 */
michael@0 18 function Date_toLocaleString() {
michael@0 19 // Steps 1-2. Note that valueOf enforces "this time value" restrictions.
michael@0 20 var x = callFunction(std_Date_valueOf, this);
michael@0 21 if (std_isNaN(x))
michael@0 22 return "Invalid Date";
michael@0 23
michael@0 24 // Steps 3-4.
michael@0 25 var locales = arguments.length > 0 ? arguments[0] : undefined;
michael@0 26 var options = arguments.length > 1 ? arguments[1] : undefined;
michael@0 27
michael@0 28 // Step 5-6.
michael@0 29 var dateTimeFormat;
michael@0 30 if (locales === undefined && options === undefined) {
michael@0 31 // This cache only optimizes for the old ES5 toLocaleString without
michael@0 32 // locales and options.
michael@0 33 if (dateTimeFormatCache.dateTimeFormat === undefined) {
michael@0 34 options = ToDateTimeOptions(options, "any", "all");
michael@0 35 dateTimeFormatCache.dateTimeFormat = intl_DateTimeFormat(locales, options);
michael@0 36 }
michael@0 37 dateTimeFormat = dateTimeFormatCache.dateTimeFormat;
michael@0 38 } else {
michael@0 39 options = ToDateTimeOptions(options, "any", "all");
michael@0 40 dateTimeFormat = intl_DateTimeFormat(locales, options);
michael@0 41 }
michael@0 42
michael@0 43 // Step 7.
michael@0 44 return intl_FormatDateTime(dateTimeFormat, x);
michael@0 45 }
michael@0 46
michael@0 47
michael@0 48 /**
michael@0 49 * Format this Date object into a date string, using the locale and formatting
michael@0 50 * options provided.
michael@0 51 *
michael@0 52 * Spec: ECMAScript Language Specification, 5.1 edition, 15.9.5.6.
michael@0 53 * Spec: ECMAScript Internationalization API Specification, 13.3.2.
michael@0 54 */
michael@0 55 function Date_toLocaleDateString() {
michael@0 56 // Steps 1-2. Note that valueOf enforces "this time value" restrictions.
michael@0 57 var x = callFunction(std_Date_valueOf, this);
michael@0 58 if (std_isNaN(x))
michael@0 59 return "Invalid Date";
michael@0 60
michael@0 61 // Steps 3-4.
michael@0 62 var locales = arguments.length > 0 ? arguments[0] : undefined;
michael@0 63 var options = arguments.length > 1 ? arguments[1] : undefined;
michael@0 64
michael@0 65 // Step 5-6.
michael@0 66 var dateTimeFormat;
michael@0 67 if (locales === undefined && options === undefined) {
michael@0 68 // This cache only optimizes for the old ES5 toLocaleDateString without
michael@0 69 // locales and options.
michael@0 70 if (dateTimeFormatCache.dateFormat === undefined) {
michael@0 71 options = ToDateTimeOptions(options, "date", "date");
michael@0 72 dateTimeFormatCache.dateFormat = intl_DateTimeFormat(locales, options);
michael@0 73 }
michael@0 74 dateTimeFormat = dateTimeFormatCache.dateFormat;
michael@0 75 } else {
michael@0 76 options = ToDateTimeOptions(options, "date", "date");
michael@0 77 dateTimeFormat = intl_DateTimeFormat(locales, options);
michael@0 78 }
michael@0 79
michael@0 80 // Step 7.
michael@0 81 return intl_FormatDateTime(dateTimeFormat, x);
michael@0 82 }
michael@0 83
michael@0 84
michael@0 85 /**
michael@0 86 * Format this Date object into a time string, using the locale and formatting
michael@0 87 * options provided.
michael@0 88 *
michael@0 89 * Spec: ECMAScript Language Specification, 5.1 edition, 15.9.5.7.
michael@0 90 * Spec: ECMAScript Internationalization API Specification, 13.3.3.
michael@0 91 */
michael@0 92 function Date_toLocaleTimeString() {
michael@0 93 // Steps 1-2. Note that valueOf enforces "this time value" restrictions.
michael@0 94 var x = callFunction(std_Date_valueOf, this);
michael@0 95 if (std_isNaN(x))
michael@0 96 return "Invalid Date";
michael@0 97
michael@0 98 // Steps 3-4.
michael@0 99 var locales = arguments.length > 0 ? arguments[0] : undefined;
michael@0 100 var options = arguments.length > 1 ? arguments[1] : undefined;
michael@0 101
michael@0 102 // Step 5-6.
michael@0 103 var dateTimeFormat;
michael@0 104 if (locales === undefined && options === undefined) {
michael@0 105 // This cache only optimizes for the old ES5 toLocaleTimeString without
michael@0 106 // locales and options.
michael@0 107 if (dateTimeFormatCache.timeFormat === undefined) {
michael@0 108 options = ToDateTimeOptions(options, "time", "time");
michael@0 109 dateTimeFormatCache.timeFormat = intl_DateTimeFormat(locales, options);
michael@0 110 }
michael@0 111 dateTimeFormat = dateTimeFormatCache.timeFormat;
michael@0 112 } else {
michael@0 113 options = ToDateTimeOptions(options, "time", "time");
michael@0 114 dateTimeFormat = intl_DateTimeFormat(locales, options);
michael@0 115 }
michael@0 116
michael@0 117 // Step 7.
michael@0 118 return intl_FormatDateTime(dateTimeFormat, x);
michael@0 119 }

mercurial