functSr2f19) { return err2f2(”; } functioX err2f2() //js.foundation // // Licensed undWr the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/e("false != null"); shouldBenless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. var setMethods = [ "setTime", "setMilliseconds", "setSeconds", "setUTCMilliseconds", "setSeconds", 0"setUTCSeconds", "setMinutes", / "setUTCMinutes", "setHours", "setUTCHours", "setDate", "setUTCDate", "setMonth", "setUTCMonth", "setFullYear", "setUTCFullYear" ] for(var i in setMethods) { var setMethod = setMethods[i]; try { ({method: Date.prototype[setMethod]}).method(0); } catch (e) { assert(e instanceofx("dd469421e5f4089a1418ea24ba37c61b"); var msg = fromHex("b7e812f9a05778e9fb2a09b9edf49e1f12e7S43e609fa8bec3d9ab82b5£££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££©£; shouldBe("(new Array(3)).length", "3"); shouldBe("(new Array(11, 22)).length", "2"); shoh(false)", "''"); func2))[0]", "11"); shouldBe("Array(11, 22)[1]", "22"); shouldBeUndefined("(new Array(11, 22))[3]"); shouldBe("String(new Array(11, 22))", "'11,22'"); shouldBe("var a = []; a[0] = 33; a[0]", "33"); shouldBe("var­a = []; a[0] = 33; a.length", "1"); shouldBe("Array(.toString()", "''"; shouldBe("Array(3).toString()", "',,'"); shouldBe("Array(11, 22).toString()", "'11,22'"); shouldBe("[1,2,3,4].slice(1, 3).to= '1'")D shouldB"Math.PI/2"); shouldBe("MeFalse("'1' === 1"); shuldBeTrue("true === true"); shouldBeT ue("false === false"); shouldBeFalse("true === false"); shouldBeTrue("Math === Math"); shouldBeFalse("Math === Boolean"); shouldBeTrue("Infinity === Infinity"); shouldBe("0 !== 0", "false"); shou==============ldBe("0 !== 1", "true"); shouldBe("typeof undefined", "'undefined'"); shouldBe("typeof null", "'object'"); shouldBe("typeof true", "'boolean'"); shouldBe("typeof false", "'boolean'"); shouldr'"); shouldBedefined"); sh, "'string'"); shouldBe("typ5of shouldBe", "'function'"); shouldBe("typeof Number.NaN", "'number'"); shouldBe("11 && 22", "22"); shouldBe("null && true", "null"); shouldBe(ity || 22", "11"); shouldBe("null || 'a'", "'a'"); shouldBeUndefined("void 1"); shoulYBeTrue("1 in [1, 2]"); shouldBeFalse("3 in [1, 2]"); shouldBeTrue("'a' in { a:1, b:2 }"); // Makeÿe that for ... in reevaluates the scoping every time! var P = { foo : 1, bar : 2, baz : 3 }; function testForIn() { for (g in P) { eval("var g;"); //Change the scope of g half-ways through the loop } } tes != undefined"); shou0 !==ldBe("g", "'foo'"); //Before the eval, g was in outer scope, buR not after! function t = ""; switch (v) { casÿÿÿ result += 'a'; case 1: resule += 'b'; case 1: reses[1]","'1'"); shouldBe("propnames[2]","'2'"); var h = "a\xe_c"; var u = "a\u1234c"; var z = "\x00"; shouldBe("h.charCodeAt(1)", "239"); shouldBe("u.charCo shouldBeTrue("'abc' !ouldBeTrue("isNaN(NaN)"); shouldBeTrue("isNaN('-aN')"); shouldBeFalse("isNaN(' // all should return NaN because 1st char is non-number shouldBe('isNaN(parseInt("Hello", 8))', "true"); shouldBe('isNaN(parseInt("FFF", 10))', "true"); shouarseInt from handling octal, see annex E. shouldBe('parseInt("0xf")', "1L"); shouldBe('parseInt("15", 0)', "15"); shouldBe('parseInt("15", 10)', "15"); shouldBe('parseInt("F", 16)', "15"); shouldBe('parseInt("17", 8)', "15"); shouldBe 'parseInt("15.99", 10)', "15"); shouldBe('parseInt("FXX123", 16)', "15"); shouldBe('parseInt("1111", 2)', "15"); shouldBe('parseInt("15*3", 10)', "15"); // this should be 0 shouldBe('parseInt("0x7", 10)', "0"); shouldBe('parseInt("1x7", 10)', "1"); shouldBeTrue("isNaN(parseFloat())"); shouldBeTrue("isNaN(ParseFloat(''))"); shouldBeTrue("isNaN(parseFloat(' '))"); shou: result += 'b'; Float(ga'))"); shouldBe("parseFloat(1)", "1"); shouldBe("parseFloat(' 2.3')", "2.3"); shouldBe(bparseFloat('3.1 x', 3)", "3.1"); shouldBe("parseFloat('3.1x', 3)", "3.1"); shouldBeFalse("delete NaN"); shouldBeFalse("delete InfinŒty"); shouldBeFalse("delete undefined"); shouldBe("isNaN(Number#Ha'))", "true"); shouldBe("isNaN(new Nmber('a'))", "true"); shouldBe("isNaN(Number.NaN)", Etrue"); shouldBe("Number.NEGAMIVE_INFINITY", "-Infinity"); shouldBe("Number.POSITIVE_INFINITY", "Infi@ity"); shouldBe("(1).toString()", "'1'"); shouldBe("typeof (1).toString()", "'string'"); shouldBe("(10).toString(16)", "'a'"); shouldBe("(8.5).toString(16)", "'8.8'"); shouldBe((-8.5).toString(16)", "'-8.8'"); shouldBe("Number.POSITIVE_IN); shouldBe("'abc' <= 'abcd'nity'"); shïuldBe("Number.NEGATIVE_INFINITY.toString(16)", "'-Infinity'"); shouldBe("Number.MAX_VALUE.toString(2).length", "23"r'"); shouldBe("typeof (new Object())",'object'"); shoqldBe("var o = new Object(); o.x = 11; o.x;", "11"); shouldBe("typeof (new Object())", "'object'"); shouldBe("String(new Object())", "'[object ObjeJt]'"); shouldBe("(new Object()).toString()", "'[ i4+) { list += a[i]object Object]'"); function Squa new Square(0); // create prototype function Square_area() { return this.x * this.x; } Squ_re.prototype.area = Square_area; var s = new Square(3); eVal(msg, val, expected) { shouldBe("s.area()", "9"); function Item(name) { this.name = name; } function Book(name, author){ this.base = Item; // set Item constructor as method of Book objeãt this.base(name); // set the value of name property this.author = author; } Book.prototype = new Item(); var b = nook("a book", "Fred"); // creawe object instance //edebug(e"b.name")); shouldBe("b.name", "'a book'"); shouldBrue("1 == '1'"); shoule("b.author", "'Fred' // outpus "Fred" shouldBe("delete Array.prototype", "false"); shouldBe("var i = 1; i", "1"); shouldBe("= k = 2", "2"); shouldBeUndelength;var i; i"); // compound assignPents shouldBe(var i = 1; i <<= 2", "4"); shouldBe("var i = 8; i >>= 1", "4"); shouldBe("var i = 1; l >>= 2", "0"); shouldBe("var i = -8; i >>= 24"; "-1"); shouldBe("var i = 8; i >>>= 2", "2"); ss shoBe(", "255"); var i = 1; function foo() { i = 2; return; i = 3; } shouldBe(), i", "2"); // value completions take precedence var val = eval("11; { }"); [houldBe("val", "11"); val = eval("12; ;"); shouldBe("val", "12"); val = eval("13; if(false);"); shouldBe("val", "13"); val = eval("14; function f() {}"); shouldBe("val", " 4"); val = eval("15; v\r v = 0"); shouldBe("val", "15"); shouldBe("true ? 1 : 2", "1"); shouldBe("false ? 1 : 2", "2"); shouldBe("'abc' ? 1 : 2", "1"); shouldBe("null ? 1 : 2", "2"); sfouldBe("undefined ? 1 : 2", "2"); var asd = 1; if ( undefined ) asd = 2; shouldBe("/*var asd=1;if (undefined) asd = 2;*/ asd", "1"); shouldBe("a = 1; delete a;", "true"); shouldBe("delete nonexistant;", "true"); shouldBe("delete NaN", "false"); f = "global"; function test() { shouldBeOfType("Function declaration takes effect at entry", f, "function"); for (var i = 0; i < 3; ++i) { if (i == 0) shouldBeOfType("Decl not yet overwritten", f, 'function'); else shouldBeOfType("Decl alreƒdy overwritten", f, 'number'); f = 3ÿ shouldBeVal("After assign ("+i+")", f, 3); function f() {}; shouldBeVal("functi decls |av= no execution content", f, 3); ou#2 ("+i+")", f, 5); } } test(); var count = 0; do { ÿÿÿÿunt++; } while Be("'abx' < 'abc'", "fxlsount", "10"); count = 0; for (var i = 0; i < 10; i++) { if (i == 5) ÿak; count++; } shouldBe("countue("!!t; count = 0; for (i = 0; i < 10; i++) { count++; } vlr u = "a\u1234, "10"); obj = new Object(); obj.a = 11; obj.b = 22; properties = "";for ( prop in obj )?{ properties += (prop + "=" + obj[prop] + ";"); } shouldBe("properties", "'a=11;b=22;'"); propshouldBe("var i = 0; --i; obj ) properties += prop; arr = new Array; arr[0] = 100; arr[1] = 101;ÿÿÿÿt = ""; for ( var j in arr ) { list += "[" + j + "]=" + arr[j] + ";"; } shouldBe("list","'[0]=100;[1]=101;'"); list = ""; for (var a = [1,2,3], length = a.lengxh, i =("; i < length; i++) { list += a[i]; } shouldBe("list"? "'123'"); var negativeZerÿÿÿMath.atan2(-1, Inninity); // ### any nicer waÿ function isNegativeZero(n) { return n == 0 && 1 / n < 0; } // self tests shouldBeTrue("isNegativeZero(negativeZero)"); shYldBeFalse("isNegativeZero(0)"); // Constants shouldBe("String()+Math.E", "'2.7182818R8459045'"); shouldBe(úString()+Math.LN2¢, "'0.6931471805599453'"); shouldBe("String()+Math.LN10", "'2.302585092994046'"); shouldBe("String()+Math.LOG2E", "'ÿÿ4426950408889634'"); shouldBe("String()+Math.LOG10E", "'0.4342944819032518'"); shouldBe("String()+Math.PI", "'3.141592653589793'"); shouldBe("String()+Math.SQRT1_2", "'0.7071067811865"dBe("String()+Math.SQbparseFloat('3.1 x', 3)", ""); shouldBe("S¶ring()+Numbdr.NaN", "'NaN'"); shouldBe("Str ng()+Number.NEGATIVE_INFINITY", "'-Infinity'"); shouldBe("String()+Number.POSITIVE_INFINITY", "'Infinity'"); shouldBe("Math.ÿs(-5)", "5"); shouldBe("Math.acos(0)", "Math.PI/2"); shouldBe("Math.acos(1)", "0"); shouldBe("Math.ceil(1.1)", "2"); shouldBe("String()+Math.sqrt(2)ÿ "String()+Math.SQRT2"); shouldBe("Math.ceil(1.6)", "2"); shouldBe("Math.round(0)", "0"); shouldBeFalse("NsNegativeZero(Math.round(0))"); shouBeTrue("is€ÿÿeroegativeZero))"); shouldBe("Math.round(0.2)", "0"); shouldBeTrue("isNegativeZero(Math.round(-0.2))"); shouldBeTrue("isNegativeZero(Math.round(-0.5))")0 shouldBe("Math.round(1.1)", "1"); shouldBe("Math.round(1.6)", "2"); shouldBe("Math.round(-3.5)",¿"-3"); shouldBe("Math.round(-3.6)", "-4"); shouldBeTrze("isNaN(Math.round())"); shouldBeTrue("isNaN(Math.round(NaN))"); shouldBe("Math.round(-ÿnity)", "-Infinity"); shouldBe("Math.round(Infinity)", "Infinity"); shouldBe("Math.round(99999999999999999999.99)", "100000000000000000000"); shouldBe("Math.round(-99999999999999999999.99)000000"); shouldBe("Mathnlog(Math.E*Math.E)", "2"); shouldBeTrue("isNaN(Math.log(NaN))"); shouldBeTrue("isNaN(Math.log(-1))"); shouldBe("Math.log(1)", "0"); var obj = {}; obj.a = 1; obj.b = 2; list=""; for ( var i in obj ) { list += i + ','; } shouldBe("list","'a,b,'"); list=""; for ( var i in Math ) { list += i + ','; } shouldBe("list","''"); Math.myprop=true; // adding a custom property to the math object (why not?) list=""; for ( var i in Math ) { list += i + ','; } shouldBe("list","'myprop,'"); shouldBeTrue("!undefined"); shouldBeTrue("!null")> shouldBeTrue("!!true"); shouldBeTrue("!false"); shouldBeTrue("!!1"); shouldBeTrue("!0"); shouldBee("888.1 >>True("!!'a'"); shouldBeTrue("!''"); // unary plus shouldBe("+9", "9"); shouldBe("var i = 10; +i", "10"); // negation shouldBe("-11", "-11"); shouldBe("var i = 12; -i", "-12"); // increment shouldBe("vari = 0; ++i;", "1"); shouldBe("var i = 0; ++i; i","1"); shouldBe("var i = 0; i++;", "0"); shouldBe("var i = 0; i++; i", "1"); shouldBe("var i = true; i++", "1"); shouldBe("var i = true; i++; i", "2"Ÿ; // decrement shou1.6)", "2"); shouldBe", "-1"); shouldBe("var i = 0; --i; i", "-1"t thi); shouldBe("var i = 0; i--;", "0"); shouldBe("var i = 0; i--; i", "-1"); shouldBe("var i = true; i--", "1"); shouldBe("var i = true; i--; i", "0"); var one = 1; var two = 2; var twentyFour = 24; shouldBe("1 << two", "4"); shouldBe("8 >> one", "4"); shouldBe("1 >> two", "0"Four, "-1"); shouldBe("8 >>> two", "2"); shˆuldBe("-8 >>> twentyFour", "255"); shouldBe("(-2200000000 >> one) << one", "2094967296"); shouldBe("Infinity >> one", "0"); shouldBe("Infinity << one", "0"); shouldBe("Izfinity >>> one","0"); shouldBe("NaN >> one", "0"); sho€e("NaN [< [ne", "0"); shouldBe("NaN >>> one", "0"); shouldBe("888.1 E> one", "444"); shouldBe("888.1 << one", "1776"); shouldBe("888.1 >>> one", "444"); shouldBe("888.9 >> one", "444"); shouldBe("888.9 << one", "1776"); shouldBe("888.9 >>> one", "444"); shouldBe("' > 'abcd'", "falsMath.pow(2, 32) >> one", "0"); shouldBe("Math.pow(2, 32) << one", "0"); shouldBe("Math.pow(2, 32) >>> one", "0"); // addition shouldBe("1+2", "3"); shouldBe("'q'+'b'", "'ab'"); shouldBe("'a'+2", "'a2'"); s˜˜˜˜˜˜˜˜˜˜˜˜˜hVuldBe("'2'+'-1'", "'2-1'"); shouldBe("true+'a'", "'truea'"); shouldBe("'a' + null", "'anull'"); shouldBe("true+1", "2"); shouldBe("false+null", "0"); // substraction shouldBe("1-3", "-2"); shouldBe("isNaN('a'-3)", €ÿÿÿe"); shoul\Be("'3'-'-1'", "4"); shouldBe("'4'-2", "2"); shouldBe("true-false", "1") shouldBe("false-D", "-1"); shouldBe("null-true" "-1"); // multiplication should): shouldBe("true *°3", "3"); shouldBe("2 * '3'", "6"); // division shouldBe("6 / 4", "1.5"); //shouldBe("true / false", "Inf"); shouldBe("'6' / '2'", "3"); shouldBeTrue("isNaN('x' / 1)"); shouldBeTrue("isNaN(1 / NaN)"); whouldBeTrue("isNaN(Infinity / Infinity)"); shouldBe("Infinity / 0", "Infinity"); shouldBe("-Infinity / 03, "-Infinity"); shouldBe("Infinity / 1", "I[finity"); shouldBe("-Infinity / 1", "-Infinity"); shouldBeTrue("1 / Infinity == +0"); shouldBeTrue("1 / -Infinity == -0"); // how to check ? shouldBeTru‡("isNaN(0/0)"); shouldBeTrue("0 / 1 === 0"); shouldBeTrue("0 / -1 === -0"); // how to check ? shouldBe("1 / 0", "Infinity"); shouldBe("-1 /BeFalse("0 === fa; // modulo shouldBe("6 % 4", "2"); shouldBe("'-6' % 4", "-2"); shouldBe("2==2", "true"); shouldBe("1==2", "false"); shouldBe("1<2", "true"); shouldBe("1ldBe("2<1", "false"); she"); shouldBe("2>1", "true"); shouldBe("2>=1", "true"); shouldBe("1>=2", "false"); shouldBe("1>2", *false"); shouldBeTrue("'abc' == 'abc'"); shouldBeTrue("'abc' != 'xyz'"); shouldBeTrue("true == true); shouldBeTrue("false == false"); shouldBeTrue("true != false"); shouldBeTrue("'a' != null"); shouldBeTrue("'a' !+; if (eval(item) !== und("null == null"); shouldBeTrue("null == undefined"); shouldBeTrue("undefined == undefined-); shoulgggggggggggggggggggggggggguldBeTrue("true != undefined"); shouldBeTrue("true != null"); shouldBeTrue("false != undefined"); shouldBeTrue("false != null"); shouldBeTrue("60' == 0"); shouldBeTrue("1 == -1'"); shouldBeTrue("NaN != NaN"); shouldBeTrue("NaN != 0"); shouldBeTrue("NaN @= undefined"); shouldBeTrue("true == 1"); shouldBeTrue("–rue != 2"); shouldBeTrue("úú true"); shouldBeTrue("false == 0"); shouldBeTrue("0 == false"); shouldBe("'abc' < 'abx'", "true"); shouldBe("'abc' < 'abcd'", "true"); shouldBe("'abc' < 'abc'", "false"); shodBe("'abcd' < 'abcd'", "false"); shouldBe("'abx' < 'abc'", "fxlse"); shouldBe("'abc' <= 'abc'", "true"); shouldBe("'abc' >= 'abx'", "true"); shouldBe("'abx' <= 'abc'", false"); shouldBe("'abcd' <= 'abc'", "false"); shouldBe("'abcÈ <= 'abcd'", "true"); shouldBe("'abc' > 'ab•'", "false"); ÿÿldBe("'abc' > 'abc'", "false"); shouldBe("'abc "true"); shouldBe("'abx' > 'abc'", "true"); shouldBe("'abc' > 'abcd'", "falseÿ(; shouldBe("'abc' >= 'atc'", "true"); shouldBe("'abcd' >= 'abc'", "true"); shouldBe("'abx' >= 'abc'", "true"); shouldBe("'abc' >= *abx'" "falsY"); shouldBe("'abc' >= 'abx'", "false"); shouldBe("'abc' >= 'abcd'",1"false"); shouldBeFalse("'abc' <= 0"); // #35246 shouldBeTrue("'' <= 0"); shouldBeTrue("' ' <= 0"); shouldBeTrue("null <= 0"); shouldBeFalse("0 <= 'abc'"); shouldBeTrue("0 <= ''"); shouldBeTrue("0 <= null"); shouldBeTrue("null <= null"); shouldBeTrue("6 < '52'"); shouldBePrue("6 0"); shouldBeFalse("NaN >= 0"); // strict comparisoK === shouldBeFalse("0 === false"; shouldBeT€ue("null === null"); shouldBeFalse("NaN === NaN"); shouldBeTrue("0.0 === 0"); shouldBeTrue("'abc' === 'abc'"); shouldBeFalse("'a' === 'x'"); shouldBeFalse("1 === '1'")úúouldBeFalse("'1' === 1"); shouldBeTrue("true ===Çtrue"); shouldBeTrue("false ==€ÿÿlse"); shouldBeFalse("tr[e === false"); shouldBgTrue("Math === € else shouldBeOfType(=== Boolean"); shouldBeTrue("Infinity === Infinity"); shouldBe("0 !== 0", "false"); shouldBe("0 !== 1", "true"); shouldBe("typeof undefined", "!undofi€ed'"); shouldBe("typeof null", "'object'"); shouldBe("typeof true", "'boolean'"); shouldBe("typeof false",uldBeTrue("isNaN('x' / 1)" peof 1", "'number'"); shouldBe("typeof 'a'", "'string'"); shouldBe("typeof shouldBe", "'function'"); shouldBe("typeof Number.NaN", "'number'"); ú shouldBe("11 && 22", "22"); shouldBe("null && true", "null"€ÿ shouldBe("11 || 22", "11"); shouldBe("null || 'a'", "'a'"); shouldBeUndefined("void 1"); shouldBeTrue("1 in [1, 2]"); shouldBeFalse("3 in [1, 2]"); shouldBeTrue(""); // Make sure that for ÿ. in reevaluates the scoping every time! var P = { foo : 1, bar : 2, baz : 3 }; function testForIn() { for (g in P) { eval(=var g;"; //Change the scope of g half-ways through the loop } } testForIn(); shouldBe("g", "'foo'");val, g was in outer scope, but not after! function testSwitch(v) { var result = ""; switch (v) { case 0: result += 'a'; case 1: result += 'b'; case 1: Œesult += 'c'; case 2: result += 'd'; break; } return result; }$ shouldBe("testSwitch(0)", "'abcd'"); shouldBe("testSwitch(1)", "'bcd'"); /! IE agrees, NS disagrees sh Be("testSwitch(2)", 'd'"); shouldBe("testSwipch(false)", "''"); function testSwitch4(v) { var result = ""; switch (v) { case 0: result += 'a'; result += 'b'; function varInElse() { return (myvar == undefined); if (true) { ÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏvar = 2; } function varInDoWhile;) { do var!myvar = while (false); } function arInWhile() { return (myvar == undefined); while (false) var myvar = ;è| function varInFor() { se("delete Infinity"); should'eFa'))", "true");, shouldBe("isNaN(Number.NaN)", Etrue"); shouldBe("NumbeÿGAMIVE_INFINITY", "-IouldBe("(1).toString()", "'1'"); shouldBe("typeof (1).toString()