G
Garrett Smith
In ECMAScript, a catch block augments the current scope chain by pushing
a new Object to the front of the scope chain.
However, official versions of JScript up to and including JScript 5.8
don't do that. Instead, when entering a catch block, these versions of
JScript add the catch block's parameter to the containing scope.
This was fixed in IE9's JScript engine, "JScript 0.9", using, however, I
have noticed that functions defined in the catch block don't get the
catch block's scope that they're defined in.
This is shown in the example below. When augmented is called, `ex` can't
be accessed.
<!doctype html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>test catch scope</title>
</head>
<body>
<script type="text/javascript">
try {
var ex = 12;
x; // throw a ReferenceError
} catch(ex) {
alert(ex.name);
var augmented = function() {
alert(ex);
};
augmented();
}
</script>
</body>
</html>
IE9 Results: "ReferenceError", "12".
Function `augmented` isn't getting the scope chain from the catch block.
Garrett
a new Object to the front of the scope chain.
However, official versions of JScript up to and including JScript 5.8
don't do that. Instead, when entering a catch block, these versions of
JScript add the catch block's parameter to the containing scope.
This was fixed in IE9's JScript engine, "JScript 0.9", using, however, I
have noticed that functions defined in the catch block don't get the
catch block's scope that they're defined in.
This is shown in the example below. When augmented is called, `ex` can't
be accessed.
<!doctype html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>test catch scope</title>
</head>
<body>
<script type="text/javascript">
try {
var ex = 12;
x; // throw a ReferenceError
} catch(ex) {
alert(ex.name);
var augmented = function() {
alert(ex);
};
augmented();
}
</script>
</body>
</html>
IE9 Results: "ReferenceError", "12".
Function `augmented` isn't getting the scope chain from the catch block.
Garrett