js/src/jit-test/tests/basic/withSourceHook.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:ca4c850379cb
1 // Check that withSourceHook passes URLs, propagates exceptions, and
2 // properly restores the original source hooks.
3
4 load(libdir + 'asserts.js');
5
6 // withSourceHook isn't defined if you pass the shell the --fuzzing-safe
7 // option. Skip this test silently, to avoid spurious failures.
8 if (typeof withSourceHook != 'function')
9 quit(0);
10
11 var log = '';
12
13 // Establish an outermost source hook.
14 withSourceHook(function (url) {
15 log += 'o';
16 assertEq(url, 'outer');
17 return '(function outer() { 3; })';
18 }, function () {
19 log += 'O';
20 // Verify that withSourceHook propagates exceptions thrown by source hooks.
21 assertThrowsValue(function () {
22 // Establish a source hook that throws.
23 withSourceHook(function (url) {
24 log += 'm';
25 assertEq(url, 'middle');
26 throw 'borborygmus'; // middle
27 }, function () {
28 log += 'M';
29 // Establish an innermost source hook that does not throw,
30 // and verify that it is in force.
31 assertEq(withSourceHook(function (url) {
32 log += 'i';
33 assertEq(url, 'inner');
34 return '(function inner() { 1; })';
35 }, function () {
36 log += 'I';
37 return evaluate('(function inner() { 2; })',
38 { fileName: 'inner', sourceIsLazy: true })
39 .toSource();
40 }),
41 '(function inner() { 1; })');
42 // Verify that the source hook that throws has been reinstated.
43 evaluate('(function middle() { })',
44 { fileName: 'middle', sourceIsLazy: true })
45 .toSource();
46 });
47 }, 'borborygmus');
48
49 // Verify that the outermost source hook has been restored.
50 assertEq(evaluate('(function outer() { 4; })',
51 { fileName: 'outer', sourceIsLazy: true })
52 .toSource(),
53 '(function outer() { 3; })');
54 });
55
56 assertEq(log, 'OMIimo');

mercurial