1// Copyright 2017 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// This is intended for permanent JS behavior changes for mocking out 6// non-deterministic behavior. For temporary suppressions, please refer to 7// v8_suppressions.js. 8// This mocks only architecture specific differences. Refer to v8_mocks.js 9// for the general case. 10// This file is loaded before each correctness test cases and won't get 11// minimized. 12 13// Mock maximum typed-array length and limit to 1MiB. 14(function () { 15 var mock = function(arrayType) { 16 var handler = { 17 construct: function(target, args) { 18 var arrayLength = args[0] 19 if (args.length > 0 && 20 Number.isInteger(args[0]) && 21 args[0] > 1048576) { 22 args[0] = 1048576 23 } else if (args.length > 2 && 24 Number.isInteger(args[2]) && 25 args[2] > 1048576) { 26 args[2] = 1048576 27 } 28 return new ( 29 Function.prototype.bind.apply(arrayType, [null].concat(args))); 30 }, 31 }; 32 return new Proxy(arrayType, handler); 33 } 34 35 ArrayBuffer = mock(ArrayBuffer); 36 Int8Array = mock(Int8Array); 37 Uint8Array = mock(Uint8Array); 38 Uint8ClampedArray = mock(Uint8ClampedArray); 39 Int16Array = mock(Int16Array); 40 Uint16Array = mock(Uint16Array); 41 Int32Array = mock(Int32Array); 42 Uint32Array = mock(Uint32Array); 43 Float32Array = mock(Float32Array); 44 Float64Array = mock(Float64Array); 45})(); 46 47// Mock typed array set function and limit maximum offset to 1MiB. 48(function () { 49 var typedArrayTypes = [ 50 Int8Array, 51 Uint8Array, 52 Uint8ClampedArray, 53 Int16Array, 54 Uint16Array, 55 Int32Array, 56 Uint32Array, 57 Float32Array, 58 Float64Array, 59 ]; 60 for (let typedArrayType of typedArrayTypes) { 61 let set = typedArrayType.prototype.set 62 typedArrayType.prototype.set = function(array, offset) { 63 set.apply(this, [array, offset > 1048576 ? 1048576 : offset]) 64 }; 65 } 66})(); 67