OLD | NEW |
---|---|
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // ECMAScript 402 API implementation. | 5 // ECMAScript 402 API implementation. |
6 | 6 |
7 /** | 7 /** |
8 * Intl object is a single object that has some named properties, | 8 * Intl object is a single object that has some named properties, |
9 * all of which are constructors. | 9 * all of which are constructors. |
10 */ | 10 */ |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 function AddBoundMethod(obj, methodName, implementation, length, type) { | 87 function AddBoundMethod(obj, methodName, implementation, length, type) { |
88 %CheckIsBootstrapping(); | 88 %CheckIsBootstrapping(); |
89 var internalName = %CreatePrivateSymbol(methodName); | 89 var internalName = %CreatePrivateSymbol(methodName); |
90 var getter = function() { | 90 var getter = function() { |
91 if (!%IsInitializedIntlObjectOfType(this, type)) { | 91 if (!%IsInitializedIntlObjectOfType(this, type)) { |
92 throw MakeTypeError(kMethodCalledOnWrongObject, methodName); | 92 throw MakeTypeError(kMethodCalledOnWrongObject, methodName); |
93 } | 93 } |
94 if (IS_UNDEFINED(this[internalName])) { | 94 if (IS_UNDEFINED(this[internalName])) { |
95 var boundMethod; | 95 var boundMethod; |
96 if (IS_UNDEFINED(length) || length === 2) { | 96 if (IS_UNDEFINED(length) || length === 2) { |
97 boundMethod = (x, y) => implementation(this, x, y); | 97 boundMethod = ANONYMOUS_FUNCTION((x, y) => implementation(this, x, y)); |
98 } else if (length === 1) { | 98 } else if (length === 1) { |
99 boundMethod = x => implementation(this, x); | 99 boundMethod = ANONYMOUS_FUNCTION(x => implementation(this, x)); |
100 } else { | 100 } else { |
101 boundMethod = (...args) => { | 101 boundMethod = ANONYMOUS_FUNCTION((...args) => { |
102 // DateTimeFormat.format needs to be 0 arg method, but can stil | 102 // DateTimeFormat.format needs to be 0 arg method, but can still |
103 // receive optional dateValue param. If one was provided, pass it | 103 // receive an optional dateValue param. If one was provided, pass it |
104 // along. | 104 // along. |
105 if (args.length > 0) { | 105 if (args.length > 0) { |
106 return implementation(this, args[0]); | 106 return implementation(this, args[0]); |
107 } else { | 107 } else { |
108 return implementation(this); | 108 return implementation(this); |
109 } | 109 } |
110 } | 110 }); |
111 } | 111 } |
112 // TODO(littledan): Once function name reform is shipped, remove the | |
113 // following line and wrap the boundMethod definition in an anonymous | |
114 // function macro. | |
115 %FunctionSetName(boundMethod, '__bound' + methodName + '__'); | |
116 %FunctionRemovePrototype(boundMethod); | |
117 %SetNativeFlag(boundMethod); | 112 %SetNativeFlag(boundMethod); |
118 this[internalName] = boundMethod; | 113 this[internalName] = boundMethod; |
119 } | 114 } |
120 return this[internalName]; | 115 return this[internalName]; |
121 }; | 116 }; |
122 | 117 |
123 InstallGetter(obj.prototype, methodName, getter, DONT_ENUM); | 118 InstallGetter(obj.prototype, methodName, getter, DONT_ENUM, |
119 true /* skipSetFunctionName */); | |
120 | |
121 // All functions returned from AddBoundMethod share a single | |
122 // SharedFunctionInfo, so we have to set the "name" property | |
123 // on the JSFunction itself. | |
124 %object_define_property(getter, "name", {value: "get " + methodName}); | |
Dan Ehrenberg
2016/06/29 21:10:12
The name should be configurable, but seems to be d
adamk
2016/06/29 22:53:10
For pre-existing properties (as "name" is here), d
adamk
2016/06/29 23:19:15
I now take a different approach. Let me know if yo
| |
124 } | 125 } |
125 | 126 |
126 // ------------------------------------------------------------------- | 127 // ------------------------------------------------------------------- |
127 | 128 |
128 var Intl = {}; | 129 var Intl = {}; |
129 | 130 |
130 %AddNamedProperty(global, "Intl", Intl, DONT_ENUM); | 131 %AddNamedProperty(global, "Intl", Intl, DONT_ENUM); |
131 | 132 |
132 /** | 133 /** |
133 * Caches available locales for each service. | 134 * Caches available locales for each service. |
(...skipping 2115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2249 } | 2250 } |
2250 ); | 2251 ); |
2251 | 2252 |
2252 utils.Export(function(to) { | 2253 utils.Export(function(to) { |
2253 to.AddBoundMethod = AddBoundMethod; | 2254 to.AddBoundMethod = AddBoundMethod; |
2254 to.IntlParseDate = IntlParseDate; | 2255 to.IntlParseDate = IntlParseDate; |
2255 to.IntlParseNumber = IntlParseNumber; | 2256 to.IntlParseNumber = IntlParseNumber; |
2256 }); | 2257 }); |
2257 | 2258 |
2258 }) | 2259 }) |
OLD | NEW |