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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 new GlobalRegExp('^([A-Za-z]+)((?:[_-][A-Za-z]+)+)*$'); | 195 new GlobalRegExp('^([A-Za-z]+)((?:[_-][A-Za-z]+)+)*$'); |
196 } | 196 } |
197 return TIMEZONE_NAME_LOCATION_PART_RE; | 197 return TIMEZONE_NAME_LOCATION_PART_RE; |
198 } | 198 } |
199 | 199 |
200 /** | 200 /** |
201 * Adds bound method to the prototype of the given object. | 201 * Adds bound method to the prototype of the given object. |
202 */ | 202 */ |
203 function addBoundMethod(obj, methodName, implementation, length) { | 203 function addBoundMethod(obj, methodName, implementation, length) { |
204 %CheckIsBootstrapping(); | 204 %CheckIsBootstrapping(); |
205 var internalName = %CreatePrivateSymbol(methodName); | |
205 function getter() { | 206 function getter() { |
206 if (!%IsInitializedIntlObject(this)) { | 207 if (!%IsInitializedIntlObject(this)) { |
207 throw MakeTypeError(kMethodCalledOnWrongObject, methodName); | 208 throw MakeTypeError(kMethodCalledOnWrongObject, methodName); |
208 } | 209 } |
209 var internalName = '__bound' + methodName + '__'; | |
210 if (IS_UNDEFINED(this[internalName])) { | 210 if (IS_UNDEFINED(this[internalName])) { |
211 var that = this; | |
212 var boundMethod; | 211 var boundMethod; |
213 if (IS_UNDEFINED(length) || length === 2) { | 212 if (IS_UNDEFINED(length) || length === 2) { |
214 boundMethod = function(x, y) { | 213 boundMethod = (x, y) => implementation(this, x, y); |
215 if (!IS_UNDEFINED(new.target)) { | |
216 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | |
217 } | |
218 return implementation(that, x, y); | |
219 } | |
220 } else if (length === 1) { | 214 } else if (length === 1) { |
221 boundMethod = function(x) { | 215 boundMethod = x => implementation(this, x); |
222 if (!IS_UNDEFINED(new.target)) { | |
223 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | |
224 } | |
225 return implementation(that, x); | |
226 } | |
227 } else { | 216 } else { |
228 boundMethod = function() { | 217 boundMethod = (...args) => { |
229 if (!IS_UNDEFINED(new.target)) { | |
230 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | |
231 } | |
232 // DateTimeFormat.format needs to be 0 arg method, but can stil | 218 // DateTimeFormat.format needs to be 0 arg method, but can stil |
233 // receive optional dateValue param. If one was provided, pass it | 219 // receive optional dateValue param. If one was provided, pass it |
234 // along. | 220 // along. |
235 if (arguments.length > 0) { | 221 if (args.length > 0) { |
236 return implementation(that, arguments[0]); | 222 return implementation(this, args[0]); |
237 } else { | 223 } else { |
238 return implementation(that); | 224 return implementation(this); |
239 } | 225 } |
240 } | 226 } |
241 } | 227 } |
242 %FunctionSetName(boundMethod, internalName); | 228 // TODO(littledan): Once function name reform is shipped, remove the |
229 // following line and wrap the boundMethod definition in an anonymous | |
230 // funciton macro. | |
adamk
2016/02/23 23:14:56
Typo nit: s/funciton/function/
| |
231 %FunctionSetName(boundMethod, '__bound' + methodName + '__'); | |
243 %FunctionRemovePrototype(boundMethod); | 232 %FunctionRemovePrototype(boundMethod); |
244 %SetNativeFlag(boundMethod); | 233 %SetNativeFlag(boundMethod); |
245 this[internalName] = boundMethod; | 234 this[internalName] = boundMethod; |
246 } | 235 } |
247 return this[internalName]; | 236 return this[internalName]; |
248 } | 237 } |
249 | 238 |
250 %FunctionSetName(getter, methodName); | 239 %FunctionSetName(getter, methodName); |
251 %FunctionRemovePrototype(getter); | 240 %FunctionRemovePrototype(getter); |
252 %SetNativeFlag(getter); | 241 %SetNativeFlag(getter); |
(...skipping 1935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2188 } | 2177 } |
2189 | 2178 |
2190 var locales = arguments[0]; | 2179 var locales = arguments[0]; |
2191 var options = arguments[1]; | 2180 var options = arguments[1]; |
2192 return toLocaleDateTime( | 2181 return toLocaleDateTime( |
2193 this, locales, options, 'time', 'time', 'dateformattime'); | 2182 this, locales, options, 'time', 'time', 'dateformattime'); |
2194 } | 2183 } |
2195 ); | 2184 ); |
2196 | 2185 |
2197 }) | 2186 }) |
OLD | NEW |