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

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

Issue 660863003: Implement .of() on typed arrays (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 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 | Annotate | Revision Log
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 // ES6 draft 08-24-14, section 22.2.2.2
63 function NAMEOf() { // length == 0
64 var length = %_ArgumentsLength();
65 // TODO: Implement IsConstructor (ES6 section 7.2.5)
66 if (!IS_SPEC_FUNCTION(this)) {
wingo 2014/10/21 15:23:13 what does this case check? wouldn't this be caugh
67 throw MakeTypeError('incompatible_method_receiver',
68 ['NAME.of', this]);
69 }
70
71 var array = new this(length);
72 for (var i = 0; i < length; i++) {
73 array[i] = %_Arguments(i);
74 }
75 // Typed arrays update the "length" property themselves. If the "of"
76 // method has been transplanted to some other constructor, the
77 // length has to be set (which may optionally trigger a setter).
78 if (!%IsTypedArray(array)) {
wingo 2014/10/21 15:23:12 This isn't in the spec.
79 array.length = length;
80 }
81 return array;
82 }
83
61 endmacro 84 endmacro
62 85
63 TYPED_ARRAYS(TYPED_ARRAY_HARMONY_ADDITIONS) 86 TYPED_ARRAYS(TYPED_ARRAY_HARMONY_ADDITIONS)
64 87
65 88
66 function HarmonyTypedArrayExtendPrototypes() { 89 function HarmonyTypedArrayExtendPrototypes() {
67 macro EXTEND_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) 90 macro EXTEND_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
68 %CheckIsBootstrapping(); 91 %CheckIsBootstrapping();
69 92
93 // Set up non-enumerable functions on the object.
94 InstallFunctions(global.NAME, DONT_ENUM, $Array(
95 "of", NAMEOf
wingo 2014/10/21 15:23:12 This outer function name is a bit misleading -- we
96 ));
97
70 // Set up non-enumerable functions on the prototype object. 98 // Set up non-enumerable functions on the prototype object.
71 InstallFunctions(global.NAME.prototype, DONT_ENUM, $Array( 99 InstallFunctions(global.NAME.prototype, DONT_ENUM, $Array(
72 "forEach", NAMEForEach 100 "forEach", NAMEForEach
73 )); 101 ));
74 endmacro 102 endmacro
75 103
76 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) 104 TYPED_ARRAYS(EXTEND_TYPED_ARRAY)
77 } 105 }
78 106
79 HarmonyTypedArrayExtendPrototypes(); 107 HarmonyTypedArrayExtendPrototypes();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/harmony/typedarrays-of.js » ('j') | test/mjsunit/harmony/typedarrays-of.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698