1/* 2 * Copyright 2010 Jacek Caban for CodeWeavers 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 17 */ 18 19eval("@_jscript_version"); 20 21var tmp; 22 23/*@ */ 24//@cc_on @*/ 25 26@_jscript_version; 27 28@cc_on 29@*/ 30 31// Standard predefined variabled 32if(isWin64) { 33 ok(@_win64 === true, "@_win64 = " + @_win64); 34 ok(@_amd64 === true, "@_amd64 = " + @_amd64); 35 ok(isNaN(@_win32), "@_win32 = " + @_win32); 36 ok(isNaN(@_x86), "@_x86 = " + @_x86); 37}else { 38 ok(@_win32 === true, "@_win32 = " + @_win32); 39 ok(@_x86 === true, "@_x86 = " + @_x86); 40 ok(isNaN(@_win64), "@_win64 = " + @_win64); 41 ok(isNaN(@_amd64), "@_amd64 = " + @_amd64); 42} 43 44ok(@_jscript === true, "@_jscript = " + @_jscript); 45ok(@_jscript_build === ScriptEngineBuildVersion(), 46 "@_jscript_build = " + @_jscript_build + " expected " + ScriptEngineBuildVersion()); 47tmp = ScriptEngineMajorVersion() + ScriptEngineMinorVersion()/10; 48ok(@_jscript_version === tmp, "@_jscript_version = " + @_jscript_version + " expected " + tmp); 49ok(isNaN(@_win16), "@_win16 = " + @_win16); 50ok(isNaN(@_mac), "@_mac = " + @_mac); 51ok(isNaN(@_alpha), "@_alpha = " + @_alpha); 52ok(isNaN(@_mc680x0), "@_mc680x0 = " + @_mc680x0); 53ok(isNaN(@_PowerPC), "@_PowerPC = " + @_PowerPC); 54 55// Undefined variable 56ok(isNaN(@xxx), "@xxx = " + @xxx); 57ok(isNaN(@x$_xx), "@x$_xx = " + @x$_xx); 58 59tmp = false; 60try { 61 eval("/*@cc_on */"); 62}catch(e) { 63 tmp = true; 64} 65ok(tmp, "expected syntax exception"); 66 67tmp = false; 68try { 69 eval("/*@_jscript_version */"); 70}catch(e) { 71 tmp = true; 72} 73ok(tmp, "expected syntax exception"); 74 75ok(isNaN(@test), "@test = " + @test); 76 77@set @test = 1 78ok(@test === 1, "@test = " + @test); 79 80@set @test = 0 81ok(@test === 0, "@test = " + @test); 82 83tmp = false 84@set @test = @test tmp=true 85ok(@test === 0, "@test = " + @test); 86ok(tmp, "expr after @set not evaluated"); 87 88@set @test = !@test 89ok(@test === true, "@test = " + @test); 90 91@set @test = (@test+1+true) 92ok(@test === 3, "@test = " + @test); 93 94@set 95 @test 96 = 97 2 98ok(@test === 2, "@test = " + @test); 99 100@set 101 @test 102 = 103 ( 104 2 105 + 106 2 107 ) 108ok(@test === 4, "@test = " + @test); 109 110@set @test = 2.5 111ok(@test === 2.5, "@test = " + @test); 112 113@set @test = 0x4 114ok(@test === 4, "@test = " + @test); 115 116@set @test = (2 + 2/2) 117ok(@test === 3, "@test = " + @test); 118 119@set @test = (false+false) 120ok(@test === 0, "@test = " + @test); 121 122@set @test = ((1+1)*((3)+1)) 123ok(@test === 8, "@test = " + @test); 124 125@set @_test = true 126ok(@_test === true, "@_test = " + @_test); 127 128@set @$test = true 129ok(@$test === true, "@$test = " + @$test); 130 131@set @newtest = (@newtest != @newtest) 132ok(@newtest === true, "@newtest = " + @newtest); 133 134@set @test = (false != 0) 135ok(@test === false, "@test = " + @test); 136 137@set @test = (1 != true) 138ok(@test === false, "@test = " + @test); 139 140@set @test = (0 != true) 141ok(@test === true, "@test = " + @test); 142 143@set @test = (true-2) 144ok(@test === -1, "@test = " + @test); 145 146@set @test = (true-@_jscript) 147ok(@test === 0, "@test = " + @test); 148 149@set @test = (true==1) 150ok(@test === true, "@test = " + @test); 151 152@set @test = (1==false+1) 153ok(@test === true, "@test = " + @test); 154 155function expect(val, exval) { 156 ok(val === exval, "got " + val + " expected " + exval); 157} 158 159@set @test = (false < 0.5) 160expect(@test, true); 161 162@set @test = (true == 0 < 0.5) 163expect(@test, true); 164 165@set @test = (false < 0) 166expect(@test, false); 167 168@set @test = (false > 0.5) 169expect(@test, false); 170 171@set @test = (1 < true) 172expect(@test, false); 173 174@set @test = (1 <= true) 175expect(@test, true); 176 177@set @test = (1 >= true) 178expect(@test, true); 179 180@set @test = (1 >= true-1) 181expect(@test, true); 182 183@if (false) 184 this wouldn not parse 185"@end 186 187@if (false) "@end 188 189tmp = "@if (false) @end"; 190ok(tmp.length === 16, "tmp.length = " + tmp.length); 191 192@if(true) 193tmp = true 194@end 195ok(tmp === true, "tmp = " + tmp); 196 197@if(false) 198@if this would not CC parse 199this will not parse 200@elif(true) 201this will also not parse 202@else 203this also will not parse 204@if let me complicate things a bit 205@end enough 206@end 207@end 208 209@if(false) 210this will not parse 211@else 212tmp = 2 213@else 214this will not be parsed 215@else 216also this 217@end 218ok(tmp === 2, "tmp = " + tmp); 219 220@if(true) 221tmp = 3; 222@else 223just skip this 224@end 225ok(tmp === 3, "tmp = " + tmp); 226 227@if(true) 228tmp = 4; 229@elif(true) 230this will not parse 231@elif nor this 232@else 233just skip this 234@end 235ok(tmp === 4, "tmp = " + tmp); 236 237@if(false) 238this will not parse 239@elif(false) 240nor this would 241@elif(true) 242tmp = 5; 243@elif nor this 244@else 245just skip this 246@end 247ok(tmp === 5, "tmp = " + tmp); 248 249@if (!@_jscript) 250this would not parse 251@if(true) 252@else 253@if(false) 254@end 255@end 256@elif (@_jscript) 257tmp = 6; 258@elif (true) 259@if xxx 260@else 261@if @elif @elif @else @end 262@end 263@else 264this would not parse 265@end 266ok(tmp === 6, "tmp = " + tmp); 267 268@if(true) 269@if(false) 270@else 271tmp = 7; 272@end 273@else 274this would not parse 275@end 276ok(tmp === 7, "tmp = " + tmp); 277 278var exception_map = { 279 JS_E_SYNTAX: {type: "SyntaxError", number: -2146827286}, 280 JS_E_MISSING_LBRACKET: {type: "SyntaxError", number: -2146827283}, 281 JS_E_EXPECTED_IDENTIFIER: {type: "SyntaxError", number: -2146827278}, 282 JS_E_EXPECTED_ASSIGN: {type: "SyntaxError", number: -2146827277}, 283 JS_E_EXPECTED_CCEND: {type: "SyntaxError", number: -2146827259}, 284 JS_E_EXPECTED_AT: {type: "SyntaxError", number: -2146827256} 285}; 286 287function testException(src, id) { 288 var ex = exception_map[id]; 289 var ret = "", num = ""; 290 291 try { 292 eval(src); 293 } catch(e) { 294 ret = e.name; 295 num = e.number; 296 } 297 298 ok(ret === ex.type, "Exception test, ret = " + ret + ", expected " + ex.type +". Executed code: " + src); 299 ok(num === ex.number, "Exception test, num = " + num + ", expected " + ex.number + ". Executed function: " + src); 300} 301 302testException("@set test=true", "JS_E_EXPECTED_AT"); 303testException("@set @1=true", "JS_E_EXPECTED_IDENTIFIER"); 304testException("@set @test x=true", "JS_E_EXPECTED_ASSIGN"); 305testException("@if false\n@end", "JS_E_MISSING_LBRACKET"); 306testException("@if (false)\n", "JS_E_EXPECTED_CCEND"); 307testException("@end\n", "JS_E_SYNTAX"); 308testException("@elif\n", "JS_E_SYNTAX"); 309testException("@else\n", "JS_E_SYNTAX"); 310testException("@if false\n@elif true\n@end", "JS_E_MISSING_LBRACKET"); 311 312reportSuccess(); 313