diff options
author | Mark Miller <erights@gmail.com> | 2011-10-04 06:52:13 +0200 |
---|---|---|
committer | Mark Miller <erights@gmail.com> | 2011-10-04 06:52:13 +0200 |
commit | b83fa1cf158dc3b287e2b32e9bbdbf3460adf9ff (patch) | |
tree | cd0f5116454ed112147b07feb19d7531d05f1aad | |
parent | b8228854b3a37c3cdfec26cb24cee134605fa8ec (diff) | |
download | test262-b83fa1cf158dc3b287e2b32e9bbdbf3460adf9ff.tar.gz |
Built-in functions should not have non-deletable, non-poisoned
"caller" and "arguments" properties.
-rw-r--r-- | test/suite/bestPractice/Sbp_A10_T1.js | 46 | ||||
-rw-r--r-- | test/suite/bestPractice/Sbp_A10_T2.js | 46 |
2 files changed, 92 insertions, 0 deletions
diff --git a/test/suite/bestPractice/Sbp_A10_T1.js b/test/suite/bestPractice/Sbp_A10_T1.js new file mode 100644 index 000000000..76647e724 --- /dev/null +++ b/test/suite/bestPractice/Sbp_A10_T1.js @@ -0,0 +1,46 @@ +// Copyright 2011 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @path bestPractice/Sbp_A10_T1.js + * @description Built-in functions should not have a non-deletable, + * non-poisoned "caller" property. + * @bestPractice + * http://wiki.ecmascript.org/doku.php?id=conventions:make_non-standard_properties_configurable + */ + +(function() { + var map = Array.prototype.map; + if (!map) { return; } + try { + delete map.caller; + } catch (err1) { + // ignore + } + if ('caller' in map) { + try { + Object.defineProperty(map, 'caller', { + writable: false, + configurable: false + }); + } catch (err2) { + // ignore + } + } + + function foo(m) { return m.caller; } + function testfn(a, f) { return a.map(f)[0]; } + var a = [map]; + var caller; + try { + caller = testfn(a, foo); + } catch (err3) { + if (err3 instanceof TypeError) { return; } + $ERROR('#1: Built-in "caller" failed with: ' + err3); + } + if (null === caller || void 0 === caller) { return; } + if (testfn === caller) { + $ERROR('#2: Built-in revealed caller'); + } + $ERROR('#3: Unexpected "caller": ' + caller); +})();
\ No newline at end of file diff --git a/test/suite/bestPractice/Sbp_A10_T2.js b/test/suite/bestPractice/Sbp_A10_T2.js new file mode 100644 index 000000000..6037a5ea3 --- /dev/null +++ b/test/suite/bestPractice/Sbp_A10_T2.js @@ -0,0 +1,46 @@ +// Copyright 2011 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @path bestPractice/Sbp_A10_T2.js + * @description Built-in functions should not have a non-deletable, + * non-poisoned "arguments" property. + * @bestPractice + * http://wiki.ecmascript.org/doku.php?id=conventions:make_non-standard_properties_configurable + */ + +(function() { + var map = Array.prototype.map; + if (!map) { return; } + try { + delete map.arguments; + } catch (err1) { + // ignore + } + if ('arguments' in map) { + try { + Object.defineProperty(map, 'arguments', { + writable: false, + configurable: false + }); + } catch (err2) { + // ignore + } + } + + function foo(m) { return m.arguments; } + function testfn(a, f) { return a.map(f)[0]; } + var a = [map]; + var args; + try { + args = testfn(a, foo); + } catch (err3) { + if (err3 instanceof TypeError) { return; } + $ERROR('#1: Built-in "arguments" failed with: ' + err3); + } + if (null === args || void 0 === args) { return; } + if (testfn === args) { + $ERROR('#2: Built-in revealed arguments'); + } + $ERROR('#3: Unexpected "arguments": ' + args); +})(); |