logic-inside-block-without-braces.html (2114B)
1 <!-- 2 Copyright (c) 2019 The Khronos Group Inc. 3 Use of this source code is governed by an MIT-style license that can be 4 found in the LICENSE.txt file. 5 --> 6 7 <!DOCTYPE html> 8 <html> 9 <head> 10 <meta charset="utf-8"> 11 <title>Short-circuiting logic operator with side effects inside if statement without braces should work</title> 12 <link rel="stylesheet" href="../../../resources/js-test-style.css"/> 13 <script src="../../../js/js-test-pre.js"></script> 14 <script src="../../../js/webgl-test-utils.js"></script> 15 <script src="../../../js/glsl-conformance-test.js"></script> 16 </head> 17 <body> 18 <div id="description"></div> 19 <div id="console"></div> 20 <script id="fshaderIf" type="x-shader/x-fragment"> 21 precision mediump float; 22 uniform bool uFalse; 23 24 float wrong = 0.0; 25 26 bool foo() { 27 wrong += 1.0; 28 return !uFalse; 29 } 30 31 bool bar() { 32 return !uFalse; 33 } 34 35 void main() { 36 // No braces here - that can affect whether the contents of the if get parsed as a block or a statement. 37 if (uFalse) 38 foo() && bar(); 39 gl_FragColor = vec4(0.0, 1.0 - wrong, 0.0, 1.0); 40 } 41 </script> 42 <script id="fshaderFor" type="x-shader/x-fragment"> 43 precision mediump float; 44 45 float wrong = 0.0; 46 47 bool foo() { 48 wrong += 1.0; 49 return false; 50 } 51 52 bool bar() { 53 return false; 54 } 55 56 void main() { 57 // No braces here - that can affect whether the contents of the for get parsed as a block or a statement. 58 for (int i = 0; i < 0; ++i) 59 foo() && bar(); 60 gl_FragColor = vec4(0.0, 1.0 - wrong, 0.0, 1.0); 61 } 62 </script> 63 <script type="application/javascript"> 64 "use strict"; 65 description("Short-circuiting logic operator with side effects inside if/for statement without braces should work."); 66 debug(""); 67 68 GLSLConformanceTester.runRenderTests([ 69 { 70 fShaderId: 'fshaderIf', 71 fShaderSuccess: true, 72 linkSuccess: true, 73 passMsg: 'Short-circuiting operator inside if statement without braces', 74 uniforms: [{name: "uFalse", functionName: "uniform1i", value: 0}] 75 }, 76 { 77 fShaderId: 'fshaderFor', 78 fShaderSuccess: true, 79 linkSuccess: true, 80 passMsg: 'Short-circuiting operator inside for statement without braces' 81 } 82 ]); 83 </script> 84 </body> 85 </html>