js/src/tests/js1_8_5/regress/regress-554955-6.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_8_5/regress/regress-554955-6.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,47 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/*
     1.6 + * Any copyright is dedicated to the Public Domain.
     1.7 + * http://creativecommons.org/licenses/publicdomain/
     1.8 + */
     1.9 +
    1.10 +var v="global";
    1.11 +function f(a) {
    1.12 +  // This eval could extend f's call object. However, the call object has
    1.13 +  // not yet been marked as a delegate at this point, so no scope chain
    1.14 +  // purge takes place when it is extended.
    1.15 +  eval(a);
    1.16 +  let (b=3) {
    1.17 +    // This eval causes the cloned block object to be added to the
    1.18 +    // scope chain. The block needs a unique shape: its parent call
    1.19 +    // could acquire bindings for anything without affecting the global
    1.20 +    // object's shape, so it's up to the block's shape to mismatch all
    1.21 +    // property cache entries for prior blocks.
    1.22 +    eval("");
    1.23 +    return v;
    1.24 +  };
    1.25 +}
    1.26 +
    1.27 +// Call the function once, to cache a reference to the global v from within
    1.28 +// f's lexical block.
    1.29 +assertEq("global", f(""));
    1.30 +
    1.31 +// Call the function again, adding a binding to the call, and ensure that
    1.32 +// we do not see any property cache entry created by the previous reference
    1.33 +// that would direct us to the global definition.
    1.34 +assertEq("local", f("var v='local'"));
    1.35 +
    1.36 +// Similarly,but with a doubly-nested block; make sure everyone gets marked.
    1.37 +function f2(a) {
    1.38 +  eval(a);
    1.39 +  let (b=3) {
    1.40 +    let (c=4) {
    1.41 +      eval("");
    1.42 +      return v;
    1.43 +    };
    1.44 +  };
    1.45 +}
    1.46 +
    1.47 +assertEq("global", f2(""));
    1.48 +assertEq("local",  f2("var v='local'"));
    1.49 +
    1.50 +reportCompare(true, true);

mercurial