| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 %SetNativeFlag(func); | 80 %SetNativeFlag(func); |
| 81 %ToFastProperties(object); | 81 %ToFastProperties(object); |
| 82 } | 82 } |
| 83 | 83 |
| 84 /** | 84 /** |
| 85 * Adds bound method to the prototype of the given object. | 85 * Adds bound method to the prototype of the given object. |
| 86 */ | 86 */ |
| 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 // Making getter an anonymous function will cause |
| 91 // %DefineGetterPropertyUnchecked to properly set the "name" |
| 92 // property on each JSFunction instance created here, rather |
| 93 // than (as utils.InstallGetter would) on the SharedFunctionInfo |
| 94 // associated with all functions returned from AddBoundMethod. |
| 95 var getter = ANONYMOUS_FUNCTION(function() { |
| 91 if (!%IsInitializedIntlObjectOfType(this, type)) { | 96 if (!%IsInitializedIntlObjectOfType(this, type)) { |
| 92 throw MakeTypeError(kMethodCalledOnWrongObject, methodName); | 97 throw MakeTypeError(kMethodCalledOnWrongObject, methodName); |
| 93 } | 98 } |
| 94 if (IS_UNDEFINED(this[internalName])) { | 99 if (IS_UNDEFINED(this[internalName])) { |
| 95 var boundMethod; | 100 var boundMethod; |
| 96 if (IS_UNDEFINED(length) || length === 2) { | 101 if (IS_UNDEFINED(length) || length === 2) { |
| 97 boundMethod = (x, y) => implementation(this, x, y); | 102 boundMethod = ANONYMOUS_FUNCTION((x, y) => implementation(this, x, y)); |
| 98 } else if (length === 1) { | 103 } else if (length === 1) { |
| 99 boundMethod = x => implementation(this, x); | 104 boundMethod = ANONYMOUS_FUNCTION(x => implementation(this, x)); |
| 100 } else { | 105 } else { |
| 101 boundMethod = (...args) => { | 106 boundMethod = ANONYMOUS_FUNCTION((...args) => { |
| 102 // DateTimeFormat.format needs to be 0 arg method, but can stil | 107 // DateTimeFormat.format needs to be 0 arg method, but can still |
| 103 // receive optional dateValue param. If one was provided, pass it | 108 // receive an optional dateValue param. If one was provided, pass it |
| 104 // along. | 109 // along. |
| 105 if (args.length > 0) { | 110 if (args.length > 0) { |
| 106 return implementation(this, args[0]); | 111 return implementation(this, args[0]); |
| 107 } else { | 112 } else { |
| 108 return implementation(this); | 113 return implementation(this); |
| 109 } | 114 } |
| 110 } | 115 }); |
| 111 } | 116 } |
| 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); | 117 %SetNativeFlag(boundMethod); |
| 118 this[internalName] = boundMethod; | 118 this[internalName] = boundMethod; |
| 119 } | 119 } |
| 120 return this[internalName]; | 120 return this[internalName]; |
| 121 }; | 121 }); |
| 122 | 122 |
| 123 InstallGetter(obj.prototype, methodName, getter, DONT_ENUM); | 123 %FunctionRemovePrototype(getter); |
| 124 %DefineGetterPropertyUnchecked(obj.prototype, methodName, getter, DONT_ENUM); |
| 125 %SetNativeFlag(getter); |
| 124 } | 126 } |
| 125 | 127 |
| 126 // ------------------------------------------------------------------- | 128 // ------------------------------------------------------------------- |
| 127 | 129 |
| 128 var Intl = {}; | 130 var Intl = {}; |
| 129 | 131 |
| 130 %AddNamedProperty(global, "Intl", Intl, DONT_ENUM); | 132 %AddNamedProperty(global, "Intl", Intl, DONT_ENUM); |
| 131 | 133 |
| 132 /** | 134 /** |
| 133 * Caches available locales for each service. | 135 * Caches available locales for each service. |
| (...skipping 2115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2249 } | 2251 } |
| 2250 ); | 2252 ); |
| 2251 | 2253 |
| 2252 utils.Export(function(to) { | 2254 utils.Export(function(to) { |
| 2253 to.AddBoundMethod = AddBoundMethod; | 2255 to.AddBoundMethod = AddBoundMethod; |
| 2254 to.IntlParseDate = IntlParseDate; | 2256 to.IntlParseDate = IntlParseDate; |
| 2255 to.IntlParseNumber = IntlParseNumber; | 2257 to.IntlParseNumber = IntlParseNumber; |
| 2256 }); | 2258 }); |
| 2257 | 2259 |
| 2258 }) | 2260 }) |
| OLD | NEW |