• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
15var ArrayToString = utils.ImportNow("ArrayToString");
16var InnerArrayJoin;
17var InnerArrayToLocaleString;
18
19macro TYPED_ARRAYS(FUNCTION)
20FUNCTION(Uint8Array, 1)
21FUNCTION(Int8Array, 1)
22FUNCTION(Uint16Array, 2)
23FUNCTION(Int16Array, 2)
24FUNCTION(Uint32Array, 4)
25FUNCTION(Int32Array, 4)
26FUNCTION(Float32Array, 4)
27FUNCTION(Float64Array, 8)
28FUNCTION(Uint8ClampedArray, 1)
29FUNCTION(BigUint64Array, 8)
30FUNCTION(BigInt64Array, 8)
31endmacro
32
33macro DECLARE_GLOBALS(NAME, SIZE)
34var GlobalNAME = global.NAME;
35endmacro
36
37TYPED_ARRAYS(DECLARE_GLOBALS)
38
39macro IS_TYPEDARRAY(arg)
40(%_IsTypedArray(arg))
41endmacro
42
43var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array);
44
45utils.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 )
53function 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
63DEFINE_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
77DEFINE_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