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 3 // found in the LICENSE file. 4 5 (function(global, utils) { 6 7 "use strict"; 8 9 %CheckIsBootstrapping(); 10 11 // ------------------------------------------------------------------- 12 // Imports 13 14 // array.js has to come before typedarray.js for this to work 15 var ArrayToString = utils.ImportNow("ArrayToString"); 16 var InnerArrayJoin; 17 var InnerArrayToLocaleString; 18 19 macro TYPED_ARRAYS(FUNCTION) 20 FUNCTION(Uint8Array, 1) 21 FUNCTION(Int8Array, 1) 22 FUNCTION(Uint16Array, 2) 23 FUNCTION(Int16Array, 2) 24 FUNCTION(Uint32Array, 4) 25 FUNCTION(Int32Array, 4) 26 FUNCTION(Float32Array, 4) 27 FUNCTION(Float64Array, 8) 28 FUNCTION(Uint8ClampedArray, 1) 29 FUNCTION(BigUint64Array, 8) 30 FUNCTION(BigInt64Array, 8) 31 endmacro 32 33 macro DECLARE_GLOBALS(NAME, SIZE) 34 var GlobalNAME = global.NAME; 35 endmacro 36 37 TYPED_ARRAYS(DECLARE_GLOBALS) 38 39 macro IS_TYPEDARRAY(arg) 40 (%_IsTypedArray(arg)) 41 endmacro 42 43 var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array); 44 45 utils.Import(function(from) { 46 InnerArrayJoin = from.InnerArrayJoin; 47 InnerArrayToLocaleString = from.InnerArrayToLocaleString; 48 }); 49 50 // --------------- Typed Arrays --------------------- 51 52 // ES6 section 22.2.3.5.1 ValidateTypedArray ( O ) 53 function ValidateTypedArray(array, methodName) { 54 if (!IS_TYPEDARRAY(array)) throw %make_type_error(kNotTypedArray); 55 56 if (%ArrayBufferViewWasNeutered(array)) 57 throw %make_type_error(kDetachedOperation, methodName); 58 } 59 60 61 // ES6 section 22.2.3.27 62 // ecma402 #sup-array.prototype.tolocalestring 63 DEFINE_METHOD( 64 GlobalTypedArray.prototype, 65 toLocaleString() { 66 ValidateTypedArray(this, "%TypedArray%.prototype.toLocaleString"); 67 68 var locales = arguments[0]; 69 var options = arguments[1]; 70 var length = %TypedArrayGetLength(this); 71 return InnerArrayToLocaleString(this, length, locales, options); 72 } 73 ); 74 75 76 // ES6 section 22.2.3.14 77 DEFINE_METHOD( 78 GlobalTypedArray.prototype, 79 join(separator) { 80 ValidateTypedArray(this, "%TypedArray%.prototype.join"); 81 82 var length = %TypedArrayGetLength(this); 83 84 return InnerArrayJoin(separator, this, length); 85 } 86 ); 87 88 // ------------------------------------------------------------------- 89 90 %AddNamedProperty(GlobalTypedArray.prototype, "toString", ArrayToString, 91 DONT_ENUM); 92 93 }) 94