| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- //-------------------------------------------------------------------------------------------------------
- // Copyright (C) Microsoft. All rights reserved.
- // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
- //-------------------------------------------------------------------------------------------------------
- this.WScript.LoadScriptFile("..\\UnitTestFramework\\SimdJsHelpers.js");
- var sf0 = SIMD.Bool32x4(1.35, -2.0, 3.4, 0.0);
- var sf1 = SIMD.Bool32x4(1.35, -2.0, 3.4, 0.0);
- var sf2 = SIMD.Bool32x4(1.35, -2.0, 3.14, 0.0);
- var sf3 = SIMD.Bool32x4(0, Infinity, NaN, -0);
- function testConstructor()
- {
- ////////////////////
- //Constructor
- ///////////////////
- equal("object", typeof SIMD.Bool32x4.prototype);
- equal("function", typeof SIMD.Bool32x4.prototype.constructor);
- equal("function", typeof SIMD.Bool32x4.prototype.toString);
- equal("function", typeof SIMD.Bool32x4.prototype.toLocaleString);
- equal("function", typeof SIMD.Bool32x4.prototype.valueOf);
- equal(SIMD.Bool32x4, SIMD.Bool32x4.prototype.constructor);
- descriptor = Object.getOwnPropertyDescriptor(SIMD.Bool32x4, 'prototype');
- equal(false, descriptor.writable);
- equal(false, descriptor.enumerable);
- equal(false, descriptor.configurable);
- }
- function testToStringTag()
- {
- ///////////////////
- //SIMDConstructor.prototype [ @@toStringTag ]
- ///////////////////
- var sym = Symbol('sym');
- var symbol_object = Object(sym);
- equal("SIMD.Bool32x4", SIMD.Bool32x4.prototype[Symbol.toStringTag]);
- descriptor = Object.getOwnPropertyDescriptor(SIMD.Bool32x4.prototype, Symbol.toStringTag);
- equal(false, descriptor.writable);
- equal(false, descriptor.enumerable);
- equal(true, descriptor.configurable);
- }
- function testToPrimitive()
- {
- ///////////////////
- //SIMDConstructor.prototype [ @@toPrimitive ]
- ///////////////////
- equal("function",typeof SIMD.Bool32x4.prototype[Symbol.toPrimitive]);
- equal(1, SIMD.Bool32x4.prototype[Symbol.toPrimitive].length);
- descriptor = Object.getOwnPropertyDescriptor(SIMD.Bool32x4.prototype, Symbol.toPrimitive);
- equal(false, descriptor.writable);
- equal(false, descriptor.enumerable);
- equal(true, descriptor.configurable);
- var functionToString = SIMD.Bool32x4.prototype[Symbol.toPrimitive].toString();
- var actualName = functionToString.substring(9, functionToString.indexOf('('));
- equal("[Symbol.toPrimitive]",actualName);
- ///////////////////////////
- //Overriding @@ToPrimitive
- ///////////////////////////
- SIMD.Bool32x4.prototype[Symbol.toPrimitive] = undefined;
- var G;
- var functionBackup = SIMD.Bool32x4.prototype.toLocaleString;
- SIMD.Bool32x4.prototype.toLocaleString = function(){
- G = this;
- }
- sf0.toLocaleString();
- try{var x = G + G;}
- catch(e)
- {equal("Error: Number expected", e);} //@@toPrimitive is not writable
- //@@toPrimitive is configurable.
- memberBackup = Object.getOwnPropertyDescriptor(SIMD.Bool32x4.prototype, Symbol.toPrimitive);
- delete SIMD.Bool32x4.prototype[Symbol.toPrimitive];
- SIMD.Bool32x4.prototype[Symbol.toPrimitive] = function() { return 1;}
- equal(2, G + G);
- equal(0, G - G);
- equal(1, G * G);
- equal(1, G / G);
- equal(true, G == G);
- equal(true, G === G);
- equal(false, G > G);
- equal(true, G >= G);
- equal(false, G < G);
- equal(true, G >= G);
- delete SIMD.Bool32x4.prototype[Symbol.toPrimitive];
- SIMD.Bool32x4.prototype[Symbol.toPrimitive] = function() { return undefined;}
- equal(NaN, G + G);
- equal(NaN, G - G);
- equal(NaN, G * G);
- equal(NaN, G / G);
- equal(true, G == G);
- equal(true, G === G);
- equal(false, G > G);
- equal(false, G >= G);
- equal(false, G < G);
- equal(false, G >= G);
- delete SIMD.Bool32x4.prototype[Symbol.toPrimitive];
- SIMD.Bool32x4.prototype[Symbol.toPrimitive] = function() { return "test";}
- equal("testtest", G + G);
- equal(NaN, G - G);
- equal(NaN, G * G);
- equal(NaN, G / G);
- equal(true, G == G);
- equal(true, G === G);
- equal(false, G > G);
- equal(true, G >= G);
- equal(false, G < G);
- equal(true, G >= G);
- delete SIMD.Bool32x4.prototype[Symbol.toPrimitive];
- SIMD.Bool32x4.prototype[Symbol.toPrimitive] = 5;
- try{var x = G + G;}
- catch(e)
- {equal("TypeError: The value of the property 'Symbol.toPrimitive' is not a Function object", e);}
- SIMD.Bool32x4.prototype[Symbol.toPrimitive] = memberBackup;
- SIMD.Bool32x4.prototype.toLocaleString = functionBackup
- }
- function testValueOf()
- {
- ///////////////////
- //ValueOf
- ///////////////////
- descriptor = Object.getOwnPropertyDescriptor(SIMD.Bool32x4.prototype, 'valueOf');
- equal(true, descriptor.writable);
- equal(false, descriptor.enumerable);
- equal(true, descriptor.configurable);
- equal("bool32x4", typeof sf0.valueOf());
- equal("SIMD.Bool32x4(true, true, true, false)", sf0.toString());
- }
- function testToString_LocaleString()
- {
- ///////////////////
- //ToString / ToLocaleString
- ///////////////////
- descriptor = Object.getOwnPropertyDescriptor(SIMD.Bool32x4.prototype, 'toString');
- equal(true, descriptor.writable);
- equal(false, descriptor.enumerable);
- equal(true, descriptor.configurable);
- descriptor = Object.getOwnPropertyDescriptor(SIMD.Bool32x4.prototype, 'toLocaleString');
- equal(true, descriptor.writable);
- equal(false, descriptor.enumerable);
- equal(true, descriptor.configurable);
- equal("SIMD.Bool32x4(true, true, true, false)", sf0.toString()); //If float use ToString on lanes, the right values will be available.
- equal("SIMD.Bool32x4(true, true, true, false)", sf0.toLocaleString());
-
- equal("SIMD.Bool32x4(false, true, false, false)", sf3.toString());
- // equal("SIMD.Bool32x4(0, ?, NaN, 0)", sf3.toLocaleString()); //How should this work?
- var origFn = SIMD.Bool32x4.prototype.toLocaleString;
- var G5;
- SIMD.Bool32x4.prototype.toLocaleString = function() {
- G5 = this;
- return "NEWTOSTRING";
- }
- equal("undefined", typeof(G5));
- equal("NEWTOSTRING", sf0.toLocaleString());
- equal("object", typeof(G5));
- equal("NEWTOSTRING", G5.toLocaleString());
- equal("NEWTOSTRING", sf0.toLocaleString());
- SIMD.Bool32x4.prototype.toLocaleString = origFn;
- ///////////////////
- //PrototypeLinking toString
- ///////////////////
- var origFn = SIMD.Bool32x4.prototype.toString;
- SIMD.Bool32x4.prototype.toString = function() {
- G = this;
- return "NEWTOSTRING";
- }
- equal("undefined", typeof(G));
- equal("NEWTOSTRING", sf0.toString());
- equal("object", typeof(G));
- equal("NEWTOSTRING", G.toString());
- equal("NEWTOSTRING", sf0.toString());
- SIMD.Bool32x4.prototype.toString = origFn;
- }
- function testProtoLinking()
- {
- ///////////////////
- //Inheritance
- ///////////////////
- SIMD.Bool32x4.prototype.myToString = function() {
- return "MYTOSTRING";
- }
- equal("MYTOSTRING", sf0.myToString());
- equal("MYTOSTRING", G.myToString());
- ///////////////////
- //PrototypeLinking valueOf
- ///////////////////
- SIMD.Bool32x4.prototype.valueOf = function() {
- G1 = this;
- return "NEWVALUEOF";
- }
- var G1;
- equal("undefined", typeof(G1));
- equal("NEWVALUEOF", sf0.valueOf());
- equal("object", typeof(G1));
- equal("NEWVALUEOF", G1.valueOf());
- equal("NEWVALUEOF", sf0.valueOf());
- }
- function testValueSemantics()
- {
- ///////////////////
- //Value semantics
- ///////////////////
- equal(true, (sf0 == sf0));
- equal(true, (sf0 === sf0));
- equal(true, (sf0 == sf1));
- equal(true, (sf0 === sf1));
- equal(true, (sf0 == sf2));
- equal(true, (sf0 === sf2));
- ///////////////////
- //Comparision
- //////////////////
- try{var x = sf0 > sf1;}
- catch(e)
- {equal("TypeError: SIMD type: cannot be converted to a number", e);}
-
- try{var x = sf0 < sf1;}
- catch(e)
- {equal("TypeError: SIMD type: cannot be converted to a number", e);}
- try{var x = sf0 >= sf1;}
- catch(e)
- {equal("TypeError: SIMD type: cannot be converted to a number", e);}
- try{var x = sf0 <= sf1;}
- catch(e)
- {equal("TypeError: SIMD type: cannot be converted to a number", e);}
- ///////////////////////
- //Arithmetic operators
- ///////////////////////
- equal("SIMD.Bool32x4(false, true, false, false)test", sf3 + "test");
- equal("testSIMD.Bool32x4(false, true, false, false)", "test" + sf3);
- try{var x = sf3 + sf3;}
- catch(e)
- {equal("Error: Number expected", e);} //Check
-
- try{var x = sf3 - sf3;}
- catch(e)
- {equal("Error: Number expected", e);}
-
- try{var x = sf3 / sf3;}
- catch(e)
- {equal("Error: Number expected", e);}
-
- try{var x = sf3 * sf3;}
- catch(e)
- {equal("Error: Number expected", e);}
- }
- //The following test can be enabled when extract lane builtin for bools are merged.
- // function testHorizontalOR()
- // {
- // var b1 = SIMD.Bool32x4(true, false, false, true);
- //
- // SIMD.Bool32x4.prototype.horizontalOR = function()
- // {
- // var b4 = this.valueOf();
- // return (SIMD.Bool32x4.extractLane(b4, 0) ||
- // SIMD.Bool32x4.extractLane(b4, 1) ||
- // SIMD.Bool32x4.extractLane(b4, 2) ||
- // SIMD.Bool32x4.extractLane(b4, 3) );
- // }
- //
- // equal(true, b1.horizontalOR());
- // }
- function testWrapperObject()
- {
- testConstructor();
- testToStringTag();
- testToPrimitive();
- testValueOf();
- testToString_LocaleString();
- testProtoLinking();
- testValueSemantics();
- // testHorizontalOR()
- }
- testWrapperObject();
- print("PASS");
|