buffer-not-object-throws.js (1251B)
1 // Copyright (C) 2016 the V8 project authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-dataview-buffer-byteoffset-bytelength 6 description: > 7 Throws a TypeError if buffer is not Object 8 info: | 9 24.2.2.1 DataView (buffer, byteOffset, byteLength ) 10 11 1. If NewTarget is undefined, throw a TypeError exception. 12 2. If Type(buffer) is not Object, throw a TypeError exception. 13 ... 14 features: [Symbol] 15 ---*/ 16 17 var obj = { 18 valueOf: function() { 19 throw new Test262Error("buffer should be verified before byteOffset"); 20 } 21 }; 22 23 assert.throws(TypeError, function() { 24 new DataView(0, obj); 25 }, "0"); 26 27 assert.throws(TypeError, function() { 28 new DataView(1, obj); 29 }, "1"); 30 31 assert.throws(TypeError, function() { 32 new DataView("", obj); 33 }, "the empty string"); 34 35 assert.throws(TypeError, function() { 36 new DataView("buffer", obj); 37 }, "string"); 38 39 assert.throws(TypeError, function() { 40 new DataView(false, obj); 41 }, "false"); 42 43 assert.throws(TypeError, function() { 44 new DataView(true, obj); 45 }, "true"); 46 47 assert.throws(TypeError, function() { 48 new DataView(NaN, obj); 49 }, "NaN"); 50 51 assert.throws(TypeError, function() { 52 new DataView(Symbol("1"), obj); 53 }, "symbol"); 54 55 reportCompare(0, 0);