michael@0: // Check that withSourceHook passes URLs, propagates exceptions, and michael@0: // properly restores the original source hooks. michael@0: michael@0: load(libdir + 'asserts.js'); michael@0: michael@0: // withSourceHook isn't defined if you pass the shell the --fuzzing-safe michael@0: // option. Skip this test silently, to avoid spurious failures. michael@0: if (typeof withSourceHook != 'function') michael@0: quit(0); michael@0: michael@0: var log = ''; michael@0: michael@0: // Establish an outermost source hook. michael@0: withSourceHook(function (url) { michael@0: log += 'o'; michael@0: assertEq(url, 'outer'); michael@0: return '(function outer() { 3; })'; michael@0: }, function () { michael@0: log += 'O'; michael@0: // Verify that withSourceHook propagates exceptions thrown by source hooks. michael@0: assertThrowsValue(function () { michael@0: // Establish a source hook that throws. michael@0: withSourceHook(function (url) { michael@0: log += 'm'; michael@0: assertEq(url, 'middle'); michael@0: throw 'borborygmus'; // middle michael@0: }, function () { michael@0: log += 'M'; michael@0: // Establish an innermost source hook that does not throw, michael@0: // and verify that it is in force. michael@0: assertEq(withSourceHook(function (url) { michael@0: log += 'i'; michael@0: assertEq(url, 'inner'); michael@0: return '(function inner() { 1; })'; michael@0: }, function () { michael@0: log += 'I'; michael@0: return evaluate('(function inner() { 2; })', michael@0: { fileName: 'inner', sourceIsLazy: true }) michael@0: .toSource(); michael@0: }), michael@0: '(function inner() { 1; })'); michael@0: // Verify that the source hook that throws has been reinstated. michael@0: evaluate('(function middle() { })', michael@0: { fileName: 'middle', sourceIsLazy: true }) michael@0: .toSource(); michael@0: }); michael@0: }, 'borborygmus'); michael@0: michael@0: // Verify that the outermost source hook has been restored. michael@0: assertEq(evaluate('(function outer() { 4; })', michael@0: { fileName: 'outer', sourceIsLazy: true }) michael@0: .toSource(), michael@0: '(function outer() { 3; })'); michael@0: }); michael@0: michael@0: assertEq(log, 'OMIimo');