js/src/tests/ecma_6/Expressions/binary-literals.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Any copyright is dedicated to the Public Domain.
michael@0 2 // http://creativecommons.org/licenses/publicdomain/
michael@0 3
michael@0 4 //-----------------------------------------------------------------------------
michael@0 5 var BUGNUMBER = 894026;
michael@0 6 var summary = "Implement ES6 binary literals";
michael@0 7
michael@0 8 print(BUGNUMBER + ": " + summary);
michael@0 9
michael@0 10 /**************
michael@0 11 * BEGIN TEST *
michael@0 12 **************/
michael@0 13
michael@0 14 var chars = ['b', 'B'];
michael@0 15
michael@0 16 for (var i = 0; i < 2; i++)
michael@0 17 {
michael@0 18 if (i === 2)
michael@0 19 {
michael@0 20 chars.forEach(function(v)
michael@0 21 {
michael@0 22 try
michael@0 23 {
michael@0 24 eval('0' + v + i);
michael@0 25 throw "didn't throw";
michael@0 26 }
michael@0 27 catch (e)
michael@0 28 {
michael@0 29 assertEq(e instanceof SyntaxError, true,
michael@0 30 "no syntax error evaluating 0" + v + i + ", " +
michael@0 31 "got " + e);
michael@0 32 }
michael@0 33 });
michael@0 34 continue;
michael@0 35 }
michael@0 36
michael@0 37 for (var j = 0; j < 2; j++)
michael@0 38 {
michael@0 39 if (j === 2)
michael@0 40 {
michael@0 41 chars.forEach(function(v)
michael@0 42 {
michael@0 43 try
michael@0 44 {
michael@0 45 eval('0' + v + i + j);
michael@0 46 throw "didn't throw";
michael@0 47 }
michael@0 48 catch (e)
michael@0 49 {
michael@0 50 assertEq(e instanceof SyntaxError, true,
michael@0 51 "no syntax error evaluating 0" + v + i + j + ", " +
michael@0 52 "got " + e);
michael@0 53 }
michael@0 54 });
michael@0 55 continue;
michael@0 56 }
michael@0 57
michael@0 58 for (var k = 0; k < 2; k++)
michael@0 59 {
michael@0 60 if (k === 2)
michael@0 61 {
michael@0 62 chars.forEach(function(v)
michael@0 63 {
michael@0 64 try
michael@0 65 {
michael@0 66 eval('0' + v + i + j + k);
michael@0 67 throw "didn't throw";
michael@0 68 }
michael@0 69 catch (e)
michael@0 70 {
michael@0 71 assertEq(e instanceof SyntaxError, true,
michael@0 72 "no syntax error evaluating 0" + v + i + j + k + ", " +
michael@0 73 "got " + e);
michael@0 74 }
michael@0 75 });
michael@0 76 continue;
michael@0 77 }
michael@0 78
michael@0 79 chars.forEach(function(v)
michael@0 80 {
michael@0 81 assertEq(eval('0' + v + i + j + k), i * 4 + j * 2 + k);
michael@0 82 });
michael@0 83 }
michael@0 84 }
michael@0 85 }
michael@0 86
michael@0 87 chars.forEach(function(v)
michael@0 88 {
michael@0 89 try
michael@0 90 {
michael@0 91 }
michael@0 92 catch (e)
michael@0 93 {
michael@0 94 assertEq(e instanceof SyntaxError, true,
michael@0 95 "no syntax error evaluating 0" + v + ", got " + e);
michael@0 96 }
michael@0 97 });
michael@0 98
michael@0 99 // Off-by-one check: '/' immediately precedes '0'.
michael@0 100 assertEq(0b110/1, 6);
michael@0 101 assertEq(0B10110/1, 22);
michael@0 102
michael@0 103 function strict()
michael@0 104 {
michael@0 105 "use strict";
michael@0 106 return 0b11010101;
michael@0 107 }
michael@0 108 assertEq(strict(), 128 + 64 + 16 + 4 + 1);
michael@0 109
michael@0 110 /******************************************************************************/
michael@0 111
michael@0 112 if (typeof reportCompare === "function")
michael@0 113 reportCompare(true, true);
michael@0 114
michael@0 115 print("Tests complete");

mercurial