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

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

Issue 699953003: Implement .fill() on typed arrays Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Make .fill() work only on typed arrays, use internal slot for length Created 6 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/harmony/typedarrays-fill.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 'use strict'; 5 'use strict';
6 6
7 // This file relies on the fact that the following declaration has been made 7 // This file relies on the fact that the following declaration has been made
8 // in runtime.js: 8 // in runtime.js:
9 // var $Array = global.Array; 9 // var $Array = global.Array;
10 10
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); 52 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f);
53 for (var i = 0; i < length; i++) { 53 for (var i = 0; i < length; i++) {
54 var element = this[i]; 54 var element = this[i];
55 // Prepare break slots for debugger step in. 55 // Prepare break slots for debugger step in.
56 if (stepping) %DebugPrepareStepInIfStepping(f); 56 if (stepping) %DebugPrepareStepInIfStepping(f);
57 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; 57 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver;
58 %_CallFunction(new_receiver, TO_OBJECT_INLINE(element), i, this, f); 58 %_CallFunction(new_receiver, TO_OBJECT_INLINE(element), i, this, f);
59 } 59 }
60 } 60 }
61
62
63 // ES6 draft 10-14-2014, section 22.1.3.6
64 function NAMEFill(value /* [, start [, end ] ] */) { // length == 1
65 if (!%IsTypedArray(this)) {
66 throw MakeTypeError('not_typed_array', []);
67 }
68
69 var length = %_TypedArrayGetLength(this);
70
71 var i = 0;
72 var end = length;
73
74 if (%_ArgumentsLength() > 1) {
75 i = %_Arguments(1);
76 i = TO_INTEGER(i);
77 if (%_ArgumentsLength() > 2) {
78 end = %_Arguments(2);
79 end = IS_UNDEFINED(end) ? length : TO_INTEGER(end);
80 }
81 }
82
83 if (i < 0) {
84 i += length;
85 if (i < 0) i = 0;
86 } else {
87 if (i > length) i = length;
88 }
89
90 if (end < 0) {
91 end += length;
92 if (end < 0) end = 0;
93 } else {
94 if (end > length) end = length;
95 }
96
97 for (; i < end; i++)
98 this[i] = value;
99 return this;
100 }
61 endmacro 101 endmacro
62 102
63 TYPED_ARRAYS(TYPED_ARRAY_HARMONY_ADDITIONS) 103 TYPED_ARRAYS(TYPED_ARRAY_HARMONY_ADDITIONS)
64 104
65 105
66 function HarmonyTypedArrayExtendPrototypes() { 106 function HarmonyTypedArrayExtendPrototypes() {
67 macro EXTEND_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) 107 macro EXTEND_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
68 %CheckIsBootstrapping(); 108 %CheckIsBootstrapping();
69 109
70 // Set up non-enumerable functions on the prototype object. 110 // Set up non-enumerable functions on the prototype object.
71 InstallFunctions(global.NAME.prototype, DONT_ENUM, $Array( 111 InstallFunctions(global.NAME.prototype, DONT_ENUM | DONT_DELETE | READ_ONLY,
72 "forEach", NAMEForEach 112 $Array(
73 )); 113 "forEach", NAMEForEach,
114 "fill", NAMEFill
115 )
116 );
74 endmacro 117 endmacro
75 118
76 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) 119 TYPED_ARRAYS(EXTEND_TYPED_ARRAY)
77 } 120 }
78 121
79 HarmonyTypedArrayExtendPrototypes(); 122 HarmonyTypedArrayExtendPrototypes();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/harmony/typedarrays-fill.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698