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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/basic/withSourceHook.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,56 @@
     1.4 +// Check that withSourceHook passes URLs, propagates exceptions, and
     1.5 +// properly restores the original source hooks.
     1.6 +
     1.7 +load(libdir + 'asserts.js');
     1.8 +
     1.9 +// withSourceHook isn't defined if you pass the shell the --fuzzing-safe
    1.10 +// option. Skip this test silently, to avoid spurious failures.
    1.11 +if (typeof withSourceHook != 'function')
    1.12 +  quit(0);
    1.13 +
    1.14 +var log = '';
    1.15 +
    1.16 +// Establish an outermost source hook.
    1.17 +withSourceHook(function (url) {
    1.18 +  log += 'o';
    1.19 +  assertEq(url, 'outer');
    1.20 +  return '(function outer() { 3; })';
    1.21 +}, function () {
    1.22 +  log += 'O';
    1.23 +  // Verify that withSourceHook propagates exceptions thrown by source hooks.
    1.24 +  assertThrowsValue(function () {
    1.25 +    // Establish a source hook that throws.
    1.26 +    withSourceHook(function (url) {
    1.27 +      log += 'm';
    1.28 +      assertEq(url, 'middle');
    1.29 +      throw 'borborygmus'; // middle
    1.30 +    }, function () {
    1.31 +      log += 'M';
    1.32 +      // Establish an innermost source hook that does not throw,
    1.33 +      // and verify that it is in force.
    1.34 +      assertEq(withSourceHook(function (url) {
    1.35 +                                log += 'i';
    1.36 +                                assertEq(url, 'inner');
    1.37 +                                return '(function inner() { 1; })';
    1.38 +                              }, function () {
    1.39 +                                log += 'I';
    1.40 +                                return evaluate('(function inner() { 2; })',
    1.41 +                                                { fileName: 'inner', sourceIsLazy: true })
    1.42 +                                       .toSource();
    1.43 +                              }),
    1.44 +               '(function inner() { 1; })');
    1.45 +      // Verify that the source hook that throws has been reinstated.
    1.46 +      evaluate('(function middle() { })',
    1.47 +               { fileName: 'middle', sourceIsLazy: true })
    1.48 +      .toSource();
    1.49 +    });
    1.50 +  }, 'borborygmus');
    1.51 +
    1.52 +  // Verify that the outermost source hook has been restored.
    1.53 +  assertEq(evaluate('(function outer() { 4; })',
    1.54 +                    { fileName: 'outer', sourceIsLazy: true })
    1.55 +           .toSource(),
    1.56 +           '(function outer() { 3; })');
    1.57 +});
    1.58 +
    1.59 +assertEq(log, 'OMIimo');

mercurial