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

Side by Side Diff: src/harmony-typedarray.js

Issue 1166623004: Implement %TypedArray%.prototype.{toString,toLocaleString,join} (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix toString Created 5 years, 6 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 unified diff | Download patch
« no previous file with comments | « src/array.js ('k') | src/prologue.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 (function(global, utils) { 5 (function(global, utils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 14 matching lines...) Expand all
25 endmacro 25 endmacro
26 26
27 macro DECLARE_GLOBALS(NAME) 27 macro DECLARE_GLOBALS(NAME)
28 var GlobalNAME = global.NAME; 28 var GlobalNAME = global.NAME;
29 endmacro 29 endmacro
30 30
31 TYPED_ARRAYS(DECLARE_GLOBALS) 31 TYPED_ARRAYS(DECLARE_GLOBALS)
32 DECLARE_GLOBALS(Array) 32 DECLARE_GLOBALS(Array)
33 33
34 var ArrayFrom; 34 var ArrayFrom;
35 var ArrayToString;
35 var InnerArrayCopyWithin; 36 var InnerArrayCopyWithin;
36 var InnerArrayEvery; 37 var InnerArrayEvery;
37 var InnerArrayFill; 38 var InnerArrayFill;
38 var InnerArrayFilter; 39 var InnerArrayFilter;
39 var InnerArrayFind; 40 var InnerArrayFind;
40 var InnerArrayFindIndex; 41 var InnerArrayFindIndex;
41 var InnerArrayForEach; 42 var InnerArrayForEach;
42 var InnerArrayIndexOf; 43 var InnerArrayIndexOf;
44 var InnerArrayJoin;
43 var InnerArrayLastIndexOf; 45 var InnerArrayLastIndexOf;
44 var InnerArrayMap; 46 var InnerArrayMap;
45 var InnerArrayReverse; 47 var InnerArrayReverse;
46 var InnerArraySome; 48 var InnerArraySome;
47 var InnerArraySort; 49 var InnerArraySort;
50 var InnerArrayToLocaleString;
48 var IsNaN; 51 var IsNaN;
49 52
50 utils.Import(function(from) { 53 utils.Import(function(from) {
51 ArrayFrom = from.ArrayFrom; 54 ArrayFrom = from.ArrayFrom;
55 ArrayToString = from.ArrayToString;
52 InnerArrayCopyWithin = from.InnerArrayCopyWithin; 56 InnerArrayCopyWithin = from.InnerArrayCopyWithin;
53 InnerArrayEvery = from.InnerArrayEvery; 57 InnerArrayEvery = from.InnerArrayEvery;
54 InnerArrayFill = from.InnerArrayFill; 58 InnerArrayFill = from.InnerArrayFill;
55 InnerArrayFilter = from.InnerArrayFilter; 59 InnerArrayFilter = from.InnerArrayFilter;
56 InnerArrayFind = from.InnerArrayFind; 60 InnerArrayFind = from.InnerArrayFind;
57 InnerArrayFindIndex = from.InnerArrayFindIndex; 61 InnerArrayFindIndex = from.InnerArrayFindIndex;
58 InnerArrayForEach = from.InnerArrayForEach; 62 InnerArrayForEach = from.InnerArrayForEach;
59 InnerArrayIndexOf = from.InnerArrayIndexOf; 63 InnerArrayIndexOf = from.InnerArrayIndexOf;
64 InnerArrayJoin = from.InnerArrayJoin;
60 InnerArrayLastIndexOf = from.InnerArrayLastIndexOf; 65 InnerArrayLastIndexOf = from.InnerArrayLastIndexOf;
61 InnerArrayMap = from.InnerArrayMap; 66 InnerArrayMap = from.InnerArrayMap;
62 InnerArrayReverse = from.InnerArrayReverse; 67 InnerArrayReverse = from.InnerArrayReverse;
63 InnerArraySome = from.InnerArraySome; 68 InnerArraySome = from.InnerArraySome;
64 InnerArraySort = from.InnerArraySort; 69 InnerArraySort = from.InnerArraySort;
70 InnerArrayToLocaleString = from.InnerArrayToLocaleString;
65 IsNaN = from.IsNaN; 71 IsNaN = from.IsNaN;
66 }); 72 });
67 73
68 // ------------------------------------------------------------------- 74 // -------------------------------------------------------------------
69 75
70 function ConstructTypedArray(constructor, array) { 76 function ConstructTypedArray(constructor, array) {
71 // TODO(littledan): This is an approximation of the spec, which requires 77 // TODO(littledan): This is an approximation of the spec, which requires
72 // that only real TypedArray classes should be accepted (22.2.2.1.1) 78 // that only real TypedArray classes should be accepted (22.2.2.1.1)
73 if (!%IsConstructor(constructor) || IS_UNDEFINED(constructor.prototype) || 79 if (!%IsConstructor(constructor) || IS_UNDEFINED(constructor.prototype) ||
74 !%HasOwnProperty(constructor.prototype, "BYTES_PER_ELEMENT")) { 80 !%HasOwnProperty(constructor.prototype, "BYTES_PER_ELEMENT")) {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 function TypedArraySome(f, receiver) { 249 function TypedArraySome(f, receiver) {
244 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 250 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
245 251
246 var length = %_TypedArrayGetLength(this); 252 var length = %_TypedArrayGetLength(this);
247 253
248 return InnerArraySome(f, receiver, this, length); 254 return InnerArraySome(f, receiver, this, length);
249 } 255 }
250 %FunctionSetLength(TypedArraySome, 1); 256 %FunctionSetLength(TypedArraySome, 1);
251 257
252 258
259 // ES6 section 22.2.3.27
260 function TypedArrayToLocaleString() {
261 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
262
263 var length = %_TypedArrayGetLength(this);
264
265 return InnerArrayToLocaleString(this, length);
266 }
267
268 // ES6 section 22.2.3.28
269 function TypedArrayToString() {
270 return %_CallFunction(this, ArrayToString);
271 }
272
273 // ES6 section 22.2.3.14
274 function TypedArrayJoin(separator) {
275 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
276
277 var length = %_TypedArrayGetLength(this);
278
279 return InnerArrayJoin(separator, this, length);
280 }
281
282
253 // ES6 draft 08-24-14, section 22.2.2.2 283 // ES6 draft 08-24-14, section 22.2.2.2
254 function TypedArrayOf() { 284 function TypedArrayOf() {
255 var length = %_ArgumentsLength(); 285 var length = %_ArgumentsLength();
256 var array = new this(length); 286 var array = new this(length);
257 for (var i = 0; i < length; i++) { 287 for (var i = 0; i < length; i++) {
258 array[i] = %_Arguments(i); 288 array[i] = %_Arguments(i);
259 } 289 }
260 return array; 290 return array;
261 } 291 }
262 292
(...skipping 16 matching lines...) Expand all
279 309
280 // Set up non-enumerable functions on the prototype object. 310 // Set up non-enumerable functions on the prototype object.
281 utils.InstallFunctions(GlobalNAME.prototype, DONT_ENUM, [ 311 utils.InstallFunctions(GlobalNAME.prototype, DONT_ENUM, [
282 "copyWithin", TypedArrayCopyWithin, 312 "copyWithin", TypedArrayCopyWithin,
283 "every", TypedArrayEvery, 313 "every", TypedArrayEvery,
284 "fill", TypedArrayFill, 314 "fill", TypedArrayFill,
285 "filter", TypedArrayFilter, 315 "filter", TypedArrayFilter,
286 "find", TypedArrayFind, 316 "find", TypedArrayFind,
287 "findIndex", TypedArrayFindIndex, 317 "findIndex", TypedArrayFindIndex,
288 "indexOf", TypedArrayIndexOf, 318 "indexOf", TypedArrayIndexOf,
319 "join", TypedArrayJoin,
289 "lastIndexOf", TypedArrayLastIndexOf, 320 "lastIndexOf", TypedArrayLastIndexOf,
290 "forEach", TypedArrayForEach, 321 "forEach", TypedArrayForEach,
291 "map", TypedArrayMap, 322 "map", TypedArrayMap,
292 "reverse", TypedArrayReverse, 323 "reverse", TypedArrayReverse,
293 "some", TypedArraySome, 324 "some", TypedArraySome,
294 "sort", TypedArraySort 325 "sort", TypedArraySort,
326 "toString", TypedArrayToString,
327 "toLocaleString", TypedArrayToLocaleString
295 ]); 328 ]);
296 endmacro 329 endmacro
297 330
298 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) 331 TYPED_ARRAYS(EXTEND_TYPED_ARRAY)
299 332
300 }) 333 })
OLDNEW
« no previous file with comments | « src/array.js ('k') | src/prologue.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698