Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(917)

Unified Diff: src/js/i18n.js

Issue 1728823002: Intl: Use private symbols to memoize bound functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix typo Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/intl/number-format/format-is-bound.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/i18n.js
diff --git a/src/js/i18n.js b/src/js/i18n.js
index 7b2f5a1a12fc0b4a402004c910edbd4f736e79b0..13e78dcd0859823a0338c7fda2ca37a84916d3dd 100644
--- a/src/js/i18n.js
+++ b/src/js/i18n.js
@@ -202,44 +202,33 @@ function GetTimezoneNameLocationPartRE() {
*/
function addBoundMethod(obj, methodName, implementation, length) {
%CheckIsBootstrapping();
+ var internalName = %CreatePrivateSymbol(methodName);
function getter() {
if (!%IsInitializedIntlObject(this)) {
throw MakeTypeError(kMethodCalledOnWrongObject, methodName);
}
- var internalName = '__bound' + methodName + '__';
if (IS_UNDEFINED(this[internalName])) {
- var that = this;
var boundMethod;
if (IS_UNDEFINED(length) || length === 2) {
- boundMethod = function(x, y) {
- if (!IS_UNDEFINED(new.target)) {
- throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
- }
- return implementation(that, x, y);
- }
+ boundMethod = (x, y) => implementation(this, x, y);
} else if (length === 1) {
- boundMethod = function(x) {
- if (!IS_UNDEFINED(new.target)) {
- throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
- }
- return implementation(that, x);
- }
+ boundMethod = x => implementation(this, x);
} else {
- boundMethod = function() {
- if (!IS_UNDEFINED(new.target)) {
- throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
- }
+ 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 (arguments.length > 0) {
- return implementation(that, arguments[0]);
+ if (args.length > 0) {
+ return implementation(this, args[0]);
} else {
- return implementation(that);
+ return implementation(this);
}
}
}
- %FunctionSetName(boundMethod, internalName);
+ // 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;
« no previous file with comments | « no previous file | test/intl/number-format/format-is-bound.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698