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

Side by Side Diff: test/mjsunit/harmony/typedarrays.js

Issue 14650014: Add type checks to typed array property getters. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Without rebase Created 7 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 TestSubArray(Uint8ClampedArray, 0xFF); 316 TestSubArray(Uint8ClampedArray, 0xFF);
317 317
318 function TestTypedArrayOutOfRange(constructor, value, result) { 318 function TestTypedArrayOutOfRange(constructor, value, result) {
319 var a = new constructor(1); 319 var a = new constructor(1);
320 a[0] = value; 320 a[0] = value;
321 assertSame(result, a[0]); 321 assertSame(result, a[0]);
322 } 322 }
323 323
324 TestTypedArrayOutOfRange(Uint8Array, 0x1FA, 0xFA); 324 TestTypedArrayOutOfRange(Uint8Array, 0x1FA, 0xFA);
325 TestTypedArrayOutOfRange(Uint8Array, -1, 0xFF); 325 TestTypedArrayOutOfRange(Uint8Array, -1, 0xFF);
326
326 TestTypedArrayOutOfRange(Int8Array, 0x1FA, 0x7A - 0x80); 327 TestTypedArrayOutOfRange(Int8Array, 0x1FA, 0x7A - 0x80);
327 328
328 TestTypedArrayOutOfRange(Uint16Array, 0x1FFFA, 0xFFFA); 329 TestTypedArrayOutOfRange(Uint16Array, 0x1FFFA, 0xFFFA);
329 TestTypedArrayOutOfRange(Uint16Array, -1, 0xFFFF); 330 TestTypedArrayOutOfRange(Uint16Array, -1, 0xFFFF);
330 TestTypedArrayOutOfRange(Int16Array, 0x1FFFA, 0x7FFA - 0x8000); 331 TestTypedArrayOutOfRange(Int16Array, 0x1FFFA, 0x7FFA - 0x8000);
331 332
332 TestTypedArrayOutOfRange(Uint32Array, 0x1FFFFFFFA, 0xFFFFFFFA); 333 TestTypedArrayOutOfRange(Uint32Array, 0x1FFFFFFFA, 0xFFFFFFFA);
333 TestTypedArrayOutOfRange(Uint32Array, -1, 0xFFFFFFFF); 334 TestTypedArrayOutOfRange(Uint32Array, -1, 0xFFFFFFFF);
334 TestTypedArrayOutOfRange(Int32Array, 0x1FFFFFFFA, 0x7FFFFFFA - 0x80000000); 335 TestTypedArrayOutOfRange(Int32Array, 0x1FFFFFFFA, 0x7FFFFFFA - 0x80000000);
335 336
336 TestTypedArrayOutOfRange(Uint8ClampedArray, 0x1FA, 0xFF); 337 TestTypedArrayOutOfRange(Uint8ClampedArray, 0x1FA, 0xFF);
337 TestTypedArrayOutOfRange(Uint8ClampedArray, -1, 0); 338 TestTypedArrayOutOfRange(Uint8ClampedArray, -1, 0);
338 339
340 var typedArrayConstructors = [
341 Uint8Array,
342 Int8Array,
343 Uint16Array,
344 Int16Array,
345 Uint32Array,
346 Int32Array,
347 Uint8ClampedArray,
348 Float32Array,
349 Float64Array]
339 function TestPropertyTypeChecks(constructor) { 350 function TestPropertyTypeChecks(constructor) {
340 function CheckThrows(name) { 351 var a = new constructor();
352 function CheckProperty(name) {
341 var d = Object.getOwnPropertyDescriptor(constructor.prototype, name); 353 var d = Object.getOwnPropertyDescriptor(constructor.prototype, name);
342 var o = {} 354 var o = {}
343 assertThrows(function() {d.get.call(o);}, TypeError); 355 assertThrows(function() {d.get.call(o);}, TypeError);
356 d.get.call(a); // shouldn't throw
357 for (var i = 0 ; i < typedArrayConstructors.length; i++) {
358 d.get.call(new typedArrayConstructors[i](10));
359 }
344 } 360 }
345 361
346 CheckThrows("buffer"); 362 CheckProperty("buffer");
347 CheckThrows("byteOffset"); 363 CheckProperty("byteOffset");
348 CheckThrows("byteLength"); 364 CheckProperty("byteLength");
349 CheckThrows("length"); 365 CheckProperty("length");
350 } 366 }
351 367
352 TestPropertyTypeChecks(Uint8Array); 368 for(i = 0; i < typedArrayConstructors.lenght; i++) {
353 TestPropertyTypeChecks(Int8Array); 369 TestPropertyTypeChecks(typedArrayConstructors[i]);
354 TestPropertyTypeChecks(Uint16Array); 370 }
355 TestPropertyTypeChecks(Int16Array); 371
356 TestPropertyTypeChecks(Uint32Array);
357 TestPropertyTypeChecks(Int32Array);
358 TestPropertyTypeChecks(Uint8ClampedArray);
359 TestPropertyTypeChecks(Float32Array);
360 TestPropertyTypeChecks(Float64Array);
361 372
362 // General tests for properties 373 // General tests for properties
363 374
364 // Test property attribute [[Enumerable]] 375 // Test property attribute [[Enumerable]]
365 function TestEnumerable(func, obj) { 376 function TestEnumerable(func, obj) {
366 function props(x) { 377 function props(x) {
367 var array = []; 378 var array = [];
368 for (var p in x) array.push(p); 379 for (var p in x) array.push(p);
369 return array.sort(); 380 return array.sort();
370 } 381 }
371 assertArrayEquals([], props(func)); 382 assertArrayEquals([], props(func));
372 assertArrayEquals([], props(func.prototype)); 383 assertArrayEquals([], props(func.prototype));
373 if (obj) 384 if (obj)
374 assertArrayEquals([], props(obj)); 385 assertArrayEquals([], props(obj));
375 } 386 }
376 TestEnumerable(ArrayBuffer, new ArrayBuffer()); 387 TestEnumerable(ArrayBuffer, new ArrayBuffer());
377 TestEnumerable(Uint8Array); 388 for(i = 0; i < typedArrayConstructors.lenght; i++) {
378 TestEnumerable(Int8Array); 389 TestEnumerable(typedArrayConstructors[i]);
379 TestEnumerable(Uint16Array); 390 }
380 TestEnumerable(Int16Array);
381 TestEnumerable(Uint32Array);
382 TestEnumerable(Int32Array);
383 TestEnumerable(Float32Array);
384 TestEnumerable(Uint8ClampedArray);
385 391
386 // Test arbitrary properties on ArrayBuffer 392 // Test arbitrary properties on ArrayBuffer
387 function TestArbitrary(m) { 393 function TestArbitrary(m) {
388 function TestProperty(map, property, value) { 394 function TestProperty(map, property, value) {
389 map[property] = value; 395 map[property] = value;
390 assertEquals(value, map[property]); 396 assertEquals(value, map[property]);
391 } 397 }
392 for (var i = 0; i < 20; i++) { 398 for (var i = 0; i < 20; i++) {
393 TestProperty(m, i, 'val' + i); 399 TestProperty(m, i, 'val' + i);
394 TestProperty(m, 'foo' + i, 'bar' + i); 400 TestProperty(m, 'foo' + i, 'bar' + i);
395 } 401 }
396 } 402 }
397 TestArbitrary(new ArrayBuffer(256)); 403 TestArbitrary(new ArrayBuffer(256));
404 for(i = 0; i < typedArrayConstructors.lenght; i++) {
405 TestArbitary(new typedArrayConstructors[i](10));
406 }
407
408
398 409
399 // Test direct constructor call 410 // Test direct constructor call
400 assertTrue(ArrayBuffer() instanceof ArrayBuffer); 411 assertTrue(ArrayBuffer() instanceof ArrayBuffer);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698