| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- //-------------------------------------------------------------------------------------------------------
- // Copyright (C) Microsoft. All rights reserved.
- // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
- //-------------------------------------------------------------------------------------------------------
- function write(v) { WScript.Echo(v + ""); }
- function PrintDescriptor(name, propDesc) {
- write(name + ":configurable : " + propDesc.configurable);
- write(name + ":enumerable : " + propDesc.enumerable);
- write(name + ":writable : " + propDesc.writable);
- write(name + ":getter : " + propDesc.get);
- write(name + ":setter : " + propDesc.set);
- write(name + ":value : " + propDesc.value);
- }
- function exceptToString(ee) {
- if (ee instanceof TypeError) return "TypeError";
- if (ee instanceof ReferenceError) return "ReferenceError";
- if (ee instanceof EvalError) return "EvalError";
- if (ee instanceof SyntaxError) return "SyntaxError";
- return "Unknown Error";
- }
- (function Test1() {
- "use strict";
- var str = "function.caller get";
-
- try {
- Test1.caller;
- } catch (e) {
- write("Exception: " + str + " " + exceptToString(e));
- return;
- }
- write("Return: " + str);
- })();
- (function Test2() {
- "use strict";
- var str = "function.caller set";
-
- try {
- Test2.caller = 10;
- } catch (e) {
- write("Exception: " + str + " " + exceptToString(e));
- return;
- }
- write("Return: " + str);
- })();
- (function Test3() {
- "use strict";
- var str = "function.arguments get";
-
- try {
- Test3.arguments;
- } catch (e) {
- write("Exception: " + str + " " + exceptToString(e));
- return;
- }
- write("Return: " + str);
- })();
- (function Test4() {
- "use strict";
- var str = "function.arguments set";
-
- try {
- Test4.arguments = 10;
- } catch (e) {
- write("Exception: " + str + " " + exceptToString(e));
- return;
- }
- write("Return: " + str);
- })();
- (function Test5() {
- "use strict";
- var str = "function.arguments and function.caller descriptors are undefined";
- // Properties on the function object.
- var callerDescriptor = Object.getOwnPropertyDescriptor(function() {}, 'caller');
- var argumentsDescriptor = Object.getOwnPropertyDescriptor(function() {}, 'arguments');
-
- write("Return: " +
- (callerDescriptor === undefined) + " " +
- (argumentsDescriptor === undefined) + ": " +
- str);
- })();
- (function Test5() {
- "use strict";
- var str = "arguments.caller is not defined and arguments.callee getter and setter are equal/strictEqual to each other";
-
- // Properties on the arguments object.
- var argumentsCallerDescriptor = Object.getOwnPropertyDescriptor(arguments, 'caller');
- var argumentsCalleeGet = Object.getOwnPropertyDescriptor(arguments, 'callee').get;
- var argumentsCalleeSet = Object.getOwnPropertyDescriptor(arguments, 'callee').set;
-
- write("Return: " +
- (argumentsCallerDescriptor === undefined).toString() + " " +
- (argumentsCalleeGet === argumentsCalleeSet).toString() + ": " +
- str);
- })();
- (function Test6() {
- var str = "function.caller's value is a strict mode function";
- function foo() {
- "use strict";
- return goo();
- }
- function goo() {
- return goo.caller; // Expected: TypeError, as the caller (foo) is a strict mode function -- ES5.15.3.5.4.
- }
- try {
- foo();
- } catch (e) {
- write("Exception: " + str + " " + exceptToString(e));
- return;
- }
- write("Return: " + str);
- })();
- /* TODO
- (function Test5() {
- "use strict";
- var str = "function.caller get";
-
- try {
- PrintDescriptor("Test5.caller", Object.getOwnPropertyDescriptor(Test5, "caller"));
- } catch (e) {
- write("Exception: " + str + " " + exceptToString(e));
- return;
- }
- write("Return: " + str);
- })();
- (function Test6() {
- "use strict";
- var str = "function.arguments get";
-
- try {
- PrintDescriptor("Test6.arguments", Object.getOwnPropertyDescriptor(Test6, "arguments"));
- } catch (e) {
- write("Exception: " + str + " " + exceptToString(e));
- return;
- }
- write("Return: " + str);
- })();
- */
|