Commit 829f951a authored by littledan's avatar littledan Committed by Commit bot

Revert of Make Intl install properties more like how other builtins do...

Revert of Make Intl install properties more like how other builtins do (patchset #1 id:1 of https://codereview.chromium.org/1733293003/ )

Reason for revert:
Breaks a bot: https://build.chromium.org/p/client.v8/builders/V8%20Linux%20-%20nosnap/builds/6812

Original issue's description:
> Make Intl install properties more like how other builtins do
>
> Intl has been somewhat of an oddball for how it integrates with V8.
> One aspect is that it largely didn't use utils to install itself
> into the snapshot, which led to some missing names, which new
> test262 tests check for, and duplicated code. This patch brings
> Intl a bit closer to how the rest of the builtins do things, though
> not entirely as it is currently structured to do unusual things,
> such as creating new constructors from JavaScript rather than C++.
> New test262 tests check for some of the names that are added in
> this patch.
>
> R=adamk
> CC=jshin
> BUG=v8:4778
> LOG=Y
>
> Committed: https://crrev.com/a40830577d80f699282dd83864619656b7a7966c
> Cr-Commit-Position: refs/heads/master@{#34311}

TBR=adamk@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=v8:4778

Review URL: https://codereview.chromium.org/1737873003

Cr-Commit-Position: refs/heads/master@{#34314}
parent 3b829ad8
......@@ -64,74 +64,6 @@ utils.Import(function(from) {
StringSubstring = from.StringSubstring;
});
// Utilities for definitions
function OverrideFunction(object, name, f) {
%CheckIsBootstrapping();
ObjectDefineProperty(object, name, { value: f,
writeable: true,
configurable: true,
enumerable: false });
%FunctionSetName(f, name);
%FunctionRemovePrototype(f);
%SetNativeFlag(f);
}
function InstallFunction(object, name, func) {
utils.InstallFunctions(object, DONT_ENUM, [name, func]);
}
function InstallConstructor(object, name, func) {
%CheckIsBootstrapping();
utils.SetFunctionName(func, name);
%AddNamedProperty(object, name, func, DONT_ENUM);
%SetNativeFlag(func);
%ToFastProperties(object);
}
/**
* Adds bound method to the prototype of the given object.
*/
function AddBoundMethod(obj, methodName, implementation, length) {
%CheckIsBootstrapping();
var internalName = %CreatePrivateSymbol(methodName);
var getter = function() {
if (!%IsInitializedIntlObject(this)) {
throw MakeTypeError(kMethodCalledOnWrongObject, methodName);
}
if (IS_UNDEFINED(this[internalName])) {
var boundMethod;
if (IS_UNDEFINED(length) || length === 2) {
boundMethod = (x, y) => implementation(this, x, y);
} else if (length === 1) {
boundMethod = x => implementation(this, x);
} else {
boundMethod = (...args) => {
// DateTimeFormat.format needs to be 0 arg method, but can stil
// receive optional dateValue param. If one was provided, pass it
// along.
if (args.length > 0) {
return implementation(this, args[0]);
} else {
return implementation(this);
}
}
}
// TODO(littledan): Once function name reform is shipped, remove the
// following line and wrap the boundMethod definition in an anonymous
// function macro.
%FunctionSetName(boundMethod, '__bound' + methodName + '__');
%FunctionRemovePrototype(boundMethod);
%SetNativeFlag(boundMethod);
this[internalName] = boundMethod;
}
return this[internalName];
};
utils.InstallGetter(obj.prototype, methodName, getter, DONT_ENUM);
}
// -------------------------------------------------------------------
var Intl = {};
......@@ -265,6 +197,56 @@ function GetTimezoneNameLocationPartRE() {
return TIMEZONE_NAME_LOCATION_PART_RE;
}
/**
* Adds bound method to the prototype of the given object.
*/
function addBoundMethod(obj, methodName, implementation, length) {
%CheckIsBootstrapping();
var internalName = %CreatePrivateSymbol(methodName);
function getter() {
if (!%IsInitializedIntlObject(this)) {
throw MakeTypeError(kMethodCalledOnWrongObject, methodName);
}
if (IS_UNDEFINED(this[internalName])) {
var boundMethod;
if (IS_UNDEFINED(length) || length === 2) {
boundMethod = (x, y) => implementation(this, x, y);
} else if (length === 1) {
boundMethod = x => implementation(this, x);
} else {
boundMethod = (...args) => {
// DateTimeFormat.format needs to be 0 arg method, but can stil
// receive optional dateValue param. If one was provided, pass it
// along.
if (args.length > 0) {
return implementation(this, args[0]);
} else {
return implementation(this);
}
}
}
// TODO(littledan): Once function name reform is shipped, remove the
// following line and wrap the boundMethod definition in an anonymous
// function macro.
%FunctionSetName(boundMethod, '__bound' + methodName + '__');
%FunctionRemovePrototype(boundMethod);
%SetNativeFlag(boundMethod);
this[internalName] = boundMethod;
}
return this[internalName];
}
%FunctionSetName(getter, methodName);
%FunctionRemovePrototype(getter);
%SetNativeFlag(getter);
ObjectDefineProperty(obj.prototype, methodName, {
get: getter,
enumerable: false,
configurable: true
});
}
/**
* Returns an intersection of locales and service supported locales.
......@@ -1008,7 +990,7 @@ function initializeCollator(collator, locales, options) {
*
* @constructor
*/
InstallConstructor(Intl, 'Collator', function() {
%AddNamedProperty(Intl, 'Collator', function() {
var locales = arguments[0];
var options = arguments[1];
......@@ -1018,14 +1000,15 @@ InstallConstructor(Intl, 'Collator', function() {
}
return initializeCollator(TO_OBJECT(this), locales, options);
}
},
DONT_ENUM
);
/**
* Collator resolvedOptions method.
*/
InstallFunction(Intl.Collator.prototype, 'resolvedOptions', function() {
%AddNamedProperty(Intl.Collator.prototype, 'resolvedOptions', function() {
if (!IS_UNDEFINED(new.target)) {
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
......@@ -1047,8 +1030,12 @@ InstallFunction(Intl.Collator.prototype, 'resolvedOptions', function() {
caseFirst: coll[resolvedSymbol].caseFirst,
collation: coll[resolvedSymbol].collation
};
}
},
DONT_ENUM
);
%FunctionSetName(Intl.Collator.prototype.resolvedOptions, 'resolvedOptions');
%FunctionRemovePrototype(Intl.Collator.prototype.resolvedOptions);
%SetNativeFlag(Intl.Collator.prototype.resolvedOptions);
/**
......@@ -1057,14 +1044,18 @@ InstallFunction(Intl.Collator.prototype, 'resolvedOptions', function() {
* order in the returned list as in the input list.
* Options are optional parameter.
*/
InstallFunction(Intl.Collator, 'supportedLocalesOf', function(locales) {
%AddNamedProperty(Intl.Collator, 'supportedLocalesOf', function(locales) {
if (!IS_UNDEFINED(new.target)) {
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
return supportedLocalesOf('collator', locales, arguments[1]);
}
},
DONT_ENUM
);
%FunctionSetName(Intl.Collator.supportedLocalesOf, 'supportedLocalesOf');
%FunctionRemovePrototype(Intl.Collator.supportedLocalesOf);
%SetNativeFlag(Intl.Collator.supportedLocalesOf);
/**
......@@ -1083,7 +1074,7 @@ function compare(collator, x, y) {
};
AddBoundMethod(Intl.Collator, 'compare', compare, 2);
addBoundMethod(Intl.Collator, 'compare', compare, 2);
/**
* Verifies that the input is a well-formed ISO 4217 currency code.
......@@ -1252,7 +1243,7 @@ function initializeNumberFormat(numberFormat, locales, options) {
*
* @constructor
*/
InstallConstructor(Intl, 'NumberFormat', function() {
%AddNamedProperty(Intl, 'NumberFormat', function() {
var locales = arguments[0];
var options = arguments[1];
......@@ -1262,14 +1253,15 @@ InstallConstructor(Intl, 'NumberFormat', function() {
}
return initializeNumberFormat(TO_OBJECT(this), locales, options);
}
},
DONT_ENUM
);
/**
* NumberFormat resolvedOptions method.
*/
InstallFunction(Intl.NumberFormat.prototype, 'resolvedOptions', function() {
%AddNamedProperty(Intl.NumberFormat.prototype, 'resolvedOptions', function() {
if (!IS_UNDEFINED(new.target)) {
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
......@@ -1309,8 +1301,13 @@ InstallFunction(Intl.NumberFormat.prototype, 'resolvedOptions', function() {
}
return result;
}
},
DONT_ENUM
);
%FunctionSetName(Intl.NumberFormat.prototype.resolvedOptions,
'resolvedOptions');
%FunctionRemovePrototype(Intl.NumberFormat.prototype.resolvedOptions);
%SetNativeFlag(Intl.NumberFormat.prototype.resolvedOptions);
/**
......@@ -1319,14 +1316,18 @@ InstallFunction(Intl.NumberFormat.prototype, 'resolvedOptions', function() {
* order in the returned list as in the input list.
* Options are optional parameter.
*/
InstallFunction(Intl.NumberFormat, 'supportedLocalesOf', function(locales) {
%AddNamedProperty(Intl.NumberFormat, 'supportedLocalesOf', function(locales) {
if (!IS_UNDEFINED(new.target)) {
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
return supportedLocalesOf('numberformat', locales, arguments[1]);
}
},
DONT_ENUM
);
%FunctionSetName(Intl.NumberFormat.supportedLocalesOf, 'supportedLocalesOf');
%FunctionRemovePrototype(Intl.NumberFormat.supportedLocalesOf);
%SetNativeFlag(Intl.NumberFormat.supportedLocalesOf);
/**
......@@ -1352,8 +1353,8 @@ function parseNumber(formatter, value) {
}
AddBoundMethod(Intl.NumberFormat, 'format', formatNumber, 1);
AddBoundMethod(Intl.NumberFormat, 'v8Parse', parseNumber, 1);
addBoundMethod(Intl.NumberFormat, 'format', formatNumber, 1);
addBoundMethod(Intl.NumberFormat, 'v8Parse', parseNumber, 1);
/**
* Returns a string that matches LDML representation of the options object.
......@@ -1646,7 +1647,7 @@ function initializeDateTimeFormat(dateFormat, locales, options) {
*
* @constructor
*/
InstallConstructor(Intl, 'DateTimeFormat', function() {
%AddNamedProperty(Intl, 'DateTimeFormat', function() {
var locales = arguments[0];
var options = arguments[1];
......@@ -1656,14 +1657,15 @@ InstallConstructor(Intl, 'DateTimeFormat', function() {
}
return initializeDateTimeFormat(TO_OBJECT(this), locales, options);
}
},
DONT_ENUM
);
/**
* DateTimeFormat resolvedOptions method.
*/
InstallFunction(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() {
%AddNamedProperty(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() {
if (!IS_UNDEFINED(new.target)) {
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
......@@ -1722,8 +1724,13 @@ InstallFunction(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() {
addWECPropertyIfDefined(result, 'second', fromPattern.second);
return result;
}
},
DONT_ENUM
);
%FunctionSetName(Intl.DateTimeFormat.prototype.resolvedOptions,
'resolvedOptions');
%FunctionRemovePrototype(Intl.DateTimeFormat.prototype.resolvedOptions);
%SetNativeFlag(Intl.DateTimeFormat.prototype.resolvedOptions);
/**
......@@ -1732,14 +1739,18 @@ InstallFunction(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() {
* order in the returned list as in the input list.
* Options are optional parameter.
*/
InstallFunction(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) {
%AddNamedProperty(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) {
if (!IS_UNDEFINED(new.target)) {
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
return supportedLocalesOf('dateformat', locales, arguments[1]);
}
},
DONT_ENUM
);
%FunctionSetName(Intl.DateTimeFormat.supportedLocalesOf, 'supportedLocalesOf');
%FunctionRemovePrototype(Intl.DateTimeFormat.supportedLocalesOf);
%SetNativeFlag(Intl.DateTimeFormat.supportedLocalesOf);
/**
......@@ -1775,8 +1786,8 @@ function parseDate(formatter, value) {
// 0 because date is optional argument.
AddBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0);
AddBoundMethod(Intl.DateTimeFormat, 'v8Parse', parseDate, 1);
addBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0);
addBoundMethod(Intl.DateTimeFormat, 'v8Parse', parseDate, 1);
/**
......@@ -1863,7 +1874,7 @@ function initializeBreakIterator(iterator, locales, options) {
*
* @constructor
*/
InstallConstructor(Intl, 'v8BreakIterator', function() {
%AddNamedProperty(Intl, 'v8BreakIterator', function() {
var locales = arguments[0];
var options = arguments[1];
......@@ -1873,14 +1884,15 @@ InstallConstructor(Intl, 'v8BreakIterator', function() {
}
return initializeBreakIterator(TO_OBJECT(this), locales, options);
}
},
DONT_ENUM
);
/**
* BreakIterator resolvedOptions method.
*/
InstallFunction(Intl.v8BreakIterator.prototype, 'resolvedOptions',
%AddNamedProperty(Intl.v8BreakIterator.prototype, 'resolvedOptions',
function() {
if (!IS_UNDEFINED(new.target)) {
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
......@@ -1899,8 +1911,13 @@ InstallFunction(Intl.v8BreakIterator.prototype, 'resolvedOptions',
locale: locale,
type: segmenter[resolvedSymbol].type
};
}
},
DONT_ENUM
);
%FunctionSetName(Intl.v8BreakIterator.prototype.resolvedOptions,
'resolvedOptions');
%FunctionRemovePrototype(Intl.v8BreakIterator.prototype.resolvedOptions);
%SetNativeFlag(Intl.v8BreakIterator.prototype.resolvedOptions);
/**
......@@ -1909,15 +1926,19 @@ InstallFunction(Intl.v8BreakIterator.prototype, 'resolvedOptions',
* order in the returned list as in the input list.
* Options are optional parameter.
*/
InstallFunction(Intl.v8BreakIterator, 'supportedLocalesOf',
%AddNamedProperty(Intl.v8BreakIterator, 'supportedLocalesOf',
function(locales) {
if (!IS_UNDEFINED(new.target)) {
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
return supportedLocalesOf('breakiterator', locales, arguments[1]);
}
},
DONT_ENUM
);
%FunctionSetName(Intl.v8BreakIterator.supportedLocalesOf, 'supportedLocalesOf');
%FunctionRemovePrototype(Intl.v8BreakIterator.supportedLocalesOf);
%SetNativeFlag(Intl.v8BreakIterator.supportedLocalesOf);
/**
......@@ -1962,11 +1983,11 @@ function breakType(iterator) {
}
AddBoundMethod(Intl.v8BreakIterator, 'adoptText', adoptText, 1);
AddBoundMethod(Intl.v8BreakIterator, 'first', first, 0);
AddBoundMethod(Intl.v8BreakIterator, 'next', next, 0);
AddBoundMethod(Intl.v8BreakIterator, 'current', current, 0);
AddBoundMethod(Intl.v8BreakIterator, 'breakType', breakType, 0);
addBoundMethod(Intl.v8BreakIterator, 'adoptText', adoptText, 1);
addBoundMethod(Intl.v8BreakIterator, 'first', first, 0);
addBoundMethod(Intl.v8BreakIterator, 'next', next, 0);
addBoundMethod(Intl.v8BreakIterator, 'current', current, 0);
addBoundMethod(Intl.v8BreakIterator, 'breakType', breakType, 0);
// Save references to Intl objects and methods we use, for added security.
var savedObjects = {
......@@ -2004,6 +2025,18 @@ function cachedOrNewService(service, locales, options, defaults) {
return new savedObjects[service](locales, useOptions);
}
function OverrideFunction(object, name, f) {
%CheckIsBootstrapping();
ObjectDefineProperty(object, name, { value: f,
writeable: true,
configurable: true,
enumerable: false });
%FunctionSetName(f, name);
%FunctionRemovePrototype(f);
%SetNativeFlag(f);
}
/**
* Compares this and that, and returns less than 0, 0 or greater than 0 value.
* Overrides the built-in method.
......
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