summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/domxpath/resolver-non-string-result.html
blob: f8834301c4ab44fafb65e1c729233d701050a8c9 (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
<!DOCTYPE html>
<meta charset=utf-8>
<title>XPathNSResolver non-string return value</title>
<link rel="help" href="https://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathEvaluator">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/invalid_namespace_test.js"></script>
<div id=log></div>
<script>
"use strict";

promise_test(t => {
  return invalid_namespace_test(t, () => undefined);
}, "undefined");

promise_test(t => {
  return invalid_namespace_test(t, () => null);
}, "null");

test(t => {
  let resolverCalls = 0;

  document.evaluate("/foo:bar", document.documentElement, () => {
    resolverCalls++;
    return 0;
  });

  assert_equals(resolverCalls, 1);
}, "number");

test(t => {
  let resolverCalls = 0;

  document.evaluate("/foo:bar", document.documentElement, () => {
    resolverCalls++;
    return false;
  });

  assert_equals(resolverCalls, 1);
}, "boolean");

promise_test(t => {
  return promise_rejects_js(t, TypeError,
    invalid_namespace_test(t, () => Symbol())
  );
}, "symbol");

promise_test(t => {
  const testError = { name: "test" };
  const resolverResult = {
    toString: () => { throw testError; },
    valueOf: t.unreached_func("`valueOf` should not be called."),
  };

  return promise_rejects_exactly(t, testError,
    invalid_namespace_test(t, () => resolverResult)
  );
}, "object coercion (abrupt completion)");
</script>
</body>