summaryrefslogtreecommitdiffstats
path: root/js/src/tests/js1_2/function
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/js1_2/function')
-rw-r--r--js/src/tests/js1_2/function/Function_object.js54
-rw-r--r--js/src/tests/js1_2/function/Number.js52
-rw-r--r--js/src/tests/js1_2/function/String.js40
-rw-r--r--js/src/tests/js1_2/function/browser.js0
-rw-r--r--js/src/tests/js1_2/function/definition-1.js43
-rw-r--r--js/src/tests/js1_2/function/function-001-n.js44
-rw-r--r--js/src/tests/js1_2/function/length.js63
-rw-r--r--js/src/tests/js1_2/function/nesting-1.js31
-rw-r--r--js/src/tests/js1_2/function/nesting.js50
-rw-r--r--js/src/tests/js1_2/function/regexparg-1.js71
-rw-r--r--js/src/tests/js1_2/function/regexparg-2-n.js40
-rw-r--r--js/src/tests/js1_2/function/shell.js0
-rw-r--r--js/src/tests/js1_2/function/tostring-1.js112
-rw-r--r--js/src/tests/js1_2/function/tostring-2.js155
14 files changed, 755 insertions, 0 deletions
diff --git a/js/src/tests/js1_2/function/Function_object.js b/js/src/tests/js1_2/function/Function_object.js
new file mode 100644
index 000000000..a6af708e2
--- /dev/null
+++ b/js/src/tests/js1_2/function/Function_object.js
@@ -0,0 +1,54 @@
+// |reftest| skip -- obsolete test
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+/**
+ Filename: Function_object.js
+ Description: 'Testing Function objects'
+
+ Author: Nick Lerissa
+ Date: April 17, 1998
+*/
+
+var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
+var VERSION = 'no version';
+startTest();
+var TITLE = 'functions: Function_object';
+
+writeHeaderToLog('Executing script: Function_object.js');
+writeHeaderToLog( SECTION + " "+ TITLE);
+
+
+function a_test_function(a,b,c)
+{
+ return a + b + c;
+}
+
+f = a_test_function;
+
+
+new TestCase( SECTION, "f.name",
+ 'a_test_function', f.name);
+
+new TestCase( SECTION, "f.length",
+ 3, f.length);
+
+new TestCase( SECTION, "f.arity",
+ 3, f.arity);
+
+new TestCase( SECTION, "f(2,3,4)",
+ 9, f(2,3,4));
+
+var fnName = (version() == 120) ? '' : 'anonymous';
+
+new TestCase( SECTION, "(new Function()).name",
+ fnName, (new Function()).name);
+
+new TestCase( SECTION, "(new Function()).toString()",
+ 'function ' + fnName + '() {\n}', (new Function()).toString());
+
+test();
+
diff --git a/js/src/tests/js1_2/function/Number.js b/js/src/tests/js1_2/function/Number.js
new file mode 100644
index 000000000..fa5288acf
--- /dev/null
+++ b/js/src/tests/js1_2/function/Number.js
@@ -0,0 +1,52 @@
+// |reftest| skip -- obsolete test
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+/**
+ Filename: Number.js
+ Description: 'This tests the function Number(Object)'
+
+ Author: Nick Lerissa
+ Date: Fri Feb 13 09:58:28 PST 1998
+*/
+
+var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
+var VERSION = 'no version';
+var TITLE = 'functions: Number';
+var BUGNUMBER="123435";
+
+startTest();
+writeHeaderToLog('Executing script: Number.js');
+writeHeaderToLog( SECTION + " "+ TITLE);
+
+date = new Date(2200);
+
+new TestCase( SECTION, "Number(new Date(2200)) ",
+ 2200, (Number(date)));
+new TestCase( SECTION, "Number(true) ",
+ 1, (Number(true)));
+new TestCase( SECTION, "Number(false) ",
+ 0, (Number(false)));
+new TestCase( SECTION, "Number('124') ",
+ 124, (Number('124')));
+new TestCase( SECTION, "Number('1.23') ",
+ 1.23, (Number('1.23')));
+new TestCase( SECTION, "Number({p:1}) ",
+ NaN, (Number({p:1})));
+new TestCase( SECTION, "Number(null) ",
+ 0, (Number(null)));
+new TestCase( SECTION, "Number(-45) ",
+ -45, (Number(-45)));
+
+// http://scopus.mcom.com/bugsplat/show_bug.cgi?id=123435
+// under js1.2, Number([1,2,3]) should return 3.
+
+new TestCase( SECTION, "Number([1,2,3]) ",
+ 3, (Number([1,2,3])));
+
+
+test();
+
diff --git a/js/src/tests/js1_2/function/String.js b/js/src/tests/js1_2/function/String.js
new file mode 100644
index 000000000..6f182d8f0
--- /dev/null
+++ b/js/src/tests/js1_2/function/String.js
@@ -0,0 +1,40 @@
+// |reftest| skip -- obsolete test
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+/**
+ Filename: String.js
+ Description: 'This tests the function String(Object)'
+
+ Author: Nick Lerissa
+ Date: Fri Feb 13 09:58:28 PST 1998
+*/
+
+var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
+var VERSION = 'no version';
+startTest();
+var TITLE = 'functions: String';
+
+writeHeaderToLog('Executing script: String.js');
+writeHeaderToLog( SECTION + " "+ TITLE);
+
+new TestCase( SECTION, "String(true) ",
+ 'true', (String(true)));
+new TestCase( SECTION, "String(false) ",
+ 'false', (String(false)));
+new TestCase( SECTION, "String(-124) ",
+ '-124', (String(-124)));
+new TestCase( SECTION, "String(1.23) ",
+ '1.23', (String(1.23)));
+new TestCase( SECTION, "String({p:1}) ",
+ '{p:1}', (String({p:1})));
+new TestCase( SECTION, "String(null) ",
+ 'null', (String(null)));
+new TestCase( SECTION, "String([1,2,3]) ",
+ '[1, 2, 3]', (String([1,2,3])));
+
+test();
+
diff --git a/js/src/tests/js1_2/function/browser.js b/js/src/tests/js1_2/function/browser.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/js1_2/function/browser.js
diff --git a/js/src/tests/js1_2/function/definition-1.js b/js/src/tests/js1_2/function/definition-1.js
new file mode 100644
index 000000000..bffd7590a
--- /dev/null
+++ b/js/src/tests/js1_2/function/definition-1.js
@@ -0,0 +1,43 @@
+/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+/**
+ File Name: definition-1.js
+ Reference: http://scopus.mcom.com/bugsplat/show_bug.cgi?id=111284
+ Description: Regression test for declaring functions.
+
+ Author: christine@netscape.com
+ Date: 15 June 1998
+*/
+
+var SECTION = "function/definition-1.js";
+var VERSION = "JS_12";
+startTest();
+var TITLE = "Regression test for 111284";
+
+writeHeaderToLog( SECTION + " "+ TITLE);
+
+f1 = function() { return "passed!" }
+
+ function f2() { f3 = function() { return "passed!" }; return f3(); }
+
+new TestCase( SECTION,
+ 'f1 = function() { return "passed!" }; f1()',
+ "passed!",
+ f1() );
+
+new TestCase( SECTION,
+ 'function f2() { f3 = function { return "passed!" }; return f3() }; f2()',
+ "passed!",
+ f2() );
+
+new TestCase( SECTION,
+ 'f3()',
+ "passed!",
+ f3() );
+
+test();
+
diff --git a/js/src/tests/js1_2/function/function-001-n.js b/js/src/tests/js1_2/function/function-001-n.js
new file mode 100644
index 000000000..fe547aa60
--- /dev/null
+++ b/js/src/tests/js1_2/function/function-001-n.js
@@ -0,0 +1,44 @@
+// |reftest| skip -- obsolete test
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+/**
+ * File Name: boolean-001.js
+ * Description:
+ *
+ * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=99232
+ *
+ * eval("function f(){}function g(){}") at top level is an error for JS1.2
+ * and above (missing ; between named function expressions), but declares f
+ * and g as functions below 1.2.
+ *
+ * Fails to produce error regardless of version:
+ * js> version(100)
+ * 120
+ * js> eval("function f(){}function g(){}")
+ * js> version(120);
+ * 100
+ * js> eval("function f(){}function g(){}")
+ * js>
+ * Author: christine@netscape.com
+ * Date: 11 August 1998
+ */
+var SECTION = "function-001.js";
+var VERSION = "JS1_1";
+var TITLE = "functions not separated by semicolons are errors in version 120 and higher";
+var BUGNUMBER="99232";
+
+startTest();
+writeHeaderToLog( SECTION + " "+ TITLE);
+
+new TestCase(
+ SECTION,
+ "eval(\"function f(){}function g(){}\")",
+ "error",
+ eval("function f(){}function g(){}") );
+
+test();
+
diff --git a/js/src/tests/js1_2/function/length.js b/js/src/tests/js1_2/function/length.js
new file mode 100644
index 000000000..f679aa14e
--- /dev/null
+++ b/js/src/tests/js1_2/function/length.js
@@ -0,0 +1,63 @@
+// |reftest| skip -- obsolete test
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+/**
+ File Name: 15.3.5.1.js
+ ECMA Section: Function.length
+ Description:
+
+ The value of the length property is usually an integer that indicates the
+ "typical" number of arguments expected by the function. However, the
+ language permits the function to be invoked with some other number of
+ arguments. The behavior of a function when invoked on a number of arguments
+ other than the number specified by its length property depends on the function.
+
+ This checks the pre-ecma behavior Function.length.
+
+ http://scopus.mcom.com/bugsplat/show_bug.cgi?id=104204
+
+
+ Author: christine@netscape.com
+ Date: 12 november 1997
+*/
+
+var SECTION = "function/length.js";
+var VERSION = "ECMA_1";
+var TITLE = "Function.length";
+var BUGNUMBER="104204";
+
+startTest();
+writeHeaderToLog( SECTION + " "+ TITLE);
+
+var f = new Function( "a","b", "c", "return f.length");
+
+if ( version() <= 120 ) {
+
+ new TestCase( SECTION,
+ 'var f = new Function( "a","b", "c", "return f.length"); f()',
+ 0,
+ f() );
+
+ new TestCase( SECTION,
+ 'var f = new Function( "a","b", "c", "return f.length"); f(1,2,3,4,5)',
+ 5,
+ f(1,2,3,4,5) );
+} else {
+
+ new TestCase( SECTION,
+ 'var f = new Function( "a","b", "c", "return f.length"); f()',
+ 3,
+ f() );
+
+ new TestCase( SECTION,
+ 'var f = new Function( "a","b", "c", "return f.length"); f(1,2,3,4,5)',
+ 3,
+ f(1,2,3,4,5) );
+
+
+}
+test();
diff --git a/js/src/tests/js1_2/function/nesting-1.js b/js/src/tests/js1_2/function/nesting-1.js
new file mode 100644
index 000000000..334f1521a
--- /dev/null
+++ b/js/src/tests/js1_2/function/nesting-1.js
@@ -0,0 +1,31 @@
+/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+/**
+ File Name: nesting-1.js
+ Reference: http://scopus.mcom.com/bugsplat/show_bug.cgi?id=122040
+ Description: Regression test for a nested function
+
+ Author: christine@netscape.com
+ Date: 15 June 1998
+*/
+
+var SECTION = "function/nesting-1.js";
+var VERSION = "JS_12";
+startTest();
+var TITLE = "Regression test for 122040";
+
+writeHeaderToLog( SECTION + " "+ TITLE);
+
+function f(a) {function g(b) {return a+b;}; return g;}; f(7);
+
+new TestCase( SECTION,
+ 'function f(a) {function g(b) {return a+b;}; return g;}; typeof f(7)',
+ "function",
+ typeof f(7) );
+
+test();
+
diff --git a/js/src/tests/js1_2/function/nesting.js b/js/src/tests/js1_2/function/nesting.js
new file mode 100644
index 000000000..1e1f18dc6
--- /dev/null
+++ b/js/src/tests/js1_2/function/nesting.js
@@ -0,0 +1,50 @@
+/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+/**
+ Filename: nesting.js
+ Description: 'This tests the nesting of functions'
+
+ Author: Nick Lerissa
+ Date: Fri Feb 13 09:58:28 PST 1998
+*/
+
+var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
+var VERSION = 'no version';
+startTest();
+var TITLE = 'functions: nesting';
+
+writeHeaderToLog('Executing script: nesting.js');
+writeHeaderToLog( SECTION + " "+ TITLE);
+
+function outer_func(x)
+{
+ var y = "outer";
+
+ new TestCase( SECTION, "outer:x ",
+ 1111, x);
+ new TestCase( SECTION, "outer:y ",
+ 'outer', y);
+ function inner_func(x)
+ {
+ var y = "inner";
+ new TestCase( SECTION, "inner:x ",
+ 2222, x);
+ new TestCase( SECTION, "inner:y ",
+ 'inner', y);
+ };
+
+ inner_func(2222);
+ new TestCase( SECTION, "outer:x ",
+ 1111, x);
+ new TestCase( SECTION, "outer:y ",
+ 'outer', y);
+}
+
+outer_func(1111);
+
+test();
+
diff --git a/js/src/tests/js1_2/function/regexparg-1.js b/js/src/tests/js1_2/function/regexparg-1.js
new file mode 100644
index 000000000..16c25bf9d
--- /dev/null
+++ b/js/src/tests/js1_2/function/regexparg-1.js
@@ -0,0 +1,71 @@
+/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+/**
+ File Name: regexparg-1.js
+ Description:
+
+ Regression test for
+ http://scopus/bugsplat/show_bug.cgi?id=122787
+ Passing a regular expression as the first constructor argument fails
+
+ Author: christine@netscape.com
+ Date: 15 June 1998
+*/
+
+var SECTION = "JS_1.2";
+var VERSION = "JS_1.2";
+startTest();
+var TITLE = "The variable statement";
+
+writeHeaderToLog( SECTION + " "+ TITLE);
+
+print("Note: Bug 61911 changed the behavior of typeof regexp in Gecko 1.9.");
+print("Prior to Gecko 1.9, typeof regexp returned 'function'.");
+print("However in Gecko 1.9 and later, typeof regexp will return 'object'.");
+
+function f(x) {return x;}
+
+x = f(/abc/);
+
+new TestCase( SECTION,
+ "function f(x) {return x;}; f()",
+ void 0,
+ f() );
+
+new TestCase( SECTION,
+ "f(\"hi\")",
+ "hi",
+ f("hi") );
+
+new TestCase( SECTION,
+ "new f(/abc/) +''",
+ "/abc/",
+ new f(/abc/) +"" );
+
+new TestCase( SECTION,
+ "f(/abc/)+'')",
+ "/abc/",
+ f(/abc/) +'');
+
+new TestCase( SECTION,
+ "typeof f(/abc/)",
+ "object",
+ typeof f(/abc/) );
+
+new TestCase( SECTION,
+ "typeof new f(/abc/)",
+ "object",
+ typeof new f(/abc/) );
+
+new TestCase( SECTION,
+ "x = new f(/abc/); x.exec(\"hi\")",
+ null,
+ x.exec("hi") );
+
+
+// js> x()
+test();
diff --git a/js/src/tests/js1_2/function/regexparg-2-n.js b/js/src/tests/js1_2/function/regexparg-2-n.js
new file mode 100644
index 000000000..f0f862dbc
--- /dev/null
+++ b/js/src/tests/js1_2/function/regexparg-2-n.js
@@ -0,0 +1,40 @@
+// |reftest| skip -- obsolete test
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+/**
+ File Name: regexparg-1.js
+ Description:
+
+ Regression test for
+ http://scopus/bugsplat/show_bug.cgi?id=122787
+ Passing a regular expression as the first constructor argument fails
+
+ Author: christine@netscape.com
+ Date: 15 June 1998
+*/
+
+var SECTION = "JS_1.2";
+var VERSION = "JS_1.2";
+startTest();
+var TITLE = "The variable statement";
+
+writeHeaderToLog( SECTION + " "+ TITLE);
+
+function f(x) {return x;}
+
+x = f(/abc/);
+
+DESCRIPTION = "function f(x) {return x;}; x = f(/abc/); x()";
+EXPECTED = "error";
+
+new TestCase( SECTION,
+ "function f(x) {return x;}; x = f(/abc/); x()",
+ "error",
+ x() );
+
+test();
+
diff --git a/js/src/tests/js1_2/function/shell.js b/js/src/tests/js1_2/function/shell.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/js1_2/function/shell.js
diff --git a/js/src/tests/js1_2/function/tostring-1.js b/js/src/tests/js1_2/function/tostring-1.js
new file mode 100644
index 000000000..2f883410e
--- /dev/null
+++ b/js/src/tests/js1_2/function/tostring-1.js
@@ -0,0 +1,112 @@
+// |reftest| skip -- obsolete test
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+/**
+ File Name: tostring-1.js
+ Section: Function.toString
+ Description:
+
+ Since the behavior of Function.toString() is implementation-dependent,
+ toString tests for function are not in the ECMA suite.
+
+ Currently, an attempt to parse the toString output for some functions
+ and verify that the result is something reasonable.
+
+ Author: christine@netscape.com
+ Date: 12 november 1997
+*/
+
+var SECTION = "tostring-1";
+var VERSION = "JS1_2";
+startTest();
+var TITLE = "Function.toString()";
+
+writeHeaderToLog( SECTION + " "+ TITLE);
+
+var tab = " ";
+
+t1 = new TestFunction( "stub", "value", tab + "return value;" );
+
+t2 = new TestFunction( "ToString", "object", tab+"return object + \"\";" );
+
+t3 = new TestFunction( "Add", "a, b, c, d, e", tab +"var s = a + b + c + d + e;\n" +
+ tab + "return s;" );
+
+t4 = new TestFunction( "noop", "value" );
+
+t5 = new TestFunction( "anonymous", "", tab+"return \"hello!\";" );
+
+var f = new Function( "return \"hello!\"");
+
+new TestCase( SECTION,
+ "stub.toString()",
+ t1.valueOf(),
+ stub.toString() );
+
+new TestCase( SECTION,
+ "ToString.toString()",
+ t2.valueOf(),
+ ToString.toString() );
+
+new TestCase( SECTION,
+ "Add.toString()",
+ t3.valueOf(),
+ Add.toString() );
+
+new TestCase( SECTION,
+ "noop.toString()",
+ t4.toString(),
+ noop.toString() );
+
+new TestCase( SECTION,
+ "f.toString()",
+ t5.toString(),
+ f.toString() );
+test();
+
+function noop( value ) {
+}
+function Add( a, b, c, d, e ) {
+ var s = a + b + c + d + e;
+ return s;
+}
+function stub( value ) {
+ return value;
+}
+function ToString( object ) {
+ return object + "";
+}
+
+function ToBoolean( value ) {
+ if ( value == 0 || value == NaN || value == false ) {
+ return false;
+ } else {
+ return true;
+ }
+}
+
+function TestFunction( name, args, body ) {
+ if ( name == "anonymous" && version() == 120 ) {
+ name = "";
+ }
+
+ this.name = name;
+ this.arguments = args.toString();
+ this.body = body;
+
+ /* the format of Function.toString() in JavaScript 1.2 is:
+ function name ( arguments ) {
+ body
+ }
+ */
+ this.value = "function " + (name ? name : "" )+
+ "("+args+") {\n"+ (( body ) ? body +"\n" : "") + "}";
+
+ this.toString = new Function( "return this.value" );
+ this.valueOf = new Function( "return this.value" );
+ return this;
+}
diff --git a/js/src/tests/js1_2/function/tostring-2.js b/js/src/tests/js1_2/function/tostring-2.js
new file mode 100644
index 000000000..feb22d709
--- /dev/null
+++ b/js/src/tests/js1_2/function/tostring-2.js
@@ -0,0 +1,155 @@
+// |reftest| skip -- obsolete test
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+/**
+ File Name: tostring-1.js
+ Section: Function.toString
+ Description:
+
+ Since the behavior of Function.toString() is implementation-dependent,
+ toString tests for function are not in the ECMA suite.
+
+ Currently, an attempt to parse the toString output for some functions
+ and verify that the result is something reasonable.
+
+ This verifies
+ http://scopus.mcom.com/bugsplat/show_bug.cgi?id=99212
+
+ Author: christine@netscape.com
+ Date: 12 november 1997
+*/
+
+var SECTION = "tostring-2";
+var VERSION = "JS1_2";
+var TITLE = "Function.toString()";
+var BUGNUMBER="123444";
+startTest();
+
+writeHeaderToLog( SECTION + " "+ TITLE);
+
+var tab = " ";
+
+
+var equals = new TestFunction( "Equals", "a, b", tab+ "return a == b;" );
+function Equals (a, b) {
+ return a == b;
+}
+
+var reallyequals = new TestFunction( "ReallyEquals", "a, b",
+ ( version() <= 120 ) ? tab +"return a == b;" : tab +"return a === b;" );
+function ReallyEquals( a, b ) {
+ return a === b;
+}
+
+var doesntequal = new TestFunction( "DoesntEqual", "a, b", tab + "return a != b;" );
+function DoesntEqual( a, b ) {
+ return a != b;
+}
+
+var reallydoesntequal = new TestFunction( "ReallyDoesntEqual", "a, b",
+ ( version() <= 120 ) ? tab +"return a != b;" : tab +"return a !== b;" );
+function ReallyDoesntEqual( a, b ) {
+ return a !== b;
+}
+
+var testor = new TestFunction( "TestOr", "a", tab+"if (a == null || a == void 0) {\n"+
+ tab +tab+"return 0;\n"+tab+"} else {\n"+tab+tab+"return a;\n"+tab+"}" );
+function TestOr( a ) {
+ if ( a == null || a == void 0 )
+ return 0;
+ else
+ return a;
+}
+
+var testand = new TestFunction( "TestAnd", "a", tab+"if (a != null && a != void 0) {\n"+
+ tab+tab+"return a;\n" + tab+ "} else {\n"+tab+tab+"return 0;\n"+tab+"}" );
+function TestAnd( a ) {
+ if ( a != null && a != void 0 )
+ return a;
+ else
+ return 0;
+}
+
+var or = new TestFunction( "Or", "a, b", tab + "return a | b;" );
+function Or( a, b ) {
+ return a | b;
+}
+
+var and = new TestFunction( "And", "a, b", tab + "return a & b;" );
+function And( a, b ) {
+ return a & b;
+}
+
+var xor = new TestFunction( "XOr", "a, b", tab + "return a ^ b;" );
+function XOr( a, b ) {
+ return a ^ b;
+}
+
+new TestCase( SECTION,
+ "Equals.toString()",
+ equals.valueOf(),
+ Equals.toString() );
+
+new TestCase( SECTION,
+ "ReallyEquals.toString()",
+ reallyequals.valueOf(),
+ ReallyEquals.toString() );
+
+new TestCase( SECTION,
+ "DoesntEqual.toString()",
+ doesntequal.valueOf(),
+ DoesntEqual.toString() );
+
+new TestCase( SECTION,
+ "ReallyDoesntEqual.toString()",
+ reallydoesntequal.valueOf(),
+ ReallyDoesntEqual.toString() );
+
+new TestCase( SECTION,
+ "TestOr.toString()",
+ testor.valueOf(),
+ TestOr.toString() );
+
+new TestCase( SECTION,
+ "TestAnd.toString()",
+ testand.valueOf(),
+ TestAnd.toString() );
+
+new TestCase( SECTION,
+ "Or.toString()",
+ or.valueOf(),
+ Or.toString() );
+
+new TestCase( SECTION,
+ "And.toString()",
+ and.valueOf(),
+ And.toString() );
+
+new TestCase( SECTION,
+ "XOr.toString()",
+ xor.valueOf(),
+ XOr.toString() );
+
+test();
+
+function TestFunction( name, args, body ) {
+ this.name = name;
+ this.arguments = args.toString();
+ this.body = body;
+
+ /* the format of Function.toString() in JavaScript 1.2 is:
+ function name ( arguments ) {
+ body
+ }
+ */
+ this.value = "function " + (name ? name : "anonymous" )+
+ "("+args+") {\n"+ (( body ) ? body +"\n" : "") + "}";
+
+ this.toString = new Function( "return this.value" );
+ this.valueOf = new Function( "return this.value" );
+ return this;
+}