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

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

Issue 737483003: Implement .every() on typed arrays Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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
« no previous file with comments | « no previous file | test/mjsunit/harmony/typedarrays-every.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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 61
62 // ES6 draft 09-14-14, section 22.2.3.7
63 function NAMEEvery(f /* thisArg */) { // length == 1
64 if (!%IsTypedArray(this)) {
65 throw MakeTypeError('not_typed_array', []);
66 }
67 if (!IS_SPEC_FUNCTION(f)) {
68 throw MakeTypeError('called_non_callable', [ f ]);
69 }
70
71 var length = %_TypedArrayGetLength(this);
72 var receiver;
73
74 if (%_ArgumentsLength() > 1) {
75 receiver = %_Arguments(1);
76 }
77
78 var needs_wrapper = false;
79 if (IS_NULL_OR_UNDEFINED(receiver)) {
80 receiver = %GetDefaultReceiver(f) || receiver;
81 } else {
82 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver);
83 }
84
85 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f);
86 for (var i = 0; i < length; i++) {
87 var element = this[i];
88 // Prepare break slots for debugger step in.
89 if (stepping) %DebugPrepareStepInIfStepping(f);
90 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver;
91 if (!%_CallFunction(new_receiver, TO_OBJECT_INLINE(element), i, this, f))
92 return false;
93 }
94 return true;
95 }
96
62 // ES6 draft 08-24-14, section 22.2.2.2 97 // ES6 draft 08-24-14, section 22.2.2.2
63 function NAMEOf() { // length == 0 98 function NAMEOf() { // length == 0
64 var length = %_ArgumentsLength(); 99 var length = %_ArgumentsLength();
65 var array = new this(length); 100 var array = new this(length);
66 for (var i = 0; i < length; i++) { 101 for (var i = 0; i < length; i++) {
67 array[i] = %_Arguments(i); 102 array[i] = %_Arguments(i);
68 } 103 }
69 return array; 104 return array;
70 } 105 }
71 106
72 endmacro 107 endmacro
73 108
74 TYPED_ARRAYS(TYPED_ARRAY_HARMONY_ADDITIONS) 109 TYPED_ARRAYS(TYPED_ARRAY_HARMONY_ADDITIONS)
75 110
76 111
77 function HarmonyTypedArrayExtendPrototypes() { 112 function HarmonyTypedArrayExtendPrototypes() {
78 macro EXTEND_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) 113 macro EXTEND_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
79 %CheckIsBootstrapping(); 114 %CheckIsBootstrapping();
80 115
81 // Set up non-enumerable functions on the object. 116 // Set up non-enumerable functions on the object.
82 InstallFunctions(global.NAME, DONT_ENUM | DONT_DELETE | READ_ONLY, $Array( 117 InstallFunctions(global.NAME, DONT_ENUM | DONT_DELETE | READ_ONLY, $Array(
83 "of", NAMEOf 118 "of", NAMEOf
84 )); 119 ));
85 120
86 // Set up non-enumerable functions on the prototype object. 121 // Set up non-enumerable functions on the prototype object.
87 InstallFunctions(global.NAME.prototype, DONT_ENUM, $Array( 122 InstallFunctions(global.NAME.prototype, DONT_ENUM | DONT_DELETE | READ_ONLY, $ Array(
88 "forEach", NAMEForEach 123 "forEach", NAMEForEach,
124 "every", NAMEEvery
89 )); 125 ));
90 endmacro 126 endmacro
91 127
92 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) 128 TYPED_ARRAYS(EXTEND_TYPED_ARRAY)
93 } 129 }
94 130
95 HarmonyTypedArrayExtendPrototypes(); 131 HarmonyTypedArrayExtendPrototypes();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/harmony/typedarrays-every.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698