summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/misc/boolean-argument-conversion.html
blob: 1423673bda319735d792c2506d72575636538151 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!--
Copyright (c) 2019 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script src="../../js/test-eval.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>

<script>
"use strict";
var wtu = WebGLTestUtils;
description("Test that conversion of boolean arguments of WebGL functions follows EcmaScript 9.2. ToBoolean");
debug("");
debug("When an object is converted to a boolean, it should always evaluate as true. Any valueOf() method should not even get called. See Mozilla bug 727590 where Gecko incorrectly converted such an argument to a Number instead of a Boolean, giving the wrong behavior. See 9.2 and 9.3 in the EcmaScript specification.");
debug("");
var gl = wtu.create3DContext();
var program = wtu.loadStandardProgram(gl);
var shader = wtu.loadStandardVertexShader(gl);
var shouldGenerateGLError = wtu.shouldGenerateGLError;

assertMsg(program != null, "Program Compiled");
assertMsg(shader != null, "Shader Compiled");

var uloc = gl.getUniformLocation(program, "u_modelViewProjMatrix");
var aloc = gl.getAttribLocation(program, "a_vertex");

gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());

wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from initialization.");
assertMsg(uloc, "Uniform not found");
assertMsg(aloc >= 0, "Attribute not found");

var boolArg = { valueOf: function() { throw "Converting an Object to a Boolean should just give 'true' without further evaluation"; } }

function shouldNotThrowWithBoolArgs(code) {
  try {
    TestEval(code);
  } catch(e) {
    testFailed(code + " threw exception: " + e);
    return;
  }
  testPassed(code + " converted its boolean arguments correctly");
}

shouldNotThrowWithBoolArgs(
  "gl.colorMask(boolArg, boolArg, boolArg, boolArg)"
);

shouldNotThrowWithBoolArgs(
  "gl.depthMask(boolArg)"
);

shouldNotThrowWithBoolArgs(
  "gl.sampleCoverage(1, boolArg)"
);

function zeroArray(length) {
  var a = new Array(length);
  for (var i = 0; i < length; i++)
    a[i] = 0;
  return a;
}

function zeroFloat32Array(length) {
  var a = new Float32Array(length);
  for (var i = 0; i < length; i++)
    a[i] = 0;
  return a;
}

shouldNotThrowWithBoolArgs(
  "gl.uniformMatrix2fv(uloc, boolArg, zeroFloat32Array(4))"
);

shouldNotThrowWithBoolArgs(
  "gl.uniformMatrix2fv(uloc, boolArg, zeroArray(4))"
);

shouldNotThrowWithBoolArgs(
  "gl.uniformMatrix3fv(uloc, boolArg, zeroFloat32Array(9))"
);

shouldNotThrowWithBoolArgs(
  "gl.uniformMatrix3fv(uloc, boolArg, zeroArray(9))"
);

shouldNotThrowWithBoolArgs(
  "gl.uniformMatrix4fv(uloc, boolArg, zeroFloat32Array(16))"
);

shouldNotThrowWithBoolArgs(
  "gl.uniformMatrix4fv(uloc, boolArg, zeroArray(16))"
);

shouldNotThrowWithBoolArgs(
  "gl.vertexAttribPointer(aloc, 4, gl.FLOAT, boolArg, 4, 0)"
);

var successfullyParsed = true;
</script>

<script src="../../js/js-test-post.js"></script>
</body>
</html>