Commit b88d96c7 authored by littledan's avatar littledan Committed by Commit bot

[intl] Remove new.target check in Intl functions and method

The Intl implementation included manual checks to see if they were
being called as a constructor. However, these checks are redundant,
as %FunctionRemovePrototype has already marked the functions as
un-constructable. This path removes the unnecessary checks.

R=yangguo

Review-Url: https://codereview.chromium.org/2587713002
Cr-Commit-Position: refs/heads/master@{#41867}
parent 6e833886
...@@ -912,10 +912,6 @@ var resolvedAccessor = { ...@@ -912,10 +912,6 @@ var resolvedAccessor = {
// ECMA 402 section 8.2.1 // ECMA 402 section 8.2.1
InstallFunction(Intl, 'getCanonicalLocales', function(locales) { InstallFunction(Intl, 'getCanonicalLocales', function(locales) {
if (!IS_UNDEFINED(new.target)) {
throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
}
return makeArray(canonicalizeLocaleList(locales)); return makeArray(canonicalizeLocaleList(locales));
} }
); );
...@@ -1051,10 +1047,6 @@ InstallConstructor(Intl, 'Collator', function() { ...@@ -1051,10 +1047,6 @@ InstallConstructor(Intl, 'Collator', function() {
* Collator resolvedOptions method. * Collator resolvedOptions method.
*/ */
InstallFunction(Intl.Collator.prototype, 'resolvedOptions', function() { InstallFunction(Intl.Collator.prototype, 'resolvedOptions', function() {
if (!IS_UNDEFINED(new.target)) {
throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
}
if (!%IsInitializedIntlObjectOfType(this, 'collator')) { if (!%IsInitializedIntlObjectOfType(this, 'collator')) {
throw %make_type_error(kResolvedOptionsCalledOnNonObject, "Collator"); throw %make_type_error(kResolvedOptionsCalledOnNonObject, "Collator");
} }
...@@ -1083,10 +1075,6 @@ InstallFunction(Intl.Collator.prototype, 'resolvedOptions', function() { ...@@ -1083,10 +1075,6 @@ InstallFunction(Intl.Collator.prototype, 'resolvedOptions', function() {
* Options are optional parameter. * Options are optional parameter.
*/ */
InstallFunction(Intl.Collator, 'supportedLocalesOf', function(locales) { InstallFunction(Intl.Collator, 'supportedLocalesOf', function(locales) {
if (!IS_UNDEFINED(new.target)) {
throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
}
return supportedLocalesOf('collator', locales, arguments[1]); return supportedLocalesOf('collator', locales, arguments[1]);
} }
); );
...@@ -1292,10 +1280,6 @@ InstallConstructor(Intl, 'NumberFormat', function() { ...@@ -1292,10 +1280,6 @@ InstallConstructor(Intl, 'NumberFormat', function() {
* NumberFormat resolvedOptions method. * NumberFormat resolvedOptions method.
*/ */
InstallFunction(Intl.NumberFormat.prototype, 'resolvedOptions', function() { InstallFunction(Intl.NumberFormat.prototype, 'resolvedOptions', function() {
if (!IS_UNDEFINED(new.target)) {
throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
}
if (!%IsInitializedIntlObjectOfType(this, 'numberformat')) { if (!%IsInitializedIntlObjectOfType(this, 'numberformat')) {
throw %make_type_error(kResolvedOptionsCalledOnNonObject, "NumberFormat"); throw %make_type_error(kResolvedOptionsCalledOnNonObject, "NumberFormat");
} }
...@@ -1342,10 +1326,6 @@ InstallFunction(Intl.NumberFormat.prototype, 'resolvedOptions', function() { ...@@ -1342,10 +1326,6 @@ InstallFunction(Intl.NumberFormat.prototype, 'resolvedOptions', function() {
* Options are optional parameter. * Options are optional parameter.
*/ */
InstallFunction(Intl.NumberFormat, 'supportedLocalesOf', function(locales) { InstallFunction(Intl.NumberFormat, 'supportedLocalesOf', function(locales) {
if (!IS_UNDEFINED(new.target)) {
throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
}
return supportedLocalesOf('numberformat', locales, arguments[1]); return supportedLocalesOf('numberformat', locales, arguments[1]);
} }
); );
...@@ -1676,10 +1656,6 @@ InstallConstructor(Intl, 'DateTimeFormat', function() { ...@@ -1676,10 +1656,6 @@ InstallConstructor(Intl, 'DateTimeFormat', function() {
* DateTimeFormat resolvedOptions method. * DateTimeFormat resolvedOptions method.
*/ */
InstallFunction(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() { InstallFunction(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() {
if (!IS_UNDEFINED(new.target)) {
throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
}
if (!%IsInitializedIntlObjectOfType(this, 'dateformat')) { if (!%IsInitializedIntlObjectOfType(this, 'dateformat')) {
throw %make_type_error(kResolvedOptionsCalledOnNonObject, "DateTimeFormat"); throw %make_type_error(kResolvedOptionsCalledOnNonObject, "DateTimeFormat");
} }
...@@ -1736,10 +1712,6 @@ InstallFunction(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() { ...@@ -1736,10 +1712,6 @@ InstallFunction(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() {
* Options are optional parameter. * Options are optional parameter.
*/ */
InstallFunction(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) { InstallFunction(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) {
if (!IS_UNDEFINED(new.target)) {
throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
}
return supportedLocalesOf('dateformat', locales, arguments[1]); return supportedLocalesOf('dateformat', locales, arguments[1]);
} }
); );
...@@ -1765,9 +1737,6 @@ function formatDate(formatter, dateValue) { ...@@ -1765,9 +1737,6 @@ function formatDate(formatter, dateValue) {
} }
function FormatDateToParts(dateValue) { function FormatDateToParts(dateValue) {
if (!IS_UNDEFINED(new.target)) {
throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
}
CHECK_OBJECT_COERCIBLE(this, "Intl.DateTimeFormat.prototype.formatToParts"); CHECK_OBJECT_COERCIBLE(this, "Intl.DateTimeFormat.prototype.formatToParts");
if (!IS_OBJECT(this)) { if (!IS_OBJECT(this)) {
throw %make_type_error(kCalledOnNonObject, this); throw %make_type_error(kCalledOnNonObject, this);
...@@ -2075,10 +2044,6 @@ function LocaleConvertCase(s, locales, isToUpper) { ...@@ -2075,10 +2044,6 @@ function LocaleConvertCase(s, locales, isToUpper) {
* Overrides the built-in method. * Overrides the built-in method.
*/ */
OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) { OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) {
if (!IS_UNDEFINED(new.target)) {
throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
}
if (IS_NULL_OR_UNDEFINED(this)) { if (IS_NULL_OR_UNDEFINED(this)) {
throw %make_type_error(kMethodInvokedOnNullOrUndefined); throw %make_type_error(kMethodInvokedOnNullOrUndefined);
} }
...@@ -2100,10 +2065,6 @@ OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) { ...@@ -2100,10 +2065,6 @@ OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) {
*/ */
OverrideFunction(GlobalString.prototype, 'normalize', function() { OverrideFunction(GlobalString.prototype, 'normalize', function() {
if (!IS_UNDEFINED(new.target)) {
throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
}
CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize"); CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize");
var s = TO_STRING(this); var s = TO_STRING(this);
...@@ -2164,10 +2125,6 @@ utils.Export(function(to) { ...@@ -2164,10 +2125,6 @@ utils.Export(function(to) {
* If locale or options are omitted, defaults are used. * If locale or options are omitted, defaults are used.
*/ */
OverrideFunction(GlobalNumber.prototype, 'toLocaleString', function() { OverrideFunction(GlobalNumber.prototype, 'toLocaleString', function() {
if (!IS_UNDEFINED(new.target)) {
throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
}
if (!(this instanceof GlobalNumber) && typeof(this) !== 'number') { if (!(this instanceof GlobalNumber) && typeof(this) !== 'number') {
throw %make_type_error(kMethodInvokedOnWrongType, "Number"); throw %make_type_error(kMethodInvokedOnWrongType, "Number");
} }
...@@ -2206,10 +2163,6 @@ function toLocaleDateTime(date, locales, options, required, defaults, service) { ...@@ -2206,10 +2163,6 @@ function toLocaleDateTime(date, locales, options, required, defaults, service) {
* present in the output. * present in the output.
*/ */
OverrideFunction(GlobalDate.prototype, 'toLocaleString', function() { OverrideFunction(GlobalDate.prototype, 'toLocaleString', function() {
if (!IS_UNDEFINED(new.target)) {
throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
}
var locales = arguments[0]; var locales = arguments[0];
var options = arguments[1]; var options = arguments[1];
return toLocaleDateTime( return toLocaleDateTime(
...@@ -2224,10 +2177,6 @@ OverrideFunction(GlobalDate.prototype, 'toLocaleString', function() { ...@@ -2224,10 +2177,6 @@ OverrideFunction(GlobalDate.prototype, 'toLocaleString', function() {
* in the output. * in the output.
*/ */
OverrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() { OverrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() {
if (!IS_UNDEFINED(new.target)) {
throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
}
var locales = arguments[0]; var locales = arguments[0];
var options = arguments[1]; var options = arguments[1];
return toLocaleDateTime( return toLocaleDateTime(
...@@ -2242,10 +2191,6 @@ OverrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() { ...@@ -2242,10 +2191,6 @@ OverrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() {
* in the output. * in the output.
*/ */
OverrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() { OverrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() {
if (!IS_UNDEFINED(new.target)) {
throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
}
var locales = arguments[0]; var locales = arguments[0];
var options = arguments[1]; var options = arguments[1];
return toLocaleDateTime( return toLocaleDateTime(
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
assertThrows(() => new Intl.getCanonicalLocales('en'), TypeError);
let collator = new Intl.Collator('en');
assertThrows(() => new collator.resolvedOptions(), TypeError);
assertThrows(() => new Intl.Collator.supportedLocalesOf('en'), TypeError);
let numberformat = new Intl.NumberFormat('en');
assertThrows(() => new numberformat.resolvedOptions(), TypeError);
assertThrows(() => new Intl.NumberFormat.supportedLocalesOf('en'), TypeError);
let datetimeformat = new Intl.DateTimeFormat('en');
assertThrows(() => new datetimeformat.resolvedOptions(), TypeError);
assertThrows(() => new datetimeformat.formatToParts(new Date()), TypeError);
assertThrows(() => new Intl.DateTimeFormat.supportedLocalesOf('en'), TypeError);
assertThrows(() => new "".localCompare(""), TypeError);
assertThrows(() => new "".normalize(), TypeError);
assertThrows(() => new "".toLocaleLowerCase(), TypeError);
assertThrows(() => new "".toLocaleUpperCase(), TypeError);
assertThrows(() => new "".toLowerCase(), TypeError);
assertThrows(() => new "".toUpperCase(), TypeError);
assertThrows(() => new 3..toLocaleString(), TypeError);
assertThrows(() => new (new Date()).toLocaleString(), TypeError);
assertThrows(() => new (new Date()).toLocaleDateString(), TypeError);
assertThrows(() => new (new Date()).toLocaleTimeString(), TypeError);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment